Hello, recently I have been working on a hats mod, and I have created several models in Techne, but when working on the events in the code, I could not get the new item to place on your head... Does anyone know how to do this? If not, how could I make it act like a skull? So it could be placed on your head?
here was my previous code, but it failed with errors all over the place...
To make your item wearable as a helmet, override Item#isValidArmor to return true when armorType is 0.
The return type of EntityPlayer#getInventory is InventoryPlayer, not PlayerInventory (which doesn't exist). None of the methods you tried to call exist in InventoryPlayer.
To get or set the item in a players equipment (hand or armour) slot, use EntityPlayer#getEquipmentInSlot and EntityPlayer#setCurrentItemOrArmor. Slot 0 is the hand, slot 4 is the head.
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.
How would I write this as one event? For example, If my event is "When right clicked in air" What would the parameters be for it to run in order to get in on your head?
Rollback Post to RevisionRollBack
Play.VindexCraft.net / The worlds most advanced CityRP server.
How would I write this as one event? For example, If my event is "When right clicked in air" What would the parameters be for it to run in order to get in on your head?
Look at ItemArmor#onItemRightClick to see how vanilla armour is equipped.
Override Item#onItemRightClick. If the stack in the head slot is null (playerIn.getEquipmentInSlot(4) == null), set the stack in the head slot to a copy of the stack that was right clicked with (playerIn.setCurrentItemOrArmor(4, itemStackIn.copy())) and set the held stack's stack size to 0 (itemStackIn.stackSize = 0). Return itemStackIn.
This assumes that your hat only stacks to 1 (like vanilla armour). If it stacks higher than that, you'll need to make sure you only equip one of it and subtract 1 from the stack size instead of setting it to 0.
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.
Hello, recently I have been working on a hats mod, and I have created several models in Techne, but when working on the events in the code, I could not get the new item to place on your head... Does anyone know how to do this? If not, how could I make it act like a skull? So it could be placed on your head?
here was my previous code, but it failed with errors all over the place...
PlayerInventory inventory = player.getInventory();
ItemStack itemHead = inventory.getHelmet();
inventory.removeItem(itemHand);
inventory.setHelmet(itemHand);
inventory.setItemInHand(itemHead);
To make your item wearable as a helmet, override Item#isValidArmor to return true when armorType is 0.
The return type of EntityPlayer#getInventory is InventoryPlayer, not PlayerInventory (which doesn't exist). None of the methods you tried to call exist in InventoryPlayer.
To get or set the item in a players equipment (hand or armour) slot, use EntityPlayer#getEquipmentInSlot and EntityPlayer#setCurrentItemOrArmor. Slot 0 is the hand, slot 4 is the head.
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 would I write this as one event? For example, If my event is "When right clicked in air" What would the parameters be for it to run in order to get in on your head?
Look at ItemArmor#onItemRightClick to see how vanilla armour is equipped.
Override Item#onItemRightClick. If the stack in the head slot is null (playerIn.getEquipmentInSlot(4) == null), set the stack in the head slot to a copy of the stack that was right clicked with (playerIn.setCurrentItemOrArmor(4, itemStackIn.copy())) and set the held stack's stack size to 0 (itemStackIn.stackSize = 0). Return itemStackIn.
This assumes that your hat only stacks to 1 (like vanilla armour). If it stacks higher than that, you'll need to make sure you only equip one of it and subtract 1 from the stack size instead of setting it to 0.
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.
Thanks for your help!