Jump to content

[1.16.1][Solved] Sending packets to client from dedicated server?


Recommended Posts

Posted (edited)

I have a custom gui screen that does not have a container, so I send a packet from the server to client in order to open the screen. While it works in single player, I cannot get this packet to work stemming from a dedicated server.

I registered the packet client side only and I placed a SideOnly DIST.client within the packet class. I'm not sure what the issue is but I've posted the error below, maybe I am just going about this wrong?

 

Sending packet from block right click:

if (!worldIn.isRemote && handIn.equals(Hand.MAIN_HAND)) {            
  	PacketOpenCustomScreen packet = new PacketOpenCustomScreen(entityID);
  	PacketHandler.sendTo(packet, (ServerPlayerEntity) player);
}
       

 

PacketHandler:

public class PacketHandler {

    public static int disc = 0;

    private static final String PROTOCOL_VERSION = Integer.toString(1);
    private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
            .named(new ResourceLocation(SexyMod.MODID, "main_channel"))
            .clientAcceptedVersions(PROTOCOL_VERSION::equals)
            .serverAcceptedVersions(PROTOCOL_VERSION::equals)
            .networkProtocolVersion(() -> PROTOCOL_VERSION)
            .simpleChannel();

    public static void register() {

        HANDLER.registerMessage(disc++, SendFlight.class, SendFlight::encode, SendFlight::new, SendFlight::handle);

    }

    public static void registerClient() {

        HANDLER.registerMessage(disc++, PacketOpenCustomScreen.class, PacketOpenCustomScreen::encode, PacketOpenCustomScreen::new, PacketOpenCustomScreen::handle);
    }

    // packet to player, called server side
    // specific player
    public static void sendTo(Object message, ServerPlayerEntity player) {

        HANDLER.sendTo(message, player.connection.netManager, NetworkDirection.PLAY_TO_CLIENT);
    }

    // to players on that chunk, can also do by dinmension, etc check packetdistrubutor...
    public static void sendToChunk(Object message, Supplier<Chunk> chunk) { HANDLER.send(PacketDistributor.TRACKING_CHUNK.with(chunk), message);}

    // to all players tracking the specified entity
    public static void sendToTrackingEntity(Object message, Supplier<Entity> entity) { HANDLER.send(PacketDistributor.TRACKING_ENTITY.with(entity), message);}

    // all connected players
    public static void sendToAll(Object message) {
        HANDLER.send(PacketDistributor.ALL.noArg(), message);
    }

    // packet to server, called client side
    public static void sendToServer(Object message) {
        HANDLER.sendToServer(message);
    }




}

Packet:

public class PacketOpenCustomScreen {

 private int entityID = 0;

    public PacketOpenCustomScreen(PacketBuffer buf) { entityID = buf.readInt(); }

    public PacketOpenCustomScreen(int entityID) { this.entityID = entityID; }

    public static void encode(PacketOpenCustomScreen packet, PacketBuffer buf) { buf.writeInt(packet.entityID); }

    @OnlyIn(Dist.CLIENT)
    public static void handle(final PacketOpenCustomScreen packet, Supplier<NetworkEvent.Context> context) {
        NetworkEvent.Context ctx = context.get();
        ctx.enqueueWork(() -> {

                Minecraft.getInstance().displayGuiScreen(new CustomScreen(new StringTextComponent("custom_screen"), packet.entityID));

        });

        ctx.setPacketHandled(true);
    }
}

Registration of packet handler: 

@SubscribeEvent
    public static void onFMLClientSetupEvent(final FMLClientSetupEvent e)
    {
       
        PacketHandler.registerClient();
}

 

Error message on block right click/sending of packet:

[05:54:58] [Server thread/ERROR] [ne.mi.fm.ne.si.IndexedMessageCodec/SIMPLENET]: Received invalid message com.landofminecraft.mysexymod.event.packet.PacketOpenCustomScreen on channel mysexymod:main_channel
[05:54:58] [Server thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Server
java.lang.IllegalArgumentException: Invalid message com.landofminecraft.mysexymod.event.packet.PacketOpenCustomScreen
	at net.minecraftforge.fml.network.simple.IndexedMessageCodec.build(IndexedMessageCodec.java:145) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.SimpleChannel.encodeMessage(SimpleChannel.java:85) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.SimpleChannel.toBuffer(SimpleChannel.java:98) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.SimpleChannel.toVanillaPacket(SimpleChannel.java:129) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.SimpleChannel.sendTo(SimpleChannel.java:109) ~[?:?] {re:classloading}
	at com.landofminecraft.mysexymod.event.PacketHandler.sendTo(PacketHandler.java:50) ~[?:?] {re:classloading}
	at com.landofminecraft.mysexymod.block.ConsoleBlock.onBlockActivated(ConsoleBlock.java:95) ~[?:?] {re:classloading}
	at net.minecraft.block.AbstractBlock$AbstractBlockState.onBlockActivated(AbstractBlock.java:725) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.management.PlayerInteractionManager.func_219441_a(PlayerInteractionManager.java:347) ~[?:?] {re:classloading}
	at net.minecraft.network.play.ServerPlayNetHandler.processTryUseItemOnBlock(ServerPlayNetHandler.java:923) ~[?:?] {re:classloading}
	at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.processPacket(CPlayerTryUseItemOnBlockPacket.java:45) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.processPacket(CPlayerTryUseItemOnBlockPacket.java:12) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[?:?] {re:classloading}
	at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) ~[?:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:139) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[?:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:763) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:157) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:109) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.driveOneInternal(MinecraftServer.java:746) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:740) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:97) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:725) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:669) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.lambda$func_240784_a_$0(MinecraftServer.java:231) ~[?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_172] {}

 

 

 

Edited by Electric
marked as solved
Posted (edited)

All packets should be registered in FMLCommonSetupEvent, no exceptions. OnlyIn does literally nothing for modders, it's just an ugly ASM hack vanilla and Forge use, to properly specify network direction use the NetworkDirection version of SimpleChannel#register. Your issue most likely stems from your registration, your packet probably isn't present on the server, it should be.

Edited by Novârch

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Posted (edited)

How would server encode your message, if you did not registered it on server? To send packet from server to client both sides should know that this message exists. If you want to specify network direction of the message, then this method:

42 minutes ago, Electric said:

HANDLER.registerMessage(disc++, PacketOpenCustomScreen.class, PacketOpenCustomScreen::encode, PacketOpenCustomScreen::new, PacketOpenCustomScreen::handle);

has a variant with Optional<NetworkDirection>, which does what you need as I believe.

Edited by Dzuchun

Everything said above may be absolutely wrong. No rights reserved.

Posted (edited)

Hi guys. So I removed OnlyIn from the packet and registered it under FMLCommonSetupEvent. I then tried changing the simpleChannel.registermessage to use NetworkDirection.PLAY_TO_CLIENT, but it gives me an error when starting up on a dedicated server.

 

New message registry:

private static final String PROTOCOL_VERSION = Integer.toString(1);
    private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
            .named(new ResourceLocation(SexyMod.MODID, "main_channel"))
            .clientAcceptedVersions(PROTOCOL_VERSION::equals)
            .serverAcceptedVersions(PROTOCOL_VERSION::equals)
            .networkProtocolVersion(() -> PROTOCOL_VERSION)
            .simpleChannel();

    public static void register() {

        HANDLER.registerMessage(disc++, PacketOpenCustomScreen.class, PacketOpenCustomScreen::encode, PacketOpenCustomScreen::new, PacketOpenCustomScreen::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));

    }

 

Error messages:

[09:02:36] [modloading-worker-2/FATAL] [ne.mi.fm.lo.RuntimeDistCleaner/DISTXFORM]: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
[09:02:36] [modloading-worker-2/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
	Index: 1
	Listeners:
		0: NORMAL
		1: net.minecraftforge.eventbus.EventBus$$Lambda$2534/1420968301@6ea18fa3
java.lang.RuntimeException: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
	at net.minecraftforge.fml.loading.RuntimeDistCleaner.processClass(RuntimeDistCleaner.java:71)
	at cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClass(ILaunchPluginService.java:103)
	at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:85)
	at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:115)
	at cpw.mods.modlauncher.TransformingClassLoader$DelegatedClassLoader.findClass(TransformingClassLoader.java:239)
	at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:126)
	at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:96)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
	at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:975)
	at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1000)
	at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1394)
	at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1750)
	at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:477)
	at com.landofminecraft.mysexymod.event.PacketHandler.register(PacketHandler.java:40)
	at com.landofminecraft.mysexymod.SexyMod.setup(SexyMod.java:80)
	at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212)
	at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106)
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112)
	at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:135)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

[09:02:36] [modloading-worker-2/ERROR] [ne.mi.fm.ja.FMLModContainer/LOADING]: Caught exception during event FMLCommonSetupEvent dispatch for modid mysexymod
java.lang.RuntimeException: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
	at net.minecraftforge.fml.loading.RuntimeDistCleaner.processClass(RuntimeDistCleaner.java:71) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-launcher.jar:32.0] {}
	at cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClass(ILaunchPluginService.java:103) ~[modlauncher-5.1.0.jar:5.1.0+69+master.79f13f7] {}
	at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:85) ~[modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:115) ~[modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.TransformingClassLoader$DelegatedClassLoader.findClass(TransformingClassLoader.java:239) ~[modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:126) ~[modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:96) ~[modlauncher-5.1.0.jar:?] {}
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_172] {}
	at java.lang.invoke.MethodHandleNatives.resolve(Native Method) ~[?:1.8.0_172] {}
	at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:975) ~[?:1.8.0_172] {}
	at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1000) ~[?:1.8.0_172] {}
	at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1394) ~[?:1.8.0_172] {}
	at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1750) ~[?:1.8.0_172] {}
	at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:477) ~[?:1.8.0_172] {}
	at com.landofminecraft.mysexymod.event.PacketHandler.register(PacketHandler.java:40) ~[main/:?] {re:classloading}
	at com.landofminecraft.mysexymod.SexyMod.setup(SexyMod.java:80) ~[main/:?] {re:classloading}
	at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106) ~[?:32.0] {re:classloading}
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_172] {}
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_172] {}
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:135) ~[?:?] {re:classloading}
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) [?:1.8.0_172] {}
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) [?:1.8.0_172] {}
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) [?:1.8.0_172] {}
	at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291) [?:1.8.0_172] {}
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731) [?:1.8.0_172] {}
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [?:1.8.0_172] {}
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) [?:1.8.0_172] {}
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) [?:1.8.0_172] {}
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [?:1.8.0_172] {}
[09:02:36] [modloading-worker-1/DEBUG] [ne.mi.fm.ja.FMLModContainer/LOADING]: Fired event for modid forge : FMLCommonSetupEvent
[09:02:36] [Forge Version Check/INFO] [ne.mi.fm.VersionChecker/]: [forge] Starting version check at https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json
[09:02:36] [main/FATAL] [ne.mi.fm.ModLoader/LOADING]: Failed to complete lifecycle event SETUP, 1 errors found
[09:02:36] [main/FATAL] [minecraft/Main]: Failed to start the minecraft server
net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [
	My Sexy mysexymod (mysexymod) encountered an error during the common_setup event phase
§7Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
]
	at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:218) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:156) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.server.ServerModLoader.load(ServerModLoader.java:50) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraft.server.Main.main(Main.java:94) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_172] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_172] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_172] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_172] {}
	at net.minecraftforge.userdev.FMLUserdevServerLaunchProvider.lambda$launchService$0(FMLUserdevServerLaunchProvider.java:54) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.1.0.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {}

 

Edited by Electric
Posted
13 minutes ago, diesieben07 said:

You need to use DistExecutor to shield dist-only code.

I have tried doing 

                DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().displayGuiScreen(new CustomScreen(new StringTextComponent("custom_screen"), packet.entityID)));

 

But I am met with the error:

[09:27:45] [modloading-worker-2/FATAL] [ne.mi.fm.lo.RuntimeDistCleaner/DISTXFORM]: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
[09:27:45] [modloading-worker-2/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
	Index: 1
	Listeners:
		0: NORMAL
		1: net.minecraftforge.eventbus.EventBus$$Lambda$2539/1155021330@1f6dd35e
java.lang.RuntimeException: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
	at net.minecraftforge.fml.loading.RuntimeDistCleaner.processClass(RuntimeDistCleaner.java:71)
	at cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClass(ILaunchPluginService.java:103)
	at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:85)
	at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:115)
	at cpw.mods.modlauncher.TransformingClassLoader$DelegatedClassLoader.findClass(TransformingClassLoader.java:239)
	at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:126)
	at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:96)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
	at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:975)
	at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1000)
	at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1394)
	at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1750)
	at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:477)
	at com.landofminecraft.mysexymod.event.PacketHandler.register(PacketHandler.java:40)
	at com.landofminecraft.mysexymod.SexyMod.setup(SexyMod.java:80)
	at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212)
	at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106)
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112)
	at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:135)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

[09:27:45] [modloading-worker-2/ERROR] [ne.mi.fm.ja.FMLModContainer/LOADING]: Caught exception during event FMLCommonSetupEvent dispatch for modid mysexymod
java.lang.RuntimeException: Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
	at net.minecraftforge.fml.loading.RuntimeDistCleaner.processClass(RuntimeDistCleaner.java:71) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-launcher.jar:32.0] {}
	at cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClass(ILaunchPluginService.java:103) ~[modlauncher-5.1.0.jar:5.1.0+69+master.79f13f7] {}
	at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:85) ~[modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:115) ~[modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.TransformingClassLoader$DelegatedClassLoader.findClass(TransformingClassLoader.java:239) ~[modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:126) ~[modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:96) ~[modlauncher-5.1.0.jar:?] {}
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_172] {}
	at java.lang.invoke.MethodHandleNatives.resolve(Native Method) ~[?:1.8.0_172] {}
	at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:975) ~[?:1.8.0_172] {}
	at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1000) ~[?:1.8.0_172] {}
	at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1394) ~[?:1.8.0_172] {}
	at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1750) ~[?:1.8.0_172] {}
	at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:477) ~[?:1.8.0_172] {}
	at com.landofminecraft.mysexymod.event.PacketHandler.register(PacketHandler.java:40) ~[main/:?] {re:classloading}
	at com.landofminecraft.mysexymod.SexyMod.setup(SexyMod.java:80) ~[main/:?] {re:classloading}
	at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106) ~[?:32.0] {re:classloading}
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_172] {}
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_172] {}
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:135) ~[?:?] {re:classloading}
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) [?:1.8.0_172] {}
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) [?:1.8.0_172] {}
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) [?:1.8.0_172] {}
	at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291) [?:1.8.0_172] {}
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731) [?:1.8.0_172] {}
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [?:1.8.0_172] {}
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) [?:1.8.0_172] {}
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) [?:1.8.0_172] {}
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [?:1.8.0_172] {}
[09:27:46] [modloading-worker-1/DEBUG] [ne.mi.fm.ja.FMLModContainer/LOADING]: Fired event for modid forge : FMLCommonSetupEvent
[09:27:46] [main/FATAL] [ne.mi.fm.ModLoader/LOADING]: Failed to complete lifecycle event SETUP, 1 errors found
[09:27:46] [Forge Version Check/INFO] [ne.mi.fm.VersionChecker/]: [forge] Starting version check at https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json
[09:27:46] [main/FATAL] [minecraft/Main]: Failed to start the minecraft server
net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [
	My Sexy Mod (mysexymod) encountered an error during the common_setup event phase
§7Attempted to load class net/minecraft/client/gui/screen/Screen for invalid dist DEDICATED_SERVER
]
	at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:218) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:156) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.server.ServerModLoader.load(ServerModLoader.java:50) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraft.server.Main.main(Main.java:94) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_172] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_172] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_172] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_172] {}
	at net.minecraftforge.userdev.FMLUserdevServerLaunchProvider.lambda$launchService$0(FMLUserdevServerLaunchProvider.java:54) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.1.0.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {}

 

Posted
23 hours ago, diesieben07 said:

Okay, I don't know what CPW did, but his safeRunWhenOn validation doesn't seem to run in the development environment (anymore...?).

You are using safeRunWhenOn incorrectly.

See the javadocs on SafeReferent for how to use it correctly. There should be validation code to check that you are doing it correctly, but apparently it is just always disabled now...

 

Once more I express my huge distaste for the giant hack that is DistExecutor.

 

So if I have to use safeRunWhenOn by doing something like this...

                DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> OpenScreenUtil::openScreen);

 

How can I send my custom packet data through if it can't take parameters?

Posted (edited)

Thanks for the help, diesieben! I got DistExecutor working. Here's my code for anyone else wondering the same:

 

Packet set to run client only code:

DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> OpenScreenUtil.openScreen(packet.entityID));

 

OpenScreenUtil:

public class OpenScreenUtil {
    
    public static DistExecutor.SafeRunnable openScreen(int entityID) {
        Minecraft.getInstance().displayGuiScreen(new CustomScreen(new StringTextComponent("custom_screen"), entityID));

        return new DistExecutor.SafeRunnable() {
            @Override
            public void run() { }
        };
    }
}

 

Edited by Electric
Posted (edited)
8 hours ago, diesieben07 said:

That defeats the purpsoe of runWhenOn... You need to perform your action inside the SafeRunnable.

 

I thought as much earlier, but neglected to do so because when using a lambda expression (below) I was thrown an error (although screen still opened properly in game

return (DistExecutor.SafeRunnable) () -> Minecraft.getInstance().displayGuiScreen(new CustomScreen(new StringTextComponent("custom_screen"), entityID));
[11:57:31] [Render thread/FATAL] [ne.mi.fm.DistExecutor/]: Detected unsafe referent usage, please view the code at com.landofminecraft.mysexymod.network.packet.player.OpenCustomScreen.lambda$handle$1(OpenCustomScreen.java:25)
[11:57:31] [Render thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client
java.lang.RuntimeException: Unsafe Referent usage found in safe referent method
	at net.minecraftforge.fml.DistExecutor.validateSafeReferent(DistExecutor.java:268) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.DistExecutor.safeRunWhenOn(DistExecutor.java:135) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at com.landofminecraft.mysexymod.network.packet.player.OpenCustomScreen.lambda$handle$1(OpenCustomScreen.java:25) ~[main/:?] {re:classloading}
	at net.minecraftforge.fml.network.NetworkEvent$Context.enqueueWork(NetworkEvent.java:215) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at com.landofminecraft.mysexymod.network.packet.player.OpenCustomScreen.handle(OpenCustomScreen.java:23) ~[main/:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.IndexedMessageCodec.lambda$tryDecode$3(IndexedMessageCodec.java:128) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_261] {}
	at net.minecraftforge.fml.network.simple.IndexedMessageCodec.tryDecode(IndexedMessageCodec.java:128) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.IndexedMessageCodec.consume(IndexedMessageCodec.java:162) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.SimpleChannel.networkEventListener(SimpleChannel.java:80) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-2.2.0-service.jar:?] {}
	at net.minecraftforge.fml.network.NetworkInstance.dispatch(NetworkInstance.java:84) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.NetworkHooks.lambda$onCustomPayload$1(NetworkHooks.java:73) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_261] {}
	at net.minecraftforge.fml.network.NetworkHooks.onCustomPayload(NetworkHooks.java:73) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraft.client.network.play.ClientPlayNetHandler.handleCustomPayload(ClientPlayNetHandler.java:2076) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.network.play.server.SCustomPayloadPlayPacket.processPacket(SCustomPayloadPlayPacket.java:68) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraft.network.play.server.SCustomPayloadPlayPacket.processPacket(SCustomPayloadPlayPacket.java:11) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:139) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:109) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:97) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:958) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:586) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_261] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_261] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_261] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_261] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-5.1.2.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-5.1.2.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-5.1.2.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-5.1.2.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.1.2.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.1-32.0.43_mapped_snapshot_20200514-1.16-recomp.jar:?] {}

 

 

But after your suggestion I did move the code into the run() method and everything works without errors.

return new DistExecutor.SafeRunnable() {
            @Override public void run() {
                Minecraft.getInstance().displayGuiScreen(new CustomScreen(new StringTextComponent("custom_screen"), entityID));} };
    }

 

Edited by Electric

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.