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.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");
|
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
private int amp;
|
2021-12-15 14:26:42 +01:00
|
|
|
private AABB bb;
|
2019-02-09 21:55:40 +01:00
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
private boolean calcValues(Level level, BlockPos pos, Integer spot) {
|
2019-02-09 21:55:40 +01:00
|
|
|
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)
|
2019-02-09 21:55:40 +01:00
|
|
|
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)
|
2019-02-09 21:55:40 +01:00
|
|
|
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);
|
2019-02-09 21:55:40 +01:00
|
|
|
return true;
|
|
|
|
}
|
2018-11-29 17:58:47 +01:00
|
|
|
|
2019-02-09 21:55:40 +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;
|
2019-02-09 21:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getDisplayIcon() {
|
2020-01-21 23:02:39 +01:00
|
|
|
return new ItemStack(Blocks.WHITE_WOOL);
|
2019-02-09 21:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 16:24:53 +01:00
|
|
|
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (level.getGameTime() % 100 != 0)
|
2019-02-09 21:55:40 +01:00
|
|
|
return;
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!this.calcValues(level, pos, spot))
|
2019-02-09 21:55:40 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|