Posted August 28, 201312 yr here`s my tileentity package mods.MCGadgetry.tileentitys; import mods.MCGadgetry.common.MCGadgetry; import mods.MCGadgetry.item.EnumPatternTypes; import mods.MCGadgetry.item.ItemMold; import mods.MCGadgetry.item.ItemPattern; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class TileEntityMoldMaker extends TileEntity implements IInventory { private ItemStack[] itemsIn; public TileEntityMoldMaker() { itemsIn=new ItemStack[3]; } @Override public int getSizeInventory() { return itemsIn.length; } @Override public ItemStack getStackInSlot(int i) { return itemsIn[i]; } @Override public ItemStack decrStackSize(int i, int count) { ItemStack itemstack=getStackInSlot(i); if(itemstack !=null) { if(itemstack.stackSize<=count) { setInventorySlotContents(i,null); } else { itemstack=itemstack.splitStack(count); onInventoryChanged(); } } return itemstack; } @Override public ItemStack getStackInSlotOnClosing(int i) { // TODO Auto-generated method stub return null; } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { itemsIn[i]=itemstack; if(itemstack !=null && itemstack.stackSize>getInventoryStackLimit()) { itemstack.stackSize=getInventoryStackLimit(); } onInventoryChanged(); } @Override public String getInvName() { // TODO Auto-generated method stub return "MoldMaker"; } @Override public boolean isInvNameLocalized() { return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer entityplayer) { return entityplayer.getDistanceSq(xCoord+0.5, yCoord+0.5, zCoord+0.5)<=64; } @Override public void openChest() { } @Override public void closeChest() { } @Override public boolean isItemValidForSlot(int i, ItemStack itemstack) { if(i==0) { return itemstack.itemID==MCGadgetry.itemPattern.itemID; } if(i==1) { return itemstack.itemID==MCGadgetry.itemMold.itemID; } if(i==2) { return itemstack.itemID==MCGadgetry.itemMold.itemID; } else { return false; } } @Override public void writeToNBT(NBTTagCompound nbtTagCompound) { super.writeToNBT(nbtTagCompound); NBTTagList items=new NBTTagList(); for(int i=0; i<getSizeInventory();i++) { ItemStack stack= getStackInSlot(i); if(stack !=null) { NBTTagCompound item=new NBTTagCompound(); item.setByte("Slot",(byte)i); stack.writeToNBT(item); items.appendTag(item); } } nbtTagCompound.setTag("Items", items); } @Override public void readFromNBT(NBTTagCompound nbtTagCompound) { super.readFromNBT(nbtTagCompound); NBTTagList items= nbtTagCompound.getTagList("Items"); for(int i=0;i<items.tagCount();i++) { NBTTagCompound item=(NBTTagCompound) items.tagAt(i); int slot=item.getByte("Slot"); if(slot >=0 && slot<=getSizeInventory()) { setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(item)); } } } public void makeMold() { ItemStack stack0=getStackInSlot(0); ItemStack stack1=getStackInSlot(1); ItemStack stack2=new ItemStack(MCGadgetry.itemMold); if(stack0.getItem() instanceof ItemPattern) { if(stack1.getItem() instanceof ItemMold) { if(stack0.getItemDamage()!=0) { if(stack1.getItemDamage()==0) { stack2.setItemDamage(stack0.getItemDamage()); setInventorySlotContents(2, stack2); setInventorySlotContents(0, null); setInventorySlotContents(1, null); } } } } } } and here is my gui for the tileentity package mods.MCGadgetry.interfaces; import mods.MCGadgetry.containers.ContainerMoldMaker; import mods.MCGadgetry.tileentitys.TileEntityMoldMaker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GuiMoldMaker extends GuiContainer { TileEntityMoldMaker tileEntityMoldMaker; private GuiButton buttonInit; public GuiMoldMaker(InventoryPlayer invPlayer, TileEntityMoldMaker tileEntityMoldMaker) { super(new ContainerMoldMaker(invPlayer,tileEntityMoldMaker)); xSize=176; ySize=166; this.tileEntityMoldMaker=tileEntityMoldMaker; } public void initGui() { buttonList.clear(); buttonList.add(this.buttonInit = new GuiButton(1,guiLeft+xSize-4,guiTop+ySize-25,50,20, "Make Mold")); super.initGui(); } protected void actionPerformed(GuiButton guibutton) { if(guibutton.id == 1) { tileEntityMoldMaker.makeMold(); } } private static final ResourceLocation texture= new ResourceLocation("mcgadgetry","textures/gui/moldMaker.png"); @Override protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { GL11.glColor4f(1,1,1,1); Minecraft.getMinecraft().func_110434_K().func_110577_a(texture); drawTexturedModalRect(guiLeft,guiTop,0,0,xSize,ySize); } } as you can see the button in the gui calls the fuction makeMold(); the function does its thing perfectly, however when I try to pick up the newly generated mold from slot 2, it deletes and the slots 0 and 1 are returned to their previous status, with a pattern and a mold. How can I make this so that I can actually pick up the new mold?
September 3, 201312 yr Author Did this: Gui package mods.MCGadgetry.interfaces; import mods.MCGadgetry.containers.ContainerMoldMaker; import mods.MCGadgetry.tileentitys.TileEntityMoldMaker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GuiMoldMaker extends GuiContainer { TileEntityMoldMaker tileEntityMoldMaker; private GuiButton buttonInit; public GuiMoldMaker(InventoryPlayer invPlayer, TileEntityMoldMaker tileEntityMoldMaker) { super(new ContainerMoldMaker(invPlayer,tileEntityMoldMaker)); xSize=176; ySize=166; this.tileEntityMoldMaker=tileEntityMoldMaker; } public void initGui() { buttonList.clear(); buttonList.add(this.buttonInit = new GuiButton(1,guiLeft+xSize-4,guiTop+ySize-100,50,20, "Make Mold")); super.initGui(); } protected void actionPerformed(GuiButton guibutton) { if(guibutton.id == 1) { Minecraft.getMinecraft().playerController.sendEnchantPacket(1, 1); } } private static final ResourceLocation texture= new ResourceLocation("mcgadgetry","textures/gui/moldMaker.png"); @Override protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { GL11.glColor4f(1,1,1,1); Minecraft.getMinecraft().func_110434_K().func_110577_a(texture); drawTexturedModalRect(guiLeft,guiTop,0,0,xSize,ySize); } } Container package mods.MCGadgetry.containers; import mods.MCGadgetry.common.MCGadgetry; import mods.MCGadgetry.item.ItemMold; import mods.MCGadgetry.item.ItemPattern; import mods.MCGadgetry.slots.SlotMold; import mods.MCGadgetry.slots.SlotPattern; import mods.MCGadgetry.tileentitys.TileEntityMoldMaker; 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 ContainerMoldMaker extends Container { TileEntityMoldMaker tileEntityMoldMaker; public ContainerMoldMaker(InventoryPlayer inventoryPlayer,TileEntityMoldMaker tileEntityMoldMaker) { this.tileEntityMoldMaker=tileEntityMoldMaker; for(int x=0; x<9;x++) { addSlotToContainer(new Slot(inventoryPlayer,x,8+18*x,142)); } for(int y=0;y <3; y++) { for(int x=0;x<9;x++) { addSlotToContainer(new Slot(inventoryPlayer,x+y*9+9,8+18*x,84+y*18)); } } addSlotToContainer(new SlotPattern(tileEntityMoldMaker,0,44,31)); addSlotToContainer(new SlotMold(tileEntityMoldMaker,1,80,31)); addSlotToContainer(new SlotMold(tileEntityMoldMaker,2,116,31)); } @Override public boolean canInteractWith(EntityPlayer entityplayer) { return this.tileEntityMoldMaker.isUseableByPlayer(entityplayer); } @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int i) { return null; } @Override public boolean enchantItem(EntityPlayer player, int i) { ItemStack stack0=getSlot(0).getStack(); ItemStack stack1=getSlot(1).getStack(); ItemStack stack2=new ItemStack(MCGadgetry.itemMold); if(stack0.getItem() instanceof ItemPattern) { if(stack1.getItem() instanceof ItemMold) { if(stack0.getItemDamage()!=0) { if(stack1.getItemDamage()==0) { stack2.setItemDamage(stack0.getItemDamage()); getSlot(2).putStack(stack2); getSlot(0).putStack(null); getSlot(1).putStack(null); } } } } return super.enchantItem(player,i); } } button click makes nothing
September 3, 201312 yr You added the player's inventory slots first to your container, so they get the first slots.
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.