Jump to content

IMessage not being sent


Socratic_Phoenix

Recommended Posts

I'm working on a mod that needs to send a seed (don't worry!! not the world seed!) from the server (or server thread) to the client (or client thread). I followed the tutorial in the forge docs on networking, but my packet isn't being sent properly, or received properly or something.

 

I register the channel like this:

package com.gmail.socraticphoenix.forge.randore.packet;

import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;

public class RandoreNetworking {
    public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("randores");

}

 

This is my packet:

package com.gmail.socraticphoenix.forge.randore.packet;

import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class RandorePacket implements IMessage {
    private long seed;

    public RandorePacket(long seed) {
        this.seed = seed;
    }

    public long getSeed() {
        return this.seed;
    }

    public void setSeed(long seed) {
        this.seed = seed;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        this.setSeed(buf.readLong());
    }

    @Override
    public void toBytes(ByteBuf buf) {
        buf.writeLong(this.getSeed());
    }
}

This is my handler:

package com.gmail.socraticphoenix.forge.randore.packet;

import com.gmail.socraticphoenix.forge.randore.Randores;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class RandorePacketHandler implements IMessageHandler<RandorePacket, IMessage> {

    @Override
    public IMessage onMessage(final RandorePacket message, MessageContext ctx) {
        Minecraft.getMinecraft().addScheduledTask(new Runnable() {
            @Override
            public void run() {
                Randores.getInstance().getLogger().info("Received seed information: " + message.getSeed());
            }
        });
        return null;
    }

}

I attempt to send the message like this:

RandoreNetworking.INSTANCE.sendToAll(new RandorePacket(world.getSeed()));

I have verified that this code is reached AND that it is called from the server thread. I am using the world seed for testing purposes.

 

I register the message like this:

RandoreNetworking.INSTANCE.registerMessage(RandorePacketHandler.class, RandorePacket.class, 0, Side.CLIENT);

I register this in the constructor. Perhaps that's the problem? (I'll try in init and pre init as well).

 

Thanks for any help!

Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes).

I know Java pretty well... So yeah...

Quote

This is where I'd put an inspirational and/or clever quote, but I can't think of one right now...

This is the output of the totally, 100% working compiler for my programming language, Planet9:

Beginning Compilation...
Failed compilation!
planet9.compiler.error.CompilationException: Compiler not yet implemented
	at planet9.compiler.Compiler.compile(Compiler.java:39)
	at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)

 

Link to comment
Share on other sites

32 minutes ago, Socratic_Phoenix said:

package com.gmail.socraticphoenix.forge.randore.packet; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; public class RandoreNetworking { public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("randores"); }

you never register the message

 

example

 

    private static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODINFO.MOD_NAME);

    public static void initNetwork(){
        INSTANCE.registerMessage(GuiSyncPacket.class, GuiSyncPacket.class, ++NetID, Side.CLIENT);
    }

and call initNetwork in preinit

Link to comment
Share on other sites

25 minutes ago, loordgek said:

you never register the message

1 hour ago, Socratic_Phoenix said:

I register the message like this:


RandoreNetworking.INSTANCE.registerMessage(RandorePacketHandler.class, RandorePacket.class, 0, Side.CLIENT);

I register this in the constructor. Perhaps that's the problem? (I'll try in init and pre init as well).

Yes I do...

 

25 minutes ago, loordgek said:

and call initNetwork in preinit

Ok thanks!

56 minutes ago, diesieben07 said:

IMessage classes must have a no-arg constructor.

Ok thanks! But.... why?

Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes).

I know Java pretty well... So yeah...

Quote

This is where I'd put an inspirational and/or clever quote, but I can't think of one right now...

This is the output of the totally, 100% working compiler for my programming language, Planet9:

Beginning Compilation...
Failed compilation!
planet9.compiler.error.CompilationException: Compiler not yet implemented
	at planet9.compiler.Compiler.compile(Compiler.java:39)
	at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)

 

Link to comment
Share on other sites

Just now, diesieben07 said:

So FML can create a new instance of the class when the message is received.

That makes sense (grumbles about it being possible to map fields to the constructor)...

 

It does persist the fields though?

Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes).

I know Java pretty well... So yeah...

Quote

This is where I'd put an inspirational and/or clever quote, but I can't think of one right now...

This is the output of the totally, 100% working compiler for my programming language, Planet9:

Beginning Compilation...
Failed compilation!
planet9.compiler.error.CompilationException: Compiler not yet implemented
	at planet9.compiler.Compiler.compile(Compiler.java:39)
	at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)

 

Link to comment
Share on other sites

Thanks everyone! It's working now!

Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes).

I know Java pretty well... So yeah...

Quote

This is where I'd put an inspirational and/or clever quote, but I can't think of one right now...

This is the output of the totally, 100% working compiler for my programming language, Planet9:

Beginning Compilation...
Failed compilation!
planet9.compiler.error.CompilationException: Compiler not yet implemented
	at planet9.compiler.Compiler.compile(Compiler.java:39)
	at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)

 

Link to comment
Share on other sites

17 minutes ago, diesieben07 said:

No, it only calls toBytes and fromBytes.

Of course, silly me!

Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes).

I know Java pretty well... So yeah...

Quote

This is where I'd put an inspirational and/or clever quote, but I can't think of one right now...

This is the output of the totally, 100% working compiler for my programming language, Planet9:

Beginning Compilation...
Failed compilation!
planet9.compiler.error.CompilationException: Compiler not yet implemented
	at planet9.compiler.Compiler.compile(Compiler.java:39)
	at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)

 

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.