KubeJS (Old)

KubeJS (Old)

3M Downloads

FoodBuilder is broken

Nyxane opened this issue ยท 2 comments

commented

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

commented

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? ๐Ÿ’€

commented

Optional[0 minecraft:air] is going to cause Minecraft to crash because it can't be empty (or 0)