fix crash on server

uggggh i hate classloading
This commit is contained in:
yrsegal@gmail.com 2022-04-09 13:21:26 -04:00
parent 505e48d4e4
commit 225f97d8a4
2 changed files with 18 additions and 8 deletions

View file

@ -0,0 +1,14 @@
package at.petrak.hexcasting.common.network;
import at.petrak.hexcasting.client.gui.GuiSpellcasting;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public record GuiOpener(MsgOpenSpellGuiAck msg) {
@OnlyIn(Dist.CLIENT)
public void open() {
var mc = Minecraft.getInstance();
mc.setScreen(new GuiSpellcasting(msg.hand(), msg.patterns(), msg.components()));
}
}

View file

@ -1,9 +1,7 @@
package at.petrak.hexcasting.common.network;
import at.petrak.hexcasting.client.gui.GuiSpellcasting;
import at.petrak.hexcasting.common.casting.ResolvedPattern;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
@ -57,12 +55,10 @@ public record MsgOpenSpellGuiAck(InteractionHand hand, List<ResolvedPattern> pat
}
public void handle(Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() ->
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
var mc = Minecraft.getInstance();
mc.setScreen(new GuiSpellcasting(hand, patterns, components));
})
);
ctx.get().enqueueWork(() -> {
GuiOpener opener = new GuiOpener(this);
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> opener::open);
});
ctx.get().setPacketHandled(true);
}