diff --git a/src/main/java/malte0811/industrialWires/IWConfig.java b/src/main/java/malte0811/industrialWires/IWConfig.java index a38d408..d036129 100644 --- a/src/main/java/malte0811/industrialWires/IWConfig.java +++ b/src/main/java/malte0811/industrialWires/IWConfig.java @@ -30,7 +30,7 @@ public class IWConfig { @Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"}) public static boolean enableConversion = true; - public static MechConversion mech; + public static MechConversion mech = new MechConversion(); public static class MechConversion { @Comment({"The amount of EU that would be produced by an ideal converter from 1 IF (default: 0.25)"}) @@ -54,7 +54,7 @@ public class IWConfig { public static double kinToRotEfficiency = .8; } - public static HVStuff hv; + public static HVStuff hv = new HVStuff(); public static class HVStuff { @Comment({"The amount of EU a Jacobs Ladder uses per tick, sorted by size of the ladder"}) diff --git a/src/main/java/malte0811/industrialWires/client/gui/GuiRenameKey.java b/src/main/java/malte0811/industrialWires/client/gui/GuiRenameKey.java index e56f600..7a1abd7 100644 --- a/src/main/java/malte0811/industrialWires/client/gui/GuiRenameKey.java +++ b/src/main/java/malte0811/industrialWires/client/gui/GuiRenameKey.java @@ -45,11 +45,13 @@ public class GuiRenameKey extends GuiContainer { @Override public void initGui() { super.initGui(); - field = new GuiTextField(0, mc.fontRenderer, (width-58)/2, (height-12)/2, 58, 12); - ItemStack held = mc.player.getHeldItem(hand); - NBTTagCompound nbt = held.getTagCompound(); - if (nbt!=null&&nbt.hasKey("name")) { - field.setText(nbt.getString("name")); + field = new GuiTextField(0, mc.fontRendererObj, (width-58)/2, (height-12)/2, 58, 12); + ItemStack held = mc.thePlayer.getHeldItem(hand); + if (held!=null) { + NBTTagCompound nbt = held.getTagCompound(); + if (nbt != null && nbt.hasKey("name")) { + field.setText(nbt.getString("name")); + } } xSize = 64; ySize = 64; diff --git a/src/main/java/malte0811/industrialWires/controlpanel/Lock.java b/src/main/java/malte0811/industrialWires/controlpanel/Lock.java index b2e174b..cdabbd1 100644 --- a/src/main/java/malte0811/industrialWires/controlpanel/Lock.java +++ b/src/main/java/malte0811/industrialWires/controlpanel/Lock.java @@ -165,15 +165,15 @@ public class Lock extends PanelComponent implements IConfigurableComponent { if (keyNBT == null) { for (EnumHand hand : EnumHand.values()) { ItemStack held = player.getHeldItem(hand); - if (held.getItem() == IndustrialWires.key && ItemKey.idForKey(held) == lockID) { + if (held!=null && held.getItem() == IndustrialWires.key && ItemKey.idForKey(held) == lockID) { keyNBT = held.serializeNBT(); - player.setHeldItem(hand, ItemStack.EMPTY); + player.setHeldItem(hand, null); break; } } } else if (!turned) { - if (player.isSneaking() && player.getHeldItemMainhand().isEmpty()) { - player.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(keyNBT)); + if (player.isSneaking() && player.getHeldItemMainhand()== null) { + player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.loadItemStackFromNBT(keyNBT)); keyNBT = null; } else { turned = true; diff --git a/src/main/java/malte0811/industrialWires/crafting/RecipeKeyLock.java b/src/main/java/malte0811/industrialWires/crafting/RecipeKeyLock.java index 4955bff..5ceece5 100644 --- a/src/main/java/malte0811/industrialWires/crafting/RecipeKeyLock.java +++ b/src/main/java/malte0811/industrialWires/crafting/RecipeKeyLock.java @@ -25,10 +25,11 @@ import malte0811.industrialWires.items.ItemPanelComponent; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; import net.minecraft.world.World; import javax.annotation.Nonnull; +import javax.annotation.Nullable; + //TODO JEI public class RecipeKeyLock implements IRecipe { @@ -40,7 +41,11 @@ public class RecipeKeyLock implements IRecipe { @Nonnull @Override public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) { - ItemStack ret = getKey(inv).copy(); + ItemStack key = getKey(inv); + if (key==null) { + return null; + } + ItemStack ret = key.copy(); ItemKey.setId(ret, getLockId(inv)); return ret; } @@ -58,12 +63,12 @@ public class RecipeKeyLock implements IRecipe { @Nonnull @Override - public NonNullList getRemainingItems(@Nonnull InventoryCrafting inv) { - NonNullList ret = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY); - for (int i = 0; i < ret.size(); i++) { + public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) { + ItemStack[] ret = new ItemStack[inv.getSizeInventory()]; + for (int i = 0; i < ret.length; i++) { ItemStack here = inv.getStackInSlot(i); - if (here.getItem() == IndustrialWires.panelComponent) { - ret.set(i, here); + if (here!=null && here.getItem() == IndustrialWires.panelComponent) { + ret[i] = here; } } return ret; @@ -74,12 +79,12 @@ public class RecipeKeyLock implements IRecipe { boolean hasKey = false; for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack here = inv.getStackInSlot(i); - if (here.getItem() == IndustrialWires.key) { + if (here!=null && here.getItem() == IndustrialWires.key) { if (hasKey || ItemKey.idForKey(here) != 0) {//too many keys or non-blanks return 0; } hasKey = true; - } else if (here.getItem() == IndustrialWires.panelComponent) { + } else if (here != null && here.getItem() == IndustrialWires.panelComponent) { if (id != 0) {//too many locks/components return 0; } @@ -97,15 +102,15 @@ public class RecipeKeyLock implements IRecipe { return id; } - @Nonnull + @Nullable //assumes that the recipe is valid private ItemStack getKey(@Nonnull InventoryCrafting inv) { for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack here = inv.getStackInSlot(i); - if (here.getItem() == IndustrialWires.key) { + if (here!=null && here.getItem() == IndustrialWires.key) { return here; } } - return ItemStack.EMPTY; + return null; } } \ No newline at end of file diff --git a/src/main/java/malte0811/industrialWires/items/ItemIC2Coil.java b/src/main/java/malte0811/industrialWires/items/ItemIC2Coil.java index 9953d69..073d88e 100644 --- a/src/main/java/malte0811/industrialWires/items/ItemIC2Coil.java +++ b/src/main/java/malte0811/industrialWires/items/ItemIC2Coil.java @@ -40,7 +40,10 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagInt; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.TextComponentTranslation; diff --git a/src/main/java/malte0811/industrialWires/items/ItemKey.java b/src/main/java/malte0811/industrialWires/items/ItemKey.java index 1162f8c..846d372 100644 --- a/src/main/java/malte0811/industrialWires/items/ItemKey.java +++ b/src/main/java/malte0811/industrialWires/items/ItemKey.java @@ -86,13 +86,13 @@ public class ItemKey extends Item implements INetGUIItem { return 1; } - @Override @Nonnull - public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) { + @Override + public ActionResult onItemRightClick(@Nonnull ItemStack stack, World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) { if (!worldIn.isRemote) { playerIn.openGui(IndustrialWires.MODID, 1, worldIn, 0, 0, hand == EnumHand.MAIN_HAND ? 1 : 0); } - return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand)); + return new ActionResult<>(EnumActionResult.SUCCESS, stack); } @Override diff --git a/src/main/java/malte0811/industrialWires/network/MessageItemSync.java b/src/main/java/malte0811/industrialWires/network/MessageItemSync.java index 41eba0d..26d4f91 100644 --- a/src/main/java/malte0811/industrialWires/network/MessageItemSync.java +++ b/src/main/java/malte0811/industrialWires/network/MessageItemSync.java @@ -56,10 +56,10 @@ public class MessageItemSync implements IMessage { public static class HandlerServer implements IMessageHandler { @Override public IMessage onMessage(MessageItemSync message, MessageContext ctx) { - EntityPlayer player = ctx.getServerHandler().player; + EntityPlayer player = ctx.getServerHandler().playerEntity; ItemStack held = player.getHeldItem(message.hand); - if (held.getItem() instanceof INetGUIItem) { - ctx.getServerHandler().player.getServerWorld().addScheduledTask(() -> + if (held!=null && held.getItem() instanceof INetGUIItem) { + ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(() -> ((INetGUIItem)held.getItem()).onChange(message.data, player, message.hand)); } return null;