Integrated Dynamics

Integrated Dynamics

63M Downloads

Custom maxByItemSize operator not working with reduce1

Minerofmillions opened this issue ยท 5 comments

commented

Issue type:

  • ๐Ÿ› Bug

Short description:

A custom maxByItemSize operator (Item -> Item -> Item) gives the correct results when applying two items to it, but when using it with reduce1 on an item list, it errors with "The property is expected to output Item, while Operator was found for operator Virtual Piped 2 Operator."

Steps to reproduce the problem:

  1. Make sure you have cheats and command blocks enabled (to cheat in the maxByItemSize card)
  2. Make a variable card with a value (it doesn't matter what it is, we're going to overwrite it.
  3. Put it in the first slot of a chest.
  4. Run the following command:
    data modify block <Chest Coordinates> Items[0].tag.value set value {serializer: "integrateddynamics:combined.pipe2", value: {operators: [{v: {serializer: "integrateddynamics:combined.pipe",value: {operators: [{v: {serializer: "integrateddynamics:combined.pipe",value: {operators: [{v: "integrateddynamics:itemstack_size"}, {v: "integrateddynamics:relational_gt"}]}}}, {v: {serializer: "integrateddynamics:curry",value: {baseOperator: "integrateddynamics:operator_pipe",values: [{value: "integrateddynamics:itemstack_size",valueType: "integrateddynamics:operator"}]}}}]}}},{v: {serializer: "integrateddynamics:combined.pipe",value: {operators: [{v: {serializer: "integrateddynamics:combined.flip",value: {operators: [{v: "integrateddynamics:general_choice"}]}}}, {v: "integrateddynamics:operator_flip"}]}}},{v: {serializer: "integrateddynamics:curry",value: {baseOperator: "integrateddynamics:operator_pipe2",values: [{value: "integrateddynamics:general_identity",valueType: "integrateddynamics:operator"}]}}}]}}
    4a. Alternatively, make the operator as described on Discord and apply itemSize.
  5. Verify the card is now a "Virtual Piped 2 Operator" of type Item -> Operator
  6. Apply2 two items to verify it gives the one with the larger stack size
  7. Reduce1 with an item list to verify it errors.

Expected behaviour:

reduce1(maxByItemSize, itemList) should return the item from the list with the highest stack size, taking the last if there are multiple.


Versions:

  • This mod: 1.18.2-1.17.5
  • Minecraft: 1.18.2
  • Mod loader version: Forge 40.2.21

Also tested with

  • ID: 1.1.11
  • Minecraft: 1.12.2
commented

Thanks for reporting!

commented

The command doesn't work unfortunately. The paste operation seems to be limited by 256 characters. With command blocks, I can't seem to get it working either.
Do you have a smaller operation to reproduce the issue with? An Integrated Scripting snippet would also work.

commented

How odd. The function function reducer(a, b) { return choice(a > b, a, b) } works as a reduction operator over numbers (with the global definition of choice), but the equivalent operator (reducer = pipe2(greaterThan, pipe(flip(choice), flip), apply(pipe2, identity))) doesn't. Both of them do, however, give the maximum of two applied numbers.
image
2024-09-03_08 16 33
2024-09-03_08 16 54
The second image shows the values I'm using to test with, the third image shows the functions that I'm testing along with the two different tests. The middle column is apply2(func, 5, 10) while the right column is reduce1(func, list).

commented

Forgot to mention, this test was Minecraft 1.20.1, Forge 47.3.7, ID 1.23.3, InScr 1.0.4

commented

On the one hand, good news the scripting approach works.
But on the other hand, this makes debugging a lot more difficult of course.