Jump to content

[Solved] Blocks equipable on head like pumpkins [1.10.2]


Dion6103

Recommended Posts

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) : 

 

2017-10-24_22.17.22.png

Edited by Dion6103
Link to comment
Share on other sites

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.

  • Like 1

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

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 by Dion6103
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.