/** * Tests if this entity should pickup a weapon or an armor. Entity drops current weapon or armor if the new one is * better. */ protected void updateEquipmentIfNeeded(EntityItem itemEntity) { ItemStack itemstack = itemEntity.getEntityItem(); EntityEquipmentSlot entityequipmentslot = func_184640_d(itemstack); boolean flag = true; ItemStack itemstack1 = this.getItemStackFromSlot(entityequipmentslot); if (itemstack1 != null) { if (entityequipmentslot.func_188453_a() == EntityEquipmentSlot.Type.HAND) { if (itemstack.getItem() instanceof ItemSword && !(itemstack1.getItem() instanceof ItemSword)) { flag = true; } else if (itemstack.getItem() instanceof ItemSword && itemstack1.getItem() instanceof ItemSword) { ItemSword itemsword = (ItemSword)itemstack.getItem(); ItemSword itemsword1 = (ItemSword)itemstack1.getItem(); if (itemsword.getDamageVsEntity() == itemsword1.getDamageVsEntity()) { flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound(); } else { flag = itemsword.getDamageVsEntity() > itemsword1.getDamageVsEntity(); } } else if (itemstack.getItem() instanceof ItemBow && itemstack1.getItem() instanceof ItemBow) { flag = itemstack.hasTagCompound() && !itemstack1.hasTagCompound(); } else { flag = false; } } else if (itemstack.getItem() instanceof ItemArmor && !(itemstack1.getItem() instanceof ItemArmor)) { flag = true; } else if (itemstack.getItem() instanceof ItemArmor && itemstack1.getItem() instanceof ItemArmor) { ItemArmor itemarmor = (ItemArmor)itemstack.getItem(); ItemArmor itemarmor1 = (ItemArmor)itemstack1.getItem(); if (itemarmor.damageReduceAmount == itemarmor1.damageReduceAmount) { flag = itemstack.getMetadata() > itemstack1.getMetadata() || itemstack.hasTagCompound() && !itemstack1.hasTagCompound(); } else { flag = itemarmor.damageReduceAmount > itemarmor1.damageReduceAmount; } } else { flag = false; } } if (flag && this.func_175448_a(itemstack)) { double d0; switch (entityequipmentslot.func_188453_a()) { case HAND: d0 = (double)this.inventoryHandsDropChances[entityequipmentslot.func_188454_b()]; break; case ARMOR: d0 = (double)this.inventoryArmorDropChances[entityequipmentslot.func_188454_b()]; break; default: d0 = 0.0D; } if (itemstack1 != null && (double)(this.rand.nextFloat() - 0.1F) < d0) { this.entityDropItem(itemstack1, 0.0F); } if (itemstack.getItem() == Items.diamond && itemEntity.getThrower() != null) { EntityPlayer entityplayer = this.worldObj.getPlayerEntityByName(itemEntity.getThrower()); if (entityplayer != null) { entityplayer.triggerAchievement(AchievementList.field_187996_x); } } this.setItemStackToSlot(entityequipmentslot, itemstack); switch (entityequipmentslot.func_188453_a()) { case HAND: this.inventoryHandsDropChances[entityequipmentslot.func_188454_b()] = 2.0F; break; case ARMOR: this.inventoryArmorDropChances[entityequipmentslot.func_188454_b()] = 2.0F; } this.persistenceRequired = true; this.onItemPickup(itemEntity, 1); itemEntity.setDead(); } }