NaturesAura/src/main/java/de/ellpeck/naturesaura/gui/ContainerEnderCrate.java

55 lines
1.9 KiB
Java
Raw Normal View History

2019-02-17 22:51:05 +01:00
package de.ellpeck.naturesaura.gui;
2019-10-20 22:30:49 +02:00
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container;
2020-01-21 23:02:39 +01:00
import net.minecraft.inventory.container.ContainerType;
2019-10-20 22:30:49 +02:00
import net.minecraft.inventory.container.Slot;
2019-02-17 22:51:05 +01:00
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
public class ContainerEnderCrate extends Container {
2020-01-21 23:02:39 +01:00
public ContainerEnderCrate(ContainerType<?> type, int id, PlayerEntity player, IItemHandler handler) {
super(type, id);
2019-02-17 22:51:05 +01:00
int i = (3 - 4) * 18;
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 9; ++k)
2020-01-21 23:02:39 +01:00
this.addSlot(new SlotItemHandler(handler, k + j * 9, 8 + k * 18, 18 + j * 18));
2019-02-17 22:51:05 +01:00
for (int l = 0; l < 3; ++l)
for (int j1 = 0; j1 < 9; ++j1)
2020-01-21 23:02:39 +01:00
this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + i));
2019-02-17 22:51:05 +01:00
for (int i1 = 0; i1 < 9; ++i1)
2020-01-21 23:02:39 +01:00
this.addSlot(new Slot(player.inventory, i1, 8 + i1 * 18, 161 + i));
2019-02-17 22:51:05 +01:00
}
@Override
2019-10-20 22:30:49 +02:00
public boolean canInteractWith(PlayerEntity playerIn) {
2019-02-18 12:15:18 +01:00
return true;
2019-02-17 22:51:05 +01:00
}
@Override
2019-10-20 22:30:49 +02:00
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
2019-02-17 22:51:05 +01:00
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index < 3 * 9) {
if (!this.mergeItemStack(itemstack1, 3 * 9, this.inventorySlots.size(), true))
return ItemStack.EMPTY;
} else if (!this.mergeItemStack(itemstack1, 0, 3 * 9, false))
return ItemStack.EMPTY;
if (itemstack1.isEmpty())
slot.putStack(ItemStack.EMPTY);
else
slot.onSlotChanged();
}
return itemstack;
}
}