Jump to content

How to replace a mob?


Ubalube

Recommended Posts

So I have a mob but when I right click it with an iron chestplate, the mob changes to my other mob that has the gear and stuff on. (It is custom gear I made that it is wearing, not minecraft gear)
So my original thought was to replace this mob with that one. 

I right click the mob with a chestplate, and the mob I right clicked will be replaced with the mob with armor.

Help would be appreciated!
 

    @Override
    public boolean processInteract(EntityPlayer player, EnumHand hand)
    {
        ItemStack itemstack = player.getHeldItem(hand);
        
        if (this.isTamed())
        {
            if (this.isOwner(player) && !this.world.isRemote && itemstack == new ItemStack (Items.IRON_CHESTPLATE))
            {
            	//Im stuck here :(
            }
        }
        return super.processInteract(player, hand);
    }

My code ^

Link to comment
Share on other sites

Why not just make the entity wear the chestplate instead, like all vanilla entities do? There is no need to replace the entity with an another one here.

5 minutes ago, Ubalube said:

itemstack == new ItemStack (Items.IRON_CHESTPLATE)

This will never be true, that's not how OOP works. These are 2 different non-primitive objects thus they will never be equal to one another in a direct == comparason.

Link to comment
Share on other sites

1 minute ago, V0idWa1k3r said:

Why not just make the entity wear the chestplate instead, like all vanilla entities do? There is no need to replace the entity with an another one here.

This will never be true, that's not how OOP works. These are 2 different non-primitive objects thus they will never be equal to one another in a direct == comparason.

Well, its also that my other mob has a sword and just the way I wan't it to work is a little better.

Link to comment
Share on other sites

You can equip a sword aswell. And you can change the AI on the go if needed too, similar to how a skeleton adapts to having a sword instead of a bow in vanilla. 

But whatever, fine.

You need to despawn your current entity using Entity#setDead, then create a new one of the type that you want(the other entity), place it in the same location as your first one(Entity#setPosition, Entity.posX/Y/Z) and do whatever else you want to do with it(if anything). Finally you only need to spawn it with World#spawnEntity. Make sure you check that you are only performing all of that on a server first.

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.



×
×
  • Create New...

Important Information

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