Search in sources :

Example 6 with IEnergyContainer

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEnergyContainer(gregtech.api.capability.IEnergyContainer) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with IEnergyContainer

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) IEnergyContainer(gregtech.api.capability.IEnergyContainer) EnumFacing(net.minecraft.util.EnumFacing) World(net.minecraft.world.World)

Aggregations

IEnergyContainer (gregtech.api.capability.IEnergyContainer)7 TileEntity (net.minecraft.tileentity.TileEntity)5 EnumFacing (net.minecraft.util.EnumFacing)5 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 PooledMutableBlockPos (net.minecraft.util.math.BlockPos.PooledMutableBlockPos)2 World (net.minecraft.world.World)2 TIntList (gnu.trove.list.TIntList)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 IElectricItem (gregtech.api.capability.IElectricItem)1 TileEntityCableEmitter (gregtech.common.blocks.tileentity.TileEntityCableEmitter)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 Style (net.minecraft.util.text.Style)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)1