Search in sources :

Example 1 with MultiTankFluidProperties

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;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) MultiTankFluidProperties(mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties)

Example 2 with MultiTankFluidProperties

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();
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) MultiTankFluidProperties(mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties) Nullable(javax.annotation.Nullable)

Example 3 with MultiTankFluidProperties

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;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) CraftingStationTileEntity(mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity) WorkbenchTileEntity(mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity) NodeTileEntity(mcjty.rftoolscontrol.blocks.node.NodeTileEntity) MultiTankTileEntity(mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MultiTankTileEntity(mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) MultiTankFluidProperties(mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties) PacketGetFluids(mcjty.rftoolscontrol.network.PacketGetFluids)

Example 4 with MultiTankFluidProperties

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;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) MultiTankFluidProperties(mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties)

Aggregations

MultiTankFluidProperties (mcjty.rftoolscontrol.blocks.multitank.MultiTankFluidProperties)4 EnumFacing (net.minecraft.util.EnumFacing)4 FluidStack (net.minecraftforge.fluids.FluidStack)3 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)2 Nullable (javax.annotation.Nullable)1 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)1 CraftingStationTileEntity (mcjty.rftoolscontrol.blocks.craftingstation.CraftingStationTileEntity)1 MultiTankTileEntity (mcjty.rftoolscontrol.blocks.multitank.MultiTankTileEntity)1 NodeTileEntity (mcjty.rftoolscontrol.blocks.node.NodeTileEntity)1 WorkbenchTileEntity (mcjty.rftoolscontrol.blocks.workbench.WorkbenchTileEntity)1 PacketGetFluids (mcjty.rftoolscontrol.network.PacketGetFluids)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IFluidTankProperties (net.minecraftforge.fluids.capability.IFluidTankProperties)1