Search in sources :

Example 6 with PooledMutableBlockPos

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

the class MetaTileEntity method pullFluidsFromNearbyHandlers.

public void pullFluidsFromNearbyHandlers(EnumFacing... allowedFaces) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    for (EnumFacing nearbyFacing : allowedFaces) {
        blockPos.setPos(getPos()).move(nearbyFacing);
        TileEntity tileEntity = getWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            continue;
        }
        IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing.getOpposite());
        // use getCoverCapability so fluid tank index filtering and fluid filtering covers will work properly
        IFluidHandler myFluidHandler = getCoverCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing);
        if (fluidHandler == null || myFluidHandler == null) {
            continue;
        }
        GTFluidUtils.transferFluids(fluidHandler, myFluidHandler, Integer.MAX_VALUE);
    }
    blockPos.release();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 7 with PooledMutableBlockPos

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

the class MetaTileEntity method pushFluidsIntoNearbyHandlers.

public void pushFluidsIntoNearbyHandlers(EnumFacing... allowedFaces) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    for (EnumFacing nearbyFacing : allowedFaces) {
        blockPos.setPos(getPos()).move(nearbyFacing);
        TileEntity tileEntity = getWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            continue;
        }
        IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing.getOpposite());
        // use getCoverCapability so fluid tank index filtering and fluid filtering covers will work properly
        IFluidHandler myFluidHandler = getCoverCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing);
        if (fluidHandler == null || myFluidHandler == null) {
            continue;
        }
        GTFluidUtils.transferFluids(myFluidHandler, fluidHandler, Integer.MAX_VALUE);
    }
    blockPos.release();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 8 with PooledMutableBlockPos

use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos 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)

Example 9 with PooledMutableBlockPos

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

the class TileEntityFluidPipeTickable method pushFluidsFromTank.

public static void pushFluidsFromTank(IPipeTile<FluidPipeType, FluidPipeProperties> pipeTile) {
    PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain();
    int blockedConnections = pipeTile.getBlockedConnections();
    BlockFluidPipe blockFluidPipe = (BlockFluidPipe) pipeTile.getPipeBlock();
    for (EnumFacing side : EnumFacing.VALUES) {
        if ((blockedConnections & 1 << side.getIndex()) > 0) {
            // do not dispatch energy to blocked sides
            continue;
        }
        blockPos.setPos(pipeTile.getPipePos()).move(side);
        if (!pipeTile.getPipeWorld().isBlockLoaded(blockPos)) {
            // do not allow cables to load chunks
            continue;
        }
        TileEntity tileEntity = pipeTile.getPipeWorld().getTileEntity(blockPos);
        if (tileEntity == null) {
            // do not emit into multiparts or other fluid pipes
            continue;
        }
        IFluidHandler sourceHandler = pipeTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        IFluidHandler receiverHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite());
        if (sourceHandler != null && receiverHandler != null && blockFluidPipe.canPushIntoFluidHandler(pipeTile, tileEntity, sourceHandler, receiverHandler)) {
            GTFluidUtils.transferFluids(sourceHandler, receiverHandler, Integer.MAX_VALUE);
        }
    }
    blockPos.release();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) EnumFacing(net.minecraft.util.EnumFacing) BlockFluidPipe(gregtech.common.pipelike.fluidpipe.BlockFluidPipe) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 10 with PooledMutableBlockPos

use of net.minecraft.util.math.BlockPos.PooledMutableBlockPos in project BetterWithAddons by DaedalusGame.

the class BlockAqueductWater method getFlowVector.

@Override
public Vec3d getFlowVector(IBlockAccess world, BlockPos pos) {
    double flowx = 0.0D;
    double flowy = 0.0D;
    double flowz = 0.0D;
    int thislevel = this.getDepth(world, pos);
    PooledMutableBlockPos checkpos = PooledMutableBlockPos.retain();
    EnumFacing flowDir = EnumFacing.DOWN;
    HashSet<BlockPos> corners = new HashSet<>();
    for (EnumFacing enumfacing : EnumFacing.HORIZONTALS) {
        checkpos.setPos(pos).move(enumfacing);
        int otherlevel = this.getDepth(world, checkpos);
        if (otherlevel >= 0) {
            int l = otherlevel - thislevel;
            flowx += (double) (enumfacing.getFrontOffsetX() * l);
            flowy += (double) (enumfacing.getFrontOffsetY() * l);
            flowz += (double) (enumfacing.getFrontOffsetZ() * l);
            corners.add(checkpos.offset(enumfacing.rotateY(), 1));
            corners.add(checkpos.offset(enumfacing.rotateY(), -1));
        }
    }
    for (BlockPos cornerpos : corners) {
        int xdiff = cornerpos.getX() - pos.getX();
        int zdiff = cornerpos.getZ() - pos.getZ();
        int otherlevel = this.getDepth(world, cornerpos);
        if (otherlevel >= 0) {
            int l = otherlevel - thislevel;
            flowx += (double) (xdiff * l);
            flowz += (double) (zdiff * l);
        }
    }
    flowDir = EnumFacing.getFacingFromVector((float) flowx, (float) flowy, (float) flowz);
    if (flowDir.getAxis().isHorizontal()) {
        EnumFacing right = flowDir.rotateY();
        EnumFacing left = flowDir.rotateYCCW();
        boolean rightDone = false;
        boolean leftDone = false;
        int leftDist = 0;
        int rightDist = 0;
        for (int i = 1; i < 8; i++) {
            if (!rightDone) {
                int rightDepth = this.getDepth(world, pos.offset(right, i));
                if (rightDepth > thislevel)
                    rightDist = 8 - 1;
                rightDone = rightDepth == -1 || rightDepth > thislevel;
            }
            if (!leftDone) {
                int leftDepth = this.getDepth(world, pos.offset(left, i));
                if (leftDepth > thislevel)
                    leftDist = 8 - i;
                leftDone = leftDepth == -1 || leftDepth > thislevel;
            }
        }
        flowx += left.getFrontOffsetX() * leftDist + right.getFrontOffsetX() * rightDist;
        flowz += left.getFrontOffsetZ() * leftDist + right.getFrontOffsetZ() * rightDist;
    }
    Vec3d vec3d = new Vec3d(flowx, flowy, flowz);
    checkpos.release();
    return vec3d.normalize();
}
Also used : PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) EnumFacing(net.minecraft.util.EnumFacing) PooledMutableBlockPos(net.minecraft.util.math.BlockPos.PooledMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) HashSet(java.util.HashSet)

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