KubeJS

KubeJS

107M Downloads

JEI/REI Incorrectly Displays 100% Chance for KubeJS-Added Create Recipes with Probabilities

Harusarri opened this issue ยท 0 comments

commented

Minecraft Version

1.20.1

KubeJS Version

2001.6.5-build 1.6

Rhino Version

2001.2.3-build.10

Architectury Version

9.2.14

Forge/Fabric Version

Forge 47.4.0

Describe your issue

Description:
When adding Create mod recipes dynamically using KubeJS (specifically reading definitions from a JSON file and processing them in server scripts), recipes with probability-based outputs (defined using { "item": "id", "chance": probability } in JSON and converted to Item.of(id).withChance(probability) in the script) function correctly in-game according to the specified chance.
However, JEI/REI does not display this chance information. Instead, it shows the output item as if it has a 100% drop rate. This visual discrepancy can be misleading for players using JEI/REI to check recipes.
This issue was specifically observed with the sandpaper_polishing recipe type and its potentially auto-generated _using_deployer variant, but it might affect other Create recipe types that support chance outputs when added via KubeJS in this manner.

Image
Image

Steps to Reproduce:

Set up a Minecraft instance with KubeJS, KubeJS Create Addon, Create Mod, and JEI/REI.
Define a Create recipe in a JSON file (e.g., kubejs/data/data.json) with an output that includes a chance modifier. Example:

// kubejs/data/data.json (inside the main object)
"debug_sandpaper_polishing_coal_to_diamond": {
  "id": "kubejs:debug_coal_to_diamond_sandpaper",
  "type": "sandpaper_polishing",
  "output": {"item": "minecraft:diamond", "chance": 0.05}, // 5% chance Diamond
  "input": "minecraft:coal"
}

Json
Use a KubeJS server script (e.g., kubejs/server_scripts/main.js) to read the JSON file and add the recipes. Crucially, the script parses the output definition and uses Item.of(item_id).withChance(probability) to create the output stack. Example parsing function:

const parseOutputItem = (outputDef) => {
  if (typeof outputDef === 'object' && outputDef !== null) {
    if (outputDef.item && outputDef.chance !== undefined) {
      let chance = parseFloat(outputDef.chance);
      // ... (validation) ...
      return Item.of(String(outputDef.item)).withChance(chance); // Key part
    } // ... (handle other types like count, string, fluid) ...
  } // ... (handle string type) ...
  return null;
};

ServerEvents.recipes(event => {
  // ... (read JSON into recipeDataFromFile) ...
  const recipesToProcess = Object.values(recipeDataFromFile);
  recipesToProcess.forEach(recipeDef => {
    // ... (validation) ...
    let parsedOutput = /* ... call parseOutputItem on recipeDef.output ... */;
    // ...
    try {
      switch(String(recipeDef.type).toLowerCase()) {
        case 'sandpaper_polishing':
          event.recipes.create.sandpaper_polishing(parsedOutput, recipeDef.input).id(String(recipeDef.id));
          break;
        // ... other cases ...
      }
    } catch (e) { /* ... error handling ... */ }
  });
});

JavaScript
Load the game or use /reload.
Check the recipe (e.g., for Sandpaper Polishing using Coal) in JEI/REI.

Observed Results:

JEI/REI displays the Diamond as an output for the sandpaper_polishing recipe (and potentially the auto-generated _using_deployer recipe) but without any indication of the 5% chance. It appears as a guaranteed (100%) output.
Testing the recipe in-game (e.g., using Sandpaper on Coal multiple times) confirms that the Diamond only drops occasionally, consistent with the defined 5% chance.

Expected Results:

JEI/REI should display the probability next to the output item (e.g., "5% Diamond") for the KubeJS-added sandpaper_polishing recipe (and ideally for the auto-generated deployer variant as well, reflecting the correct chance).

Possible Cause:

The issue likely resides in the JEI/REI integration within the KubeJS Create addon or potentially Create itself when handling recipes added programmatically via KubeJS. The probability information from the Item.of().withChance() object might not be correctly passed to or interpreted by the JEI/REI recipe handler for these specific Create recipe types.
Thank you for looking into this!

Crash report/logs

No response