Basically I'm trying to recreate Magic Armour from Zelda games where you're invincible if you have Rupees, but your amount of Rupees drains at a rate of like 2 per second and when it's gone you're unable to move or anything.
I got it all working except the money part.
I'm not sure how to set it so the amount decreases by 1 every 10 ticks.
Right now it just decreases by 1 every tick since I can't figure out how to slow it.
Anyone want to point me in the right direction?
My code if that matters:
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
{
if(player.getCurrentArmor(3) != null && player.getCurrentArmor(2) != null && player.getCurrentArmor(1) != null)
{
ItemStack crown = player.getCurrentArmor(3);
ItemStack armour = player.getCurrentArmor(2);
ItemStack mail = player.getCurrentArmor(1);
//If player is wearing all 3 armour pieces
if(crown.getItem() == Main.MagicCrown && armour.getItem() == Main.MagicArmour && mail.getItem() == Main.MagicChainmail)
{
//If player has Rupees in their inventory they become invincible and Rupees are drained
if(player.inventory.hasItem(Main.rupeeGreen ))
{
player.addPotionEffect(new PotionEffect(Potion.resistance.getId(), 1, 5));
player.inventory.consumeInventoryItem(Main.rupeeGreen);
}
//If player doesn't have Rupees, they are slowed, can't use items and are no longer invincible
else
{
player.stopUsingItem();
player.setInWeb();
player.removePotionEffect(11);
}
}
}
//If player is wearing Megaton Boots they are slowed and knockback is prevented
//Rupees are irrelevant for these
if(player.getCurrentArmor(0) != null)
{
ItemStack boots = player.getCurrentArmor(0);
if(boots.getItem() == Main.MegatonBoots)
{
player.setInWeb();
}
}
}
Store an integer somewhere, set to 0. Every tick add one to the integer, and then check if it's >= 10. If it is, set it to 0 and take away one of the items.
Store an integer somewhere, set to 0. Every tick add one to the integer, and then check if it's >= 10. If it is, set it to 0 and take away one of the items.
So I changed it to this, and it works, but instead of taking away 1 every 10 ticks, it takes away 3 every 10 ticks for some reason.
Any idea how that managed to happen? :l
int t;
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
{
if(player.getCurrentArmor(3) != null && player.getCurrentArmor(2) != null && player.getCurrentArmor(1) != null)
{
ItemStack crown = player.getCurrentArmor(3);
ItemStack armour = player.getCurrentArmor(2);
ItemStack mail = player.getCurrentArmor(1);
//If player is wearing all 3 armour pieces
if(crown.getItem() == Main.MagicCrown && armour.getItem() == Main.MagicArmour && mail.getItem() == Main.MagicChainmail)
{
//If player has Rupees in their inventory they become invincible
if(player.inventory.hasItem(Main.rupeeGreen ))
{
player.addPotionEffect(new PotionEffect(Potion.resistance.getId(), 1, 5));
//If 10 ticks has gone by [a] Rupee [should be] drained
if(t == 10)
{
player.inventory.consumeInventoryItem(Main.rupeeGreen);
t = 0;
}
else
{
t++;
}
}
//If player doesn't have Rupees, they are slowed, can't use items and are no longer invincible
else
{
player.stopUsingItem();
player.setInWeb();
player.removePotionEffect(11);
}
}
}
1) Minecraft doesn't initialise separate items from the item class. That's why ItemStack exists. Therefore, if I have 100 people on the server, each wearing 1 piece of armor, 't' is gonna increase by 100 each tick.
2, or actually 1a) The more armor you have, the faster it decreases (Not sure if intended)
Solution: You have two ways of doing this - The best one is to use NBT Data to store 't' per itemstack. Increase 't' by 1 every tick using the NBT data.
The other way is to store a static HashMap of player names/UUID's to 't', and save and load it, etc.
I got it all working except the money part.
I'm not sure how to set it so the amount decreases by 1 every 10 ticks.
Right now it just decreases by 1 every tick since I can't figure out how to slow it.
Anyone want to point me in the right direction?
My code if that matters:
So I changed it to this, and it works, but instead of taking away 1 every 10 ticks, it takes away 3 every 10 ticks for some reason.
Any idea how that managed to happen? :l
1) Minecraft doesn't initialise separate items from the item class. That's why ItemStack exists. Therefore, if I have 100 people on the server, each wearing 1 piece of armor, 't' is gonna increase by 100 each tick.
2, or actually 1a) The more armor you have, the faster it decreases (Not sure if intended)
Solution: You have two ways of doing this - The best one is to use NBT Data to store 't' per itemstack. Increase 't' by 1 every tick using the NBT data.
The other way is to store a static HashMap of player names/UUID's to 't', and save and load it, etc.
But not yet