Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DevDyna opened this issue Oct 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@DevDyna
Copy link

DevDyna commented Oct 18, 2024

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

@DevDyna
Copy link
Author

DevDyna commented Nov 5, 2024

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");
});

@DevDyna DevDyna changed the title keepIngredient() dont work properly on specific situations keepIngredient() dont work properly when used variables or dynamic values as parameters Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant