Jump to content

Electric

Members
  • Posts

    50
  • Joined

  • Last visited

Posts posted by Electric

  1. I have a tile entity that renders a frame buffer to a block with stenciling. I'm attempting to update my mod from 1.12.2 to 1.16.2, and I believe that BufferBuilder.setTranslation was replaced by matrixStack.translate. Can I just replace the buffer builder translations with matrix stack? Or how does that work exactly?

     

    Here is my old code:

    final Tessellator tessellator = Tessellator.getInstance();
            final BufferBuilder renderer = tessellator.getBuffer();
            renderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
            renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
            blockRenderer.getBlockModelRenderer().renderModel(world, model, state, pos, matrixStackIn, buffer.getBuffer(RenderType.getSolid()), false, new Random(), state.getPositionRandom(te.getPos()), OverlayTexture.NO_OVERLAY);
            tessellator.draw();
            renderer.setTranslation(0, 0, 0);

     

  2. I'm rendering a custom block using openGL, and to do this I am calling Gl.capabilities in order to setup a framebuffer. In 1.12 I had called this during the client FMLPostInitialization event, but this no longer exists. I cannot call it during the FMLClientSetupEvent because it needs to run after vanilla Minecraft has run GL.createcapabilities on the main thread. Any suggestions as to when/where I can call this in order to setup my frame buffer?

     

    Error given when calling the Gl.createcapabilities method on FMLClientSetupEvent:

    [19:56:40] [modloading-worker-3/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: No GLCapabilities instance set for the current thread. Possible solutions:
    	a) Call GL.createCapabilities() after making a context current in the current thread.
    	b) Call GL.setCapabilities() if a GLCapabilities instance already exists for the current context.
    	Index: 1
    	Listeners:
    		0: NORMAL
    		1: ASM: class com.mymod.main.event.EventSubscriberClient onFMLClientSetup(Lnet/minecraftforge/fml/event/lifecycle/FMLClientSetupEvent;)V
    java.lang.IllegalStateException: No GLCapabilities instance set for the current thread. Possible solutions:
    	a) Call GL.createCapabilities() after making a context current in the current thread.
    	b) Call GL.setCapabilities() if a GLCapabilities instance already exists for the current context.

     

  3. 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));} };
        }

     

  4. 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() { }
            };
        }
    }

     

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

  6. 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:?] {}

     

  7. 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:?] {}

     

  8. 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] {}

     

     

     

  9. Thanks guys! I added the getShareTag and readShareTag to my item class. Now everything works well! 

    @Override
        public CompoundNBT getShareTag(ItemStack stack) {
            CompoundNBT nbt = stack.getOrCreateTag();
            IConsoleItem cap = stack.getCapability(CONSOLE_ITEM, null).orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!"));
    
            nbt.putString("linkedUUID", cap.getLinkedUUID());
    
            return nbt;
        }
    
        @Override
        public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) {
            super.readShareTag(stack, nbt);
    
            if (nbt != null) {
                IConsoleItem cap = stack.getCapability(CONSOLE_ITEM, null).orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!"));
                cap.setLinkedUUID(nbt.getString("linkedUUID"));
            }
        }

     

    I'm wondering what exactly what these methods do. I turned off my packet syncing from earlier and the client still seems to have an updated item stack whenever I change my capability server side. So do these methods sync the capability between server and client by themselves? And it updates every tick or just knows when I change something server side?

  10. I have attached a capability to my custom item, and it successfully stores the data server side. But I cannot figure out how to sync it to the client item stack properly. 

    EDIT: I'm not storing the item stack itself within this capability, just some extra string data that I can edit/change.

     

    I sync the server side cap to client every tick in the item class:

    /**
         * Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and
         * update it's contents.
         */
        public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    
            if (!worldIn.isRemote && entityIn instanceof ServerPlayerEntity) {
                IConsoleItem cap = stack.getCapability(CONSOLE_ITEM, null).orElseThrow(() -> new IllegalArgumentException(("LazyOptional must not be empty!")));
    
                PacketConsoleItemSync newPacket = new PacketConsoleItemSync(cap.getLinkedUUID(), stack);
                PacketHandler.sendTo(newPacket, (ServerPlayerEntity) entityIn);
            }
        }

     

    Here is my packet:

    public class PacketConsoleItemSync {
    
        private String linkedUUID = "none";
        private ItemStack stack = null;
    
        public PacketConsoleItemSync(PacketBuffer buf) {
            linkedUUID = buf.readString();
            stack = buf.readItemStack();
        }
    
        public PacketConsoleItemSync(String linkedUUID, ItemStack stack) {
            this.linkedUUID = linkedUUID;
            this.stack = stack;
    
        }
    
        public static void encode(PacketConsoleItemSync packet, PacketBuffer buf) {
            buf.writeString(packet.linkedUUID);
            buf.writeItemStack(packet.stack);
    
        }
    
        public static void handle(final PacketConsoleItemSync packet, Supplier<NetworkEvent.Context> context) {
            NetworkEvent.Context ctx = context.get();
            ctx.enqueueWork(() -> {
    
                   if (packet.stack != null) {
    
                       IConsoleItem cap = packet.stack.getCapability(CONSOLE_ITEM, null).orElseThrow(() -> new IllegalArgumentException(("LazyOptional must not be empty!")));
    //                   System.out.println(packet.stack);
                       cap.setLinkedUUID(packet.linkedUUID);
    //                   System.out.println(packet.linkedUUID);
    
                   }
    
            });
    
            ctx.setPacketHandled(true);
        }
    }
    

     

    I'm pretty certain that the problem lies with my packet class, as I'm not sure how to properly get the itemstack and replace it client side. Simply sending it through the packet buff and accessing its capability isn't working. It isn't null, but it just won't change.

  11. I'm trying to open the player's inventory by sending a packet server-side like I do with my custom inventory. But when I attempt this I get the error: Unable to construct this menu by type. I feel like maybe there's an easier way to do this, or maybe by using a vanilla Minecraft packet?

     

    My packet code:

    public class PacketOpenNormalInv {
    
        public PacketOpenNormalInv(PacketBuffer buf) { }
    
        public static void encode(PacketOpenNormalInv packet, PacketBuffer buf) { }
    
        public static void handle(final PacketOpenNormalInv packet, Supplier<NetworkEvent.Context> context) {
            NetworkEvent.Context ctx = context.get();
            ctx.enqueueWork(() -> {
                if (ctx.getSender() instanceof ServerPlayerEntity) {
    
                    ctx.getSender().openContainer(new INamedContainerProvider() {
                        @Override
                        public ITextComponent getDisplayName() {
                            return new TranslationTextComponent("inventory");
                        }
    
                        @Nullable
                        @Override
                        public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
    
                            return new PlayerContainer(ctx.getSender().inventory, !ctx.getSender().world.isRemote, ctx.getSender());
                        }
                    });
                }
    
            });
    
            ctx.setPacketHandled(true);
        }
    }

     

  12. I'm attempting to render a mob within my Gui screen. In the past I was able to do this using getRenderManager#renderEntity, but since this no longer exists I am trying to use getRenderManager#renderEntityStatic. 

    My current attempt: 

            Minecraft.getInstance().getRenderManager().renderEntityStatic(new PigEntity(EntityType.PIG,field_230706_i_.world), 0.0D, 0.0D, 0.0D, 0.0f, partialticks, matrixStack, field_230706_i_.getRenderTypeBuffers().getBufferSource(), 500);

     

    This method causes some weird orientation, as shown in the screenshot below. I just want this entity to render from a normal, third person viewpoint. There used to be a getRenderManager#setPlayerViewY but this is gone as well. I found the method getRenderManager#setCameraOrientation, but it doesn't seem to do anything (I'm horrible with Quaternions).  I tried:

    getRenderManager().setCameraOrientation(Vector3f.YP.rotationDegrees(180));

    Any suggestions? 

    315279627_ScreenShot2020-07-10at10_09_24AM.thumb.png.b505dbcda80598291d321c727cce6c89.png

     

    Pig feet are nice but what I'm really tryna stare at is some thicc cakeee ;) 

    my simple Gui screen class: https://pastebin.com/KMtCvxRy

     

    Edit: I figured it out. Just needed to change z pos to move it in front of me lol.

     

  13. 7 minutes ago, ChampionAsh5357 said:

    Dismounting an entity on client causes an infinite loop. Further testing reveals that only the player is affected when dismounting and can still control the riding entity. Server information syncs to client on game reload. ClientPlayerEntity movement input is no longer being sampled nor is livingTick even called. ClientPlayerEntity overrides isSneaking making setSneaking for setting the flag pointless on the client.

     

    This is most likely a bug.

    Thank you for testing this! So I guess this event is just sort of broken in the sense of not being cancellable right now :/

  14. 29 minutes ago, diesieben07 said:

    You probably have to cancel it on client and server.

    My event handler is set up normally, so it runs on both client and server. When the event is cancelled it does indeed prevent me from dismounting, but then puts my player in a state where I can't move except to look up and down, so something is not working.

     

    Also in past Minecraft versions it only worked if I just cancelled the event server side, but that no longer works either, so I'm sort of at a loss. 

  15. I am trying to cancel the dismount event, but its being weird. If I simply do the following in my event handler:

    @SubscribeEvent
    public void onMountEvent(EntityMountEvent e) {
            if (e.isDismounting()) {
                e.setCanceled(true);
            }
    }

    it will cancel successfully server side but my client does a weird thing where it sort of twitches back and forth and only lets me look up/down while not being able to move. If I try running the event with !world.isremote, it will only cancel server side and my client still dismounts (remounts when leaving/rejoining). How can I make this event cancel properly? 

  16. I'm simply trying to do something when I right click on my entity. The methods I've used in the past no longer exist in 1.16, so I am using 

    ActionResultType func_230254_b_(PlayerEntity player, Hand p_230254_2_)

     

    Weirdly, this runs 4 times, as in twice on client and server side... I'm wondering if there is another method I can use instead or how I can prevent this from happening. 

  17. I'm trying to load an OBJ model within my entity renderer using an IBakedModel. When I call ModelLoaderRegistry.getModel it requires resourcelocation, JsonDeserializationContext, and JsonObject. I'm confused as to what the last two parameters are for and how to use them. I am just trying to point to my OBJ model file location, so why are other parameters needed? 

  18. I'm trying to create different ranks in a permissions system for my mod. I am trying to use forge's permissionAPI. Here is my code so far:

    Spoiler
    
    public class Permissions implements IPermissionHandler {
    
        @Override
        public void registerNode(String node, DefaultPermissionLevel level, String desc) {
            
        }
    
        @Override
        public Collection<String> getRegisteredNodes() {
            return null;
        }
    
        @Override
        public boolean hasPermission(GameProfile profile, String node, @Nullable IContext context) {
            return false;
        }
    
        @Override
        public String getNodeDescription(String node) {
            return null;
        }
    }

    I'm guessing I need to use the registerNode method, but I'm not sure how to use it. Any ideas?

     

  19. I'm slightly confused on what you mean by that. Do I need to have my entity extend MultiPartEntityPart or make a whole new class that extends it? And if its the latter, how am I supposed to reference it for my own entity's parts? I tried this but I am lost:

    Spoiler
    
    public class EntityTest extends MultiPartEntityPart {
    
    
        public EntityTest(IEntityMultiPart parent, String partName, float width, float height) {
            super(parent, partName, width, height);
        }
    
        @Override
        public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
        {
            System.out.println(partName);
            return false;
        }

     

     

  20. Here is my Entity class:

    Spoiler
    
    public class EntityConsoleBrachacki extends EntityLiving implements IEntityMultiPart {
    
        protected final EntityAILookIdle aiLookIdle = new EntityAILookIdle(this);
        /** An array containing all body parts of this dragon */
        public MultiPartEntityPart[] consolePartArray;
        /** The head bounding box of a dragon */
        public MultiPartEntityPart consolePartRotor = new MultiPartEntityPart(this, "rotor", 1.0F, 3.0F);
        public MultiPartEntityPart consolePartFront = new MultiPartEntityPart(this, "front", 1.0F, 1.0F);
        public MultiPartEntityPart consolePartBack = new MultiPartEntityPart(this, "back", 1.0F, 1.0F);
    
        public static ITardisConsole getHandler(Entity entity) {
            if (entity.hasCapability(TARDIS_CONSOLE, EnumFacing.DOWN))
                return entity.getCapability(TARDIS_CONSOLE, EnumFacing.DOWN);
            return null;
        }
    
        public EntityConsoleBrachacki(World worldIn) {
            super(worldIn);
            this.consolePartArray = new MultiPartEntityPart[] {this.consolePartRotor, this.consolePartFront, this.consolePartBack};
            this.isImmuneToFire = true;
            setSize(4.0F, 1.5F);
            tasks.removeTask(aiLookIdle);
    
        }
    
    //    @Override
    //    public boolean shouldRenderInPass(int pass)
    //    {
    //        return pass == 0;
    //    }
    
        @Override
        protected boolean canDespawn()
        {
            return false;
        }
    
        public void onLivingUpdate()
        {
            super.onLivingUpdate();
    
            this.consolePartRotor.onUpdate();
            this.consolePartRotor.setLocationAndAngles(this.posX + 1.5, this.posY, this.posZ, 0, 0);
        }
    
        public void onEntityUpdate() {
            super.onEntityUpdate();
        }
    
        /**
         * Returns the <b>solid</b> collision bounding box for this entity. Used to make (e.g.) boats solid. Return null if
         * this entity is not solid.
         *
         * For general purposes, use {@link #width} and {@link #height}.
         *
         * see getEntityBoundingBox
         * omg this updates in real time
         */
        @Nullable
        public AxisAlignedBB getCollisionBoundingBox()
        {
            return this.getEntityBoundingBox();
    
        }
    
        @Override
        public void onCollideWithPlayer(EntityPlayer entityIn) {}
    
        @Override
        public boolean hitByEntity(Entity entityIn) { return true; }
    
        @Override
        public boolean canBePushed() { return false; }
    
        @Override
        protected void collideWithEntity(Entity p_82167_1_) {}
    
        @Override
        protected void collideWithNearbyEntities() { }
    
        @Override
        public boolean processInteract(EntityPlayer player, EnumHand hand) {
    
            System.out.println(this.getCollisionBoundingBox());
            System.out.println(this.getEntityBoundingBox());
            System.out.println(this.getParts());
            
            return true;
        }
    
        /**
         * Makes the entity despawn if requirements are reached
         * I don't know if this is needed
         */
        @Override
        protected void despawnEntity()
        {
        }
    
        /**
         * Return the Entity parts making up this Entity (currently only for dragons)
         */
        @Override
        public Entity[] getParts()
        {
            return this.consolePartArray;
        }
    
        @Override
        public World getWorld() {
            return this.world;
        }
    
        /**
         * Run when one of the parts is hit by a player :D
         */
        @Override
        public boolean attackEntityFromPart(MultiPartEntityPart consolePart, DamageSource source, float damage) {
            System.out.println(consolePart.partName);
            return false;
        }
    }

     

     

  21. I have tried the interact method, but I'm still not sure how to detect which part is being right clicked. Printing out items such as getCollisionBoundingBox and getEntityBoundingBox always return the same thing, regardless of which part on the entity is being clicked. I'm not sure how to differentiate between the boxes within the processInteract method.

×
×
  • Create New...

Important Information

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