Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[RESOLVED][1.7.10] How can I make a Battery Item Based In Durability?

Featured Replies

Posted

Hello! I am making a technical mod, I know a lot in GUI, Models, Blocks, but I know a little bit in Items... =(

And I want to make a Battery that shows a Durability Bar and this bar represents it's energy like this photo:

width=231 height=139http://vignette2.wikia.nocookie.net/mctechnicpack/images/6/6f/Powering_a_machine.png/revision/latest?cb=20120311220125[/img]

and when I add the item to the GUI(Allready made) you see the bar depleting just like some technical mods.(Like it is damaging the Item)

Thanks!

  • Author

You can return whatever value you want for the durability bar. Use the showDurabilityBar and getDurabilityForDisplay methods in your Item for that.

I know about that, I've also created a ToolMaterial, but I can't assign a material to a normal Item that has no "abilities"(Sword, Hoe, Pickaxe...)

So How do I do that?

ScratchForFun on youtube actually made a few videos covering the creation of battery's and such. You should check them out!

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

  • Author

ScratchForFun on youtube actually made a few videos covering the creation of battery's and such. You should check them out!

Allready checked! But they are [1.6.4] so It won't work on 1.7.10, also, I think I found a way...

  • Author

This has nothing to do with a tool material or Item damage. In that 2nd method you posted you can return ANY value you want. Be it the actual damage value or some data you get out of the NBT of the ItemStack or even the current room temperature (in lack of a better example).

My idea was using a Material for the Item - MaxDurability as the MaxPower - Durability as CurrentPower - but  the way I found was: create 2 variables: MaxPower and Power both defined, then on getDurabilityBarForDisplay I divide them Power/MaxPower, it gives me what I want, but using another block, how can I change this variables?

Then if you want to change it, well, just change it.

 

magic.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Got It in a Very Very Very Stupid Way! I made the Item as a pickaxe and I used ToolMaterial in it adding Durability as Power, and when you add the Item to the GUI I made, it uses slot[0].setItemDamage(slot[0].getItemDamage() + 10) so it damages the item trought time it is there and add power, when the Item has no Durability it won't add. So, latest problem is: How can I slow down The For?!

 

For Code:
if(ItemStack.areItemStacksEqual(slots[0], new ItemStack(ITEM)))
{
	if(slots[0].getItemDamage() >= slots[0].getMaxDamage())
	{

	}
	else
	{
		for(i=0;i<10000;i++){
			power = power+1;
			slots[0].setItemDamage(slots[0].getItemDamage() + 1);
	}
}

How can I slow this down?

Also, make the ToolMaterial worse than Gold and Wood, it does no damaged to blocks!

Do not create a new ItemStack in order to compare the itemstack's item.  Use ItemStack.getItem()

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I just want to slow down the power add, the ToolMaterial works for every block that needs power, but if I use as a normal variable, I can't change it using a TileEntity, that's why a ToolMaterial, also, I don't need to save things into NBTTAG, the game saves auto then.

  • Author

You do not need to use ToolMaterial to use ItemDamage. Not sure I get what you said there with NBT.

About slowing it down, just increase/decrease less often (e.g. only every 3rd tick).

Just Inclrease/decreate what?

That's True I don't need to Use ToolMaterial Fort that... Trying with "setMaxDamage"

RESULT: Without ToolMaterial the game Crashes before Mojang Logo

 

You're probably trying to extend ItemTool, which you do not need to do, in order for items to have durability.  ALL ITEMS have the possibility of having a damage value.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Sorry, it was a Stupid Error! =( I forgot to make if(slots[0] !=null) so then CRASH, but now worked, I used setMaxDamage(int); on the Item and it worked, perfectly! Now just need the "slow down" on the power adding(means that when I add power it will slowly add, not add in one single tick)

onUpdate {
takeALittlePower();
}

takeALittlePower() {
power += 1;
slot[0].damageItem(1);
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

onUpdate {
takeALittlePower();
}

takeALittlePower() {
power += 1;
slot[0].damageItem(1);
}

Thanks For that! Worked!

magic.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.