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

Hello everyone, fairly new with packets and networking so I just tried to put this together for a test run by using the Forge documentation on SimpleImpl. It did not work when I tried sending and receiving the packet and I got this error. Any hints? Thanks.

public class Main {
 
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("mechannel");
 
public void init(FMLInitializationEvent event)
    {
        INSTANCE.registerMessage(MyMessageHandler.class, MyMessage.class, 0, Side.CLIENT);
    }
}
 
 
public class MyMessage implements IMessage {
     
      public MyMessage() { }
 
      private int testInt;
      public MyMessage(int testInt) {
        this.setTestInt(testInt);
      }
 
      @Override public void toBytes(ByteBuf buf) {
        buf.writeInt(getTestInt());
      }
 
      @Override public void fromBytes(ByteBuf buf) {  
        setTestInt(buf.readInt());
      }
 
    public int getTestInt() {
        return testInt;
    }
 
    public void setTestInt(int testInt) {
        this.testInt = testInt;
    }
    }
 
 
public class MyMessageHandler implements IMessageHandler<MyMessage, IMessage> {
 
  @Override public IMessage onMessage(MyMessage message, MessageContext ctx) {
     
    int number = message.getTestInt();
    System.out.println(number);
 
    return null;
  }
 
}
 
 
public class Executor {
 Main.INSTANCE.sendToServer(new MyMessage(4));
}

 

Edited by olie304

1 hour ago, olie304 said:

INSTANCE.registerMessage(MyMessageHandler.class, MyMessage.class, 0, Side.CLIENT);

 

1 hour ago, olie304 said:

Main.INSTANCE.sendToServer(new MyMessage(4));

The Side parameter in registerMessage should be the side which receives the message - but you're sending the packet to the server. Where/when do you actually send it? It should also be surrounded by a world#isRemote check to make sure it's being sent only from the correct side.

Quote

at cpw.mods.fml.server.FMLServerHandler.getClientToServerNetworkManager

1.7.10 & below are not supported in this forum any longer. Please update to at least 1.8.9, but preferably to 1.11.2.
A moderator will likely lock this thread in the near future.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

  • Author
1 hour ago, Jay Avery said:

 

The Side parameter in registerMessage should be the side which receives the message - but you're sending the packet to the server. It should also be surrounded by a world#isRemote check to make sure it's being sent only from the correct side.

Ah thanks.

Quote

Where/when do you actually send it?

I just have an event that runs the command when the player left clicks a block at my executor class.

Main.INSTANCE.sendToServer(new MyMessage(4)); //Sends the integer 4 to the server upon left clicking a block

EDIT: Alright I fixed that stuff up and I get no errors but I don't think it is running because I should be seeing the number 4 in the console. Basically I just 

if (!MinecraftServer.getServer().isDedicatedServer()) //before sending the packet
// changed Side.CLIENT to Side.SERVER in the message register

 

Edited by olie304

  • Guest locked this topic
Guest
This topic is now closed to further replies.

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.