use of com.bluepowermod.api.power.IPowerBase in project BluePower by Qmunity.
the class BlockBattery method getStateForPlacement.
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
TileEntity tile = context.getLevel().getBlockEntity(context.getClickedPos());
if (tile != null && tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY).isPresent()) {
IPowerBase storage = tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY).orElse(null);
double voltage = storage.getVoltage();
int level = (int) ((voltage / storage.getMaxVoltage()) * 6);
return this.stateDefinition.any().setValue(LEVEL, level);
}
return super.getStateForPlacement(context);
}
use of com.bluepowermod.api.power.IPowerBase in project BluePower by Qmunity.
the class TileThermopile method tick.
@Override
public void tick() {
if (!level.isClientSide) {
storage.resetCurrent();
if (level.getBlockState(worldPosition.relative(Direction.DOWN)).getBlock() == Blocks.LAVA && storage.getEnergy() < MAX_VOLTAGE)
storage.addEnergy(0.1, false);
// Balance power of attached blulectric blocks.
for (Direction facing : Direction.values()) {
TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
if (tile != null && tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).isPresent()) {
IPowerBase exStorage = tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).orElse(null);
EnergyHelper.balancePower(exStorage, storage);
}
}
}
}
Aggregations