use of gregtech.api.capability.IEnergyContainer in project GregTech by GregTechCE.
the class BlockCable method getActiveNodeConnections.
@Override
public int getActiveNodeConnections(IBlockAccess world, BlockPos nodePos, IPipeTile<Insulation, WireProperties> selfTileEntity) {
int activeNodeConnections = 0;
for (EnumFacing side : EnumFacing.VALUES) {
BlockPos offsetPos = nodePos.offset(side);
TileEntity tileEntity = world.getTileEntity(offsetPos);
// do not connect to null cables and ignore cables
if (tileEntity == null || getPipeTileEntity(tileEntity) != null)
continue;
EnumFacing opposite = side.getOpposite();
IEnergyContainer energyContainer = tileEntity.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, opposite);
if (energyContainer != null) {
activeNodeConnections |= 1 << side.getIndex();
}
}
return activeNodeConnections;
}
use of gregtech.api.capability.IEnergyContainer in project GregTech by GregTechCE.
the class CableEnergyContainer method dispatchEnergyToNode.
private long dispatchEnergyToNode(BlockPos nodePos, int nodeBlockedConnections, long voltage, long amperage) {
long amperesUsed = 0L;
// use pooled mutable to avoid creating new objects every tick
World world = tileEntityCable.getPipeWorld();
PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
for (EnumFacing facing : EnumFacing.VALUES) {
if ((nodeBlockedConnections & 1 << facing.getIndex()) > 0) {
// do not dispatch energy to blocked sides
continue;
}
blockPos.setPos(nodePos).move(facing);
if (!world.isBlockLoaded(nodePos)) {
// do not allow cables to load chunks
continue;
}
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity == null || tileEntityCable.getPipeBlock().getPipeTileEntity(tileEntity) != null) {
// do not emit into other cable tile entities
continue;
}
IEnergyContainer energyContainer = tileEntity.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, facing.getOpposite());
if (energyContainer == null)
continue;
amperesUsed += energyContainer.acceptEnergyFromNetwork(facing.getOpposite(), voltage, amperage - amperesUsed);
if (amperesUsed == amperage)
break;
}
blockPos.release();
return amperesUsed;
}
Aggregations