2018-11-29 17:58:47 +01:00
|
|
|
package de.ellpeck.naturesaura.potion;
|
|
|
|
|
2021-12-04 19:17:21 +01:00
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
|
import net.minecraft.world.effect.MobEffectCategory;
|
|
|
|
import net.minecraft.world.effect.MobEffectInstance;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
2018-11-29 17:58:47 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingHealEvent;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2018-11-29 17:58:47 +01:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class PotionBreathless extends PotionImpl {
|
|
|
|
|
|
|
|
private final Random random = new Random();
|
|
|
|
|
2020-01-21 23:02:39 +01:00
|
|
|
public PotionBreathless() {
|
2021-12-04 19:17:21 +01:00
|
|
|
super("breathless", MobEffectCategory.HARMFUL, 0);
|
2018-11-29 17:58:47 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onHeal(LivingHealEvent event) {
|
2021-12-04 19:17:21 +01:00
|
|
|
MobEffectInstance effect = event.getEntityLiving().getEffect(this);
|
2018-11-29 17:58:47 +01:00
|
|
|
if (effect == null)
|
|
|
|
return;
|
|
|
|
float chance = (effect.getAmplifier() + 1) / 15F;
|
|
|
|
if (this.random.nextFloat() <= chance) {
|
|
|
|
event.setAmount(event.getAmount() / 4F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 19:17:21 +01:00
|
|
|
public boolean isDurationEffectTick(int duration, int amplifier) {
|
2018-11-29 17:58:47 +01:00
|
|
|
int mod = 200 >> amplifier;
|
|
|
|
return mod > 0 && duration % mod == 0 && this.random.nextBoolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 19:17:21 +01:00
|
|
|
public void applyEffectTick(LivingEntity entity, int amplifier) {
|
|
|
|
entity.hurt(DamageSource.MAGIC, 1F);
|
2018-11-29 17:58:47 +01:00
|
|
|
}
|
|
|
|
}
|