From 900d2cdbb01ef90e5bb42fe413c6d9f2543bfca0 Mon Sep 17 00:00:00 2001 From: TimeBather Date: Thu, 28 Nov 2024 12:09:03 +0800 Subject: [PATCH] fix: invalid dist on DEDICATED_SERVER (#15) in AllExampleElements --- .../kasuga/lib/example_env/AllExampleElements.java | 5 ++--- .../lib/example_env/OperateScreenCommand.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/main/java/kasuga/lib/example_env/OperateScreenCommand.java diff --git a/src/main/java/kasuga/lib/example_env/AllExampleElements.java b/src/main/java/kasuga/lib/example_env/AllExampleElements.java index 50b972dd..d2222158 100644 --- a/src/main/java/kasuga/lib/example_env/AllExampleElements.java +++ b/src/main/java/kasuga/lib/example_env/AllExampleElements.java @@ -42,6 +42,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.SoundAction; import net.minecraftforge.common.SoundActions; +import net.minecraftforge.fml.DistExecutor; public class AllExampleElements { @@ -182,9 +183,7 @@ public class AllExampleElements { .setHandler(new CommandHandler() { @Override public void run() { - RenderSystem.recordRenderCall(()->{ - Minecraft.getInstance().setScreen(new GuiOperatingPerspectiveScreen()); - }); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, ()->OperateScreenCommand::invoke); } }) .submit(REGISTRY); diff --git a/src/main/java/kasuga/lib/example_env/OperateScreenCommand.java b/src/main/java/kasuga/lib/example_env/OperateScreenCommand.java new file mode 100644 index 00000000..0e2e4c9b --- /dev/null +++ b/src/main/java/kasuga/lib/example_env/OperateScreenCommand.java @@ -0,0 +1,13 @@ +package kasuga.lib.example_env; + +import com.mojang.blaze3d.systems.RenderSystem; +import kasuga.lib.core.client.interaction.GuiOperatingPerspectiveScreen; +import net.minecraft.client.Minecraft; + +public class OperateScreenCommand { + public static void invoke(){ + RenderSystem.recordRenderCall(()->{ + Minecraft.getInstance().setScreen(new GuiOperatingPerspectiveScreen()); + }); + } +}