From 00d3dc3a47ed484d4c6e698b353f912eaf383f87 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Wed, 31 Jan 2018 11:02:22 -0600 Subject: [PATCH] Minor bugfixes on spawner mover --- .../botania/common/item/ItemSpawnerMover.java | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/main/java/vazkii/botania/common/item/ItemSpawnerMover.java b/src/main/java/vazkii/botania/common/item/ItemSpawnerMover.java index 689f756dd..fb34f50cf 100644 --- a/src/main/java/vazkii/botania/common/item/ItemSpawnerMover.java +++ b/src/main/java/vazkii/botania/common/item/ItemSpawnerMover.java @@ -21,6 +21,7 @@ import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityMobSpawner; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; @@ -44,7 +45,6 @@ import java.util.List; public class ItemSpawnerMover extends ItemMod { public static final String TAG_SPAWNER = "spawner"; - private static final String TAG_PLACE_DELAY = "placeDelay"; public ItemSpawnerMover() { super(LibItemNames.SPAWNER_MOVER); @@ -76,14 +76,6 @@ public class ItemSpawnerMover extends ItemMod { return getEntityId(stack) != null; } - private static int getDelay(ItemStack stack) { - NBTTagCompound tag = stack.getTagCompound(); - if(tag != null) - return tag.getInteger(TAG_PLACE_DELAY); - - return 0; - } - @SideOnly(Side.CLIENT) @Override public void addInformation(ItemStack stack, World world, List infoList, ITooltipFlag flags) { @@ -92,13 +84,6 @@ public class ItemSpawnerMover extends ItemMod { infoList.add(I18n.format("entity." + id + ".name")); } - @Override - public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { - NBTTagCompound tag = stack.getTagCompound(); - if(tag != null && tag.hasKey(TAG_PLACE_DELAY) && tag.getInteger(TAG_PLACE_DELAY) > 0) - tag.setInteger(TAG_PLACE_DELAY, tag.getInteger(TAG_PLACE_DELAY) - 1); - } - @Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xOffset, float yOffset, float zOffset) { @@ -110,12 +95,12 @@ public class ItemSpawnerMover extends ItemMod { NBTTagCompound tag = new NBTTagCompound(); tag.setTag(TAG_SPAWNER, new NBTTagCompound()); te.writeToNBT(tag.getCompoundTag(TAG_SPAWNER)); - tag.setInteger(TAG_PLACE_DELAY, 20); + player.getCooldownTracker().setCooldown(this, 20); itemstack.setTagCompound(tag); world.setBlockToAir(pos); UseItemSuccessTrigger.INSTANCE.trigger((EntityPlayerMP) player, itemstack, (WorldServer) world, pos.getX(), pos.getY(), pos.getZ()); - } else { player.renderBrokenItemStack(itemstack); + } else { for(int i = 0; i < 50; i++) { float red = (float) Math.random(); float green = (float) Math.random(); @@ -126,7 +111,7 @@ public class ItemSpawnerMover extends ItemMod { return EnumActionResult.SUCCESS; } else return EnumActionResult.PASS; } else { - return getDelay(itemstack) <= 0 && placeBlock(itemstack, player, world, pos, side, xOffset, yOffset, zOffset) ? EnumActionResult.SUCCESS : EnumActionResult.PASS; + return placeBlock(itemstack, player, world, pos, side, xOffset, yOffset, zOffset) ? EnumActionResult.SUCCESS : EnumActionResult.PASS; } } @@ -167,16 +152,17 @@ public class ItemSpawnerMover extends ItemMod { return false; Block block = world.getBlockState(pos).getBlock(); - if(block.equals(Blocks.MOB_SPAWNER)) { + if(block == Blocks.MOB_SPAWNER) { TileEntity te = world.getTileEntity(pos); NBTTagCompound tag = stack.getTagCompound(); - if (tag.hasKey(TAG_SPAWNER)) + if (te instanceof TileEntityMobSpawner && tag.hasKey(TAG_SPAWNER)) { tag = tag.getCompoundTag(TAG_SPAWNER); - tag.setInteger("x", pos.getX()); - tag.setInteger("y", pos.getY()); - tag.setInteger("z", pos.getZ()); - te.readFromNBT(tag); - VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos); + tag.setInteger("x", pos.getX()); + tag.setInteger("y", pos.getY()); + tag.setInteger("z", pos.getZ()); + te.readFromNBT(tag); + VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos); + } } return true;