NaturesAura/src/main/java/de/ellpeck/naturesaura/chunk/effect/BreathlessEffect.java

78 lines
2.8 KiB
Java
Raw Normal View History

2018-11-29 17:58:47 +01:00
package de.ellpeck.naturesaura.chunk.effect;
import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.chunk.AuraChunk;
2018-11-29 17:58:47 +01:00
import de.ellpeck.naturesaura.potion.ModPotions;
2021-12-15 16:24:53 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
2018-11-29 17:58:47 +01:00
public class BreathlessEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "breathless");
private int amp;
private AABB bb;
2021-12-04 15:40:09 +01:00
private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot >= 0)
return false;
2021-12-15 16:30:22 +01:00
var aura = IAuraChunk.getAuraInArea(level, pos, 50);
2018-11-29 17:58:47 +01:00
if (aura > 0)
return false;
2021-12-15 16:30:22 +01:00
var dist = Math.min(Math.abs(aura) / 50000, 75);
2018-11-29 17:58:47 +01:00
if (dist < 10)
return false;
2021-12-04 19:17:21 +01:00
this.amp = Math.min(Mth.floor(Math.abs(aura) / 2500000F), 3);
2021-12-15 16:24:53 +01:00
this.bb = new AABB(pos).inflate(dist);
return true;
}
2018-11-29 17:58:47 +01:00
@Override
2021-12-15 16:24:53 +01:00
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
2021-12-04 15:40:09 +01:00
if (!this.calcValues(player.level, pos, spot))
2020-01-23 16:05:52 +01:00
return ActiveType.INACTIVE;
2021-12-15 16:24:53 +01:00
if (!this.bb.contains(player.getEyePosition()))
2020-01-23 16:05:52 +01:00
return ActiveType.INACTIVE;
return ActiveType.ACTIVE;
}
@Override
public ItemStack getDisplayIcon() {
2020-01-21 23:02:39 +01:00
return new ItemStack(Blocks.WHITE_WOOL);
}
@Override
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot, AuraChunk.DrainSpot actualSpot) {
2021-12-04 15:40:09 +01:00
if (level.getGameTime() % 100 != 0)
return;
2021-12-04 15:40:09 +01:00
if (!this.calcValues(level, pos, spot))
return;
2021-12-15 16:30:22 +01:00
var entities = level.getEntitiesOfClass(LivingEntity.class, this.bb);
for (var entity : entities)
2021-12-15 16:24:53 +01:00
entity.addEffect(new MobEffectInstance(ModPotions.BREATHLESS, 300, this.amp));
2018-11-29 17:58:47 +01:00
}
@Override
2021-12-15 16:24:53 +01:00
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
2020-01-24 17:05:41 +01:00
return ModConfig.instance.breathlessEffect.get();
2018-11-29 17:58:47 +01:00
}
@Override
public ResourceLocation getName() {
2022-06-27 15:24:04 +02:00
return BreathlessEffect.NAME;
2018-11-29 17:58:47 +01:00
}
}