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.

Featured Replies

Posted

I have build my network communication on one channel sending different classes of Packets, derived from the Packet250CustomPayload class. In the Packet handler I check for the class of the just received packet, to decide which class should do the handling:

 

 

package chococraft.common.network;

import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;

public class ChocoboPacketHandler implements IPacketHandler
{    
   public ChocoboPacketHandler()
   {
   }

   @Override
   public void onPacketData(NetworkManager manager, Packet250CustomPayload packet, Player player)
   {
      if (packet instanceof PacketChocoboHealth)
      {
         PacketChocoboHealth.handleUpdate(packet, player);
      }
      else if (packet instanceof PacketChocoboMount)
      {
         PacketChocoboMount.handleUpdate(packet, player);
      }
      else if (packet instanceof PacketChocoboTamed)
      {
         PacketChocoboTamed.handleUpdate(packet, player);
      }
      else if (packet instanceof PacketChocoboAttribute)
      {
         PacketChocoboAttribute.handleUpdate(packet, player);
      }
      else if (packet instanceof PacketChocoboRiderJump)
      {
         PacketChocoboRiderJump.handleUpdate(packet, player);
      }
      else if (packet instanceof PacketChocoboDropSaddleAndBags)
      {
         PacketChocoboDropSaddleAndBags.handleUpdate(packet, player);
      }
   }
}

 

 

this works well on the SSP side. But, as I had to learn just now, crashes when I try to run my mod with an SMP server.

 

The problem is, the Packet class does not know about my new Packet classes, so they produce a NullPointerException.

 

 

2012-10-21 18:54:00 [iNFO] [sTDERR] java.lang.NullPointerException

2012-10-21 18:54:00 [iNFO] [sTDERR] at db.k(Packet.java:122)

2012-10-21 18:54:00 [iNFO] [sTDERR] at db.a(Packet.java:176)

2012-10-21 18:54:00 [iNFO] [sTDERR] at bb.h(TcpConnection.java:201)

2012-10-21 18:54:00 [iNFO] [sTDERR] at bb.d(TcpConnection.java:533)

2012-10-21 18:54:00 [iNFO] [sTDERR] at bd.run(SourceFile:114)

 

 

 

The vanilla packets themselve are added statically, hard coded in the Packet class to the list of known Packets. Of course the Packet lists are not protected, but private...

 

from the net.minecraft.src.Packet class:

 

/** List of the client's packet IDs. */
private static Set clientPacketIdList = new HashSet();

/** List of the server's packet IDs. */
private static Set serverPacketIdList = new HashSet();

 

 

now there is a static method in the Packet class adding new Packets to the list. In fact it is used in the static part of the Packet class to add the vanilla Packets to the above mentioned lists.

 

 

static void addIdClassMapping(int par0, boolean par1, boolean par2, Class par3Class)

 

 

and this time the method has no explicitly declared access modifier and thus it is effectively private (ARGH!!! sloppy programming, but I presume they would have made it private anyway ...).

 

Thus even so, my Packet class is ultimately derived from the Packet class, I can not access the Packet list nor the add method, thus can not use my Packets in SMP (and I wonder how it is working in SSP in the first place).

 

So, my suggestion is, could you have the Forge packet alter the Packet class so that

 

a) the addIdClassMapping will receive the protected access modifier

 

and

 

b) there is a method to get the next free packetId to be used for the next Packet registration?

running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है!

width=289 height=100http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]

Simple, don't add a new packet type, there is no need to and you fuck up compatibility if you do.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.