Search in sources :

Example 1 with IFluidHandlerBypass

use of me.haydenb.assemblylinemachines.registry.Utils.IFluidHandlerBypass in project assemblylinemachines by HaydenBelanger.

the class BathCrafting method assemble.

@Override
public ItemStack assemble(Container inv) {
    if (inv instanceof IMachineDataBridge) {
        IMachineDataBridge data = (IMachineDataBridge) inv;
        IFluidHandler handler = data.getCraftingFluidHandler(Optional.empty());
        BiFunction<Integer, FluidAction, FluidStack> drain = handler instanceof IFluidHandlerBypass ? (i, a) -> ((IFluidHandlerBypass) handler).drainBypassRestrictions(i, a) : (i, a) -> handler.drain(i, a);
        if (handler == null || handler.getFluidInTank(0).getFluid() != fluid.getAssocFluid() || drain.apply(percent.getMB(), FluidAction.SIMULATE).getAmount() != percent.getMB())
            return ItemStack.EMPTY;
        int rand = RAND.nextInt(9) * data.getUpgradeAmount(Upgrades.MACHINE_CONSERVATION);
        int cons = percent.getMB();
        if (rand > 21) {
            cons = 0;
        } else if (rand > 15) {
            cons = (int) Math.round((double) cons * 0.25d);
        } else if (rand > 10) {
            cons = (int) Math.round((double) cons * 0.5d);
        } else if (rand > 5) {
            cons = (int) Math.round((double) cons * 0.75d);
        }
        drain.apply(cons, FluidAction.EXECUTE);
        inv.getItem(1).shrink(1);
        inv.getItem(2).shrink(1);
        data.setCycles((float) stirs * 3.6f);
    }
    return this.output.copy();
}
Also used : IMachineDataBridge(me.haydenb.assemblylinemachines.block.helpers.MachineBuilder.MachineBlockEntityBuilder.IMachineDataBridge) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandlerBypass(me.haydenb.assemblylinemachines.registry.Utils.IFluidHandlerBypass) FluidAction(net.minecraftforge.fluids.capability.IFluidHandler.FluidAction) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

IMachineDataBridge (me.haydenb.assemblylinemachines.block.helpers.MachineBuilder.MachineBlockEntityBuilder.IMachineDataBridge)1 IFluidHandlerBypass (me.haydenb.assemblylinemachines.registry.Utils.IFluidHandlerBypass)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 FluidAction (net.minecraftforge.fluids.capability.IFluidHandler.FluidAction)1