How do I have my ItemSword being consumed and when it's consumed another ItemSword is given to the player? Similar to the lightsabers from star wars, when you press a button on the lightsaber, it lights up. I'm doing something similar with 2 items, one "off" and another "on". When the "off" ItemSword is consumed, the game will then give the player the "on" ItemSword and vice versa with the "on" ItemSword to the "off" ItemSword. Is that possible or is there another way around this?
It depends how the player switches the sword on and off.
If they do it from a right click, just return a new ItemStack from Item#onItemRightClick.
If they do it from a key binding, send a packet to the server, find the sword in the player's inventory (InventoryPlayer#mainInventory) then replace it with the new ItemStack.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Say, i follow the first suggestion, i looked at the minecraft itemsword code. How will the sword be "on" and "off"? How does returning a new itemstack do that?
Say, i follow the first suggestion, i looked at the minecraft itemsword code. How will the sword be "on" and "off"? How does returning a new itemstack do that?
The ItemStack you return at the end of the onItemRightClick method will always "replace" whatever was there when the player clicked. Usually it either stays the same, damages the item, reduces stack size, etc. depending what you want. So in this case you simply check which "sword" they had and replace the opposite one.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
You don't need to manually add the new item and consume the old one, just return an ItemStack of the new item from onItemRightClick (like sky_01 and I explained).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
return new ItemStack(StarWars.lightsaber_red_on);
}
It worked like that too. But I prefer the manual way.
Edit #1: Oh and I forgot, what does translation does in the json file?
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
How do I have my ItemSword being consumed and when it's consumed another ItemSword is given to the player? Similar to the lightsabers from star wars, when you press a button on the lightsaber, it lights up. I'm doing something similar with 2 items, one "off" and another "on". When the "off" ItemSword is consumed, the game will then give the player the "on" ItemSword and vice versa with the "on" ItemSword to the "off" ItemSword. Is that possible or is there another way around this?
Thanks in advance,
Spyeedy
It depends how the player switches the sword on and off.
If they do it from a right click, just return a new ItemStack from Item#onItemRightClick.
If they do it from a key binding, send a packet to the server, find the sword in the player's inventory (InventoryPlayer#mainInventory) then replace it with the new ItemStack.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Say, i follow the first suggestion, i looked at the minecraft itemsword code. How will the sword be "on" and "off"? How does returning a new itemstack do that?
The ItemStack you return at the end of the onItemRightClick method will always "replace" whatever was there when the player clicked. Usually it either stays the same, damages the item, reduces stack size, etc. depending what you want. So in this case you simply check which "sword" they had and replace the opposite one.
I did it, thanks for your explanation sky_01!
Here's the sword "off":
As for the sword "on", I swapped the items.
You don't need to manually add the new item and consume the old one, just return an ItemStack of the new item from onItemRightClick (like sky_01 and I explained).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
It worked like that too. But I prefer the manual way.
Edit #1: Oh and I forgot, what does translation does in the json file?
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Ah thanks!