Jump to content

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


Xerus

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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