Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.demoxin.minecraft.moreenchants;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.ItemSword;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.potion.Potion;
- import net.minecraft.potion.PotionEffect;
- import net.minecraft.world.World;
- public class Item_MagicSword extends ItemSword
- {
- public ItemMagicSword(ToolMaterial p_i45356_1_) {
- super(p_i45356_1_);
- }
- public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
- {
- // Make sure we're not going to get any NPEs by working on a tag compound that doesn't exist
- if(!par1ItemStack.hasTagCompound())
- {
- // Create the tag compound
- par1ItemStack.setTagCompound(new NBTTagCompound());
- }
- // If we don't already have the tag set, we need to create it. Our tag name is katanaInvis
- if(!par1ItemStack.getTagCompound().hasKey("katanaInvis"))
- {
- // Create the initial tag.
- par1ItemStack.getTagCompound().setBoolean("katanaInvis", true);
- }
- else
- {
- // Toggle the true/false value of the tag.
- par1ItemStack.getTagCompound().setBoolean("katanaInvis", !par1ItemStack.getTagCompound().getBoolean("katanaInvis"));
- }
- // Return the sword to reflect the changes
- return par1ItemStack;
- }
- public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
- {
- // Make sure we're gonna be able to cast safely.
- if(!(par3Entity instanceof EntityLivingBase))
- return;
- // Cast the basic Entity to a more specific EntityLivingBase, used for players and mobs
- EntityLivingBase user = (EntityLivingBase)par3Entity;
- // Make sure the ELB is holding an item.
- if(user.getHeldItem() == null)
- return;
- // Make sure the item they're holding is this one.
- if(user.getHeldItem().getItem() != this)
- return;
- // If there's no tag compound, we can assume they haven't ever toggled invisibility on, so no need to test any further.
- if(!par1ItemStack.hasTagCompound())
- return;
- // Make sure the key is valid to avoid NPEs, then check for that value.
- if(par1ItemStack.getTagCompound().hasKey("katanaInvis") && par1ItemStack.getTagCompound().getBoolean("katanaInvis") == true)
- {
- // The katanaInvis tag is true, add the effect for 1 second.
- user.addPotionEffect(new PotionEffect(Potion.invisibility.id, 20, 1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement