Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 ^

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.

  • Author
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.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.