use of mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties in project RFToolsControl by McJty.
the class ProcessorTileEntity method pushLiquid.
public int pushLiquid(IProgram program, @Nonnull Inventory inv, int amount, int virtualSlot) {
IFluidHandler handler = getFluidHandlerAt(inv);
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
int realSlot = info.getRealFluidSlot(virtualSlot);
EnumFacing side = EnumFacing.values()[realSlot / TANKS];
int idx = realSlot % TANKS;
MultiTankFluidProperties properties = getFluidPropertiesFromMultiTank(side, idx);
if (properties == null) {
return 0;
}
if (!properties.hasContents()) {
return 0;
}
amount = Math.min(amount, properties.getContentsInternal().amount);
// getContents() already does a copy()
FluidStack topush = properties.getContents();
topush.amount = amount;
int filled = handler.fill(topush, true);
properties.drain(filled);
return filled;
}
use of mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties in project RFToolsControl by McJty.
the class ProcessorTileEntity method examineLiquidInternal.
@Nullable
public FluidStack examineLiquidInternal(IProgram program, int virtualSlot) {
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
int realSlot = info.getRealFluidSlot(virtualSlot);
EnumFacing side = EnumFacing.values()[realSlot / TANKS];
int idx = realSlot % TANKS;
MultiTankFluidProperties properties = getFluidPropertiesFromMultiTank(side, idx);
if (properties == null) {
return null;
}
return properties.getContents();
}
use of mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties in project RFToolsControl by McJty.
the class ProcessorTileEntity method getFluids.
public List<PacketGetFluids.FluidEntry> getFluids() {
List<PacketGetFluids.FluidEntry> pars = new ArrayList<>();
for (int i = 0; i < MAXFLUIDVARS; i++) {
if (isFluidSlotAvailable(i)) {
EnumFacing side = EnumFacing.values()[i / TANKS];
TileEntity te = getWorld().getTileEntity(getPos().offset(side));
if (te instanceof MultiTankTileEntity) {
MultiTankTileEntity mtank = (MultiTankTileEntity) te;
MultiTankFluidProperties[] propertyList = mtank.getProperties();
IFluidTankProperties properties = propertyList[i % TANKS];
FluidStack fluidStack = properties == null ? null : properties.getContents();
pars.add(new PacketGetFluids.FluidEntry(fluidStack, true));
} else {
pars.add(new PacketGetFluids.FluidEntry(null, true));
}
} else {
pars.add(new PacketGetFluids.FluidEntry(null, false));
}
}
return pars;
}
use of mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties in project RFToolsControl by McJty.
the class ProcessorTileEntity method fetchLiquid.
public int fetchLiquid(IProgram program, @Nonnull Inventory inv, int amount, @Nullable FluidStack fluidStack, int virtualSlot) {
IFluidHandler handler = getFluidHandlerAt(inv);
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
int realSlot = info.getRealFluidSlot(virtualSlot);
EnumFacing side = EnumFacing.values()[realSlot / TANKS];
int idx = realSlot % TANKS;
MultiTankFluidProperties properties = getFluidPropertiesFromMultiTank(side, idx);
if (properties == null) {
return 0;
}
int internalAmount = 0;
if (properties.hasContents()) {
// There is already some fluid in the slot
if (fluidStack != null) {
// This has to match
if (!fluidStack.isFluidEqual(properties.getContentsInternal())) {
return 0;
}
}
internalAmount = properties.getContentsInternal().amount;
}
// Make sure we only drain what can fit in the internal slot
if (internalAmount + amount > MAXCAPACITY) {
amount = MAXCAPACITY - internalAmount;
}
if (amount <= 0) {
return 0;
}
if (fluidStack == null) {
// Just drain any fluid
FluidStack drained = handler.drain(amount, false);
if (drained != null) {
// Check if the fluid matches
if ((!properties.hasContents()) || properties.getContentsInternal().isFluidEqual(drained)) {
drained = handler.drain(amount, true);
properties.fill(drained);
return drained.amount;
}
return 0;
}
} else {
// Drain only that fluid
FluidStack todrain = fluidStack.copy();
todrain.amount = amount;
FluidStack drained = handler.drain(todrain, true);
if (drained != null) {
int drainedAmount = drained.amount;
if (properties.hasContents()) {
drained.amount += properties.getContentsInternal().amount;
}
properties.fill(drained);
return drainedAmount;
}
}
return 0;
}
Aggregations