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

FoodBuilder is broken #943

Open
Nyxane opened this issue Jan 26, 2025 · 1 comment
Open

FoodBuilder is broken #943

Nyxane opened this issue Jan 26, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Nyxane
Copy link

Nyxane commented Jan 26, 2025

Minecraft Version

1.21.1

KubeJS Version

2101.7.1-build.181

Rhino Version

2101.2.6-build.66

Architectury Version

Forge/Fabric Version

Neoforge 21.1.107

Describe your issue

Using the following Startup script, FoodBuilder(FoodProperties) does not yield the same FoodProperties
Notable effects:
Saturation gets set to (Nutrition * Saturation * 2) from FoodConstant.saturationByModifier
usingConvertsTo never gets initialized and is, null crashing the instance

ItemEvents.modification((event) => {
    const $FoodBuilder = Java.loadClass("dev.latvian.mods.kubejs.item.FoodBuilder");
    event.modify("*", (item) => {
        if (item.get("food")) {
            console.log(item.get("food"))
            console.log($FoodBuilder(item.get("food")).build())
        }
    });
  });

public FoodProperties build() {
return new FoodProperties(nutrition, FoodConstants.saturationByModifier(nutrition, saturation), alwaysEdible, eatSeconds, usingConvertsTo, effects);
}

public FoodBuilder(FoodProperties properties) {
this.nutrition = properties.nutrition();
this.saturation = properties.saturation();
this.alwaysEdible = properties.canAlwaysEat();
this.eatSeconds = properties.eatSeconds();
this.effects = new ArrayList<>();
this.effects.addAll(properties.effects());
}

Crash report/logs

No response

@Nyxane Nyxane added the bug Something isn't working label Jan 26, 2025
@pietro-lopes
Copy link
Contributor

pietro-lopes commented Jan 27, 2025

That should be deprecated, currently KubeJS/Rhino can typewrap records like the FoodProperties is

just use []

like

ItemEvents.modification(event => {
  event.modify("*", item => {
    let originalFood = item.get("food")
    if (originalFood) {
      console.log(originalFood)
      console.log(item)
      item.setFood(
        [originalFood.nutrition(),
          originalFood.saturation(),
          originalFood.canAlwaysEat(),
          originalFood.eatSeconds(),
          originalFood.usingConvertsTo(),
          originalFood.effects()
        ])
    }
    let newFood = item.get("food")
    console.log(newFood)
  })
})

Btw @LatvianModder

[03:27:02] [Render thread/INFO] [KubeJS Startup/]: FoodProperties[nutrition=9, saturation=21.6, canAlwaysEat=false, eatSeconds=1.6, usingConvertsTo=Optional.empty, effects=[]] [net.minecraft.world.food.FoodProperties]
[03:27:02] [Render thread/INFO] [KubeJS Startup/]: ItemModifications[item=pamhc2foodextended:tomatosoupitem] [dev.latvian.mods.kubejs.item.ItemModificationKubeEvent$ItemModifications]
[03:27:02] [Render thread/INFO] [KubeJS Startup/]: FoodProperties[nutrition=9, saturation=21.6, canAlwaysEat=false, eatSeconds=1.6, usingConvertsTo=Optional[0 minecraft:air], effects=[]] [net.minecraft.world.food.FoodProperties]

is this Optional.empty -> Optional[0 minecraft:air] fine? 💀

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

2 participants