NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAuraDetector.java

27 lines
987 B
Java
Raw Normal View History

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-04 15:40:09 +01:00
import net.minecraft.tileentity.ITickableBlockEntity;
2018-10-28 17:39:53 +01:00
import net.minecraft.util.math.MathHelper;
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-04 15:40:09 +01:00
public BlockEntityAuraDetector() {
2020-01-22 01:32:26 +01:00
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() {
2021-12-04 15:40:09 +01:00
if (!this.level.isClientSide && this.level.getGameTime() % 20 == 0) {
int totalAmount = IAuraChunk.triangulateAuraInArea(this.level, this.worldPosition, 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;
2021-12-04 15:40:09 +01:00
this.level.updateComparatorOutputLevel(this.worldPosition, this.getBlockState().getBlock());
2018-10-28 17:39:53 +01:00
}
}
}
}