diff --git a/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemMagnetRing.java b/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemMagnetRing.java index 97b95c7c1..b42edb994 100644 --- a/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemMagnetRing.java +++ b/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemMagnetRing.java @@ -13,43 +13,94 @@ package vazkii.botania.common.item.equipment.bauble; import java.util.List; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.item.ItemTossEvent; +import vazkii.botania.client.core.helper.IconHelper; import vazkii.botania.common.Botania; +import vazkii.botania.common.core.helper.ItemNBTHelper; import vazkii.botania.common.core.helper.MathHelper; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.lib.LibItemNames; import baubles.api.BaubleType; +import baubles.common.container.InventoryBaubles; +import baubles.common.lib.PlayerHandler; public class ItemMagnetRing extends ItemBauble { + IIcon iconOff; + + private static final String TAG_COOLDOWN = "cooldown"; + public ItemMagnetRing() { super(LibItemNames.MAGNET_RING); + MinecraftForge.EVENT_BUS.register(this); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister par1IconRegister) { + itemIcon = IconHelper.forItem(par1IconRegister, this, 0); + iconOff = IconHelper.forItem(par1IconRegister, this, 1); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIconIndex(ItemStack stack) { + return getCooldown(stack) <= 0 ? itemIcon : iconOff; + } + + @SubscribeEvent + public void onTossItem(ItemTossEvent event) { + InventoryBaubles inv = PlayerHandler.getPlayerBaubles(event.player); + for(int i = 0; i < inv.getSizeInventory(); i++) { + ItemStack stack = inv.getStackInSlot(i); + if(stack != null && stack.getItem() == this) + setCooldown(stack, 100); + } } @Override public void onWornTick(ItemStack stack, EntityLivingBase player) { super.onWornTick(stack, player); - if(player.isSneaking()) { - int range = 6; - double x = player.posX; - double y = player.posY -(player.worldObj.isRemote ? 1.62 : 0) + 0.75; - double z = player.posZ; + int cooldown = getCooldown(stack); + + if(cooldown <= 0) { + if(!player.isSneaking()) { + int range = 6; + double x = player.posX; + double y = player.posY -(player.worldObj.isRemote ? 1.62 : 0) + 0.75; + double z = player.posZ; - List items = player.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x - range, y - range, z - range, x + range, y + range, z + range)); - for(EntityItem item : items) { - MathHelper.setEntityMotionFromVector(item, new Vector3(x, y, z), 0.45F); - if(player.worldObj.isRemote) { - boolean red = player.worldObj.rand.nextBoolean(); - Botania.proxy.sparkleFX(player.worldObj, item.posX, item.posY, item.posZ, red ? 1F : 0F, 0F, red ? 0F : 1F, 1F, 3); + List items = player.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x - range, y - range, z - range, x + range, y + range, z + range)); + for(EntityItem item : items) { + MathHelper.setEntityMotionFromVector(item, new Vector3(x, y, z), 0.45F); + if(player.worldObj.isRemote) { + boolean red = player.worldObj.rand.nextBoolean(); + Botania.proxy.sparkleFX(player.worldObj, item.posX, item.posY, item.posZ, red ? 1F : 0F, 0F, red ? 0F : 1F, 1F, 3); + } } } - } + } else setCooldown(stack, cooldown - 1); } + public static int getCooldown(ItemStack stack) { + return ItemNBTHelper.getInt(stack, TAG_COOLDOWN, 0); + } + + public static void setCooldown(ItemStack stack, int cooldown) { + ItemNBTHelper.setInt(stack, TAG_COOLDOWN, cooldown); + } + @Override public BaubleType getBaubleType(ItemStack arg0) { return BaubleType.RING; diff --git a/resources/assets/botania/lang/en_US.lang b/resources/assets/botania/lang/en_US.lang index a84d683f6..9f499db72 100644 --- a/resources/assets/botania/lang/en_US.lang +++ b/resources/assets/botania/lang/en_US.lang @@ -1499,7 +1499,7 @@ botania.page.miningRing1=Diggy diggy hole # -- RING OF MAGNETIZATION botania.entry.magnetRing=Ring of Magnetization -botania.page.magnetRing0=By turning a &1Magnetizing Lens&0 into a wearable ring, one can use it to magnetize nearby items.
While equipped, this ring will make any nearby items magnetize towards the wearer if they're sneaking. +botania.page.magnetRing0=By turning a &1Magnetizing Lens&0 into a wearable ring, one can use it to magnetize nearby items. While equipped, this ring will make any nearby items magnetize towards the wearer if they're not sneaking.
A notable feature of this piece is that it'll negate its effect for 5 seconds after the wearer tosses an item so as to not interfere with whatever means it was tossed for. botania.page.magnetRing1=How do they work? # -- RING OF FAR REACH diff --git a/resources/assets/botania/textures/items/magnetRing.png b/resources/assets/botania/textures/items/magnetRing0.png similarity index 100% rename from resources/assets/botania/textures/items/magnetRing.png rename to resources/assets/botania/textures/items/magnetRing0.png diff --git a/resources/assets/botania/textures/items/magnetRing1.png b/resources/assets/botania/textures/items/magnetRing1.png new file mode 100644 index 000000000..55e0953cf Binary files /dev/null and b/resources/assets/botania/textures/items/magnetRing1.png differ