Jump to content

[1.12.1]How would one spawn a custom mob with custom armor and a custom weapon?


Recommended Posts

Posted (edited)

Use Entity#setItemStackToSlot to set the item in an entity's equipment slot.

 

If the mob should always spawn with this equipment or always has a chance to spawn with it, override EntityLiving#setEquipmentBasedOnDifficulty to set the equipment and then override EntityLiving#onInitialSpawn to call it.

 

If the equipment is specific to the way it's being spawned, set the equipment manually before spawning it.

 

Edit: Forgot to mention that EntityLiving#setEquipmentBasedOnDifficulty needs to be called from EntityLiving#onInitialSpawn.

Edited by Choonster

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.

Posted (edited)

I'm doing this, but I don't know what to put in new ItemStack(), when it comes to my custom items

    @SubscribeEvent
    public static void onJacketSpawn(EntityJoinWorldEvent event)
    {
        if (!(event.getEntity() instanceof EntityMasterJacket)) 
        {
            return;
        }      
        
        EntityMasterJacket mj = (EntityMasterJacket) event.getEntity();
        
        mj.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack());
        
    }

Edited by Plgue
Posted

Seems to be that the code stops here: 

 

 if (!(event.getEntity() instanceof EntityMasterJacket)) 
        {
            return;
        }      

Posted
23 minutes ago, Plgue said:

I'm doing this, but I don't know what to put in new ItemStack(), when it comes to my custom items

 

Why are you using EntityJoinWorldEvent for your own entity?

 

Look at the constructors of the ItemStack class to what parameters they require. You should have your Item and Block instances stored in static fields of a class (usually called something like ModItems/ModBlocks), you can get the instances from these fields to pass to the ItemStack constructor.

 

Do you actually know Java? You need to have a solid understanding of both Java and OO programming in general to a make a mod. This forum isn't for helping people with basic Java issues.

 

13 minutes ago, Plgue said:

Seems to be that the code stops here: 

 

Do you ever spawn an EntityMasterJacket?

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.

Posted
2 minutes ago, Plgue said:

What method would I put it in?

 

I explained that in my first reply.

 

I've also just edited it to include a detail that I forgot (EntityLiving#setEquipmentBasedOnDifficulty needs to be called from EntityLiving#onInitialSpawn).

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.

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.