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();
}
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();
}
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;
}
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();
}
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();
}
Aggregations