Search in sources :

Example 16 with ItemArmor

use of net.minecraft.item.ItemArmor in project ImmersiveEngineering by BluSunrize.

the class RecipeEarmuffs method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    ItemStack earmuffs = ItemStack.EMPTY;
    ItemStack armor = ItemStack.EMPTY;
    int[] colourArray = new int[3];
    int j = 0;
    int totalColourSets = 0;
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stackInSlot = inv.getStackInSlot(i);
        if (!stackInSlot.isEmpty())
            if (earmuffs.isEmpty() && IEContent.itemEarmuffs.equals(stackInSlot.getItem())) {
                earmuffs = stackInSlot;
                int colour = ((IColouredItem) earmuffs.getItem()).getColourForIEItem(earmuffs, 0);
                float r = (float) (colour >> 16 & 255) / 255.0F;
                float g = (float) (colour >> 8 & 255) / 255.0F;
                float b = (float) (colour & 255) / 255.0F;
                j = (int) ((float) j + Math.max(r, Math.max(g, b)) * 255.0F);
                colourArray[0] = (int) ((float) colourArray[0] + r * 255.0F);
                colourArray[1] = (int) ((float) colourArray[1] + g * 255.0F);
                colourArray[2] = (int) ((float) colourArray[2] + b * 255.0F);
                ++totalColourSets;
            } else if (Utils.isDye(stackInSlot)) {
                float[] afloat = EntitySheep.getDyeRgb(EnumDyeColor.byDyeDamage(Utils.getDye(stackInSlot)));
                int r = (int) (afloat[0] * 255.0F);
                int g = (int) (afloat[1] * 255.0F);
                int b = (int) (afloat[2] * 255.0F);
                j += Math.max(r, Math.max(g, b));
                colourArray[0] += r;
                colourArray[1] += g;
                colourArray[2] += b;
                ++totalColourSets;
            } else if (armor.isEmpty() && stackInSlot.getItem() instanceof ItemArmor && ((ItemArmor) stackInSlot.getItem()).armorType == EntityEquipmentSlot.HEAD && !IEContent.itemEarmuffs.equals(stackInSlot.getItem()))
                armor = stackInSlot;
    }
    if (!earmuffs.isEmpty()) {
        if (totalColourSets > 1) {
            int r = colourArray[0] / totalColourSets;
            int g = colourArray[1] / totalColourSets;
            int b = colourArray[2] / totalColourSets;
            float colourMod = (float) j / (float) totalColourSets;
            float highestColour = (float) Math.max(r, Math.max(g, b));
            r = (int) ((float) r * colourMod / highestColour);
            g = (int) ((float) g * colourMod / highestColour);
            b = (int) ((float) b * colourMod / highestColour);
            int newColour = (r << 8) + g;
            newColour = (newColour << 8) + b;
            ItemNBTHelper.setInt(earmuffs, Lib.NBT_EarmuffColour, newColour);
        }
        ItemStack output;
        if (!armor.isEmpty()) {
            output = armor.copy();
            ItemNBTHelper.setItemStack(output, Lib.NBT_Earmuffs, earmuffs.copy());
        } else
            output = earmuffs.copy();
        return output;
    } else if (!armor.isEmpty() && ItemNBTHelper.hasKey(armor, Lib.NBT_Earmuffs)) {
        ItemStack output = armor.copy();
        ItemNBTHelper.remove(output, Lib.NBT_Earmuffs);
        return output;
    }
    return ItemStack.EMPTY;
}
Also used : ItemArmor(net.minecraft.item.ItemArmor) ItemStack(net.minecraft.item.ItemStack)

Example 17 with ItemArmor

use of net.minecraft.item.ItemArmor in project MorePlanets by SteveKunG.

the class BlockInfectedVines method onEntityCollision.

@Override
public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity) {
    if (entity instanceof EntityLivingBase) {
        EntityLivingBase living = (EntityLivingBase) entity;
        if (living instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            InventoryPlayer inventory = player.inventory;
            for (int i = 0; i < 4; i++) {
                if (inventory.armorInventory.get(i).isEmpty() || !(inventory.armorInventory.get(i).getItem() instanceof ItemArmor)) {
                    if (!player.capabilities.isCreativeMode) {
                        player.attackEntityFrom(DamageSourceMP.INFECTED_GAS, (int) (4.0D * 0.1D + 1.0D));
                        player.addPotionEffect(new PotionEffect(MobEffects.POISON, 50, 1));
                    }
                }
            }
        }
        if (!(living instanceof EntityPlayer) && !(entity instanceof ISpaceMob && ((ISpaceMob) entity).getMobType() == EnumMobType.NIBIRU)) {
            living.attackEntityFrom(DamageSourceMP.INFECTED_GAS, (int) (4.0D * 0.1D + 1.0D));
            living.addPotionEffect(new PotionEffect(MobEffects.POISON, 50, 1));
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ISpaceMob(stevekung.mods.moreplanets.utils.entity.ISpaceMob) PotionEffect(net.minecraft.potion.PotionEffect) ItemArmor(net.minecraft.item.ItemArmor) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 18 with ItemArmor

use of net.minecraft.item.ItemArmor in project Almura by AlmuraDev.

the class UIUserPanel method updateArmor.

private void updateArmor() {
    int maxArmor = 0;
    int currentDamage = 0;
    for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
        if (slot == EntityEquipmentSlot.MAINHAND || slot == EntityEquipmentSlot.OFFHAND) {
            continue;
        }
        final ItemStack stack = this.client.player.getItemStackFromSlot(slot);
        if (stack.getItem() instanceof ItemArmor) {
            maxArmor += ((ItemArmor) stack.getItem()).getArmorMaterial().getDurability(slot);
            currentDamage += stack.getItem().getDamage(stack);
        }
    }
    this.updateBarProperties(this.armorBar, maxArmor - currentDamage, maxArmor);
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ItemArmor(net.minecraft.item.ItemArmor) ItemStack(net.minecraft.item.ItemStack)

Example 19 with ItemArmor

use of net.minecraft.item.ItemArmor in project NetherEx by LogicTechCorp.

the class ArmorUtil method isWearingFullArmorSet.

public static boolean isWearingFullArmorSet(EntityPlayer player, ItemArmor.ArmorMaterial material) {
    Iterable<ItemStack> armor = player.getArmorInventoryList();
    List<ItemArmor.ArmorMaterial> armorMaterials = Lists.newArrayList();
    for (ItemStack testStack : armor) {
        if (testStack == ItemStack.EMPTY || !(testStack.getItem() instanceof ItemArmor)) {
            return false;
        }
        armorMaterials.add(((ItemArmor) testStack.getItem()).getArmorMaterial());
    }
    for (ItemArmor.ArmorMaterial testMaterial : armorMaterials) {
        if (testMaterial != material) {
            return false;
        }
    }
    return true;
}
Also used : ItemArmor(net.minecraft.item.ItemArmor) ItemStack(net.minecraft.item.ItemStack)

Example 20 with ItemArmor

use of net.minecraft.item.ItemArmor in project minecolonies by Minecolonies.

the class EntityCitizen method updateArmorDamage.

/**
     * Updates the armour damage after being hit.
     *
     * @param damage damage dealt.
     */
private void updateArmorDamage(final double damage) {
    for (final ItemStack stack : this.getArmorInventoryList()) {
        if (stack == null || stack.getItem() == null || !(stack.getItem() instanceof ItemArmor)) {
            continue;
        }
        stack.damageItem((int) (damage / 2), this);
        if (stack.getCount() < 1) {
            setItemStackToSlot(getSlotForItemStack(stack), ItemStack.EMPTY);
        }
        setItemStackToSlot(getSlotForItemStack(stack), stack);
    }
}
Also used : ItemArmor(net.minecraft.item.ItemArmor) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemArmor (net.minecraft.item.ItemArmor)45 ItemStack (net.minecraft.item.ItemStack)27 Item (net.minecraft.item.Item)12 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 ModelBiped (net.minecraft.client.model.ModelBiped)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 Color (java.awt.Color)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)4 IArmorImbuement (am2.api.items.armor.IArmorImbuement)3 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)3 Slot (net.minecraft.inventory.Slot)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 Minecraft (net.minecraft.client.Minecraft)2 TextureManager (net.minecraft.client.renderer.texture.TextureManager)2 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)2 ItemBlock (net.minecraft.item.ItemBlock)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2