[1.19.2] KJS6, FoodBuilder eaten handler on item-modification event not working
MrNovado opened this issue ยท 2 comments
Minecraft Version
1.19.2
KubeJS Version
1902.6.0-build.114
Rhino Version
1902.2.1-build.257
Architectury Version
6.3.49
Forge/Fabric Version
Forge 43.1.52
Describe your issue
I'm playing with the food builder and trying to make inedible stuff into edibles with added effects, but I noticed eaten
event is only triggered on newly registered items, eg:
// this works!
StartupEvents.registry("item", (e) => {
e.create("example_item", "basic")
.maxStackSize(10)
.food((fb) => {
fb.eaten((et) => {
// gets triggered and works fine
const actor = et.getEntity();
actor.runCommandSilent("/tell @a Actor, hello!");
})
//
.alwaysEdible(true)
.fastToEat(true)
.meat(true)
.hunger(1)
.saturation(1)
.build();
});
});
But on modification
event, while food-builder is available and you can use it to change most properties just fine, the eaten
event handler would not be triggered:
// modification works, charcoal is edible, but eaten wont be triggered!
ItemEvents.modification((e) => {
e.modify("minecraft:charcoal", (charcoal) => {
if (typeof charcoal === "string") {
return;
}
charcoal.maxStackSize = 10;
charcoal.setFoodProperties((fb) => {
fb.eaten((et) => {
// not triggered at all
const actor = et.getEntity();
actor.runCommandSilent("/tell @a Actor, hello!");
})
//
.alwaysEdible(true)
.fastToEat(true)
.meat(true)
.hunger(1)
.saturation(1)
.build();
});
});
});
Also, I believe it's the same for prev. versions of kjs (at least for 1.18.2 [obv. with different syntax]).
Crash report/logs
No response
This is a design problem since modified items do not have any itemBuilder
, where foodBuilder.eaten
is accessed when player eats through it.
For a workaround, use:
ItemEvents.foodEaten("minecraft:charcoal", event => {
})
Which will have the same behavior as setting in foodBuilder
. We might need to consider separating things in builder to mixins.