Search in sources :

Example 1 with IElectricItem

use of ic2.api.item.IElectricItem in project compactsolars by cpw.

the class ItemSolarHat method onArmorTickUpdate.

@Override
public void onArmorTickUpdate(World worldObj, EntityPlayer player, ItemStack itemStack) {
    // client side or no sky: no charge
    if (worldObj.isRemote || worldObj.provider.hasNoSky) {
        return;
    }
    // productionrate is set, and the tick is not zero : no charge
    if (CompactSolars.productionRate != 1 && random.nextInt(CompactSolars.productionRate) != 0) {
        return;
    }
    int xCoord = MathHelper.floor_double(player.posX);
    int zCoord = MathHelper.floor_double(player.posZ);
    boolean isRaining = false;
    if (!this.playerState.containsKey(player)) {
        this.playerState.put(player, new PlayerState());
    }
    PlayerState state = playerState.get(player);
    if (worldObj.getTotalWorldTime() % 20 == 0) {
        boolean canRain = worldObj.getWorldChunkManager().getBiomeGenAt(xCoord, zCoord).getIntRainfall() > 0;
        state.canRain = canRain;
    }
    isRaining = state.canRain && (worldObj.isRaining() || worldObj.isThundering());
    boolean theSunIsVisible = worldObj.isDaytime() && !isRaining && worldObj.canBlockSeeTheSky(xCoord, MathHelper.floor_double(player.posY) + 1, zCoord);
    if (!theSunIsVisible) {
        return;
    }
    int available = type.getOutput();
    for (ItemStack is : player.inventory.armorInventory) {
        if (is == itemStack) {
            continue;
        }
        if (is != null) {
            if (is.getItem() instanceof IElectricItem) {
                IElectricItem electricItem = (IElectricItem) is.getItem();
                available -= ElectricItem.manager.charge(is, available, type.ordinal() + 1, false, false);
            }
        }
    }
    if (available <= 0) {
        state.buildUp += IntMath.pow(2, type.ordinal());
    } else {
        state.buildUp = Math.max(state.buildUp - (worldObj.getTotalWorldTime() - state.lastTick), 0);
    }
    state.lastTick = worldObj.getTotalWorldTime();
    int dose = IntMath.pow(10, type.ordinal()) * 5;
    if (state.buildUp > dose) {
        player.addPotionEffect(new PotionEffect(Potion.confusion.id, dose >> 2, 0));
        state.buildUp -= dose;
    }
}
Also used : IElectricItem(ic2.api.item.IElectricItem) PotionEffect(net.minecraft.potion.PotionEffect) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IElectricItem (ic2.api.item.IElectricItem)1 ItemStack (net.minecraft.item.ItemStack)1 PotionEffect (net.minecraft.potion.PotionEffect)1