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

28 lines
1 KiB
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;
2020-01-21 21:04:44 +01:00
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
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-21 21:04:44 +01:00
public TileEntityAuraDetector(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
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) {
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
}
}
}
}