CyclopsMC / IntegratedDynamics

A Minecraft mod to take full and automated control of your appliances.
http://cyclopsmc.github.io/IntegratedDynamics/
MIT License
132 stars 62 forks source link

Custom maxByItemSize operator not working with reduce1 #1387

Closed Minerofmillions closed 3 weeks ago

Minerofmillions commented 2 months ago

Issue type:


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:

Also tested with

rubensworks commented 2 months ago

Thanks for reporting!

rubensworks commented 2 months ago

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.

Minerofmillions commented 2 months ago

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).

Minerofmillions commented 2 months ago

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

rubensworks commented 2 months ago

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