Jump to content

[1.16.x] Packet Invalid Message


urbanxx001

Recommended Posts

I have a button in my screen class to send a packet to the container in order to update the inventory (client to server), according to this. Opening the gui and clicking the button in-game, I receive an invalid message error that originates from:

PacketHandler.CHANNEL.send(PacketDistributor.ALL.noArg(), new CapCompContainer(ModContainerTypes.MULTI_9X3.get(), containerID, containerInd, senderInv, 3));

According to this the issue could stem from registration, but I ensured that the packet is registered in FMLCommonSetup and specified the network direction PLAY_TO_SERVER.

 

Classes:

PacketHandler

PacketUpdateContainer

CapCompContainer

CapCompScreen

Link to comment
Share on other sites

It's called in:

private static void commonSetup(FMLCommonSetupEvent event) {
    DeferredWorkQueue.runLater(() -> {
        CapCompScreen.register();
        PacketHandler.register();
    });
}

which in turn is called in the Common Proxy class as:

final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(CommonProxy::commonSetup);
Edited by urbanxx001
Link to comment
Share on other sites

Alright I've redone a bit and it's working as long as the block position is given manually in the packet handler. I've been trying to pass it from the tile entity => container => screen instead, however something strange occurs in the container. It receives the correct te and block position, but then a second te with null position is detected. Classes below.

 

ModBlock

ModTileEntity

ModContainer

Edited by urbanxx001
Link to comment
Share on other sites

35 minutes ago, urbanxx001 said:

It receives the correct te and block position, but then a second te with null position is detected. Classes below.

From what I can see, you are not using the BlockPos you are sending NetworkHooks.openGui(), and thus the 'dummy' ModTileEntity the container creates on the client will have a null BlockPos.

 

As a side note, I would encourage you to stay away from LockableLootTileEntity and IInventory, and instead use the recommended forge alternative IItemHandler.

Link to comment
Share on other sites

2 hours ago, vemerion said:

I would encourage you to stay away from LockableLootTileEntity and IInventory, and instead use the recommended forge alternative IItemHandler.

I'll definitely consider IItemHandler down the line, thanks.

With openGui() I was passing the block pos:

NetworkHooks.openGui((ServerPlayerEntity) player, ((INamedContainerProvider) tileentity), t -> t.writeBlockPos(pos));

 

So the problem is this isn't synced with the client. I'll try getUpdatePacket() and onDataPacket() in the te then.

Edited by urbanxx001
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.