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.

Featured Replies

Override this method in Item to update your item every tick.

Now create a simple field and edit it every tick.

public void onUpdate(ItemStack item, World world, Entity entity, int a, boolean b)

  • Author

Override this method in Item to update your item every tick.

Now create a simple field and edit it every tick.

public void onUpdate(ItemStack item, World world, Entity entity, int a, boolean b)

Sorry, but could you give an example of the code?

Don't make a field in your Item class - every single one of your weapons will then be on the same timer, so if I right-click, my friend's timer will start, too. This is because Items are each a static object, i.e. there is only ONE of each Item in the game.

 

Instead, you need to store the timer in the ItemStack's NBT compound. See the Forge Wiki article.

  • Author

Don't make a field in your Item class - every single one of your weapons will then be on the same timer, so if I right-click, my friend's timer will start, too. This is because Items are each a static object, i.e. there is only ONE of each Item in the game.

 

Instead, you need to store the timer in the ItemStack's NBT compound. See the Forge Wiki article.

Some of that is outdated, and I am not sure what they have changed to. Like the hold.itemID

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

hold.getItem() ?

That removes the error for that bit, but still the line next to that wont work. It doesnt have getItem() or itemID

hold.getItem() ?

That removes the error for that bit, but still the line next to that wont work. It doesnt have getItem() or itemID

And we're supposed to magically know what the next line is?

 

As for the article being outdated, sure, slightly, but any required code changes would be readily apparent with just a bit of Java knowledge and poking around a little in vanilla code.

 

Anyway, show your code or we cannot help.

  • Author

hold.getItem() ?

That removes the error for that bit, but still the line next to that wont work. It doesnt have getItem() or itemID

And we're supposed to magically know what the next line is?

 

As for the article being outdated, sure, slightly, but any required code changes would be readily apparent with just a bit of Java knowledge and poking around a little in vanilla code.

 

Anyway, show your code or we cannot help.

http://pastebin.com/2t0H4vw6

I don't see anywhere in there where you tried to implement what I suggested, storing the cooldown in the ItemStack's NBT tag. The way you have it now, every single player with your item is using the same cooldown field (which doesn't even cool down, since you didn't implement onUpdate).

 

Item#onCreated only gets called if the item is crafted, btw, so your NBT tag will not be initialized if you get one from the Creative tab, by command, as loot, or any other such means.

  • Author

I don't see anywhere in there where you tried to implement what I suggested, storing the cooldown in the ItemStack's NBT tag. The way you have it now, every single player with your item is using the same cooldown field (which doesn't even cool down, since you didn't implement onUpdate).

 

Item#onCreated only gets called if the item is crafted, btw, so your NBT tag will not be initialized if you get one from the Creative tab, by command, as loot, or any other such means.

1. Im not sure how to store the cooldown in the Itemstack's NBT tag.

2. I didnt implement onUpdate because Im not sure what to do with it. That is why I am here

The wiki provides an excellent primer tut on NBT here:

http://www.minecraftforge.net/wiki/Creating_NBT_for_items

 

The two methods that have been suggested to you so far both involve the onUpdate function (called every tick by the game)

Cool's has a variable stored per Itemstack that could be named "coolDownTicksToGo" which is the number of ticks left until the item can be reused. The update function just decreases the number if it's >=0.

Using the item sets the variable to the number of ticks needed to count down.

 

Sieben's provides a bit more accuracy since tick rate can be variable. He stores the date/time (a 'Long' type in Java) the item was last used in the Itemstack nbt tag and uses the update function to check if the time difference between that stored time and the current time is >= the cooldown period.

Using the item just sets have var to the current time.

nbt.setInteger("MyCooldown",400) ?

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

ItemStack#stackTagCompound

is the NBT data for an ItemStack, put anything you want into it.

For the cooldown use

World#getTotalWorldTime

it gives you the amount of ticks since the world was created. Using that you can then check how many ticks have passed since the last time the Item was used.

Yeah but how do I use those, I haven't messed with really anthing like these before

They're variables like any other variable.  Use them as variables that have values and do whatever you want to.

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

They're variables like any other variable.  Use them as variables that have values and do whatever you want to.

I realise that. But if its as easy as you guys are implying it then why can't anyone give me an example?

My two cents.

 

 

It's better to teach a man to fish than to give him fish.

Maker of the Craft++ mod.

Here's what you need to know:

 

1. NBT tags can be made to store pretty much anything - use your IDE to check out NBTTagCompound's class methods and you should get a pretty good idea.

2. To access an 'Item' NBT, you need an ItemStack, because ItemStacks are what actually store the individual 'Item' data (such as current item damage).

3. ItemStack has class methods that allow you to create, modify and access a class field which stores an NBTTagCompound

 

Thus, all you need to do is use your ItemStack instance (which is provided as a parameter in pretty much every single class method of Item), get the tag compound from it (or create one if it does not yet exist), then access and modify as needed whatever tags you have stored in there.

 

It's as simple as that. If you don't understand how to use class methods and fields, you should take some time to brush up on Java basics. If you don't understand what we mean by nbt tags, just look at vanilla code for a second.

 

 

  • Author

My two cents.

 

 

It's better to teach a man to fish than to give him fish.

Except if I see the code I can learn it, I know you were using it as a metaphor but you cant learn how to fish by looking at a fish. Two completely different things.

I realise that. But if its as easy as you guys are implying it then why can't anyone give me an example?

 

Because that would require that I instruct you on the basics of Java.

At which point I point you at my signature.

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.

Ok, I already done that, it's seriously the most simple in my drone launcher weapon. Take example on the code, here is my github link https://github.com/Yuri6037/AncientAddinMod/blob/master/src/main/java/net/yuri6037/AncientAddinMod/items/ItemHandDroneLauncher.java

 

Just watch on my onUpdate and onItemRightClick, it's not as much complicated, just use the Minecraft damage system to make the timer, and use some nbt booleans.

 

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.