Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jinkhya.pinkmod.pinkblocks.pinkgrinder;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.ItemStack;
- import net.minecraftforge.items.CapabilityItemHandler;
- import net.minecraftforge.items.IItemHandler;
- import net.minecraftforge.items.SlotItemHandler;
- public class ContainerPinkGrinder extends Container {
- private TilePinkGrinder te;
- public ContainerPinkGrinder(IInventory playerInventory, TilePinkGrinder te) {
- this.te = te;
- addOwnSlots();
- addPlayerSlots(playerInventory);
- }
- private void addPlayerSlots(IInventory playerInventory) {
- // Slots for the main inventory
- for (int row = 0; row < 3; ++row) {
- for (int col = 0; col < 9; ++col) {
- int x = 10 + col * 18;
- int y = row * 18 + 70;
- this.addSlotToContainer(new Slot(playerInventory, col + row * 9 + 9, x, y));
- }
- }
- // Slots for the hotbar
- for (int row = 0; row < 9; ++row) {
- int x = 10 + row * 18;
- int y = 58 + 70;
- this.addSlotToContainer(new Slot(playerInventory, row, x, y));
- }
- }
- private void addOwnSlots() {
- IItemHandler itemHandler = this.te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
- int x = 10;
- int y = 26;
- int slotIndex = 0;
- addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
- x += 18;
- addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
- x += 18;
- addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
- x = 118;
- addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
- x += 18;
- addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
- x += 18;
- addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex++, x, y));
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
- ItemStack itemstack = ItemStack.EMPTY;
- Slot slot = this.inventorySlots.get(index);
- if (slot != null && slot.getHasStack()) {
- ItemStack itemstack1 = slot.getStack();
- itemstack = itemstack1.copy();
- if (index < TilePinkGrinder.SIZE) {
- if (!this.mergeItemStack(itemstack1, TilePinkGrinder.SIZE, this.inventorySlots.size(), true)) {
- return ItemStack.EMPTY;
- }
- } else if (!this.mergeItemStack(itemstack1, 0, TilePinkGrinder.SIZE, false)) {
- return ItemStack.EMPTY;
- }
- if (itemstack1.isEmpty()) {
- slot.putStack(ItemStack.EMPTY);
- } else {
- slot.onSlotChanged();
- }
- }
- return itemstack;
- }
- @Override
- public boolean canInteractWith(EntityPlayer playerIn) {
- return te.canInteractWith(playerIn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement