Search in sources :

Example 6 with EnergyUpgradeHolder

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

the class EnergyUpgradeManager method receiveEnergy.

public static int receiveEnergy(@Nonnull ItemStack container, @Nonnull IDarkSteelItem item, int maxReceive, boolean simulate) {
    EnergyUpgradeHolder eu = loadFromItem(container);
    if (eu == null) {
        return 0;
    }
    int res = eu.receiveEnergy(maxReceive, simulate);
    if (!simulate && res > 0) {
        eu.writeToItem(container, item);
    }
    return res;
}
Also used : EnergyUpgradeHolder(crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder)

Example 7 with EnergyUpgradeHolder

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

the class ItemDarkSteelAxe method absorbDamageWithEnergy.

private boolean absorbDamageWithEnergy(@Nonnull ItemStack stack, int amount) {
    EnergyUpgradeHolder eu = EnergyUpgradeManager.loadFromItem(stack);
    if (eu != null && eu.getUpgrade().isAbsorbDamageWithPower() && eu.getEnergy() > 0) {
        eu.extractEnergy(amount, false);
        eu.writeToItem(stack, this);
        return true;
    } else {
        return false;
    }
}
Also used : EnergyUpgradeHolder(crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder)

Example 8 with EnergyUpgradeHolder

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

the class ItemDarkSteelBow method absorbDamageWithEnergy.

private boolean absorbDamageWithEnergy(@Nonnull ItemStack stack, int amount) {
    EnergyUpgradeHolder eu = EnergyUpgradeManager.loadFromItem(stack);
    if (eu != null && eu.getUpgrade().isAbsorbDamageWithPower() && eu.getEnergy() > 0) {
        eu.extractEnergy(amount, false);
        eu.writeToItem(stack, this);
        return true;
    }
    return false;
}
Also used : EnergyUpgradeHolder(crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder)

Example 9 with EnergyUpgradeHolder

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

the class ItemDarkSteelBow method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(@Nonnull ItemStack stack, @Nonnull World worldIn, @Nonnull EntityLivingBase entityLiving, int timeLeft) {
    if (!(entityLiving instanceof EntityPlayer)) {
        return;
    }
    EntityPlayer entityplayer = (EntityPlayer) entityLiving;
    boolean hasInfinateArrows = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
    ItemStack itemstack = getArrowsToShoot(entityplayer);
    int draw = getMaxItemUseDuration(stack) - timeLeft;
    draw = ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, draw, Prep.isValid(itemstack) || hasInfinateArrows);
    if (draw < 0) {
        return;
    }
    if (itemstack.isEmpty() && hasInfinateArrows) {
        itemstack = new ItemStack(Items.ARROW);
    }
    if (itemstack.isEmpty()) {
        return;
    }
    float drawRatio = getCustumArrowVelocity(stack, draw);
    if (drawRatio >= 0.1) {
        boolean arrowIsInfinite = hasInfinateArrows && itemstack.getItem() instanceof ItemArrow;
        if (!worldIn.isRemote) {
            EnergyUpgradeHolder upgrade = EnergyUpgradeManager.loadFromItem(stack);
            ItemArrow itemarrow = ((ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW));
            EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
            // ATTENTION:
            entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, drawRatio * 3.0F * getForceMultiplier(upgrade), 0.25F);
            if (drawRatio == 1.0F) {
                entityarrow.setIsCritical(true);
            }
            int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
            if (powerLevel > 0) {
                entityarrow.setDamage(entityarrow.getDamage() + powerLevel * 0.5D + 0.5D);
            }
            int knockBack = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
            if (knockBack > 0) {
                entityarrow.setKnockbackStrength(knockBack);
            }
            if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
                entityarrow.setFire(100);
            }
            stack.damageItem(1, entityplayer);
            if (arrowIsInfinite) {
                entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
            }
            entityarrow.setDamage(entityarrow.getDamage() + damageBonus);
            worldIn.spawnEntity(entityarrow);
            int used = getRequiredPower(draw, upgrade);
            if (used > 0) {
                upgrade.setEnergy(upgrade.getEnergy() - used);
                upgrade.writeToItem(stack, this);
            }
        }
        worldIn.playSound((EntityPlayer) null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + drawRatio * 0.5F);
        if (!arrowIsInfinite) {
            itemstack.shrink(1);
        }
        supressed(entityplayer);
    }
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EnergyUpgradeHolder(crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade.EnergyUpgradeHolder) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemArrow(net.minecraft.item.ItemArrow)

Example 10 with EnergyUpgradeHolder

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

the class ItemDarkSteelShears method setDamage.

@Override
public void setDamage(@Nonnull ItemStack stack, int newDamage) {
    int oldDamage = getDamage(stack);
    if (newDamage <= oldDamage) {
        super.setDamage(stack, newDamage);
    }
    int damage = newDamage - oldDamage;
    EnergyUpgradeHolder eu = EnergyUpgradeManager.loadFromItem(stack);
    if (eu != null && eu.getUpgrade().isAbsorbDamageWithPower() && eu.getEnergy() > 0) {
        eu.extractEnergy(damage * Config.darkSteelShearsPowerUsePerDamagePoint, false);
    } else {
        super.setDamage(stack, newDamage);
    }
    if (eu != null) {
        eu.writeToItem(stack, this);
    }
}
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