Posted April 23, 201510 yr Whenever I close Minecraft and re-launch it the TileEntity is missing some data, but not all? Also it seems the GUI is not updating on certain things. Block: package dudesmods.fancycheeses.block; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; public class CheeseMaker extends BlockContainer { private boolean isActive; @SideOnly(Side.CLIENT) private IIcon iconFront; @SideOnly(Side.CLIENT) private IIcon iconTop; private static boolean keepInventory; private Random rand = new Random(); public CheeseMaker() { super(Material.iron); setHardness(3.5F); setCreativeTab(FancyCheeses.tabfancycheeses); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon("fancycheeses:milkmaker_side"); this.iconFront = iconRegister.registerIcon("fancycheeses:milkmaker_front"); this.iconTop = iconRegister.registerIcon("fancycheeses:milkmaker_top"); } @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int metadata) { return metadata == 0 && side == 3 ? this.iconFront : side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side == metadata ? this.iconFront : this.blockIcon)); //return side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side != metadata ? this.blockIcon : this.iconFront)); } public Item getItemDropped(int i, Random random, int j) { return Item.getItemFromBlock(FancyCheeses.cheeseMakerIdle); } public void onBlockAdded(World world, int x, int y, int z) { super.onBlockAdded(world, x, y, z); this.setDefaultDirection(world, x, y, z); } private void setDefaultDirection(World world, int x, int y, int z) { if(!world.isRemote) { Block b1 = world.getBlock(x, y, z - 1); Block b2 = world.getBlock(x, y, z + 1); Block b3 = world.getBlock(x - 1, y, z); Block b4 = world.getBlock(x + 1, y, z); byte b0 = 3; if (b1.func_149730_j() && !b2.func_149730_j()) { b0 = 3; } if (b2.func_149730_j() && !b1.func_149730_j()) { b0 = 2; } if (b3.func_149730_j() && !b4.func_149730_j()) { b0 = 5; } if (b4.func_149730_j() && !b3.func_149730_j()) { b0 = 4; } world.setBlockMetadataWithNotify(x, y, z, b0, 2); } } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if(!world.isRemote) { FMLNetworkHandler.openGui(player, FancyCheeses.instance, FancyCheeses.guiCheeseMaker, world, x, y, z); } return true; } @Override public TileEntity createNewTileEntity(World world, int i) { return new TileEntityCheeseMaker(); } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityplayer, ItemStack itemstack) { int l = MathHelper.floor_double((double)(entityplayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if(l == 0) { world.setBlockMetadataWithNotify(x, y, z, 2, 2); } if(l == 1) { world.setBlockMetadataWithNotify(x, y, z, 5, 2); } if(l == 2) { world.setBlockMetadataWithNotify(x, y, z, 3, 2); } if(l == 3) { world.setBlockMetadataWithNotify(x, y, z, 4, 2); } if(itemstack.hasDisplayName()) { ((TileEntityCheeseMaker)world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName()); } } public static void updateCheeseMakerBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) { int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); TileEntity tileentity = worldObj.getTileEntity(xCoord, yCoord, zCoord); if(tileentity != null) { tileentity.validate(); worldObj.setTileEntity(xCoord, yCoord, zCoord, tileentity); } } public void breakBlock(World world, int x, int y, int z, Block oldblock, int oldMetadata) { if(!keepInventory) { TileEntityCheeseMaker tileentity = (TileEntityCheeseMaker) world.getTileEntity(x, y, z); if(tileentity != null) { for(int i = 0; i < tileentity.getSizeInventory(); i++) { ItemStack itemstack = tileentity.getStackInSlot(i); if(itemstack != null) { float f = this.rand.nextFloat() * 0.8F + 0.1F; float f1 = this.rand.nextFloat() * 0.8F + 0.1F; float f2 = this.rand.nextFloat() * 0.8F + 0.1F; while(itemstack.stackSize > 0) { int j = this.rand.nextInt(21) + 10; if(j > itemstack.stackSize) { j = itemstack.stackSize; } itemstack.stackSize -= j; EntityItem item = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage())); if(itemstack.hasTagCompound()) { item.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } world.spawnEntityInWorld(item); } } } world.func_147453_f(x, y, z, oldblock); } } super.breakBlock(world, x, y, z, oldblock, oldMetadata); } public Item getItem(World world, int x, int y, int z) { return Item.getItemFromBlock(FancyCheeses.cheeseMakerIdle); } } Container package dudesmods.fancycheeses.container; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotFurnace; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.tileentity.TileEntityFurnace; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.inventory.CheeseMakerSlot; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; public class ContainerCheeseMaker extends Container { private TileEntityCheeseMaker cheeseMaker; public ContainerCheeseMaker(InventoryPlayer inventory, TileEntityCheeseMaker tileentity) { this.cheeseMaker = tileentity; this.addSlotToContainer(new CheeseMakerSlot(tileentity, 0, 8, 54, new Item[]{Items.bucket, Items.milk_bucket})); //Input 1 (Cow Milk?) this.addSlotToContainer(new CheeseMakerSlot(tileentity, 1, 133, 54, new Item[]{FancyCheeses.time_piece})); //Time Piece this.addSlotToContainer(new SlotFurnace(inventory.player, tileentity, 2, 133, 17)); //Output this.addSlotToContainer(new CheeseMakerSlot(tileentity, 3, 29, 54, new Item[]{Items.bucket, FancyCheeses.sheep_milk_bucket})); //Input 2 (Sheep Milk?) this.addSlotToContainer(new CheeseMakerSlot(tileentity, 4, 50, 54, new Item[]{Items.bucket, FancyCheeses.goat_milk_bucket})); //Input 3 (Goat Milk?) for(int i = 0; i < 3; i++) { for(int j = 0; j < 9; j++){ this.addSlotToContainer(new Slot(inventory, j + i*9 + 9, 8 + j*18, 84 + i * 18)); } } for(int i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142)); } } public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (par2 == 2) { if (!this.mergeItemStack(itemstack1, 3, 39, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (par2 != 1 && par2 != 0) { if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null) { if (!this.mergeItemStack(itemstack1, 0, 1, false)) { return null; } } else if (TileEntityFurnace.isItemFuel(itemstack1)) { if (!this.mergeItemStack(itemstack1, 1, 2, false)) { return null; } } else if (par2 >= 3 && par2 < 30) { if (!this.mergeItemStack(itemstack1, 30, 39, false)) { return null; } } else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 3, 39, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(par1EntityPlayer, itemstack1); } return itemstack; } @Override public boolean canInteractWith(EntityPlayer var1) { return true; } } Custom Slot: package dudesmods.fancycheeses.inventory; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class CheeseMakerSlot extends Slot { Item[] items; boolean shouldCheck; boolean valid; public CheeseMakerSlot(IInventory p_i1824_1_, int p_i1824_2_,int p_i1824_3_, int p_i1824_4_, Item[] validItems) { super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_); this.items = validItems; shouldCheck = true; } public CheeseMakerSlot(IInventory p_i1824_1_, int p_i1824_2_,int p_i1824_3_, int p_i1824_4_, boolean valid) { super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_); shouldCheck = true; this.valid = valid; } @Override public boolean isItemValid(ItemStack p_75214_1_) { if (shouldCheck){ int i; for(i=0;i<=(items.length)-1;i++) { if(p_75214_1_.getItem() == items[i]) { return true; } } return false; } else { return valid; } } } GUI: package dudesmods.fancycheeses.gui; import org.lwjgl.opengl.GL11; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.container.ContainerCheeseMaker; import dudesmods.fancycheeses.proxy.CheesingMessage; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; public class GuiCheeseMaker extends GuiContainer { public static final ResourceLocation bground = new ResourceLocation("fancycheeses", "textures/gui/GuiCheeseMaker.png"); public static final ResourceLocation goudaCheese = new ResourceLocation("fancycheeses", "textures/items/gouda_cheese_wheel.png"); public TileEntityCheeseMaker cheeseMaker; public static String error = "none"; public GuiCheeseMaker(InventoryPlayer inventoryPlayer, TileEntityCheeseMaker entity) { super(new ContainerCheeseMaker(inventoryPlayer, entity)); this.cheeseMaker = entity; this.xSize = 176; this.ySize = 166; } @Override public void initGui() { super.initGui(); this.buttonList.add(new GuiButton(0, guiLeft + 78, guiTop + 13, 10, 18, "<")); //Cheese Left this.buttonList.add(new GuiButton(1, guiLeft + 108, guiTop + 13, 10, 18, ">")); //Cheese Right this.buttonList.add(new GuiButton(2, guiLeft + 78, guiTop + 32, 40, 18, "Cheese")); //Cheese Make this.buttonList.add(new GuiButton(3, guiLeft + 78, guiTop + 50, 10, 18, "<")); //Time Left this.buttonList.add(new GuiButton(4, guiLeft + 108, guiTop + 50, 10, 18, ">")); //Time Right } @Override public void actionPerformed(GuiButton button) { switch(button.id) { case 0: //Cheese Left FancyCheeses.network.sendToServer(new CheesingMessage("cheeseleft", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; case 1: //Cheese Right FancyCheeses.network.sendToServer(new CheesingMessage("cheeseright", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; case 2: //Cheese Make FancyCheeses.network.sendToServer(new CheesingMessage("docheese", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; case 3: //Time Left FancyCheeses.network.sendToServer(new CheesingMessage("timeleft", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; case 4: //Time Right FancyCheeses.network.sendToServer(new CheesingMessage("timeright", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; default: break; } } public void drawGuiContainerForegroundLayer(int par1, int par2) { String name = this.cheeseMaker.hasCustomInventoryName() ? this.cheeseMaker.getInventoryName() : I18n.format(this.cheeseMaker.getInventoryName(), new Object[0]); this.fontRendererObj.drawString(name, (this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2) + 40, 4, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); this.fontRendererObj.drawString(cheeseMaker.cheeses[cheeseMaker.cheeseToMake], 95, 15, 4210752); //Debugging this.fontRendererObj.drawString(Integer.toString(cheeseMaker.timeAmounts[cheeseMaker.cheeseToMake][cheeseMaker.timeAmount]), 95, 55, 4210752); this.fontRendererObj.drawString(I18n.format("container.cheesemaker.error." + error, new Object[0]), 68, 72, 4210752); this.fontRendererObj.drawString(String.valueOf(cheeseMaker.cowMilkAmount), 13, 20, 4210752); this.fontRendererObj.drawString(String.valueOf(cheeseMaker.sheepMilkAmount), 34, 20, 4210752); this.fontRendererObj.drawString(String.valueOf(cheeseMaker.goatMilkAmount), 55, 20, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { guiDraw(bground); guiDrawLiquid("water", guiLeft + 8, guiTop + 33, cheeseMaker.cowMilkAmount, 50); //TODO:Cow Milk guiDrawLiquid("sheep_milk", guiLeft + 29, guiTop + 33, cheeseMaker.sheepMilkAmount, 50); //Sheep Milk guiDrawLiquid("goat_milk", guiLeft + 50, guiTop + 33, cheeseMaker.goatMilkAmount, 50); //Goat Milk if(cheeseMaker.cheeseToMake == 0) { guiDrawCheeseIcon(this.goudaCheese); } } protected void guiDraw(ResourceLocation var1) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(var1); this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); } protected void guiDrawCheeseIcon(ResourceLocation var1) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(var1); this.drawTexturedModalRect(guiLeft + 90, guiTop + 13, 0, 0, 16, 16); } protected void guiDrawLiquid(String fluidName, int x, int y, int fluidAmount, int fluidCapacity) { if(fluidAmount > 50) { fluidAmount = 50; System.out.println("ERROR: Cheese Maker conatins more " + fluidName + " than it possibly should!"); } Fluid fluid = FluidRegistry.getFluid(fluidName); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); //RenderUtil.setIntColor3(fluid.getColor()); IIcon icon = fluid.getStillIcon(); double height = 1; height = fluidAmount; height = height / fluidCapacity; height = height * 100; height = height / 2.33; GL11.glEnable(GL11.GL_BLEND); this.drawTexturedModelRectFromIcon(x, (int) ((y - (20 * 65 / 50))), icon != null ? icon : fluid.getBlock().getIcon(0, 0), 16, (int) Math.round(height)); GL11.glDisable(GL11.GL_BLEND); } } GUI Handler: package dudesmods.fancycheeses.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.container.ContainerCheeseMaker; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch(ID) { case FancyCheeses.guiCheeseMaker: if(entity instanceof TileEntityCheeseMaker) { return new ContainerCheeseMaker(player.inventory, (TileEntityCheeseMaker) entity); } } } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch(ID) { case FancyCheeses.guiCheeseMaker: if(entity instanceof TileEntityCheeseMaker) { return new GuiCheeseMaker(player.inventory, (TileEntityCheeseMaker) entity); } } } return null; } } TileEntity: package dudesmods.fancycheeses.tileentity; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import cpw.mods.fml.common.registry.GameRegistry; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.block.CheeseMaker; import dudesmods.fancycheeses.gui.GuiCheeseMaker; public class TileEntityCheeseMaker extends TileEntity implements ISidedInventory { private String localizedName; private static final int[] slots_top = new int[]{3, 4, 0}; private static final int[] slots_bottom = new int[]{2, 1}; private static final int[] slots_side = new int[]{1}; public ItemStack[] slots = new ItemStack [5]; public int cheeseToMake; public int cowMilkAmount; public int sheepMilkAmount; public int goatMilkAmount; public int timeAmount; public String[] cheeses = {"gouda", "", "", "", ""}; public Item[] itemCheeses = {FancyCheeses.gouda_cheese_wheel, FancyCheeses.time_piece, FancyCheeses.time_piece, FancyCheeses.time_piece, FancyCheeses.time_piece}; public int[][] timeAmounts = {new int[]{4, 48}, new int[]{40}, new int[]{40}, new int[]{40}, new int[]{40}}; public int[][] milkAmounts = {new int[]{10,0,0}, new int[]{0,0,0}, new int[]{0,0,0}, new int[]{0,0,0}, new int[]{0,0,0}}; public void setGuiDisplayName(String displayName) { this.localizedName = displayName; } public String getInventoryName() { return this.hasCustomInventoryName() ? this.localizedName : "container.cheesemaker"; } public boolean hasCustomInventoryName() { return this.localizedName != null && this.localizedName.length() > 0; } public int getSizeInventory() { return this.slots.length; } @Override public ItemStack getStackInSlot(int var1) { return this.slots[var1]; } @Override public ItemStack decrStackSize(int var1, int var2) { ItemStack itemstack = getStackInSlot(var1); if(this.slots[var1] != null) { if(this.slots[var1].stackSize <= var2 ){ itemstack = this.slots[var1]; this.slots[var1] = null; return itemstack; }else{ itemstack = this.slots[var1].splitStack(var2); if(this.slots[var1].stackSize == 0){ this.slots[var1] = null; } return itemstack; } }else { return itemstack; } } @Override public ItemStack getStackInSlotOnClosing(int var1) { if(this.slots[var1] != null) { ItemStack itemstack = this.slots[var1]; this.slots[var1] = null; return itemstack; } return null; } /** * Increases the counter specifying the cheese to make (output). */ public void incCheese() { if(this.cheeseToMake > 0) { this.cheeseToMake--; } this.markDirty(); } /** * Decreases the counter specifying the cheese to make (output). */ public void decCheese() { if(this.cheeseToMake < 4) { this.cheeseToMake++; } this.markDirty(); } /** * Increases the counter specifying the alternate aging amounts. */ public void incTime() { if(this.timeAmount > 0) { this.timeAmount--; } this.markDirty(); } /** * Decreases the counter specifying the alternate aging amounts. */ public void decTime() { if(this.timeAmount <(this.timeAmounts[this.cheeseToMake].length - 1)) { this.timeAmount++; } this.markDirty(); } /** * Checks to see if the item can be output, and outputs it. If not, tells the error. */ public void doCheese() { if(this.cowMilkAmount >= this.milkAmounts[this.cheeseToMake][0]) { if(this.sheepMilkAmount >= this.milkAmounts[this.cheeseToMake][1]) { if(this.goatMilkAmount >= this.milkAmounts[this.cheeseToMake][2]) { if(this.slots[1] != null && this.slots[1].getItem() == FancyCheeses.time_piece) { if((this.slots[1].getMaxDamage() - this.slots[1].getItemDamage()) >= this.timeAmounts[this.cheeseToMake][this.timeAmount]) { ItemStack itemstack = new ItemStack(this.itemCheeses[this.cheeseToMake], 1); if(this.slots[2] == null) { this.cowMilkAmount = this.cowMilkAmount - this.milkAmounts[this.cheeseToMake][0]; this.sheepMilkAmount = this.sheepMilkAmount - this.milkAmounts[this.cheeseToMake][1]; this.goatMilkAmount = this.goatMilkAmount - this.milkAmounts[this.cheeseToMake][2]; this.slots[1].attemptDamageItem(this.timeAmounts[this.cheeseToMake][this.timeAmount], new Random()); this.setInventorySlotContents(2, itemstack); } else if (this.slots[2].getItem() == this.itemCheeses[this.cheeseToMake]) { this.cowMilkAmount = this.cowMilkAmount - this.milkAmounts[this.cheeseToMake][0]; this.sheepMilkAmount = this.sheepMilkAmount - this.milkAmounts[this.cheeseToMake][1]; this.goatMilkAmount = this.goatMilkAmount - this.milkAmounts[this.cheeseToMake][2]; this.slots[1].attemptDamageItem(this.timeAmounts[this.cheeseToMake][this.timeAmount], new Random()); this.setInventorySlotContents(2, new ItemStack(this.itemCheeses[this.cheeseToMake], this.getStackInSlot(2).stackSize + 1)); } } else { GuiCheeseMaker.error = "timepiecedamage"; } } else { GuiCheeseMaker.error = "timepieceneed"; } } else { GuiCheeseMaker.error = "goatmilk"; } } else { GuiCheeseMaker.error = "sheepmilk"; } } else { GuiCheeseMaker.error = "cowmilk"; } this.markDirty(); } @Override public void setInventorySlotContents(int var1, ItemStack var2) { this.slots[var1] = var2; if(var2 != null && var2.stackSize > this.getInventoryStackLimit()) { var2.stackSize = this.getInventoryStackLimit(); } } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer var1) { return this.worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : var1.getDistanceSq((double)xCoord +0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64.0D; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int var1, ItemStack var2) { Item item = var2.getItem(); if(var1 == 0) { if(item == Items.bucket){return true;} else if(item == Items.milk_bucket){return true;} else{return false;} } else if(var1 == 1){ if(item == FancyCheeses.time_piece){return true;} else {return false;} } else if(var1 == 2) { return false; } else if(var1 == 3) { if(item == Items.bucket){return true;} else if(item == FancyCheeses.sheep_milk_bucket){return true;} else{return false;} } else if(var1 == 4) { if(item == Items.bucket){return true;} else if(item == FancyCheeses.goat_milk_bucket){return true;} else{return false;} } else { return false; } } public void updateEntity() { boolean flag1 = false; if(this.slots[0] != null) { if(this.slots[0].getItem() == Items.milk_bucket) { if(this.cowMilkAmount < 50) { this.slots[0] = new ItemStack(Items.bucket, 1); this.cowMilkAmount++; flag1 = true; } } } if(this.slots[3] != null) { if(this.slots[3].getItem() == FancyCheeses.sheep_milk_bucket) { if(this.sheepMilkAmount < 50) { this.slots[3] = new ItemStack(Items.bucket, 1); this.sheepMilkAmount++; flag1 = true; } } } if(this.slots[4] != null) { if(this.slots[4].getItem() == FancyCheeses.goat_milk_bucket) { if(this.goatMilkAmount < 50) { this.slots[4] = new ItemStack(Items.bucket, 1); this.goatMilkAmount++; flag1 = true; } } } if (flag1) { this.markDirty(); } } @Override public int[] getAccessibleSlotsFromSide(int var1) { return var1 == 0 ? slots_bottom : (var1 == 1 ? slots_top : slots_side); } @Override public boolean canInsertItem(int var1, ItemStack var2, int var3) { return this.isItemValidForSlot(var1, var2); } @Override public boolean canExtractItem(int var1, ItemStack var2, int var3) { //return var3 != 0 || var1 != 1 || var2.getItem() == Items.bucket; if(var1 == 0 || var1 == 3 || var1 == 4) { if(var2.getItem() == Items.bucket) { return true; } else { return false; } } else { return false; } } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("Items", 10); this.slots = new ItemStack[this.getSizeInventory()]; for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound compound = (NBTTagCompound) list.getCompoundTagAt(i); byte b = compound.getByte("Slot"); if(b >= 0 && b < this.slots.length) { this.slots[b] = ItemStack.loadItemStackFromNBT(compound); } } this.cheeseToMake = (int)nbt.getShort("CheeseToMake"); this.cowMilkAmount = (int)nbt.getShort("CowMilkAmount"); this.sheepMilkAmount = (int)nbt.getShort("SheepMilkAmount"); this.goatMilkAmount = (int)nbt.getShort("GoatMilkAmount"); this.timeAmount = (int)nbt.getShort("TimeAmount"); if(nbt.hasKey("CustomName")) { this.localizedName = nbt.getString("CustomName"); } } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setShort("CheeseToMake", (short)this.cheeseToMake); nbt.setShort("CowMilkAmount", (short)this.cowMilkAmount); nbt.setShort("SheepMilkAmount", (short)this.sheepMilkAmount); nbt.setShort("GoatMilkAmount", (short)this.goatMilkAmount); nbt.setShort("TimeAmount", (short)this.timeAmount); NBTTagList list = new NBTTagList(); for(int i = 0; i< this.slots.length; i++) { if(this.slots[i] != null) { NBTTagCompound compound = new NBTTagCompound(); compound.setByte("Slot", (byte)i); this.slots[i].writeToNBT(compound); list.appendTag(compound); } } nbt.setTag("Items", list); if(this.hasCustomInventoryName()) { nbt.setString("CustomName", this.localizedName); } } } IMessage Class: package dudesmods.fancycheeses.proxy; import net.minecraft.world.World; import io.netty.buffer.ByteBuf; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; public class CheesingMessage implements IMessage { private String text; private static int x,y,z; public CheesingMessage() { } public CheesingMessage(String text) { this.text = text; } public CheesingMessage(String text, int x, int y, int z) { this.text = text; this.x = x; this.y = y; this.z = z; } @Override public void fromBytes(ByteBuf buf) { text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, text); } public static class Handler implements IMessageHandler<CheesingMessage, IMessage> { @Override public IMessage onMessage(CheesingMessage message, MessageContext ctx) { System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName())); World world = ctx.getServerHandler().playerEntity.worldObj; TileEntityCheeseMaker cheeseMaker = (TileEntityCheeseMaker) world.getTileEntity(x, y, z); if(message.text.startsWith("docheese")) { cheeseMaker.doCheese(); } else if (message.text.startsWith("cheeseleft")) { cheeseMaker.decCheese(); } else if (message.text.startsWith("cheeseright")) { cheeseMaker.incCheese(); } else if (message.text.startsWith("timeleft")) { cheeseMaker.decTime(); }else if (message.text.startsWith("timeright")) { cheeseMaker.incTime(); } return null; // no response in this case } } } stuff from main class: //... @EventHandler public void preInit(FMLPreInitializationEvent event) { //... network = NetworkRegistry.INSTANCE.newSimpleChannel("MyChannel"); network.registerMessage(CheesingMessage.Handler.class, CheesingMessage.class, 0, Side.SERVER); //... } @EventHandler public void init(FMLInitializationEvent event) { //... NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler()); GameRegistry.registerTileEntity(TileEntityCheeseMaker.class, "CheeseMaker"); //... } //... Legend of Zelda Mod[updated September 20th to 3.1.1] Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0] Fancy Cheeses[updated May 8th to 0.5.0]
April 23, 201510 yr By gui is not updating on sertain thing, you mean that progress bar isn't going or what? If first - you need crafting and crafters methods to sync client and server containers. This includes 3 methods: addCraftingToCrafters(ICrafting crafting) detectAndSendChanges updateProgressBar(int id, int amount) Using those, you are syncing data between client and server. Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
April 23, 201510 yr Author This includes 3 methods: addCraftingToCrafters(ICrafting crafting) detectAndSendChanges updateProgressBar(int id, int amount) OK, using these has solved some most of my problems. Sorry for being vague earlier. At the moment, the issue is that when I click a button on my gui, it doesn't seem to do anything. My System.out.println()s are telling me the IMessage class is receiving the message, but then the functions in the TileEntity class that they call don't seem to do anything. Legend of Zelda Mod[updated September 20th to 3.1.1] Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0] Fancy Cheeses[updated May 8th to 0.5.0]
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.