Search in sources :

Example 11 with EnergyUpgradeHolder

use of crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder in project EnderIO by SleepyTrousers.

the class ItemDarkSteelSword method hitEntity.

@Override
public boolean hitEntity(@Nonnull ItemStack stack, @Nonnull EntityLivingBase entity, @Nonnull EntityLivingBase playerEntity) {
    if (playerEntity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) playerEntity;
        ItemStack sword = player.getHeldItemMainhand();
        // Durability damage
        EnergyUpgradeHolder eu = EnergyUpgradeManager.loadFromItem(stack);
        if (eu != null && eu.getUpgrade().isAbsorbDamageWithPower() && eu.getEnergy() > 0) {
            eu.extractEnergy(powerPerDamagePoint, false);
        } else {
            super.hitEntity(stack, entity, playerEntity);
        }
        // sword hit
        if (eu != null) {
            eu.writeToItem(sword, this);
            if (eu.getEnergy() > Config.darkSteelSwordPowerUsePerHit) {
                extractInternal(player.getHeldItemMainhand(), Config.darkSteelSwordPowerUsePerHit);
                entity.getEntityData().setBoolean(HIT_BY_DARK_STEEL_SWORD, true);
            }
        }
    }
    return true;
}
Also used : EnergyUpgradeHolder(crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 12 with EnergyUpgradeHolder

use of crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder in project EnderIO by SleepyTrousers.

the class EnergyUpgradeManager method setPowerFull.

public static void setPowerFull(@Nonnull ItemStack container, @Nonnull IDarkSteelItem item) {
    if (!itemHasAnyPowerUpgrade(container)) {
        return;
    }
    EnergyUpgradeHolder eu = loadFromItem(container);
    eu.setEnergy(eu.getCapacity());
    eu.writeToItem(container, item);
}
Also used : EnergyUpgradeHolder(crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder)

Aggregations

EnergyUpgradeHolder (crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder)12 ItemStack (net.minecraft.item.ItemStack)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityArrow (net.minecraft.entity.projectile.EntityArrow)1 ItemArrow (net.minecraft.item.ItemArrow)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1