From cff54cda62935ff91a72152b9209bbaf5652474b Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Thu, 28 May 2015 13:42:07 -0400 Subject: [PATCH] Better fix for #312, null checking for the chisel item in the GUI --- src/main/java/com/cricketcraft/chisel/api/IMC.java | 5 +++-- .../com/cricketcraft/chisel/inventory/ContainerChisel.java | 2 +- .../cricketcraft/chisel/item/chisel/ChiselController.java | 2 +- .../com/cricketcraft/chisel/network/ChiselGuiHandler.java | 6 ++---- src/main/java/com/cricketcraft/chisel/utils/General.java | 4 ++++ 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cricketcraft/chisel/api/IMC.java b/src/main/java/com/cricketcraft/chisel/api/IMC.java index e19dcdf1..17cf57fe 100644 --- a/src/main/java/com/cricketcraft/chisel/api/IMC.java +++ b/src/main/java/com/cricketcraft/chisel/api/IMC.java @@ -1,8 +1,9 @@ package com.cricketcraft.chisel.api; - /** * Use the enum constants (using {@link #key} or calling {@link #toString()}) in this class as keys for IMC messages sent to chisel + *

+ * It is also acceptable to copy the Strings in this class to avoid referencing this API. */ public enum IMC { @@ -56,7 +57,7 @@ public enum IMC { */ @Deprecated public static final String CHISEL_MODID = "chisel"; - + public static final String getModid() { return ChiselAPIProps.MOD_ID; } diff --git a/src/main/java/com/cricketcraft/chisel/inventory/ContainerChisel.java b/src/main/java/com/cricketcraft/chisel/inventory/ContainerChisel.java index 93cd72af..114b11cb 100644 --- a/src/main/java/com/cricketcraft/chisel/inventory/ContainerChisel.java +++ b/src/main/java/com/cricketcraft/chisel/inventory/ContainerChisel.java @@ -50,7 +50,7 @@ public class ContainerChisel extends Container { } chisel = inventoryplayer.getCurrentItem(); - if (chisel.stackTagCompound != null) { + if (chisel != null && chisel.stackTagCompound != null) { ItemStack stack = ItemStack.loadItemStackFromNBT(chisel.stackTagCompound.getCompoundTag("chiselTarget")); inventory.setInventorySlotContents(InventoryChiselSelection.normalSlots, stack); } diff --git a/src/main/java/com/cricketcraft/chisel/item/chisel/ChiselController.java b/src/main/java/com/cricketcraft/chisel/item/chisel/ChiselController.java index 72f5fb53..c0aa31d3 100644 --- a/src/main/java/com/cricketcraft/chisel/item/chisel/ChiselController.java +++ b/src/main/java/com/cricketcraft/chisel/item/chisel/ChiselController.java @@ -105,7 +105,7 @@ public final class ChiselController { } else { lastTickClick = event.world.getTotalWorldTime(); } - if (!event.world.isRemote && chisel.canOpenGui(event.world, event.entityPlayer, held) && event.world.getTileEntity(event.x, event.y, event.z) == null) { + if (!event.world.isRemote && chisel.canOpenGui(event.world, event.entityPlayer, held)) { event.entityPlayer.openGui(Chisel.instance, 0, event.world, 0, 0, 0); } break; diff --git a/src/main/java/com/cricketcraft/chisel/network/ChiselGuiHandler.java b/src/main/java/com/cricketcraft/chisel/network/ChiselGuiHandler.java index 5283737c..002b357a 100644 --- a/src/main/java/com/cricketcraft/chisel/network/ChiselGuiHandler.java +++ b/src/main/java/com/cricketcraft/chisel/network/ChiselGuiHandler.java @@ -22,8 +22,7 @@ public class ChiselGuiHandler implements IGuiHandler { public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: - if (player.getCurrentEquippedItem() != null) - return new ContainerChisel(player.inventory, new InventoryChiselSelection(player.getCurrentEquippedItem())); + return new ContainerChisel(player.inventory, new InventoryChiselSelection(player.getCurrentEquippedItem())); case 1: TileEntity tileentity = world.getTileEntity(x, y, z); if (tileentity instanceof TileEntityAutoChisel) @@ -41,8 +40,7 @@ public class ChiselGuiHandler implements IGuiHandler { public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 0: - if (player.getCurrentEquippedItem() != null) - return new GuiChisel(player.inventory, new InventoryChiselSelection(player.getCurrentEquippedItem())); + return new GuiChisel(player.inventory, new InventoryChiselSelection(player.getCurrentEquippedItem())); case 1: TileEntity tileentity = world.getTileEntity(x, y, z); if (tileentity instanceof TileEntityAutoChisel) diff --git a/src/main/java/com/cricketcraft/chisel/utils/General.java b/src/main/java/com/cricketcraft/chisel/utils/General.java index 97938ae1..174a28a8 100644 --- a/src/main/java/com/cricketcraft/chisel/utils/General.java +++ b/src/main/java/com/cricketcraft/chisel/utils/General.java @@ -126,6 +126,10 @@ public class General { private static final String MODE_KEY = "chiselMode"; public static IChiselMode getChiselMode(ItemStack chisel) { + if (chisel == null) { + return ChiselMode.SINGLE; + } + if (chisel.stackTagCompound == null || Strings.isNullOrEmpty(chisel.stackTagCompound.getString(MODE_KEY))) { initTag(chisel); chisel.stackTagCompound.setString(MODE_KEY, ChiselMode.SINGLE.name());