Skip to content

Commit

Permalink
fix: fix crash on server startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Apr 11, 2023
1 parent accecf4 commit 4988deb
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.PlayState;
Expand Down Expand Up @@ -64,15 +66,20 @@ public InteractionResultHolder<ItemStack> use(Level level, Player player, Intera
ItemStack stack = player.getItemInHand(usedHand);

if (level.isClientSide) {
boolean canOpenBook = ModsCompatHandler.getModonomiconHelper().openBook(GUIDE_BOOK_ID);
if (!canOpenBook && player instanceof LocalPlayer localPlayer) {
Minecraft.getInstance().setScreen(new AdvancementsScreen(localPlayer.connection.getAdvancements())); //fallback
}
tryToOpenClientScreen(player);
}

return InteractionResultHolder.sidedSuccess(stack, level.isClientSide);
}

@OnlyIn(Dist.CLIENT)
private void tryToOpenClientScreen(Player player) {
boolean canOpenBook = ModsCompatHandler.getModonomiconHelper().openBook(GUIDE_BOOK_ID);
if (!canOpenBook && player instanceof LocalPlayer localPlayer) {
Minecraft.getInstance().setScreen(new AdvancementsScreen(localPlayer.connection.getAdvancements())); //fallback
}
}

@Override
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
if (level.isClientSide) return;
Expand Down

0 comments on commit 4988deb

Please sign in to comment.