2018-11-13 14:52:19 +01:00
|
|
|
package de.ellpeck.naturesaura.chunk.effect;
|
|
|
|
|
|
|
|
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 net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
2018-12-26 12:00:25 +01:00
|
|
|
import org.apache.commons.lang3.mutable.MutableInt;
|
2018-11-13 14:52:19 +01:00
|
|
|
|
2018-11-18 19:49:30 +01:00
|
|
|
public class BalanceEffect implements IDrainSpotEffect {
|
2018-11-13 14:52:19 +01:00
|
|
|
|
2018-11-18 19:49:30 +01:00
|
|
|
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "balance");
|
2018-11-13 14:52:19 +01:00
|
|
|
|
|
|
|
@Override
|
2018-12-02 01:36:41 +01:00
|
|
|
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
2019-01-29 11:46:38 +01:00
|
|
|
if (spot < 100000)
|
2018-11-13 14:52:19 +01:00
|
|
|
return;
|
2021-01-30 17:21:41 +01:00
|
|
|
if (world.getGameTime() % 200 != 0)
|
|
|
|
return;
|
2019-01-29 11:46:38 +01:00
|
|
|
int searchRadius = Math.min(45, spot / 10000);
|
2018-12-26 12:00:25 +01:00
|
|
|
MutableInt positiveAura = new MutableInt();
|
|
|
|
IAuraChunk.getSpotsInArea(world, pos, searchRadius, (otherPos, otherSpot) -> {
|
|
|
|
if (otherSpot > 0)
|
|
|
|
positiveAura.add(otherSpot);
|
|
|
|
});
|
2019-01-29 11:46:38 +01:00
|
|
|
int radius = Math.min(80, positiveAura.intValue() / 5000);
|
2018-12-04 21:18:45 +01:00
|
|
|
BlockPos lowestPos = IAuraChunk.getLowestSpot(world, pos, radius, null);
|
|
|
|
if (lowestPos == null)
|
2018-11-13 14:52:19 +01:00
|
|
|
return;
|
2021-01-30 17:21:41 +01:00
|
|
|
int stored = IAuraChunk.getAuraChunk(world, lowestPos).storeAura(lowestPos, spot / 50);
|
2018-12-04 21:31:22 +01:00
|
|
|
auraChunk.drainAura(pos, stored);
|
2018-11-13 14:52:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-11-13 18:21:41 +01:00
|
|
|
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
|
2018-11-13 14:52:19 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getName() {
|
|
|
|
return NAME;
|
|
|
|
}
|
|
|
|
}
|