deerangle Posted December 8, 2015 Posted December 8, 2015 I am trying to lock a slot in my inventory to a specific item, so i can oly inert THAT item in THAT slot and no other. i tried it with "isItemValidForSlot" but i couldnt get it to work that way. Quote
deerangle Posted December 8, 2015 Author Posted December 8, 2015 thats how i tried it: @Override public boolean isItemValidForSlot(int slot, ItemStack item) { if(slot == 0 && item.getItem() == ModItems.toolOsniumKnife) return true; return false; } Quote
deerangle Posted December 8, 2015 Author Posted December 8, 2015 package com.wizcraft.gui; import com.wizcraft.tile.entity.TileEntityTableWittle; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerTableWittle extends Container { protected TileEntityTableWittle tile; public ContainerTableWittle(InventoryPlayer invPlayer, TileEntityTableWittle tile){ this.tile = tile; this.addSlotToContainer(new Slot(tile, 0, 52, 7)); this.addSlotToContainer(new Slot(tile, 1, 52, 34)); this.addSlotToContainer(new Slot(tile, 2, 52, 61)); this.addSlotToContainer(new Slot(tile, 3, 25, 34)); this.addSlotToContainer(new Slot(tile, 4, 79, 34)); this.addSlotToContainer(new Slot(tile, 5, 131, 34)); bindPlayerInventory(invPlayer); } @Override public boolean canInteractWith(EntityPlayer player) { return tile.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer invPlayer) { for(int i = 0; i<3;i++){ for(int j = 0; j<9;j++){ this.addSlotToContainer(new Slot(invPlayer, 9+j+i*9, 8 + j*18, 84+i*18)); } } for(int i = 0; i<9;i++){ this.addSlotToContainer(new Slot(invPlayer, i, 8 + i*18, 142)); } } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); //null checks and checks if the item can be stacked (maxStackSize > 1) if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); //merges the item into player inventory since its in the tile if (slot < tile.getSizeInventory()) { if (!this.mergeItemStack(stackInSlot, tile.getSizeInventory(), 36+tile.getSizeInventory(), true)) { return null; } } //places it into the tile is possible since its in the player inventory else if (!this.mergeItemStack(stackInSlot, 0, tile.getSizeInventory(), false)) { return null; } if (stackInSlot.stackSize == 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } if (stackInSlot.stackSize == stack.stackSize) { return null; } slotObject.onPickupFromSlot(player, stackInSlot); } return stack; } } Quote
deerangle Posted December 8, 2015 Author Posted December 8, 2015 I created a custom slot class and set the "isitemValid" to similar to what was in the method from the tileentity and now it works. PS: i never made a more complex gui than a chest before. THANK YOU Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.