Jump to content

Recommended Posts

Posted

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)

Posted

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?

Posted

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

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

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?

Posted

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.

 

 

Posted

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.

Posted

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.

Posted

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

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