Search in sources :

Example 1 with IPowerBase

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPowerBase(com.bluepowermod.api.power.IPowerBase) Nullable(javax.annotation.Nullable)

Example 2 with IPowerBase

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);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPowerBase(com.bluepowermod.api.power.IPowerBase) Direction(net.minecraft.util.Direction)

Aggregations

IPowerBase (com.bluepowermod.api.power.IPowerBase)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Nullable (javax.annotation.Nullable)1 Direction (net.minecraft.util.Direction)1