Posted June 21, 201411 yr I have a throwable item and I want it to remember the entity it hit whereupon hitting the entity the entity and data associated with it is saved to the item particular item stack that was spawned when the throwable item hit the entity. Is there a way to implement this functionality. I have been looking at @Override public Packet getDescriptionPacket() { NBTTagCompound tag = new NBTTagCompound(); writeToNBT(tag); return new S35PacketUpdateTileEntity(); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); } @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); } and also at public void addInformation (Itemstack itemstack, EntityPlayer player, List list boolean par4){ super.addInformation (itemstack, player, list, par4) } located in the item class.
June 21, 201411 yr I would suggest looking into NBTTagCompounds. An ITEMSTACK has a variable called stackTagCompound which is defaulted to null. With this, you could store any data you want. If your entity had special data, you could retrieve it from the entity and store it in the stack compound. You are almost asking what I have been implementing in my own mod. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 21, 201411 yr Author I have figured out how to write data to the itemstack. How would I write the entity to the itemstack though I tried entity.writeToNBT(itemstack.stackTagCompound) but I got a weird output where my System.Out.Println placed into the console (DropChances: (0:0.085f,1:0,.....),Age:0,UUIDLeast:-... a bunch of stuff). It would be nice if I could get the name from the entity or something like that
June 21, 201411 yr Author Ok I figured out how to write the entities name to NBT along with what appears to be the entity itself and have the item stack save the data (from what I can tell the stuff in my console is the entity data). I was wondering how to read that NBT data and then use it to respawn the entity from my item.
June 21, 201411 yr Well... You can read the nbt by going itemstack.stackTagCompound.get***("key_to_retrieve"); The *** is the type of whatever your wanting to retrieve. We all stuff up sometimes... But I seem to be at the bottom of that pot.
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.