Search in sources :

Example 1 with IElectricItem

use of gregtech.api.capability.IElectricItem in project GregTech by GregTechCE.

the class ModHandler method useElectricItem.

/**
 * Uses an Electric Item. Only if it's a valid Electric Item for that of course.
 *
 * @return if the action was successful
 */
public static boolean useElectricItem(ItemStack stack, long charge, EntityPlayer player) {
    boolean electricItem = isElectricItem(stack);
    if (!electricItem) {
        return false;
    }
    IElectricItem item = stack.getCapability(IElectricItem.CAPABILITY_ELECTRIC_ITEM, null);
    return item.use(charge, player);
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem)

Example 2 with IElectricItem

use of gregtech.api.capability.IElectricItem in project GregTech by GregTechCE.

the class ElectricItem method chargeFromArmor.

@Override
public void chargeFromArmor(EntityLivingBase entity) {
    if (maxCharge > 0 && chargeable && charge != maxCharge) {
        entity.getEquipmentAndArmor().forEach(otherStack -> {
            if (ModHandler.isElectricItem(otherStack, tier)) {
                IElectricItem capability = otherStack.getCapability(IElectricItem.CAPABILITY_ELECTRIC_ITEM, null);
                charge += capability.discharge(maxCharge - charge, tier, false, true, false);
            }
        });
    }
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem)

Example 3 with IElectricItem

use of gregtech.api.capability.IElectricItem in project GregTech by GregTechCE.

the class ToolMetaItem method doDamageToItem.

@Override
public boolean doDamageToItem(ItemStack stack, int vanillaDamage, boolean simulate) {
    if (!isUsable(stack, vanillaDamage)) {
        return false;
    }
    IElectricItem capability = stack.getCapability(IElectricItem.CAPABILITY_ELECTRIC_ITEM, null);
    if (!simulate) {
        if (capability == null || capability.getMaxCharge() == 0) {
            setInternalDamage(stack, getInternalDamage(stack) + vanillaDamage);
        } else {
            capability.discharge(vanillaDamage, capability.getTier(), true, false, false);
            setInternalDamage(stack, getInternalDamage(stack) + (vanillaDamage / 10));
        }
    }
    return true;
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem)

Example 4 with IElectricItem

use of gregtech.api.capability.IElectricItem in project GregTech by GregTechCE.

the class ModHandler method canUseElectricItem.

/**
 * Uses an Electric Item. Only if it's a valid Electric Item for that of course.
 *
 * @return if the action was successful
 */
public static boolean canUseElectricItem(ItemStack stack, long charge) {
    boolean electricItem = isElectricItem(stack);
    if (!electricItem) {
        return false;
    }
    IElectricItem item = stack.getCapability(IElectricItem.CAPABILITY_ELECTRIC_ITEM, null);
    return item.canUse(charge);
}
Also used : IElectricItem(gregtech.api.capability.IElectricItem)

Aggregations

IElectricItem (gregtech.api.capability.IElectricItem)4