Search in sources :

Example 1 with IMachineDataBridge

use of me.haydenb.assemblylinemachines.block.helpers.MachineBuilder.MachineBlockEntityBuilder.IMachineDataBridge 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)

Example 2 with IMachineDataBridge

use of me.haydenb.assemblylinemachines.block.helpers.MachineBuilder.MachineBlockEntityBuilder.IMachineDataBridge in project assemblylinemachines by HaydenBelanger.

the class PurifierCrafting method assemble.

@Override
public ItemStack assemble(Container inv) {
    if (inv instanceof IMachineDataBridge) {
        IMachineDataBridge data = (IMachineDataBridge) inv;
        boolean requiresUpgrade = this.requiresUpgrade();
        if (requiresUpgrade && data.getUpgradeAmount(Upgrades.PURIFIER_EXPANDED) == 0)
            return ItemStack.EMPTY;
        int conservationCount = requiresUpgrade ? 0 : data.getUpgradeAmount(Upgrades.MACHINE_CONSERVATION);
        if (RAND.nextInt(10) * conservationCount < 10)
            inv.getItem(1).shrink(1);
        if (RAND.nextInt(10) * conservationCount < 10)
            inv.getItem(2).shrink(1);
        data.setCycles(requiresUpgrade ? time / 8f : time / 10f);
        inv.getItem(3).shrink(1);
    }
    return this.output.copy();
}
Also used : IMachineDataBridge(me.haydenb.assemblylinemachines.block.helpers.MachineBuilder.MachineBlockEntityBuilder.IMachineDataBridge)

Example 3 with IMachineDataBridge

use of me.haydenb.assemblylinemachines.block.helpers.MachineBuilder.MachineBlockEntityBuilder.IMachineDataBridge in project assemblylinemachines by HaydenBelanger.

the class GrinderCrafting method assemble.

@Override
public ItemStack assemble(Container inv) {
    if (inv instanceof IMachineDataBridge) {
        inv.getItem(1).shrink(1);
        ((IMachineDataBridge) inv).setCycles(grinds * 2.3f);
    }
    ItemStack stack = output.get().copy();
    if (chanceToDouble != 0f && RAND.nextFloat() <= chanceToDouble)
        stack.setCount(stack.getCount() * 2);
    return stack;
}
Also used : IMachineDataBridge(me.haydenb.assemblylinemachines.block.helpers.MachineBuilder.MachineBlockEntityBuilder.IMachineDataBridge) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

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