Jump to content

[1.8] Damage Offset


Curlip

Recommended Posts

Hello Curlip here,

 

I have been creating a tool that must be charged using Redstone Dust and when fired uses TNT. Currently that all works fine, however when I started the attempt to display the Redstone level using the Damage bar, it starts with a damage offset of 14 damage and caps the top of the redstone level at 50 instead of 64.

 

ExplodingMiner:

 

public class ExplodingTool extends SimpleItem {

public ExplodingTool(String itemid) {
	super(itemid);

	setMaxDamage(50);
	setNoRepair();
}

@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player){
	if(stack.getTagCompound().getInteger("Redstone") != 0){
		if(player.inventory.consumeInventoryItem(Blocks.tnt.getItem(player.worldObj, pos))){
			player.worldObj.createExplosion(new EntityTNTPrimed(player.worldObj), (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 2, true);

			NBTTagCompound compound = stack.getTagCompound();
			int redstone = compound.getInteger("Redstone");

			compound.setInteger("Redstone", redstone - 1);

			return true;
		}
		return false;
	}
	return true;
}

@Override
public int getDamage(ItemStack stack){
	if(stack.getTagCompound() != null){
		int redstone = stack.getTagCompound().getInteger("Redstone");

		return getMaxDamage() - redstone;
	}

	return getMaxDamage();
}

@Override
public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer player){
	NBTTagCompound compound = stack.getTagCompound();

	System.out.println(compound.getInteger("Redstone"));  //Debug

	if(compound.getInteger("Redstone") != getMaxDamage()){
		if(player.inventory.consumeInventoryItem(Items.redstone)){
			compound.setInteger("Redstone", (compound.getInteger("Redstone"))+1);
		}
	}

	return stack;
}

public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	if(stack.getTagCompound() == null){
		stack.setTagCompound(new NBTTagCompound());
	}
}

@Override
public int getMaxDamage(ItemStack stack){
	return 64;
}

@Override
public float getDigSpeed(ItemStack stack, IBlockState state){
	return 5;
}

@Override
public boolean showDurabilityBar(ItemStack stack){
	return true;
}
}

 

Thanks in Advance

 

- Curlip

 

(First Post)

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.