Modular Machinery: Community Edition

Modular Machinery: Community Edition

239k Downloads

RecipeModifierBuilder multiplies

iLamirry opened this issue · 2 comments

commented

RecipeModifierBuilder multiplies a recipe only 1 time. If I input a recipe materials 10+ times and the recipe is multiplied by 5, it uses 5 on the first crafting and will use 1 at a time until it empties the input.
Maybe I'm using it wrong, then please advise how to use it so that it multiplies the recipe every time.

#loader crafttweaker reloadable

import mods.modularmachinery.RecipeBuilder;
import mods.modularmachinery.RecipePrimer;
import mods.modularmachinery.RecipeModifier;
import mods.modularmachinery.RecipeModifierBuilder;

import mods.modularmachinery.RecipeFinishEvent;
import mods.modularmachinery.RecipeCheckEvent;

import mods.modularmachinery.IMachineController;
import mods.modularmachinery.SmartInterfaceData;
import mods.modularmachinery.SmartInterfaceType;
import mods.modularmachinery.MachineModifier;


import mods.modularmachinery.MMEvents;
import mods.modularmachinery.MachineTickEvent;
import mods.modularmachinery.ControllerGUIRenderEvent;
import mods.modularmachinery.MachineStructureFormedEvent;
import mods.modularmachinery.SmartInterfaceUpdateEvent;

import crafttweaker.item.IItemStack;
import crafttweaker.item.IIngredient;
import crafttweaker.oredict.IOreDictEntry;
import crafttweaker.data.IData;
import crafttweaker.formatting.IFormattedText;
import crafttweaker.util.Math;

MachineModifier.addSmartInterfaceType("quantum_placeholder", SmartInterfaceType.create("stack", 1.0 as float).setHeaderInfo("some text").setValueInfo("%.0f").setFooterInfo("another text"));

val Qfiller = RecipeBuilder.newBuilder("loader_for_quantumcount", "quantum_placeholder", 10);
Qfiller.addSmartInterfaceDataInput("stack", 1, 64);
Qfiller.addEnergyPerTickInput(512);
Qfiller.addItemInput(<advanced_solar_panels:machines:1> * 1);

Qfiller.addFinishHandler(function(event as RecipeFinishEvent) {
    val ctrl = event.controller;
    val data = ctrl.customData;
    val map = data.asMap();

    val Stack = map["Stack"];
    val QuantumCount = map["QuantumCount"];

    map["QuantumCount"] = QuantumCount + Stack;

    ctrl.customData = data;
});

Qfiller.build();

MMEvents.onStructureFormed("quantum_placeholder", function(event as MachineStructureFormedEvent) {
    val ctrl = event.controller;
    val data = ctrl.customData;
    val map = data.asMap();

    map["Stack"] = 1 as float;
    map["QuantumCount"] = 0 as float;
    map["QCstorage"] = 0 as int;

    ctrl.customData = data;
});

MMEvents.onMachinePreTick("quantum_placeholder", function(event as MachineTickEvent) {
    val ctrl = event.controller;
    val data = ctrl.customData;
    val map = data.asMap();

    val Stack = map["Stack"];
    ctrl.addModifier("iim", RecipeModifierBuilder.create("modularmachinery:item", "input", Stack, 1, false).build()); //iim = ItemInputMultiplier
});

MMEvents.onSmartInterfaceUpdate("quantum_placeholder", function(event as SmartInterfaceUpdateEvent) {
    val ctrl = event.controller;
    val data = ctrl.customData;
    val map = data.asMap();

    val Stack = event.newData.value;
    map["Stack"] = Stack; 
    ctrl.customData = data;
});

MMEvents.onControllerGUIRender("quantum_placeholder", function(event as ControllerGUIRenderEvent) {
    val ctrl = event.controller;
    val data = ctrl.customData;
    val map = data.asMap();

    val Stack = map["Stack"];
    val QuantumCount = map["QuantumCount"];
    val QCstorage = map["QCstorage"];

    val info as string[] = [
        "§eMultiplier: " + Stack,
        "§eQuantumCount: " + QuantumCount
    ];

    event.extraInfo = info;
});

P.S. There's more import than necessary, as I've tried different options.

commented

It worked. Thanks a lot. I hope you continue to work on your mod and its tutorial :)

commented

try use addPermanentModifier()