KubeJS

KubeJS

69M Downloads

keepIngredient() dont work properly when used variables or dynamic values as parameters

DevDyna opened this issue ยท 1 comments

commented

Minecraft Version

1.20.1

KubeJS Version

kubejs-forge-2001.6.5-build.14

Rhino Version

rhino-forge-2001.2.3-build.6

Architectury Version

architectury-9.2.14-forge

Forge/Fabric Version

Forge - 47.3.11

Describe your issue

I have decided to make many recipes using keepIngredient() so i have started with a thing like that just to test how it work
[it work perfectly]

// all items are custom using kubejs
ServerEvents.recipes((event) => {
  event.recipes.kubejs
      .shapeless("kubejs:" + 2, [
        "kubejs:" + 1,
        "kubejs:" + 'plus',
        "kubejs:" + 1,
      ])
      .keepIngredient("kubejs:" + 'plus');
})

2024-10-18_16 00 34

so on next i have try to make it inside a function

ServerEvents.recipes((event) => {
// same code but inside a function
  function shapeless (operator, inputs, output) {
    event.recipes.kubejs
      .shapeless("kubejs:" + output, [
        "kubejs:" + inputs[0],
        "kubejs:" + operator,
        "kubejs:" + inputs[1],
      ])
      .keepIngredient("kubejs:" + operator);
  };
  shapeless("plus", [1, 2], 3);
})

but i have found this (it keep all ingredients ignoring the filter)

2024-10-18_16 03 21

also i have tested and persist as same on this

ServerEvents.recipes((event) => {
// same code but using variables
  let n2= 2
  let n1 = 1
  let plus = 'plus'

  event.recipes.kubejs
      .shapeless("kubejs:" + n2, [
        "kubejs:" + n1,
        "kubejs:" + plus,
        "kubejs:" + n1,
      ])
      .keepIngredient("kubejs:" + plus);
})
ServerEvents.recipes((event) => {
// same code using  *arrow function*
  let shapeless = (operator, inputs, output) => {
    event.recipes.kubejs
      .shapeless("kubejs:" + output, [
        "kubejs:" + inputs[0],
        "kubejs:" + operator,
        "kubejs:" + inputs[1],
      ])
      .keepIngredient("kubejs:" + operator);
  };
  shapeless("plus", [1, 2], 3);
})

Crash report/logs

No response

commented

Edit.
I have found what cause that issue:
it was caused by using variables or dynamic values inside .keepIngredient() like

ServerEvents.recipes((event) => {
  //it dont want work properly but persist all items
  let operator = "plus";
  event.recipes.kubejs
    .shapeless("kubejs:" + 2, [
      "kubejs:" + 1,
      "kubejs:" + "plus",
      "kubejs:" + 1,
    ])
    .keepIngredient("kubejs:" + operator);

  //it work perfectly persisting only the specific item
  event.recipes.kubejs
    .shapeless("kubejs:" + 3, [
      "kubejs:" + 2,
      "kubejs:" + "plus",
      "kubejs:" + 1,
    ])
    .keepIngredient("kubejs:" + "plus");
});