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.

[1.14.4] sync tile entity on client/server; serialize/deserialize error

Featured Replies

Posted

I have a TE that stores a List, i'm using a ListNBT with CompoundNBT to store the block position and the list beloging to the TE, it works perfectly on client, but it does not load/save on server.

 

This are probably the useful errors:

Client

Quote

    [Render thread/ERROR] [ne.mi.fm.ne.si.IndexedMessageCodec/SIMPLENET]: Received empty payload on channel fml:handshake
    [Netty Client IO #0/ERROR] [minecraft/ArgumentTypes]: Could not deserialize minecraft:
    [Netty Client IO #0/ERROR] [minecraft/ArgumentTypes]: Could not deserialize minecraft:

Server:

Quote

    [Netty Server IO #1/ERROR] [minecraft/ArgumentTypes]: Could not serialize net.minecraftforge.server.command.ModIdArgument@37225730 (class net.minecraftforge.server.command.ModIdArgument) - will not be sent to client!
    [Netty Server IO #1/ERROR] [minecraft/ArgumentTypes]: Could not serialize net.minecraftforge.server.command.EnumArgument@1d34fe74 (class net.minecraftforge.server.command.EnumArgument) - will not be sent to client!

 

 

And this is the write/read functions:

Quote

	@Nonnull
    @Override
    public CompoundNBT write(CompoundNBT compound) {
        ListNBT mList = new ListNBT();
        Map<BlockPos, Set<ResourceLocation>> mPos = SMBlock.getMap();
        if (mPos != null) {
            mPos.forEach((pos, rec) -> {
                if (rec.size() > 0) {
                    CompoundNBT map = new CompoundNBT();
                    map.putString(pos.toString(), rec.toString());
                    mList.add(map);
                }
            });
        }
        compound.put("mComp", mList);
        return super.write(compound);
    }

    @Override
    public void read(CompoundNBT compound) {
        Set<ResourceLocation> mPos = new HashSet<>();
        ListNBT mList = compound.getList("mComp", 10);
        for (int i = 0; i < mList.size(); i++) {
            CompoundNBT mCompound = mList.getCompound(i);
            BlockPos position = getPosition(mCompound.keySet().toString());
            String sArray = mCompound.getString(position.toString());
            if (SMBlock.getPositions().contains(position)) return;
            SMBlock.setPosition(position);
            if (!sArray.equals("")) {
                for (String s : sArray.split(", ")) {
                    sList.add(new ResourceLocation(s.replaceAll("]\\[", "")));
                }
            }
            SMBlock.setMap(position, rec);
            sArray.clear();
        }
        super.read(compound);
    }

Obviously i am missing something, can anyone help me?

Howdy

The only thing that leaps out at me on your existing code - try putting your calls to super as the first statement in your method (might not help but worth a try)

eg

 

 public CompoundNBT write(CompoundNBT compound) {
super.write(compound);
        ListNBT mList = new ListNBT();
        Map<BlockPos, Set<ResourceLocation>> mPos = SMBlock.getMap();
        if (mPos != null) {
            mPos.forEach((pos, rec) -> {
                if (rec.size() > 0) {
                    CompoundNBT map = new CompoundNBT();
                    map.putString(pos.toString(), rec.toString());
                    mList.add(map);
                }
            });
        }
        compound.put("mComp", mList);
      return compound;
    }

 

Do you have the other sync methods defined properly?

  1. getUpdatePacket() and onDataPacket() -- for single TileEntity updates
  2. getUpdateTag() and handleUpdateTag() -- for sending as part of a chunk update packet

eg see here

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe20_tileentity_data

 

and here

 

https://mcforge.readthedocs.io/en/latest/tileentities/tileentity/

 

-TGG

 

  • Author

Certainly i was missing getUpdatePacket() , but still it is not working, it seems that the server can't access to the list i am saving, i put a print in the write/read functions and it prints empty while the client prints correctly, i assume i have to use a custom network for this?

Hi

No you shouldn't need to use a custom network, NBTList transmit fine just using vanilla.

 

If you haven't already I'd suggest you use your debugger to step through what your code is doing, it should become more obvious then.

BTW this also looks wrong:

if (SMBlock.getPositions().contains(position)) return;

 

Cheers

  TGG

  • Author

I basically have a gui with buttons, if you press a button, its name is added to the list.

The problem seems to be that the server can't access that list, or maybe it access a different one, so when the nbt is saved, the position is ok but the list is empty.

 

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.