NovaEngineering-Source / ModularMachinery-Community-Edition

Customize your machinery with more powerful features.
https://www.curseforge.com/minecraft/mc-mods/modularmachinery-community-edition
GNU General Public License v3.0
28 stars 12 forks source link

Example of using RecipeModifierBuilder #62

Closed iLamirry closed 6 months ago

iLamirry commented 6 months ago

Hi, can you please write an example script using RecipeModifierBuilder. I am trying to multiply an entire recipe by a number from Smart Interface. I was able to get the interface value, but how to use RecipeModifierBuilder I can't figure out for a few days now.

iLamirry commented 6 months ago

Somehow I came up with this code, but I don't know what the "key" in addModifier(key, RecipeModifier) means

MMEvents.onSmartInterfaceUpdate("water_pump", function(event as SmartInterfaceUpdateEvent) {
    val ctrl = event.controller;
    val data = ctrl.customData;
    val map = data.asMap();
    map["FluidMultiply"] = event.newData.value; //receive value in event
    val FluidMultiply = map["FluidMultiply"];

    ctrl.addModifier("key", RecipeModifierBuilder.create("modularmachinery:energy", "input", 10, 1, false).build()));

    ctrl.customData = data;
});

Now this script doesn't give errors, but it doesn't change the amount of energy either.

iLamirry commented 6 months ago

Ok, I realized what the problem was and moved the RecipeModifierBuilder to onMachinePreTick event. But I encountered a new problem: the inability to change item input.

ctrl.addModifier("ItemInputModifier", RecipeModifierBuilder.create("modularmachinery:item", "input", 2, 1, false).build());
ctrl.addModifier("ItemOutputModifier", RecipeModifierBuilder.create("modularmachinery:item", "output", 2, 1, false).build());
ctrl.addModifier("EnergyInputModifier", RecipeModifierBuilder.create("modularmachinery:energy", "input", 2, 1, false).build()); 

Output resources are multiplied, input energy is also multiplied, but input resources persistently ignore RecipeModifierBuilder, and there are no errors in the log.

iLamirry commented 6 months ago

Okay, this seems to work fine in RecipeCheckEvent.