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;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.tileentity.ITickableTileEntity;
|
2018-10-28 17:39:53 +01:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
public class TileEntityAuraDetector extends TileEntityImpl implements ITickableTileEntity {
|
2018-10-28 17:39:53 +01:00
|
|
|
|
|
|
|
public int redstonePower;
|
|
|
|
|
2020-01-22 01:32:26 +01:00
|
|
|
public TileEntityAuraDetector() {
|
|
|
|
super(ModTileEntities.AURA_DETECTOR);
|
2020-01-21 21:04:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-28 17:39:53 +01:00
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
public void tick() {
|
|
|
|
if (!this.world.isRemote && this.world.getGameTime() % 20 == 0) {
|
2018-12-05 11:21:08 +01:00
|
|
|
int totalAmount = IAuraChunk.triangulateAuraInArea(this.world, this.pos, 25);
|
|
|
|
int power = MathHelper.clamp(MathHelper.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15);
|
2018-10-28 17:39:53 +01:00
|
|
|
if (this.redstonePower != power) {
|
|
|
|
this.redstonePower = power;
|
2020-01-21 21:04:44 +01:00
|
|
|
this.world.updateComparatorOutputLevel(this.pos, this.getBlockState().getBlock());
|
2018-10-28 17:39:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|