use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class CoverDigitalInterface method getFluidCapability.
public IFluidHandler getFluidCapability() {
TileEntity te = getCoveredTE();
IFluidHandler capability = te == null ? null : te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, getCoveredFacing());
if (capability == null && this.coverHolder instanceof MultiblockControllerBase) {
List<IFluidTank> input = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.IMPORT_FLUIDS);
List<IFluidTank> output = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.EXPORT_FLUIDS);
List<IFluidTank> list = new ArrayList<>();
if (input.size() > 0) {
list.addAll(input);
}
if (output.size() > 0) {
list.addAll(output);
}
capability = new FluidTankList(true, list);
}
return capability;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class LargeTurbineWorkableHandler method updateTanks.
public void updateTanks() {
FuelMultiblockController controller = (FuelMultiblockController) this.metaTileEntity;
List<IFluidHandler> tanks = controller.getNotifiedFluidInputList();
for (IFluidTank tank : controller.getAbilities(MultiblockAbility.IMPORT_FLUIDS)) {
tanks.add((FluidTank) tank);
}
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class FluidTankList method drain.
@Nullable
@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
if (resource == null || resource.amount <= 0) {
return null;
}
resource = resource.copy();
FluidStack totalDrained = null;
for (IFluidTank handler : fluidTanks) {
if (!resource.isFluidEqual(handler.getFluid())) {
continue;
}
FluidStack drain = handler.drain(resource.amount, doDrain);
if (drain == null) {
continue;
}
if (totalDrained == null) {
totalDrained = drain;
} else
totalDrained.amount += drain.amount;
resource.amount -= drain.amount;
if (resource.amount == 0)
break;
}
return totalDrained;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class FluidTankList method fillTanksImpl.
// fills exactly one tank if multi-filling is not allowed
// and as much tanks as possible otherwise
// note that it will always try to fill tanks with same fluid first
private int fillTanksImpl(FluidStack resource, boolean doFill) {
int totalFilled = 0;
// first, try to fill tanks that already have same fluid type
for (IFluidTank handler : fluidTanks) {
if (resource.isFluidEqual(handler.getFluid())) {
int filledAmount = handler.fill(resource, doFill);
totalFilled += filledAmount;
resource.amount -= filledAmount;
// if filling multiple tanks is not allowed, or resource is empty, return now
if (!allowSameFluidFill() || resource.amount == 0)
return totalFilled;
}
}
// otherwise, try to fill empty tanks
for (IFluidTank handler : fluidTanks) {
if (handler.getFluidAmount() == 0) {
int filledAmount = handler.fill(resource, doFill);
totalFilled += filledAmount;
resource.amount -= filledAmount;
if (!allowSameFluidFill() || resource.amount == 0)
return totalFilled;
}
}
return totalFilled;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class FluidTankList method drain.
@Nullable
@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
if (maxDrain == 0) {
return null;
}
FluidStack totalDrained = null;
for (IFluidTank handler : fluidTanks) {
if (totalDrained == null) {
totalDrained = handler.drain(maxDrain, doDrain);
if (totalDrained != null)
maxDrain -= totalDrained.amount;
} else {
FluidStack copy = totalDrained.copy();
copy.amount = maxDrain;
if (!copy.isFluidEqual(handler.getFluid()))
continue;
FluidStack drain = handler.drain(copy.amount, doDrain);
if (drain != null) {
totalDrained.amount += drain.amount;
maxDrain -= drain.amount;
}
}
if (maxDrain <= 0)
break;
}
return totalDrained;
}
Aggregations