use of net.minecraftforge.fluids.IFluidHandler in project LogisticsPipes by RS485.
the class PipeFluidBasic method sinkAmount.
@Override
public int sinkAmount(FluidStack stack) {
if (!guiOpenedBy.isEmpty()) {
//Don't sink when the gui is open
return 0;
}
FluidIdentifier ident = FluidIdentifier.get(stack);
if (filterInv.getStackInSlot(0) == null) {
return 0;
}
if (!ident.equals(FluidIdentifier.get(filterInv.getIDStackInSlot(0).getItem()))) {
return 0;
}
int onTheWay = this.countOnRoute(ident);
int freeSpace = -onTheWay;
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(true)) {
FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
freeSpace += ident.getFreeSpaceInsideTank((IFluidHandler) pair.getValue1(), pair.getValue2().getOpposite());
freeSpace += ident.getFreeSpaceInsideTank(tank);
if (freeSpace >= stack.amount) {
return stack.amount;
}
}
return freeSpace;
}
use of net.minecraftforge.fluids.IFluidHandler in project LogisticsPipes by RS485.
the class BuildCraftTankHandler method getAvailableLiquid.
@Override
public Map<FluidIdentifier, Long> getAvailableLiquid(TileEntity tile) {
Map<FluidIdentifier, Long> map = new HashMap<>();
FluidTankInfo[] tanks = ((IFluidHandler) tile).getTankInfo(ForgeDirection.UNKNOWN);
for (FluidTankInfo tank : tanks) {
if (tank == null) {
continue;
}
FluidStack liquid;
if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
FluidIdentifier ident = FluidIdentifier.get(liquid);
if (((IFluidHandler) tile).drain(ForgeDirection.UNKNOWN, 1, false) != null) {
if (map.containsKey(ident)) {
long addition = map.get(ident) + tank.fluid.amount;
map.put(ident, addition);
} else {
map.put(ident, (long) tank.fluid.amount);
}
}
}
}
return map;
}
use of net.minecraftforge.fluids.IFluidHandler in project Galacticraft by micdoodle8.
the class FluidNetwork method refreshAcceptors.
public void refreshAcceptors() {
if (this.acceptors == null) {
this.acceptors = Maps.newHashMap();
} else {
this.acceptors.clear();
}
try {
Iterator<IBufferTransmitter<FluidStack>> it = this.pipes.iterator();
while (it.hasNext()) {
IBufferTransmitter<FluidStack> transmitter = it.next();
TileEntity tile = (TileEntity) transmitter;
if (transmitter == null || tile.isInvalid() || tile.getWorld() == null) {
it.remove();
continue;
}
if (!transmitter.canTransmit()) {
continue;
}
int i = 0;
for (TileEntity acceptor : transmitter.getAdjacentConnections()) {
if (!(acceptor instanceof IBufferTransmitter) && acceptor instanceof IFluidHandler) {
EnumFacing facing = EnumFacing.getFront(i).getOpposite();
BlockPos acceptorPos = tile.getPos().offset(facing.getOpposite());
EnumSet<EnumFacing> facingSet = this.acceptorDirections.get(acceptorPos);
if (facingSet != null) {
facingSet.add(facing);
} else {
facingSet = EnumSet.of(facing);
}
this.acceptors.put(acceptorPos, (IFluidHandler) acceptor);
this.acceptorDirections.put(acceptorPos, facingSet);
}
i++;
}
}
} catch (Exception e) {
FMLLog.severe("Failed to refresh liquid acceptors");
e.printStackTrace();
}
}
use of net.minecraftforge.fluids.IFluidHandler in project Galacticraft by micdoodle8.
the class FluidNetwork method getAcceptors.
public List<Pair<BlockPos, IFluidHandler>> getAcceptors(FluidStack toSend) {
List<Pair<BlockPos, IFluidHandler>> toReturn = new LinkedList<>();
if (GCCoreUtil.getEffectiveSide() == Side.CLIENT) {
return toReturn;
}
if (this.acceptors == null || this.acceptors.isEmpty()) {
this.refreshAcceptors();
}
List<BlockPos> acceptorsCopy = new ArrayList<>();
acceptorsCopy.addAll(acceptors.keySet());
for (BlockPos coords : acceptorsCopy) {
EnumSet<EnumFacing> sides = acceptorDirections.get(coords);
if (sides == null || sides.isEmpty()) {
continue;
}
TileEntity tile = this.worldObj.getTileEntity(coords);
if (!(tile instanceof IFluidHandler)) {
continue;
}
IFluidHandler acceptor = (IFluidHandler) tile;
Fluid fluidToSend = toSend.getFluid();
for (EnumFacing side : sides) {
if (acceptor.canFill(side, fluidToSend)) {
toReturn.add(Pair.of(coords, acceptor));
break;
}
}
}
return toReturn;
}
use of net.minecraftforge.fluids.IFluidHandler in project BuildCraft by BuildCraft.
the class TankUtils method pushFluidToConsumers.
public static void pushFluidToConsumers(IFluidTank tank, int flowCap, BlockTileCache[] tileBuffer) {
int amountToPush = flowCap;
for (EnumFacing side : EnumFacing.VALUES) {
FluidStack fluidStack = tank.drain(amountToPush, false);
if (fluidStack != null && fluidStack.amount > 0) {
TileEntity tile = tileBuffer[side.ordinal()].getTile();
if (tile instanceof IFluidHandler) {
int used = ((IFluidHandler) tile).fill(side.getOpposite(), fluidStack, true);
if (used > 0) {
amountToPush -= used;
tank.drain(used, true);
if (amountToPush <= 0) {
return;
}
}
}
}
}
}
Aggregations