Search in sources :

Example 1 with PooledMutableBlockPos

use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.

the class BlockCable method notifyNetworkAboutRefresh.

private void notifyNetworkAboutRefresh(World world, BlockPos initialPos) {
    PooledMutableBlockPos currentPos = PooledMutableBlockPos.retain(initialPos.getX(), initialPos.getY(), initialPos.getZ());
    List<BlockPos> visited = new ArrayList<>();
    Stack<EnumFacing> moveStack = new Stack<>();
    while (true) {
        for (EnumFacing facing : EnumFacing.VALUES) {
            currentPos.move(facing);
            EnumFacing opposite = facing.getOpposite();
            if (!visited.contains(currentPos)) {
                visited.add(currentPos.toImmutable());
            } else {
                currentPos.move(opposite);
                continue;
            }
            if (world.getBlockState(currentPos).getBlock() instanceof BlockCable) {
                world.setBlockState(currentPos.up(), Blocks.LOG.getDefaultState());
                // if we are cable, move forward, and update emitter, if we has one
                TileEntityCableEmitter emitter = (TileEntityCableEmitter) world.getTileEntity(currentPos);
                if (emitter != null)
                    emitter.refreshConnections();
                moveStack.push(opposite);
                continue;
            }
            // move back if we aren't cable and din't continue
            currentPos.move(opposite);
        }
        // if we didn't found any cable, go back, or return
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
        } else
            break;
    }
    // DebugRenderer.blockPosSet = ImmutableSet.copyOf(visited);
    currentPos.release();
}
Also used : PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) EnumFacing(net.minecraft.util.EnumFacing) TileEntityCableEmitter(gregtech.common.blocks.tileentity.TileEntityCableEmitter) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) Stack(java.util.Stack)

Example 2 with PooledMutableBlockPos

use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.

the class MetaTileEntity method pushItemsIntoNearbyHandlers.

public void pushItemsIntoNearbyHandlers(EnumFacing... allowedFaces) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    for (EnumFacing nearbyFacing : allowedFaces) {
        blockPos.setPos(getPos()).move(nearbyFacing);
        TileEntity tileEntity = getWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            continue;
        }
        IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing.getOpposite());
        // use getCoverCapability so item/ore dictionary filter covers will work properly
        IItemHandler myItemHandler = getCoverCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing);
        if (itemHandler == null || myItemHandler == null) {
            continue;
        }
        moveInventoryItems(myItemHandler, itemHandler);
    }
    blockPos.release();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos)

Example 3 with PooledMutableBlockPos

use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.

the class MetaTileEntity method pullItemsFromNearbyHandlers.

public void pullItemsFromNearbyHandlers(EnumFacing... allowedFaces) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    for (EnumFacing nearbyFacing : allowedFaces) {
        blockPos.setPos(getPos()).move(nearbyFacing);
        TileEntity tileEntity = getWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            continue;
        }
        IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing.getOpposite());
        // use getCoverCapability so item/ore dictionary filter covers will work properly
        IItemHandler myItemHandler = getCoverCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, nearbyFacing);
        if (itemHandler == null || myItemHandler == null) {
            continue;
        }
        moveInventoryItems(itemHandler, myItemHandler);
    }
    blockPos.release();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos)

Example 4 with PooledMutableBlockPos

use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.

the class CoverPump method doTransferFluids.

protected int doTransferFluids(int transferLimit) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    blockPos.setPos(coverHolder.getPos()).move(attachedSide);
    TileEntity tileEntity = coverHolder.getWorld().getTileEntity(blockPos);
    blockPos.release();
    IFluidHandler fluidHandler = tileEntity == null ? null : tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, attachedSide.getOpposite());
    IFluidHandler myFluidHandler = coverHolder.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, attachedSide);
    if (fluidHandler == null || myFluidHandler == null) {
        return 0;
    }
    return doTransferFluidsInternal(myFluidHandler, fluidHandler, transferLimit);
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 5 with PooledMutableBlockPos

use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project GregTech by GregTechCE.

the class BlockCable method refreshSelfState.

private void refreshSelfState(World world, BlockPos selfPos) {
    boolean shouldPlaceEmitter = false;
    PooledMutableBlockPos mutableBlockPos = PooledMutableBlockPos.retain(selfPos);
    for (EnumFacing facing : EnumFacing.VALUES) {
        mutableBlockPos.move(facing);
        EnumFacing opposite = facing.getOpposite();
        IBlockState blockState = world.getBlockState(mutableBlockPos);
        if (blockState.getBlock().hasTileEntity(blockState)) {
            TileEntity tileEntity = world.getTileEntity(mutableBlockPos);
            IEnergyContainer container = tileEntity == null ? null : tileEntity.getCapability(IEnergyContainer.CAPABILITY_ENERGY_CONTAINER, opposite);
            if (container != null && container.outputsEnergy(opposite)) {
                shouldPlaceEmitter = true;
                break;
            }
        }
        mutableBlockPos.move(opposite);
    }
    mutableBlockPos.release();
    // remove emitter if we don't have inputs, or add if we have inputs and it doesn't exist
    TileEntity currentTileEntity = world.getTileEntity(selfPos);
    if (shouldPlaceEmitter) {
        if (!(currentTileEntity instanceof TileEntityCableEmitter)) {
            TileEntityCableEmitter tileEntityCableEmitter = new TileEntityCableEmitter();
            world.setTileEntity(selfPos, tileEntityCableEmitter);
            tileEntityCableEmitter.refreshConnections();
        }
    } else if (currentTileEntity instanceof TileEntityCableEmitter) {
        world.removeTileEntity(selfPos);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) IBlockState(net.minecraft.block.state.IBlockState) IEnergyContainer(gregtech.api.capability.IEnergyContainer) EnumFacing(net.minecraft.util.EnumFacing) TileEntityCableEmitter(gregtech.common.blocks.tileentity.TileEntityCableEmitter)

Aggregations

PooledMutableBlockPos (net.minecraft.util.math.BlockPos.PooledMutableBlockPos)11 TileEntity (net.minecraft.tileentity.TileEntity)8 EnumFacing (net.minecraft.util.EnumFacing)5 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)4 IEnergyContainer (gregtech.api.capability.IEnergyContainer)2 TileEntityCableEmitter (gregtech.common.blocks.tileentity.TileEntityCableEmitter)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockPos (net.minecraft.util.math.BlockPos)2 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 BlockFluidPipe (gregtech.common.pipelike.fluidpipe.BlockFluidPipe)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1 CrashReport (net.minecraft.crash.CrashReport)1 CrashReportCategory (net.minecraft.crash.CrashReportCategory)1 ReportedException (net.minecraft.util.ReportedException)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1