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.

[SOLVED][1.10] Tileentity calling writetonbt() only on server side

Featured Replies

Posted

I am having some really annoying difficultied with my Tileentity, and now I've found the problem: writetonbt() is only called on server side, while readfromnbt() is called on both server and client, and this is just making madness. Have been sitting here for 2 hours trying to find a solution...

 

 

	
String keys = new String[]{"fuel","lastfuel","yoffset"}
@Override
    public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
        super.writeToNBT(nbt);
        if(name!="bulkcore"){
        	NBTTagList list = new NBTTagList();
        for (int i = 0; i < this.getSizeInventory(); ++i) {
            if (this.getStackInSlot(i) != null) {
                NBTTagCompound stackTag = new NBTTagCompound();
                stackTag.setByte("Slot", (byte) i);
                this.getStackInSlot(i).writeToNBT(stackTag);
                list.appendTag(stackTag);
            }
        }
        nbt.setTag("Items", list);
        }
        if (this.hasCustomName()) nbt.setString("CustomName", this.getCustomName());
        for(int i=0;i<keys.length;i++){
        	nbt.setInteger(keys[i],this.getField(i));
        }
    	System.out.println(keys[0]+" written to "+nbt.getInteger("fuel"));
	return nbt;
    }

    @Override
    public void readFromNBT(NBTTagCompound nbt) {
        super.readFromNBT(nbt);
        NBTTagList list = nbt.getTagList("Items", 10);
        for (int i = 0; i < list.tagCount(); ++i) {
            NBTTagCompound stackTag = list.getCompoundTagAt(i);
            int slot = stackTag.getByte("Slot") & 255;
            this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));
        }
        if (nbt.hasKey("CustomName")) this.setCustomName(nbt.getString("CustomName"));
        for(int i=0;i<keys.length;i++){
        	String key=keys[i];
            if(nbt.hasKey(key)) this.setField(i,nbt.getInteger(key));
        }
    	System.out.println(keys[0]+" read to "+nbt.getInteger("fuel"));
    }

 

notice these sysout commands?

the console outputs of these:

[21:06:09] [server thread/INFO] [sTDOUT]: [com.xerus.simpleautomation.te.TEInventory:readFromNBT:77]: fuel read to 50

[21:06:15] [Client thread/INFO] [sTDOUT]: [com.xerus.simpleautomation.te.TEInventory:readFromNBT:77]: fuel read to 0

...

[21:07:06] [server thread/INFO] [sTDOUT]: [com.xerus.simpleautomation.te.TEInventory:writeToNBT:59]: fuel written to 50

 

and now my gui displays the client value while my tileentity is using a bit of both...

 

That is what is supposed to happen, you need to override onDescriptionPacket and getDescriptionPacket (not sure if i got those names right) in your TE's class.

 

*Edit that is for syncing client and server.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

well if that is how it's supposed to work, then why is the client receiving an NBTTagCompound with the same keys as the server but the value 0?

  • Author

Ok Thanks getUpdateTag solved it!

 

(how) can i put a [solved] in the topic name?

Modify thread (main/1st) post and change title with "[sOLVED]" (changing non-main post will not rename whole thread).

 

While I personally appreciate doing above - most ppl don't really care, thus it kinda kills the idea of doing it (I wish WM would add some features like that).

1.7.10 is no longer supported by forge, you are on your own.

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.