Jump to content

[1.7.10] Prevent Item in Hand From "Bouncing" When Durability Changes?


Izzy Axel

Recommended Posts

The constant bouncing (item in hand moving up and down) when using durability as a timer is pretty annoying and looks bad, is there a way to keep it from doing this?

 

This applies to most of the items I'm making, so here's an example of one of the item classes that needs it:

 

public class ItemAirTalisman extends ItemArcaneArtifact
{
IIcon[] icons;
public ItemAirTalisman()
{
	super();
	setUnlocalizedName("airTalisman");
	setTextureName(Reference.MODID + ":" + getUnlocalizedName().substring(5));
	setMaxStackSize(1);
	setMaxDamage(512);
}

@Override
public void registerIcons(IIconRegister iconRegister)
{
	icons = new IIcon[512];
	for(int i = 0; i < icons.length; i++)
	{
		icons[i] = iconRegister.registerIcon(Reference.MODID + ":" + (this.getUnlocalizedName().substring(5)) + i);
	}
}

@Override
public IIcon getIconFromDamage(int index)
{
	return icons[index];
}


@Override
public void onCreated(ItemStack stack, World world, EntityPlayer player)
{
	if(!NBTHelper.hasNBT(stack))
	{
		NBTHelper.initNBT(stack);
		NBTHelper.setInt(stack, "Damage", 0);
		NBTHelper.setBool(stack, "Active", false);
		NBTHelper.setBool(stack, "Recharging", false);
		NBTHelper.setBool(stack, "Used", false);
	}
}


@Override
public void onUpdate(ItemStack stack, World world, Entity player, int slot, boolean hahanope)
{
	if(!NBTHelper.hasNBT(stack))
	{
		NBTHelper.initNBT(stack);
		NBTHelper.setInt(stack, "Damage", 0);
		NBTHelper.setBool(stack, "Active", false);
		NBTHelper.setBool(stack, "Recharging", false);
		NBTHelper.setBool(stack, "Used", false);
	}

	if(NBTHelper.hasNBT(stack))
	{
		if(player.isInWater())
		{
			NBTHelper.setBool(stack, "Active", true);
		}
		else
		{
			NBTHelper.setBool(stack, "Active", false);
		}


		if(NBTHelper.getBool(stack, "Active") && !NBTHelper.getBool(stack, "Recharging") && !NBTHelper.getBool(stack, "Used") && NBTHelper.getInt(stack, "Damage") < this.getMaxDamage() - 2)
		{
			NBTHelper.setBool(stack, "Recharging", false);
			NBTHelper.incrementIntSetDamage(stack, "Damage");
			player.setAir(300);
		}
		else if(NBTHelper.getInt(stack, "Damage") > 0 && !NBTHelper.getBool(stack, "Active"))
		{
			NBTHelper.decrementIntSetDamage(stack, "Damage");
		}


		if(NBTHelper.getInt(stack, "Damage") == 0)
		{
			NBTHelper.setBool(stack, "Used", false);
			NBTHelper.setBool(stack, "Recharging", false);
		}


		if(!NBTHelper.getBool(stack, "Used") && NBTHelper.getInt(stack, "Damage") > this.getMaxDamage() - 12)
		{
			NBTHelper.setBool(stack, "Used", true);
		}

		NBTHelper.boundMin(stack, "Damage");
		NBTHelper.boundMax(stack, "Damage", this.getMaxDamage() - 1);
	}
}}

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.



×
×
  • Create New...

Important Information

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