EntityInventory inv = getOwner().get(EntityInventory.class);
ArmorInventory armorInv = inv.getArmor();
// Check if this item is equipable armor and has more protection than the currently equipped item
boolean equip = false;
if (item.getItemStack().getMaterial() instanceof Armor) {
Armor armor = (Armor) item.getItemStack().getMaterial();
for (int i = 0; i < armorInv.size(); i++) {
if (armorInv.canSet(i, item.getItemStack())) {
ItemStack slot = armorInv.get(i);
if (slot == null || (slot.getMaterial() instanceof Armor && ((Armor) slot.getMaterial()).getBaseProtection() < armor.getBaseProtection())) {
getOwner().getNetwork().callProtocolEvent(new EntityCollectItemEvent(getOwner(), entity));
if (slot != null) {
Item.drop(getOwner().getPhysics().getPosition(), slot, Vector3f.ZERO);
}
armorInv.set(i, item.getItemStack(), true);