From adc9b7199268ffe57b631a89e4bb2c327a02d615 Mon Sep 17 00:00:00 2001 From: Juuxel Date: Wed, 24 Jun 2020 17:51:37 +0300 Subject: Fix dedicated server crash with the test mod --- GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java b/GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java index b777361..699c38e 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java @@ -2,6 +2,8 @@ package io.github.cottonmc.test; import io.github.cottonmc.cotton.gui.client.CottonClientScreen; import io.github.cottonmc.test.client.TestClientGui; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; @@ -21,10 +23,15 @@ public class GuiItem extends Item { @Override public TypedActionResult use(World world, PlayerEntity player, Hand hand) { - if (world.isClient) { - MinecraftClient.getInstance().openScreen(new CottonClientScreen(new TestClientGui())); + if (world.isClient) { + openScreen(); // In its own method to prevent class loading issues } return new TypedActionResult(ActionResult.SUCCESS, (hand==Hand.MAIN_HAND) ? player.getMainHandStack() : player.getOffHandStack()); } + + @Environment(EnvType.CLIENT) + private void openScreen() { + MinecraftClient.getInstance().openScreen(new CottonClientScreen(new TestClientGui())); + } } -- cgit