So I'm attempting to make items update every 100 ticks to increase their health, is there a method I can use for this eg.
Public ItemStack MagicalMethod(ItemStack item)
{
item.setItemDamage(ItemHealthVariable);
//Yes yes, I know I can use item.damageItem() but just humor me =D
{
So any ideas? I really don't want to edit ItemStack.class to make a new method.
So I'm attempting to make items update every 100 ticks to increase their health, is there a method I can use for this eg.
Public ItemStack MagicalMethod(ItemStack item)
{
item.setItemDamage(ItemHealthVariable);
//Yes yes, I know I can use item.damageItem() but just humor me =D
{
So any ideas? I really don't want to edit ItemStack.class to make a new method.
yeah every tick decrease a count from 100 when it gets to 0 increase the damage and reset the count, just like TNT detonation.
yeah every tick decrease a count from 100 when it gets to 0 increase the damage and reset the count, just like TNT detonation.
Thanks for the reply but about that, you see the problem is updating the item every second, not calculating the delay.
Also keep in mind this is about an ITEM not a block.
Could you give me an example of this, I'm not that good at for loops. :/
A better way, although harder, but more reliable, if to edit Item.java to have a method called updateTick() and a void called onUpdate(), in which it does nothing. then hijack the updateTick() from any existing block that uses it and call Item.onUpdate(), in onUpdate() in the Item class you should call the updateTick method for each item stored in Item.java. Old Items will not be affected, as it will just run the updateTick() it gets from it's superclass, which does nothing. However, on your Item, override the updateTick() method and add 1 to a variable until you get to 100 and do something.
or you could just use the OnTickInGame method in modloader...
just make your onUpdate method in that item class and call it every number of ticks you want
Rollback Post to RevisionRollBack
Remeber: that little green plus sign is a great way to say thank you!
or you could just use the OnTickInGame method in modloader...
just make your onUpdate method in that item class and call it every number of ticks you want
Wait, I thought onTickInGame didn't work for items, hmm I will try that.
EDIT: Ok I got the onTickInGame part of code to not give errors, but the ModLoader.SetInGameHook in my constructor will not accept (this, true, true);. I'm probably doing something wrong here.
EDIT2: Herp Derp, I see what you're on about now, will try it. Should it be a boolean or a void? And how would I tell it when to tick? Coding time annoys me so. I'm lost ><
NEVER do that! While looping it will just freeze the entire game until the loop is done.
A better way, although harder, but more reliable, if to edit Item.java to have a method called updateTick() and a void called onUpdate(), in which it does nothing. then hijack the updateTick() from any existing block that uses it and call Item.onUpdate(), in onUpdate() in the Item class you should call the updateTick method for each item stored in Item.java. Old Items will not be affected, as it will just run the updateTick() it gets from it's superclass, which does nothing. However, on your Item, override the updateTick() method and add 1 to a variable until you get to 100 and do something.
Although I do agree with you on that, I want the most compatible mod possible, and editing base files is something I need to avoid.
That makes perfect sense, there are several ways to accomplish this, and probably some that people don't even know yet. Good luck.
Here is another suggestion, In you're tool class make a method called onTick(), then with the ModLoader onTickInGame() in your main class or somewhere, cycle through the inventory every 100 ticks and if the item is instanceof YourItemClass, cast to that class and call its onTick() method. cause you can use the onTickInGame() other ways, however you may not get the best results if it's only affecting the class, you would want to use it on all the instances of the item.
That makes perfect sense, there are several ways to accomplish this, and probably some that people don't even know yet. Good luck.
Here is another suggestion, In you're tool class make a method called onTick(), then with the ModLoader onTickInGame() in your main class or somewhere, cycle through the inventory every 100 ticks and if the item is instanceof YourItemClass, cast to that class and call its onTick() method. cause you can use the onTickInGame() other ways, however you may not get the best results if it's only affecting the class, you would want to use it on all the instances of the item.
Right, how will I cycle through inventory for an item? I understand the inventory is a form of array, with each value being the shifted index of it's item, but how would I call and examine it? Thanks for your help BTW, I really appreciate this =D
EDIT: What a wonderful downtime! Anyways I figured out how to retrive the player inventory, now I just need to figure out what Item is in slot X.
ItemStack Test = game.thePlayer.inventory.getItemStack();
//This appears to give me the players inventory, now how to analyse it...
However I realized that it will give you a nnew instance of that item in the slot, so it's a little more advanced. Instead of having the method in your class, what you would do is every 100 ticks you'd cycle through the inventory and for each item of your type heal it.
for(ItemStack itemstack : player.getInventory()){
if(itemstack.getItem() instanceof YourItem){
itemstack.damageItem(-1, null);//you may want to heal more than 1 however
//healing one use every 100 ticks is REALLY slow, it would take over 100,000 for diamond (for example)
}
}
However I realized that it will give you a nnew instance of that item in the slot, so it's a little more advanced. Instead of having the method in your class, what you would do is every 100 ticks you'd cycle through the inventory and for each item of your type heal it.
for(ItemStack itemstack : player.getInventory()){
if(itemstack.getItem() instanceof YourItem){
itemstack.damageItem(-1, null);//you may want to heal more than 1 however
//healing one use every 100 ticks is REALLY slow, it would take over 100,000 for diamond (for example)
}
}
The For loop crashes the game ><
I've decided to make a new void instead that is called every X ticks using OnTickInGame().
EDIT: It seems I'm able to make the void work within my .Class but not outside it, even though it is set to public. Any Ideas? Will keep searching regardless.
So any ideas? I really don't want to edit ItemStack.class to make a new method.
yeah every tick decrease a count from 100 when it gets to 0 increase the damage and reset the count, just like TNT detonation.
Thanks for the reply but about that, you see the problem is updating the item every second, not calculating the delay.
Also keep in mind this is about an ITEM not a block.
Could you give me an example of this, I'm not that good at for loops. :/
NEVER do that! While looping it will just freeze the entire game until the loop is done.
A better way, although harder, but more reliable, if to edit Item.java to have a method called updateTick() and a void called onUpdate(), in which it does nothing. then hijack the updateTick() from any existing block that uses it and call Item.onUpdate(), in onUpdate() in the Item class you should call the updateTick method for each item stored in Item.java. Old Items will not be affected, as it will just run the updateTick() it gets from it's superclass, which does nothing. However, on your Item, override the updateTick() method and add 1 to a variable until you get to 100 and do something.
just make your onUpdate method in that item class and call it every number of ticks you want
Wait, I thought onTickInGame didn't work for items, hmm I will try that.
EDIT: Ok I got the onTickInGame part of code to not give errors, but the ModLoader.SetInGameHook in my constructor will not accept (this, true, true);. I'm probably doing something wrong here.
EDIT2: Herp Derp, I see what you're on about now, will try it. Should it be a boolean or a void? And how would I tell it when to tick? Coding time annoys me so. I'm lost ><
Although I do agree with you on that, I want the most compatible mod possible, and editing base files is something I need to avoid.
Here is another suggestion, In you're tool class make a method called onTick(), then with the ModLoader onTickInGame() in your main class or somewhere, cycle through the inventory every 100 ticks and if the item is instanceof YourItemClass, cast to that class and call its onTick() method. cause you can use the onTickInGame() other ways, however you may not get the best results if it's only affecting the class, you would want to use it on all the instances of the item.
Right, how will I cycle through inventory for an item? I understand the inventory is a form of array, with each value being the shifted index of it's item, but how would I call and examine it? Thanks for your help BTW, I really appreciate this =D
EDIT: What a wonderful downtime! Anyways I figured out how to retrive the player inventory, now I just need to figure out what Item is in slot X.
However I realized that it will give you a nnew instance of that item in the slot, so it's a little more advanced. Instead of having the method in your class, what you would do is every 100 ticks you'd cycle through the inventory and for each item of your type heal it.
The For loop crashes the game ><
I've decided to make a new void instead that is called every X ticks using OnTickInGame().
EDIT: It seems I'm able to make the void work within my .Class but not outside it, even though it is set to public. Any Ideas? Will keep searching regardless.