Posted September 30, 201411 yr Hello ! Today, I have a pretty simple question. I am making a custom crafting table, and want the output slot to be able to be taken out of, but not put in. This is my code for the container: package com.harry9137.ct.client.gui; import com.harry9137.ct.tileentity.TileEntityTechTable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class ContainerTechTable extends Container { protected TileEntityTechTable tileEntity; protected IInventory playerinventory; public ContainerTechTable(InventoryPlayer inventoryPlayer, TileEntityTechTable te) { tileEntity = te; playerinventory = inventoryPlayer; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { addSlotToContainer(new Slot(this.tileEntity, j + i * 3, 62 + j * 18, 17 + i * 18)); } } addSlotToContainer(new Slot(this.tileEntity, 10, getSlotFromInventory(this.tileEntity, .xDisplayPosition + 15, getSlotFromInventory(this.tileEntity, .yDisplayPosition)); bindPlayerInventory(inventoryPlayer); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); } } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); if (slot < 9) { if (!this.mergeItemStack(stackInSlot, 0, 35, true)) { 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; } @Override public boolean canInteractWith(EntityPlayer player) { return true; } (Yes I took code from the minecraft forge tutorial, but I have no reason to change it ) Thanks!
September 30, 201411 yr public class RestrictedSlot extends Slot { public RestrictedSlot(IInventory inventory1, int id, int x, int y) { super(inventory1, id, x, y); } @Override public boolean isItemValid(ItemStack par1ItemStack) { return false; } }
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.