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

80 lines
2.7 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.NaturesAuraAPI;
2018-11-29 17:58:47 +01:00
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;
2019-10-20 22:30:49 +02:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
2019-10-20 22:30:49 +02:00
import net.minecraft.potion.EffectInstance;
2018-11-29 17:58:47 +01:00
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import java.util.List;
public class BreathlessEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "breathless");
private int amp;
private AxisAlignedBB bb;
private boolean calcValues(World world, BlockPos pos, Integer spot) {
if (spot >= 0)
return false;
2018-11-29 17:58:47 +01:00
int aura = IAuraChunk.getAuraInArea(world, pos, 50);
if (aura > 0)
return false;
int dist = Math.min(Math.abs(aura) / 50000, 75);
2018-11-29 17:58:47 +01:00
if (dist < 10)
return false;
this.amp = Math.min(MathHelper.floor(Math.abs(aura) / 2500000F), 3);
this.bb = new AxisAlignedBB(pos).grow(dist);
return true;
}
2018-11-29 17:58:47 +01:00
@Override
2019-10-20 22:30:49 +02:00
public int isActiveHere(PlayerEntity player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.world, pos, spot))
return -1;
if (!this.bb.contains(player.getPositionVector()))
return -1;
return 1;
}
@Override
public ItemStack getDisplayIcon() {
return new ItemStack(Blocks.WOOL);
}
@Override
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (world.getTotalWorldTime() % 100 != 0)
return;
if (!this.calcValues(world, pos, spot))
return;
2019-10-20 22:30:49 +02:00
List<LivingEntity> entities = world.getEntitiesWithinAABB(LivingEntity.class, this.bb);
for (LivingEntity entity : entities)
entity.addPotionEffect(new EffectInstance(ModPotions.BREATHLESS, 300, this.amp));
2018-11-29 17:58:47 +01:00
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.enabledFeatures.breathlessEffect;
}
@Override
public ResourceLocation getName() {
return NAME;
}
}