Jump to content

How To make a tooltip display damage


c-ab-o-o-s-e

Recommended Posts

The idea is I have a battery and I want the tool tip to say "Power Left: " and then how much power the battery has in it at the moment it is registered with a max power of 10000 (using metadata) but I'm unsure on how to get the current damage value to add to the end of the string.

 

 

This is the battery class the damage and id are registered in the main class

public class CarbonBattery extends Item {
private final String setInfo;
private final String setColor;


public CarbonBattery(int id, int maxPower) {
	super(id);

	this.setMaxDamage(maxPower);
	this.setInfo = "Power Left: ";
	this.setColor = "\u00A75";

}

public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean bool){
	list.add(setToolTipData());
}

private String setToolTipData(){
	return this.setColor + this.setInfo;
}

}

Link to comment
Share on other sites

No. I really don't know what I'm doing. Why I'm here trying to learn, as well as looking for every tutorial I can to figure out how it works. Thanks for the help I don't intend to seem like and Idiot. I used the example you gave me to make it how I wanted.

public CarbonBattery(int id, int maxPower) {
	super(id);

	this.setMaxDamage(maxPower);
}

public void addInformation(ItemStack stack, EntityPlayer entityplayer, List list, boolean extendedToolTips){
	list.add("Power Left: " + (this.getMaxDamage() - stack.getItemDamage()) + "/" + this.getMaxDamage());
}


}

 

So now it will display "Power Left: 1000/1000" and will count down.

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.