Search in sources :

Example 21 with ItemArmor

use of net.minecraft.item.ItemArmor in project SilentGems by SilentChaos512.

the class EquipmentTooltips method getToughness.

private float getToughness(ItemStack stack, float defaultValue) {
    if (StackHelper.isEmpty(stack))
        return defaultValue;
    ItemArmor itemArmor = (ItemArmor) stack.getItem();
    EntityEquipmentSlot slot = itemArmor.armorType;
    UUID uuid = ItemArmor.ARMOR_MODIFIERS[slot.getIndex()];
    Multimap<String, AttributeModifier> multimap = stack.getAttributeModifiers(slot);
    for (Entry<String, AttributeModifier> entry : multimap.entries()) {
        String key = entry.getKey();
        AttributeModifier mod = entry.getValue();
        if (key.equals(SharedMonsterAttributes.ARMOR_TOUGHNESS.getName()) && mod.getID().equals(uuid)) {
            return (float) mod.getAmount();
        }
    }
    return 0f;
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ItemArmor(net.minecraft.item.ItemArmor) UUID(java.util.UUID) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 22 with ItemArmor

use of net.minecraft.item.ItemArmor in project SilentGems by SilentChaos512.

the class EquipmentTooltips method onRenderTooltip.

@SubscribeEvent
public void onRenderTooltip(RenderTooltipEvent.PostText event) {
    ItemStack stack = event.getStack();
    Item item = stack.getItem();
    boolean isTinkersHarvestTool = isTinkersLoaded && item instanceof slimeknights.tconstruct.library.tools.AoeToolCore;
    boolean isTinkersWeapon = isTinkersLoaded && item instanceof slimeknights.tconstruct.library.tools.SwordCore;
    boolean isTinkersBow = isTinkersLoaded && item instanceof slimeknights.tconstruct.library.tools.ranged.BowCore;
    // Tools (pickaxes, shovels, axes, and more)
    if (item instanceof ItemTool || item instanceof ItemHoe || item instanceof ItemShears || item instanceof ItemFishingRod || isTinkersHarvestTool) {
        renderBackground(event);
        renderForTool(event, stack);
    } else // Swords
    if (item instanceof ItemSword || isTinkersWeapon) {
        boolean isCaster = item instanceof ITool && ToolHelper.getToolTier(stack).ordinal() >= EnumMaterialTier.SUPER.ordinal();
        renderBackground(event);
        renderForWeapon(event, stack);
    } else // Bows
    if (item instanceof ItemBow || isTinkersBow) {
        renderBackground(event);
        renderForBow(event, stack);
    } else // Shields
    if (item instanceof ItemShield) {
        renderBackground(event);
        renderForShield(event, stack);
    } else // Armor
    if (item instanceof ItemArmor) {
        renderBackground(event);
        renderForArmor(event, stack);
    }
// Unknown
}
Also used : ItemSword(net.minecraft.item.ItemSword) ItemTool(net.minecraft.item.ItemTool) ItemShield(net.minecraft.item.ItemShield) ItemFishingRod(net.minecraft.item.ItemFishingRod) ItemArmor(net.minecraft.item.ItemArmor) ITool(net.silentchaos512.gems.api.ITool) ItemBow(net.minecraft.item.ItemBow) Item(net.minecraft.item.Item) ItemHoe(net.minecraft.item.ItemHoe) ItemShears(net.minecraft.item.ItemShears) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 23 with ItemArmor

use of net.minecraft.item.ItemArmor in project SilentGems by SilentChaos512.

the class EquipmentTooltips method getProtection.

private float getProtection(ItemStack stack, float defaultValue) {
    if (StackHelper.isEmpty(stack))
        return defaultValue;
    ItemArmor itemArmor = (ItemArmor) stack.getItem();
    EntityEquipmentSlot slot = itemArmor.armorType;
    UUID uuid = ItemArmor.ARMOR_MODIFIERS[slot.getIndex()];
    Multimap<String, AttributeModifier> multimap = stack.getAttributeModifiers(slot);
    for (Entry<String, AttributeModifier> entry : multimap.entries()) {
        String key = entry.getKey();
        AttributeModifier mod = entry.getValue();
        if (key.equals(SharedMonsterAttributes.ARMOR.getName()) && mod.getID().equals(uuid)) {
            return (float) mod.getAmount();
        }
    }
    return 0f;
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ItemArmor(net.minecraft.item.ItemArmor) UUID(java.util.UUID) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 24 with ItemArmor

use of net.minecraft.item.ItemArmor in project SpongeCommon by SpongePowered.

the class DamageEventHandler method createArmorModifiers.

public static Optional<List<DamageFunction>> createArmorModifiers(EntityLivingBase entityLivingBase, DamageSource damageSource, double damage) {
    if (!damageSource.isUnblockable()) {
        damage *= 25;
        net.minecraft.item.ItemStack[] inventory = Iterables.toArray(entityLivingBase.getArmorInventoryList(), net.minecraft.item.ItemStack.class);
        List<DamageFunction> modifiers = new ArrayList<>();
        List<DamageObject> damageObjects = new ArrayList<>();
        for (int index = 0; index < inventory.length; index++) {
            net.minecraft.item.ItemStack itemStack = inventory[index];
            if (itemStack.isEmpty()) {
                continue;
            }
            Item item = itemStack.getItem();
            if (item instanceof ItemArmor) {
                ItemArmor armor = (ItemArmor) item;
                double reduction = armor.damageReduceAmount / 25D;
                DamageObject object = new DamageObject();
                object.slot = index;
                object.ratio = reduction;
                damageObjects.add(object);
            }
        }
        boolean first = true;
        double ratio = 0;
        for (DamageObject prop : damageObjects) {
            EquipmentType type = resolveEquipment(prop.slot);
            final DamageObject object = new DamageObject();
            object.ratio = ratio;
            if (first) {
                object.previousDamage = damage;
                object.augment = true;
            }
            DoubleUnaryOperator function = incomingDamage -> {
                incomingDamage *= 25;
                if (object.augment) {
                    // This is the damage that needs to be archived for the "first" armor modifier
                    // function since the armor modifiers work based on the initial damage and not as
                    // a chain one after another.
                    damageToHandle = incomingDamage;
                }
                double functionDamage = damageToHandle;
                object.previousDamage = functionDamage;
                object.ratio = prop.ratio;
                object.ratio += prop.ratio;
                return -((functionDamage * prop.ratio) / 25);
            };
            ratio += prop.ratio;
            // TODO: direct cause creation: bad bad bad
            DamageModifier modifier = DamageModifier.builder().cause(Cause.of(EventContext.empty(), ((org.spongepowered.api.item.inventory.ItemStack) inventory[prop.slot]).createSnapshot(), // We need this property to refer to the slot.
            prop, // We need this object later on.
            object)).type(DamageModifierTypes.ARMOR).build();
            modifiers.add(new DamageFunction(modifier, function));
            first = false;
        }
        if (!modifiers.isEmpty()) {
            return Optional.of(modifiers);
        }
    }
    return Optional.empty();
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Item(net.minecraft.item.Item) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) NBTTagList(net.minecraft.nbt.NBTTagList) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Map(java.util.Map) EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ItemArmor(net.minecraft.item.ItemArmor) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) NbtDataUtil(org.spongepowered.common.data.util.NbtDataUtil) Location(org.spongepowered.api.world.Location) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) Predicate(java.util.function.Predicate) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) EntityUtil(org.spongepowered.common.entity.EntityUtil) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(org.spongepowered.api.world.World) Optional(java.util.Optional) MobEffects(net.minecraft.init.MobEffects) EventContext(org.spongepowered.api.event.cause.EventContext) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Iterables(com.google.common.collect.Iterables) Enchantment(net.minecraft.enchantment.Enchantment) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) DamageModifierTypes(org.spongepowered.api.event.cause.entity.damage.DamageModifierTypes) Multimap(com.google.common.collect.Multimap) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Chunk(net.minecraft.world.chunk.Chunk) Entity(net.minecraft.entity.Entity) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) BlockPos(net.minecraft.util.math.BlockPos) DamageSource(net.minecraft.util.DamageSource) IBlockState(net.minecraft.block.state.IBlockState) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) EntityLivingBase(net.minecraft.entity.EntityLivingBase) MathHelper(net.minecraft.util.math.MathHelper) EntityDamageSource(net.minecraft.util.EntityDamageSource) EnumCreatureAttribute(net.minecraft.entity.EnumCreatureAttribute) EquipmentTypes(org.spongepowered.api.item.inventory.equipment.EquipmentTypes) ItemArmor(net.minecraft.item.ItemArmor) ArrayList(java.util.ArrayList) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Item(net.minecraft.item.Item) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) ItemStack(org.spongepowered.api.item.inventory.ItemStack) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 25 with ItemArmor

use of net.minecraft.item.ItemArmor in project SpongeCommon by SpongePowered.

the class DamageAbsorptionPropertyStore method getFor.

@Override
protected Optional<DamageAbsorptionProperty> getFor(ItemStack itemStack) {
    if (itemStack.getItem() instanceof ItemArmor) {
        final ItemArmor armor = (ItemArmor) itemStack.getItem();
        final int reduction = armor.damageReduceAmount;
        return Optional.of(new DamageAbsorptionProperty(reduction));
    }
    return Optional.empty();
}
Also used : DamageAbsorptionProperty(org.spongepowered.api.data.property.item.DamageAbsorptionProperty) ItemArmor(net.minecraft.item.ItemArmor)

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