From 46aa5a0fb5f978eda50c4e7182b293cb0d759442 Mon Sep 17 00:00:00 2001 From: Progwml6 Date: Fri, 28 Mar 2014 01:37:13 -0400 Subject: [PATCH] fix npe in potionlauncher closes #537 --- .../items/tools/PotionLauncher.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/tconstruct/items/tools/PotionLauncher.java b/src/main/java/tconstruct/items/tools/PotionLauncher.java index 8fa0b4fb..6b7e19ae 100644 --- a/src/main/java/tconstruct/items/tools/PotionLauncher.java +++ b/src/main/java/tconstruct/items/tools/PotionLauncher.java @@ -135,24 +135,27 @@ public class PotionLauncher extends Item @Override public boolean onEntitySwing (EntityLivingBase player, ItemStack stack) { - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - if (tags.getBoolean("Loaded")) + if (stack != null && stack.hasTagCompound()) { - NBTTagCompound potionTag = tags.getCompoundTag("LoadedPotion"); - ItemStack potion = ItemStack.loadItemStackFromNBT(potionTag);// findPotion(player);InventoryLogic - if (potion != null) + NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); + if (tags.getBoolean("Loaded")) { - World world = player.worldObj; - world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); - - if (!world.isRemote) + NBTTagCompound potionTag = tags.getCompoundTag("LoadedPotion"); + ItemStack potion = ItemStack.loadItemStackFromNBT(potionTag);// findPotion(player);InventoryLogic + if (potion != null) { - world.spawnEntityInWorld(new LaunchedPotion(world, player, potion)); + World world = player.worldObj; + world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); + + if (!world.isRemote) + { + world.spawnEntityInWorld(new LaunchedPotion(world, player, potion)); + } + tags.removeTag("LoadedPotion"); + tags.setBoolean("Loaded", false); } - tags.removeTag("LoadedPotion"); - tags.setBoolean("Loaded", false); + return true; } - return true; } return false; }