aboutsummaryrefslogtreecommitdiff
path: root/GuiTest/src
diff options
context:
space:
mode:
authorJuuxel <kasperi.kauppi@gmail.com>2020-06-24 17:51:37 +0300
committerJuuxel <kasperi.kauppi@gmail.com>2020-06-24 17:51:37 +0300
commitadc9b7199268ffe57b631a89e4bb2c327a02d615 (patch)
tree1ec43a22ae5a83aa0d73f973c476416a123e11d8 /GuiTest/src
parent30ce0f093d90dd979ad5fab5c86bb21338265c55 (diff)
downloadLibGui-adc9b7199268ffe57b631a89e4bb2c327a02d615.tar.gz
LibGui-adc9b7199268ffe57b631a89e4bb2c327a02d615.tar.bz2
LibGui-adc9b7199268ffe57b631a89e4bb2c327a02d615.zip
Fix dedicated server crash with the test mod
Diffstat (limited to 'GuiTest/src')
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/GuiItem.java11
1 files 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<ItemStack> 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<ItemStack>(ActionResult.SUCCESS, (hand==Hand.MAIN_HAND) ? player.getMainHandStack() : player.getOffHandStack());
}
+
+ @Environment(EnvType.CLIENT)
+ private void openScreen() {
+ MinecraftClient.getInstance().openScreen(new CottonClientScreen(new TestClientGui()));
+ }
}