Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.x] Packet Invalid Message
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
urbanxx001

[1.16.x] Packet Invalid Message

By urbanxx001, October 27, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

urbanxx001    8

urbanxx001

urbanxx001    8

  • Creeper Killer
  • urbanxx001
  • Members
  • 8
  • 139 posts
Posted October 27, 2020

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

  • Quote

Share this post


Link to post
Share on other sites

Danebi    26

Danebi

Danebi    26

  • Diamond Finder
  • Danebi
  • Members
  • 26
  • 432 posts
Posted October 27, 2020 (edited)

When do you call the register method?

Edited October 27, 2020 by Danebi
  • Quote

Share this post


Link to post
Share on other sites

urbanxx001    8

urbanxx001

urbanxx001    8

  • Creeper Killer
  • urbanxx001
  • Members
  • 8
  • 139 posts
Posted October 27, 2020 (edited)

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 October 27, 2020 by urbanxx001
  • Quote

Share this post


Link to post
Share on other sites

poopoodice    114

poopoodice

poopoodice    114

  • Dragon Slayer
  • poopoodice
  • Members
  • 114
  • 904 posts
Posted October 27, 2020 (edited)

I believe this is sending the packet to everyone

PacketDistributor.ALL.noArg()

You can simply use SimpleChannel#sendToServer()

Edited October 27, 2020 by poopoodice
  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

urbanxx001    8

urbanxx001

urbanxx001    8

  • Creeper Killer
  • urbanxx001
  • Members
  • 8
  • 139 posts
Posted October 27, 2020 (edited)

Ah that makes sense. I replaced it with that, but receive the same error. Hopefully it's not an issue on the receiving end (container).

Edited October 27, 2020 by urbanxx001
  • Quote

Share this post


Link to post
Share on other sites

poopoodice    114

poopoodice

poopoodice    114

  • Dragon Slayer
  • poopoodice
  • Members
  • 114
  • 904 posts
Posted October 27, 2020

What's the reason of you sending another packet in PacketUpdateContainer.handle ?

Also in encode you've written a int array into the buffer, but then you read two ints out of the buffer which won't work because the first int will be the length of the array.

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

urbanxx001    8

urbanxx001

urbanxx001    8

  • Creeper Killer
  • urbanxx001
  • Members
  • 8
  • 139 posts
Posted October 27, 2020 (edited)

Right it's being sent in two places, idk why I sent a second one in PacketUpdateContainer.  I'll fix the argument mismatch as well. Thanks for catching those.

Edited October 27, 2020 by urbanxx001
  • Quote

Share this post


Link to post
Share on other sites

urbanxx001    8

urbanxx001

urbanxx001    8

  • Creeper Killer
  • urbanxx001
  • Members
  • 8
  • 139 posts
Posted October 30, 2020 (edited)

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 October 30, 2020 by urbanxx001
  • Quote

Share this post


Link to post
Share on other sites

vemerion    56

vemerion

vemerion    56

  • Creeper Killer
  • vemerion
  • Members
  • 56
  • 220 posts
Posted October 30, 2020
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.

  • Quote

Share this post


Link to post
Share on other sites

urbanxx001    8

urbanxx001

urbanxx001    8

  • Creeper Killer
  • urbanxx001
  • Members
  • 8
  • 139 posts
Posted October 30, 2020 (edited)
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 October 31, 2020 by urbanxx001
  • Quote

Share this post


Link to post
Share on other sites

urbanxx001    8

urbanxx001

urbanxx001    8

  • Creeper Killer
  • urbanxx001
  • Members
  • 8
  • 139 posts
Posted October 31, 2020

Woo got it to sync by setting the pos in the read/write methods, which are called by getUpdateTag().

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      Unable to install forge 1.16.5

      By diesieben07 · Posted 34 minutes ago

      Do not extract it. It is not an archive.   Some zip managers like to take control of the .jar file extension away from Java. Make sure you have Java installed and try running Jarfix once, then try the installer again.
    • gtf7dvygiduivtd
      I have a crash message with error code: 0

      By gtf7dvygiduivtd · Posted 57 minutes ago

      it only happens in 1.15+   logs.txt
    • IchBinEinToast
      Task :runClient FAILED | FAILURE: Build failed with an exception.

      By IchBinEinToast · Posted 1 hour ago

      Oh I solved it  Thank you @diesieben07
    • domi0908
      fix hitbox red baby mobs version forge

      By domi0908 · Posted 1 hour ago

      fix bug 
    • Tavi007
      Need help with modifying some vanilla rendering [1.16.4]

      By Tavi007 · Posted 1 hour ago

      Hello! I'm modifying the damage calculation by subscribing to LivingHurtEvent and scaling the damage value. This works fine, but now I also want to change the rendering a bit. My current LivingHurtEvent looks like this (I removed some unnecessary stuff) @SubscribeEvent public static void elementifyLivingHurtEvent(LivingHurtEvent event) { // compute new damage value .... // heals the target, if damage is lower than 0. This can happen with my modification if(damageAmount <= 0) { target.heal(-damageAmount); event.setCanceled(true); //does this even do something? damageAmount = 0; } event.setAmount(damageAmount); }   1. I want to change the red texture (an OverlayTexture?) to a green one, if the targets is healed. But I don't really know, where I should start with this task. I couldn't even find the code, that applies the red texture. So which Event do I need to hook in, so I can change this texture? Is it RenderLivingEvent? I also would like to read the vanilla code. I'm assuming, that the red overlayTexture is applied as long as hurttime>0, and that I might need to work around this with capabilities. 2. I also would like to reduce the screen shake (or at least disable it, when no damage has been dealt). Here I got the same question as 1. As you can see, I'm not really experienced with all the render stuff. It's my first time working with it.   3. Not really a question about rendering, but I didn't want to create a new thread for a single problem. I would also like to prevent the hurt-sound from firing, if no damage has been dealt and instead play another sound. Again I have no idea, where I would have to start looking in the vanilla code or which event I should use.   So yeah, I'm quite clueless and I hope you can help me out. Here is my repository, if you need more informations: https://github.com/Tavi007/ElementalCombat
  • Topics

    • Tyrone117
      3
      Unable to install forge 1.16.5

      By Tyrone117
      Started 10 hours ago

    • gtf7dvygiduivtd
      0
      I have a crash message with error code: 0

      By gtf7dvygiduivtd
      Started 58 minutes ago

    • IchBinEinToast
      5
      Task :runClient FAILED | FAILURE: Build failed with an exception.

      By IchBinEinToast
      Started 3 hours ago

    • domi0908
      1
      fix hitbox red baby mobs version forge

      By domi0908
      Started 22 hours ago

    • Tavi007
      0
      Need help with modifying some vanilla rendering [1.16.4]

      By Tavi007
      Started 1 hour ago

  • Who's Online (See full list)

    • Ottercorn
    • Zemelua
    • GGanze
    • VelioK
    • Tavi007
    • diesieben07
    • AzizD
    • PacketNarc
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.x] Packet Invalid Message
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community