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;
|
2021-12-06 14:38:12 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.util.Mth;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2018-10-28 17:39:53 +01:00
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
public class BlockEntityAuraDetector extends BlockEntityImpl implements ITickableBlockEntity {
|
2018-10-28 17:39:53 +01:00
|
|
|
|
|
|
|
public int redstonePower;
|
|
|
|
|
2021-12-06 14:38:12 +01:00
|
|
|
public BlockEntityAuraDetector(BlockPos pos, BlockState state) {
|
|
|
|
super(ModTileEntities.AURA_DETECTOR, pos, state);
|
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() {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!this.level.isClientSide && this.level.getGameTime() % 20 == 0) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var totalAmount = IAuraChunk.triangulateAuraInArea(this.level, this.worldPosition, 25);
|
|
|
|
var power = Mth.clamp(Mth.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15);
|
2018-10-28 17:39:53 +01:00
|
|
|
if (this.redstonePower != power) {
|
|
|
|
this.redstonePower = power;
|
2021-12-06 14:38:12 +01:00
|
|
|
this.level.updateNeighbourForOutputSignal(this.worldPosition, this.getBlockState().getBlock());
|
2018-10-28 17:39:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|