2018-10-28 17:39:53 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks.tiles;
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
2018-10-28 17:39:53 +01:00
|
|
|
import net.minecraft.util.ITickable;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
2018-12-04 21:31:22 +01:00
|
|
|
import org.apache.commons.lang3.mutable.MutableFloat;
|
2018-10-28 17:39:53 +01:00
|
|
|
|
|
|
|
public class TileEntityAuraDetector extends TileEntityImpl implements ITickable {
|
|
|
|
|
|
|
|
public int redstonePower;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
2018-12-05 01:12:53 +01:00
|
|
|
if (!this.world.isRemote && this.world.getTotalWorldTime() % 20 == 0) {
|
2018-12-04 21:31:22 +01:00
|
|
|
MutableFloat totalAmount = new MutableFloat(IAuraChunk.DEFAULT_AURA);
|
|
|
|
IAuraChunk.getSpotsInArea(this.world, this.pos, 25, (pos, spot) -> {
|
|
|
|
float percentage = 1F - (float) this.pos.getDistance(pos.getX(), pos.getY(), pos.getZ()) / 25F;
|
|
|
|
totalAmount.add(spot * percentage);
|
|
|
|
});
|
|
|
|
int power = MathHelper.clamp(MathHelper.ceil(totalAmount.intValue() / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15);
|
2018-10-28 17:39:53 +01:00
|
|
|
if (this.redstonePower != power) {
|
|
|
|
this.redstonePower = power;
|
|
|
|
this.world.updateComparatorOutputLevel(this.pos, this.getBlockType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|