Posted November 9, 20186 yr 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 ^
November 9, 20186 yr 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.
November 9, 20186 yr 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.
November 9, 20186 yr 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.