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 cant seem to get my TileEntity to save its NBT, ive looked at updated 1.7.2 tutorials on saving NBT and it just wont work.

 

Here is my code:

 

public Packet getDescriptionPacket() {
	NBTTagCompound nbtTag = new NBTTagCompound();
	this.writeToNBT(nbtTag);
	return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}

public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
	readFromNBT(packet.func_148857_g());
}

public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
	super.readFromNBT(par1NBTTagCompound);
        NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < tagList.tagCount(); i++) 
          {
                NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
                byte slot = tag.getByte("Slot");                                                 
                if (slot >= 0 && slot < slots.length)   
                  {
                	slots[slot] = ItemStack.loadItemStackFromNBT(tag); 
                  }                                                                                                
          }
}

public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
	super.writeToNBT(par1NBTTagCompound);

	NBTTagList itemList = new NBTTagList();
        for (int i = 0; i < slots.length; i++)                             
          {
                ItemStack stack = slots[i];                                               
                if (stack != null)                                                                      
                  {
                        NBTTagCompound tag = new NBTTagCompound();  
                        tag.setByte("Slot", (byte) i);                   
                        stack.writeToNBT(tag);  
                        itemList.appendTag(tag);
                  }
          }
        par1NBTTagCompound.setTag("Inventory", itemList);     
}

 

Slots is indeed the itemstack array used by the container/gui.

 

I'll give any more code if needed. ;)

  • Author

 

After trial and error, I came to the conclusion that writeNBT/getDescriptionPacket is called but onDataPacket/readFromNBT is not. Any ideas?

I don't see any constructors, but...

When the game reloads it will call a constructor with no arguments and then call "readFromNBT(...)". If there is no empty constructor available it will give up.

When this is the problem Eclipse throws a bunch of red text at me upon attempts to load the world. Pay attention to the red text.

  • Author

When this is the problem Eclipse throws a bunch of red text at me upon attempts to load the world. Pay attention to the red text.

 

Thanks, Ive been doing this for a long time so I am looking over exceptions since vanilla minecraft makes so many. Thanks again!

Are you just trying to get it to save the nbt data?

 

world.markBlockForUpdate(x,y,z);

Long time Bukkit & Forge Programmer

Happy to try and help

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.