Dion6103 Posted October 25, 2017 Posted October 25, 2017 (edited) I am currently working on a mod where I want to have a block able to be placed and equipped in the helmet slot like a pumpkin would. I have been looking at the code of a pumpkin and have found nothing. So far, I have a working block, it's model including it being placed and worn on the head. How would I make it so that I can put a block onto my head without having to use commands? Picture of the block placed and being worn on my head using the command ./replaceitem entity @p slot.armor.head modid:blockmagichat (Still need to know how to get it equipable normally) : Edited October 28, 2017 by Dion6103 Quote
Draco18s Posted October 25, 2017 Posted October 25, 2017 You're not going to make this work. Sorry! Here's the code that handles whether or not the player can wear a pumpkin: public static EntityEquipmentSlot getSlotForItemStack(ItemStack stack) { if (stack.getItem() != Item.getItemFromBlock(Blocks.PUMPKIN) && stack.getItem() != Items.SKULL) { if (stack.getItem() instanceof ItemArmor) { return ((ItemArmor)stack.getItem()).armorType; } else if (stack.getItem() == Items.ELYTRA) { return EntityEquipmentSlot.CHEST; } else { return stack.getItem().isShield(stack, null) ? EntityEquipmentSlot.OFFHAND : EntityEquipmentSlot.MAINHAND; } } else { return EntityEquipmentSlot.HEAD; } } Which is in EntityLiving.class You'll have to instead create an item that is a subclass ItemArmor, that when right clicked, creates your block in the world (think about how Cake works, or Seeds). Your hat-block would then not have an accompanying ItemBlock, and would instead drop the hat armor when broken. 1 Quote 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.
Dion6103 Posted October 28, 2017 Author Posted October 28, 2017 On 10/25/2017 at 4:14 AM, diesieben07 said: Make a custom ItemBlock for your block and override isValidArmor. I did this and it half worked. Is there a way to make it so that It can only be equipped in one slot, in this case the head slot? P.S. Sorry if I am being a noob and this is some basic Java thing that I haven't encountered yet Quote
Choonster Posted October 28, 2017 Posted October 28, 2017 8 minutes ago, Dion6103 said: I did this and it half worked. Is there a way to make it so that It can only be equipped in one slot, in this case the head slot? P.S. Sorry if I am being a noob and this is some basic Java thing that I haven't encountered yet Item#isValidArmor receives the EntityEquipmentSlot that's being checked as an argument, only return true if it's EntityEquipmentSlot.HEAD. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Dion6103 Posted October 28, 2017 Author Posted October 28, 2017 (edited) 16 minutes ago, Choonster said: Item#isValidArmor receives the EntityEquipmentSlot that's being checked as an argument, only return true if it's EntityEquipmentSlot.HEAD. Thanks a bunch! (Don't know why I didn't think of this before.... XD) https://imgur.com/a/cg7ti For anyone looking for the answer in the future, this is what I did. In your ItemBlock class I put: @Override public boolean isValidArmor(ItemStack stack, EntityEquipmentSlot armorType, Entity entity) { if(armorType == EntityEquipmentSlot.HEAD) { return true; }else { return false; } } (Change EntityEquipmentSlot.HEAD to the respective armor piece or just return true if you want it to equip in all slots. Edited October 28, 2017 by Dion6103 Quote
Recommended Posts
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.