Posted September 7, 201411 yr I have a tile entity that updates on right-click with certain items. Whenever I relog, the contents of the jar I'm making is deleted. Any help is appreciated! Code: TileEntityJar.java: package net.mc42.mods.eclipses.tileentities; import net.mc42.mods.eclipses.mod_Eclipses; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; public class TileEntityJar extends TileEntity { private FluidStack contents; private int amRst; //private int capacity; public TileEntityJar(){ contents = new FluidStack(0, 0); amRst = 0; //setFluid(mod_Eclipses.lunarEssence); //setAmount(2100); } public void setFluid(Fluid f){ contents = new FluidStack(f, amRst); } public void setAmount(int i){ contents.amount = i; this.amRst = i; } public boolean remove(int mb){ if(contents.amount >= mb){ contents.amount -= mb; amRst = contents.amount; if(contents.amount == 0) contents = new FluidStack(0, 0); return true; } return false; } public boolean add(int mb){ if(!(contents.amount + mb > mod_Eclipses.JarCapacity)){ contents.amount += mb; if(contents.amount == 0) contents = new FluidStack(0, 0); amRst = contents.amount; return true; } return false; } public int getPercentFull(){ //System.out.println((contents.amount/(float)mod_Eclipses.JarCapacity)*(float)100); return Math.round((contents.amount/(float)mod_Eclipses.JarCapacity)*(float)100); } public boolean hasFluid(Fluid f) { // TODO Auto-generated method stub return contents.isFluidEqual(new FluidStack(f, 0)); } @Override public void writeToNBT(NBTTagCompound par1) { super.writeToNBT(par1); NBTTagCompound par2 = new NBTTagCompound(); par2.setInteger("Amount", contents.amount); par2.setInteger("FluID", contents.fluidID); System.out.println("Saving... " + contents.amount + " " + contents.fluidID); //par2 = contents.writeToNBT(par2); par1.setTag("Content", par2); } @Override public void readFromNBT(NBTTagCompound par1) { super.readFromNBT(par1); //this.contents.loadFluidStackFromNBT((NBTTagCompound) par1.getTag("Content")); NBTTagCompound par2 = new NBTTagCompound(); par2 = (NBTTagCompound) par1.getTag("Content"); int amo = par2.getInteger("Amount"); int id = par2.getInteger("FluID"); System.out.println("Loaded " + amo + " " + id); contents = new FluidStack(id, amo); amRst = contents.amount; } }
September 7, 201411 yr Hi you need to override onDataPacket and getDescriptionPacket for the TileEntity. Otherwise there is no way for the server to tell the client what the contents of the jar are. This example code for 1.6.4 shows you a working example. https://github.com/mnn/jaffas/blob/59b59f01a1f2f6b21b0dc87e5a15e6761a3f3f19/src/minecraft/monnef/jaffas/food/block/TileEntityPie.java#L117 Should still work in 1.7 with some tweaking (i.e. Packet name change) -TGG
September 7, 201411 yr Hi The vanilla and forge code show the way forward.... TileEntity:: /** * Called when you receive a TileEntityData packet for the location this * TileEntity is currently in. On the client, the NetworkManager will always * be the remote server. On the server, it will be whomever is responsible for * sending the packet. * * @param net The NetworkManager the packet originated from * @param pkt The data packet */ public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { // your code here } Similarly getDescriptionPacket should return the same S35 packet. -TGG
November 24, 201410 yr Alright thats what I came up with: @Override public Packet getDescriptionPacket() { NBTTagCompound nbt = new NBTTagCompound(); nbt.setInteger("meta", this.blockMetadata); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbt); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { super.onDataPacket(net, pkt); this.blockMetadata = pkt.func_148857_g().getInteger("meta"); } in my TileEntity and in the renderer: @Override public void renderTileEntityAt(TileEntity entity, double x, double y, double z, float f) { //.... int m = entity.blockMetadata; //.... But still not working
November 24, 201410 yr instead of sending the meta data using nbt.setInteger("meta", this.blockMetadata); you can use the write nbt and read nbt code you already have to retrieve the tile entity data. i.e. this.readFromNBT(nbt); and this.writeToNBT(nbt)
November 24, 201410 yr Why do you synchronize the metadata... Use world.getBlockMetadata. nbt.setInteger("meta", worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); alright now its working, thanks
November 24, 201410 yr No no no no. Don't send your metadata in the packet at all! Block metadata is already synced between client and server. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.