Jump to content

Recommended Posts

Posted

Greetings, I am currently trying to register a packet listener for forge 1.8.9 like this:
 

public class NameChangePacketListener {
    @SubscribeEvent
    @SideOnly(Side.CLIENT)
    public void onPacketReceived(FMLNetworkEvent.ClientCustomPacketEvent event) throws IOException {
        System.out.println("test");
        

        if (event.packet.toS3FPackets() instanceof S38PacketPlayerListItem) {
            S38PacketPlayerListItem packet = (S38PacketPlayerListItem) event.packet.toS3FPackets();

            if (packet.func_179768_b() == S38PacketPlayerListItem.Action.UPDATE_DISPLAY_NAME) {
                for (S38PacketPlayerListItem.AddPlayerData playerData : packet.func_179767_a()) {
                    String newName = playerData.getDisplayName().getUnformattedText();

                    IChatComponent chatComponent = new ChatComponentText("Your name has been changed")
                            .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN));
                    Minecraft.getMinecraft().thePlayer.addChatMessage(chatComponent);
                }
            }
        }
    }
}

Now, in the init method, I register this listener to the event bus like so:
 

@Mod.EventHandler
    @SideOnly(Side.CLIENT)
    public static void init(FMLInitializationEvent event){
        MinecraftForge.EVENT_BUS.register(new NameChangePacketListener());
    }


I know for a fact the init method works, so why does the "onPacketReceived" method not get called? the "test" doesn't print at all

Posted

The only place I can think of is the Forge discord (or any other modding discord servers). But beside Forge and Kaupenjoe I don't know other Forge discord servers

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.