Skip to content

Commit

Permalink
fix: prevent mode from being null in certain edge cases
Browse files Browse the repository at this point in the history
Closes #1103
  • Loading branch information
klikli-dev committed Mar 31, 2024
1 parent 550406d commit 40b533b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.klikli_dev.occultism.network.MessageSetItemMode;
import com.klikli_dev.occultism.network.MessageSetWorkAreaSize;
import com.klikli_dev.occultism.network.OccultismPackets;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -83,13 +82,13 @@ protected void init() {
Component.translatable(this.mode.translationKey()), (b) -> {
LocalPlayer player = Minecraft.getInstance().player;
ItemStack stack = player.getItemInHand(player.getUsedItemHand());
this.mode = stack.getItem() instanceof BookOfCallingItem ?
((BookOfCallingItem) stack.getItem()).nextItemMode(stack):null;
if(this.mode!=null)
{
OccultismPackets.sendToServer(new MessageSetItemMode(((BookOfCallingItem)stack.getItem()).modeValue(this.mode)));
this.init();
}

//go to the next mode, if the selected item somehow changed keep the old mode.
this.mode = stack.getItem() instanceof BookOfCallingItem bookOfCallingItem ?
bookOfCallingItem.nextItemMode(stack) : this.mode;

OccultismPackets.sendToServer(new MessageSetItemMode(((BookOfCallingItem) stack.getItem()).modeValue(this.mode)));
this.init();
})));

boolean showSize = this.mode.hasSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public static String getBoundSpiritName(ItemStack stack) {
}

public static int getItemMode(ItemStack stack) {
CompoundTag compound = stack.getTag();
if (!stack.getOrCreateTag().contains(ITEM_MODE_TAG))
setItemMode(stack, 0);

Expand Down

0 comments on commit 40b533b

Please sign in to comment.