Search in sources :

Example 1 with IModule

use of mekanism.api.gear.IModule in project Mekanism by mekanism.

the class ModuleInhalationPurificationUnit method tickServer.

@Override
public void tickServer(IModule<ModuleInhalationPurificationUnit> module, PlayerEntity player) {
    FloatingLong usage = MekanismConfig.gear.mekaSuitEnergyUsagePotionTick.get();
    boolean free = usage.isZero() || player.isCreative();
    IEnergyContainer energyContainer = free ? null : module.getEnergyContainer();
    if (free || (energyContainer != null && energyContainer.getEnergy().greaterOrEqual(usage))) {
        // Gather all the active effects that we can handle, so that we have them in their own list and
        // don't run into any issues related to CMEs
        List<EffectInstance> effects = player.getActiveEffects().stream().filter(effect -> canHandle(effect.getEffect().getCategory())).collect(Collectors.toList());
        for (EffectInstance effect : effects) {
            if (free) {
                speedupEffect(player, effect);
            } else if (module.useEnergy(player, energyContainer, usage, true).isZero()) {
                // If we can't actually extract energy, exit
                break;
            } else {
                speedupEffect(player, effect);
                if (energyContainer.getEnergy().smallerThan(usage)) {
                    // If after using energy, our remaining energy is now smaller than how much we need to use, exit
                    break;
                }
            }
        }
    }
}
Also used : ModuleBooleanData(mekanism.api.gear.config.ModuleBooleanData) IModule(mekanism.api.gear.IModule) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ICustomModule(mekanism.api.gear.ICustomModule) ModuleConfigItemCreator(mekanism.api.gear.config.ModuleConfigItemCreator) Collectors(java.util.stream.Collectors) DamageSource(net.minecraft.util.DamageSource) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) IModuleConfigItem(mekanism.api.gear.config.IModuleConfigItem) MekanismUtils(mekanism.common.util.MekanismUtils) List(java.util.List) EffectInstance(net.minecraft.potion.EffectInstance) FloatingLong(mekanism.api.math.FloatingLong) EffectType(net.minecraft.potion.EffectType) IEnergyContainer(mekanism.api.energy.IEnergyContainer) MekanismLang(mekanism.common.MekanismLang) MekanismConfig(mekanism.common.config.MekanismConfig) Nullable(javax.annotation.Nullable) FloatingLong(mekanism.api.math.FloatingLong) IEnergyContainer(mekanism.api.energy.IEnergyContainer) EffectInstance(net.minecraft.potion.EffectInstance)

Example 2 with IModule

use of mekanism.api.gear.IModule in project Mekanism by mekanism.

the class ModuleInhalationPurificationUnit method tickClient.

@Override
public void tickClient(IModule<ModuleInhalationPurificationUnit> module, PlayerEntity player) {
    // Messy rough estimate version of tickServer so that the timer actually properly updates
    if (!player.isSpectator()) {
        FloatingLong usage = MekanismConfig.gear.mekaSuitEnergyUsagePotionTick.get();
        boolean free = usage.isZero() || player.isCreative();
        FloatingLong energy = free ? FloatingLong.ZERO : module.getContainerEnergy().copy();
        if (free || energy.greaterOrEqual(usage)) {
            // Gather all the active effects that we can handle, so that we have them in their own list and
            // don't run into any issues related to CMEs
            List<EffectInstance> effects = player.getActiveEffects().stream().filter(effect -> canHandle(effect.getEffect().getCategory())).collect(Collectors.toList());
            for (EffectInstance effect : effects) {
                if (free) {
                    speedupEffect(player, effect);
                } else {
                    energy = energy.minusEqual(usage);
                    speedupEffect(player, effect);
                    if (energy.smallerThan(usage)) {
                        // If after using energy, our remaining energy is now smaller than how much we need to use, exit
                        break;
                    }
                }
            }
        }
    }
}
Also used : ModuleBooleanData(mekanism.api.gear.config.ModuleBooleanData) IModule(mekanism.api.gear.IModule) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ICustomModule(mekanism.api.gear.ICustomModule) ModuleConfigItemCreator(mekanism.api.gear.config.ModuleConfigItemCreator) Collectors(java.util.stream.Collectors) DamageSource(net.minecraft.util.DamageSource) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) IModuleConfigItem(mekanism.api.gear.config.IModuleConfigItem) MekanismUtils(mekanism.common.util.MekanismUtils) List(java.util.List) EffectInstance(net.minecraft.potion.EffectInstance) FloatingLong(mekanism.api.math.FloatingLong) EffectType(net.minecraft.potion.EffectType) IEnergyContainer(mekanism.api.energy.IEnergyContainer) MekanismLang(mekanism.common.MekanismLang) MekanismConfig(mekanism.common.config.MekanismConfig) Nullable(javax.annotation.Nullable) FloatingLong(mekanism.api.math.FloatingLong) EffectInstance(net.minecraft.potion.EffectInstance)

Aggregations

List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)2 IEnergyContainer (mekanism.api.energy.IEnergyContainer)2 ICustomModule (mekanism.api.gear.ICustomModule)2 IModule (mekanism.api.gear.IModule)2 IModuleConfigItem (mekanism.api.gear.config.IModuleConfigItem)2 ModuleBooleanData (mekanism.api.gear.config.ModuleBooleanData)2 ModuleConfigItemCreator (mekanism.api.gear.config.ModuleConfigItemCreator)2 FloatingLong (mekanism.api.math.FloatingLong)2 MekanismLang (mekanism.common.MekanismLang)2 MekanismConfig (mekanism.common.config.MekanismConfig)2 MekanismUtils (mekanism.common.util.MekanismUtils)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 EffectInstance (net.minecraft.potion.EffectInstance)2 EffectType (net.minecraft.potion.EffectType)2 DamageSource (net.minecraft.util.DamageSource)2