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;
}
}
}
}
}
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;
}
}
}
}
}
}
Aggregations