Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

  • 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

  • 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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.