Jump to content

[1.7.10]store damage in nbt


denbukki

Recommended Posts

i have this growth amulet it has an max damge but i want to use the meta data for an ative and an non aactive version. mayby nbt or something i have no clue

 

public class ItemAmuletGrowth extends ItemBaubles {

public ItemAmuletGrowth(){
	this.setUnlocalizedName("ItemAmuletGrowth");
    setMaxDamage(1001);
this.canRepair = true;

}

 private int tickDelay = 100;
@Override
public BaubleType getBaubleType(ItemStack arg0) {
	return BaubleType.AMULET;
}


@Override
public void onWornTick(ItemStack stack, EntityLivingBase entity) {
	  {

		  World par2World = entity.worldObj;
	        if (!(entity instanceof EntityPlayer))
	        {
	            return;
	        }

	        EntityPlayer par3EntityPlayer = (EntityPlayer) entity;
	      
	        if (stack.stackTagCompound == null)
	        {
	        	stack.setTagCompound(new NBTTagCompound());
	        }
	        {
	            if (par2World.getWorldTime() % tickDelay == stack.stackTagCompound.getInteger("worldTimeDelay") && entity instanceof EntityPlayer)
	            {
	            	
	            }

	            int range = 5;
	            int verticalRange = 2;
	            int posX = (int) Math.round(entity.posX - 0.5f);
	            int posY = (int) entity.posY;
	            int posZ = (int) Math.round(entity.posZ - 0.5f);

	            for (int ix = posX - range; ix <= posX + range; ix++)
	            {
	                for (int iz = posZ - range; iz <= posZ + range; iz++)
	                {
	                    for (int iy = posY - verticalRange; iy <= posY + verticalRange; iy++)
	                    {
	                        Block block = par2World.getBlock(ix, iy, iz);
	                        

	                        if (block instanceof IPlantable)
	                        {
	                        	
	                            if (par2World.rand.nextInt(20) == 0)
	                            {
	                            	
	                            	
	                            	
	                                block.updateTick(par2World, ix, iy, iz, par2World.rand);
	                                
	                                if (par2World.rand.nextInt(100) == 0){
	                                	stack.damageItem(1, par3EntityPlayer);
	                                }
	                               
	                            }
	                        }
	                    }
	                }
	            }
	        }

	        return;
	     
	    }
}
  
	   



}


[code/]

Link to comment
Share on other sites

I would use the normal item damage for the damage and the state of on and off with NBT

 

well i got it working with on item right click but i want to do it with an key bind but i cant figure it out it got this

 

 

@SubscribeEvent
    public void onKey(KeyInputEvent evt) {
    	
        boolean toggle = keyToggle.isPressed();
        ItemStack stack = new ItemStack (BaubleliciousItems.ItemAmuletGrowth);
  
      
        if (toggle) {
            if (mc.inGameHasFocus) {

        	        if (stack.stackTagCompound == null)
        	        {
        	        	stack.setTagCompound(new NBTTagCompound());
        	        }

        	        NBTTagCompound tag = stack.stackTagCompound;
        	        tag.setBoolean("isActive", (tag.getBoolean("isActive")));

        	        if (tag.getBoolean("isActive"))
        	        {
        	           System.out.print("yay");
        	         //  tag.setBoolean("isActive",true);
        	            
        	            
        	        } else
        	        {
        	        	System.out.print("nah");
        	        	// tag.setBoolean("isActive",false);
        	        }

        	    }
            return;
                    
                }
            }
        
    }
[code/]

Link to comment
Share on other sites

First of all: You're just creating a new ItemStack and then don't do anything with that. This will not do anything at all.

Then: KeyHandlers are client-only. For things like this you'll need to send a packet when the key is pressed and then do the actions on the server.

 

ok Thanks i will take a look at it

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.