mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 00:07:37 +00:00
Better fix for #312, null checking for the chisel item in the GUI
This commit is contained in:
1 parent
daf95276af
commit
74bb2b700d
5 files changed
+11
-8
No files matched your search
@@ -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
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user