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;
}
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));
}
}
}
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);
}
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;
}
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);
}
}
Aggregations