use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.
the class FluidUtilities method outputToPipe.
public static void outputToPipe(GenericTile tile, FluidTank[] tanks, Direction... outputDirections) {
ComponentDirection componentDirection = tile.getComponent(ComponentType.Direction);
for (Direction relative : outputDirections) {
Direction direction = BlockEntityUtils.getRelativeSide(componentDirection.getDirection(), relative.getOpposite());
BlockPos face = tile.getBlockPos().relative(direction.getOpposite());
BlockEntity faceTile = tile.getLevel().getBlockEntity(face);
if (faceTile != null) {
boolean electroPipe = faceTile instanceof GenericTilePipe;
LazyOptional<IFluidHandler> cap = faceTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction);
if (cap.isPresent()) {
IFluidHandler fHandler = cap.resolve().get();
for (FluidTank fluidTank : tanks) {
FluidStack tankFluid = fluidTank.getFluid();
if (electroPipe) {
if (fluidTank.getFluidAmount() > 0) {
fluidTank.getFluid().shrink(fHandler.fill(tankFluid, FluidAction.EXECUTE));
}
} else {
int amtAccepted = fHandler.fill(tankFluid, FluidAction.SIMULATE);
FluidStack taken = new FluidStack(tankFluid.getFluid(), amtAccepted);
fHandler.fill(taken, FluidAction.EXECUTE);
fluidTank.drain(taken, FluidAction.EXECUTE);
}
}
}
}
}
}
use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.
the class FluidUtilities method drainItem.
public static void drainItem(GenericTile tile) {
ComponentInventory inv = tile.getComponent(ComponentType.Inventory);
AbstractFluidHandler<?> handler = tile.getComponent(ComponentType.FluidHandler);
FluidTank[] tanks = handler.getInputTanks();
List<ItemStack> buckets = inv.getInputBucketContents();
for (int i = 0; i < buckets.size(); i++) {
FluidTank tank = tanks[i];
ItemStack stack = buckets.get(i);
if (!stack.isEmpty() && !CapabilityUtils.isFluidItemNull()) {
FluidStack containerFluid = CapabilityUtils.simDrain(stack, Integer.MAX_VALUE);
if (handler.getValidInputFluids().contains(containerFluid.getFluid()) && tank.isFluidValid(containerFluid)) {
int amtDrained = tank.fill(containerFluid, FluidAction.SIMULATE);
FluidStack drained = new FluidStack(containerFluid.getFluid(), amtDrained);
CapabilityUtils.drain(stack, drained);
tank.fill(drained, FluidAction.EXECUTE);
if (stack.getItem() instanceof BucketItem) {
inv.setItem(inv.getInputBucketStartIndex() + i, new ItemStack(Items.BUCKET, 1));
}
}
}
}
}
use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.
the class TileFluidVoid method tickServer.
private void tickServer(ComponentTickable tick) {
ComponentInventory inv = getComponent(ComponentType.Inventory);
ComponentFluidHandlerSimple handler = getComponent(ComponentType.FluidHandler);
ItemStack input = inv.getItem(0);
if (!input.isEmpty() && CapabilityUtils.hasFluidItemCap(input)) {
FluidTank tank = handler.getInputTanks()[0];
FluidStack containerFluid = CapabilityUtils.simDrain(input, Integer.MAX_VALUE);
if (handler.getValidInputFluids().contains(containerFluid.getFluid()) && tank.isFluidValid(containerFluid)) {
int amtDrained = tank.fill(containerFluid, FluidAction.SIMULATE);
FluidStack drained = new FluidStack(containerFluid.getFluid(), amtDrained);
CapabilityUtils.drain(input, drained);
tank.fill(drained, FluidAction.EXECUTE);
if (input.getItem() instanceof BucketItem) {
inv.setItem(0, new ItemStack(Items.BUCKET, 1));
}
}
}
FluidTank tank = handler.getInputTanks()[0];
tank.drain(tank.getFluidAmount(), FluidAction.EXECUTE);
}
use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.
the class TileCoolantResavoir method hasEnoughFluid.
public boolean hasEnoughFluid(int fluidAmnt) {
ComponentFluidHandlerSimple simple = getComponent(ComponentType.FluidHandler);
FluidTank tank = simple.getInputTanks()[0];
return !tank.isEmpty() && tank.getFluidAmount() >= fluidAmnt;
}
use of net.minecraftforge.fluids.capability.templates.FluidTank in project Beyond-Earth by MrScautHD.
the class FluidMultiTank method drain.
@Override
public FluidStack drain(FluidStack resource, FluidAction action) {
resource = resource.copy();
FluidStack drained = resource.copy();
drained.setAmount(0);
for (FluidTank tank : this.getTankList()) {
int amount = tank.drain(resource, action).getAmount();
drained.grow(amount);
resource.shrink(amount);
}
return drained;
}
Aggregations