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.effect.MobEffectCategory;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
2024-02-03 14:56:07 +01:00
|
|
|
import net.neoforged.neoforge.common.NeoForge;
|
|
|
|
import net.neoforged.neoforge.event.entity.living.LivingHealEvent;
|
|
|
|
import net.neoforged.bus.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);
|
2024-02-03 14:56:07 +01:00
|
|
|
NeoForge.EVENT_BUS.register(this);
|
2018-11-29 17:58:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onHeal(LivingHealEvent event) {
|
2022-08-01 16:14:37 +02:00
|
|
|
var effect = event.getEntity().getEffect(this);
|
2018-11-29 17:58:47 +01:00
|
|
|
if (effect == null)
|
|
|
|
return;
|
2021-12-15 16:30:22 +01:00
|
|
|
var chance = (effect.getAmplifier() + 1) / 15F;
|
2018-11-29 17:58:47 +01:00
|
|
|
if (this.random.nextFloat() <= chance) {
|
|
|
|
event.setAmount(event.getAmount() / 4F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-12 19:04:56 +01:00
|
|
|
public boolean shouldApplyEffectTickThisTick(int duration, int amplifier) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var mod = 200 >> amplifier;
|
2018-11-29 17:58:47 +01:00
|
|
|
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) {
|
2023-07-08 12:32:27 +02:00
|
|
|
entity.hurt(entity.damageSources().magic(), 1F);
|
2018-11-29 17:58:47 +01:00
|
|
|
}
|
2024-03-12 19:04:56 +01:00
|
|
|
|
2018-11-29 17:58:47 +01:00
|
|
|
}
|