Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

IMessage not being sent


Socratic_Phoenix
 Share

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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Oh ok, thank you. Should I uninstall java 17 and get java 8, or have both?
    • I have installed a forge server, and tried launching it. It launches as a vanilla server if I run the file called "minecraft_server.1.16.5.jar" If i run the file called "forge-1.16.5-36.2.23.jar", nothing at all happens, it just creates a log with these 2 lines: [19Jan2022 16:08:29.340] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge] [19Jan2022 16:08:29.345] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.1 by Oracle Corporation I have also tried running both files (since I don't know which one I'm supposed to use) using the command line like this: java -Xmx6000M -Xms6000M -jar {serverName}.jar nogui pause If I run the the server file, i get a vanilla server as well. If i run the forge file, the log file looks the same as before, and I get this result in the terminal: D:\MCS\VH>java -Xmx6000M -Xms6000M -jar forge-1.16.5-36.2.23.jar nogui 2022-01-19 16:16:32,476 main WARN Advanced terminal features are not available in this environment [16:16:32] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [16:16:32] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.1 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0xadd0edd) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0xadd0edd at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:41) at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95) at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:41) at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47) at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62) at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55) at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) D:\MCS\VH>pause Press any key to continue . . . I have also tried launching old servers that I had on SkyFactory 3 that worked fine before, but they have stopped working too. When I launch them I get this result: Starting Sky Factory 3 Server... A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:62) at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:31) Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap') at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) ... 6 more Press any key to continue . . . I assume this means that something has changed on my pc, causing forge servers not to run correctly, but I cannot imagine what that could be. I hope this is enough information to be able to help
    • Check it out, you won't regret https://shrinke.me/I0iwHJ3
    • These should be static initializers and the fields should be final. That is the point of DeferredRegister. Your code looks fine and should work, however you can use EnchantmentHelper.getItemEnchantmentLevel if you just want the level for one Enchantment. This call will be more efficient as it does not need to build the whole enchantment map.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.