2018-11-29 17:58:47 +01:00
|
|
|
package de.ellpeck.naturesaura.chunk.effect;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2019-02-09 21:55:40 +01:00
|
|
|
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;
|
2019-02-09 21:55:40 +01:00
|
|
|
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");
|
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
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)
|
2019-02-09 21:55:40 +01:00
|
|
|
return false;
|
2019-01-29 11:46:38 +01:00
|
|
|
int 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;
|
|
|
|
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
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public int isActiveHere(PlayerEntity player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
2019-02-09 21:55:40 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|