Skip to content

Commit

Permalink
Don't crash if, somehow, no book data was registered
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickMG authored and Dream-Master committed Jan 28, 2024
1 parent f741fe5 commit 1bbd5c9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/tconstruct/tools/items/Manual.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tconstruct.tools.items;

import java.util.List;
import java.util.Objects;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -41,22 +42,25 @@ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer pla

@SideOnly(Side.CLIENT)
public void openBook(ItemStack stack, World world, EntityPlayer player) {
player.openGui(TConstruct.instance, mantle.client.MProxyClient.manualGuiID, world, 0, 0, 0);
FMLClientHandler.instance().displayGuiScreen(player, new GuiManual(stack, getData(stack)));
BookData data = BookDataStore.getBookfromName(TConstruct.modID, getBookName(stack.getItemDamage()));
if (Objects.nonNull(data)) {
player.openGui(TConstruct.instance, mantle.client.MProxyClient.manualGuiID, world, 0, 0, 0);
FMLClientHandler.instance().displayGuiScreen(player, new GuiManual(stack, data));
}
}

private BookData getData(ItemStack stack) {
switch (stack.getItemDamage()) {
private static String getBookName(int bookItemDamage) {
switch (bookItemDamage) {
case 0:
return BookDataStore.getBookfromName(TConstruct.modID, "tconstruct.manual.beginner");
return "tconstruct.manual.beginner";
case 1:
return BookDataStore.getBookfromName(TConstruct.modID, "tconstruct.manual.toolstation");
return "tconstruct.manual.toolstation";
case 2:
return BookDataStore.getBookfromName(TConstruct.modID, "tconstruct.manual.smeltery");
return "tconstruct.manual.smeltery";
case 4:
return BookDataStore.getBookfromName(TConstruct.modID, "tconstruct.manual.weaponry");
return "tconstruct.manual.weaponry";
default:
return BookDataStore.getBookfromName(TConstruct.modID, "tconstruct.manual.diary");
return "tconstruct.manual.diary";
}
}

Expand Down

0 comments on commit 1bbd5c9

Please sign in to comment.