Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.techmage.magetech.item;
- import com.techmage.magetech.reference.Names;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.potion.Potion;
- import net.minecraft.potion.PotionEffect;
- import net.minecraft.world.World;
- public class ItemTalismanWater extends ItemMageTech_Magic
- {
- public ItemTalismanWater()
- {
- super();
- this.setUnlocalizedName(Names.Items.TALISMAN_WATER);
- this.setMaxStackSize(1);
- }
- @Override
- public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
- {
- // Only active on the server
- if (!worldIn.isRemote)
- {
- // Check if the item has a tagCompound
- if (itemStackIn.hasTagCompound())
- {
- // Set the items tagCompound's key "activated" to true
- itemStackIn.getTagCompound().setBoolean("activated", true);
- }
- // Create a new tagCompound for the item and set it's key "activated" to true
- else
- {
- itemStackIn.setTagCompound(new NBTTagCompound());
- itemStackIn.getTagCompound().setBoolean("activated", true);
- }
- }
- return itemStackIn;
- }
- @Override
- public void onUpdate(ItemStack itemStackIn, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
- {
- // Only active on the server
- if (!worldIn.isRemote)
- {
- // Check if the entity holding the item a a player
- if (entityIn instanceof EntityPlayer)
- {
- // Check if the item has a tagCompound
- if (itemStackIn.hasTagCompound())
- {
- // Check if the "passive" key is true
- if (itemStackIn.getTagCompound().getBoolean("activated"))
- {
- // Check if the player is in water
- if (entityIn.isInWater())
- {
- // Set the items tagCompound's key "buffed" to true
- itemStackIn.getTagCompound().setBoolean("buffed", true);
- // Set the items tagCompound's key "activated" to false
- itemStackIn.getTagCompound().setBoolean("activated", false);
- EntityPlayer player = ((EntityPlayer) entityIn);
- // Add Effects to the player
- player.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, Integer.MAX_VALUE, 0));
- player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, Integer.MAX_VALUE, 0));
- player.addPotionEffect(new PotionEffect(Potion.nightVision.id, Integer.MAX_VALUE, 0));
- }
- }
- // Check if the "buffed" key is true
- if (itemStackIn.getTagCompound().getBoolean("buffed"))
- {
- if (!entityIn.isInWater())
- {
- EntityPlayer player = ((EntityPlayer) entityIn);
- // Remove Effects from the player
- player.removePotionEffect(Potion.waterBreathing.getId());
- player.removePotionEffect(Potion.damageBoost.getId());
- player.removePotionEffect(Potion.nightVision.getId());
- // Set the "buffed" key to false
- itemStackIn.getTagCompound().setBoolean("buffed", false);
- }
- }
- }
- }
- }
- }
- @Override
- public boolean hasEffect(ItemStack itemStackIn)
- {
- // Check if the item has a tagCompound
- if (itemStackIn.hasTagCompound())
- {
- // Check if there is a "activated" or a "buffed" key
- if (itemStackIn.getTagCompound().hasKey("activated") || itemStackIn.getTagCompound().hasKey("buffed"))
- {
- // Return true whether "activated" or "buffed" is true
- return itemStackIn.getTagCompound().getBoolean("activated") || itemStackIn.getTagCompound().getBoolean("buffed");
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement