Non-vanilla potion effects on food items still crash the game
pm065 opened this issue ยท 6 comments
Since apparently nobody noticed #63 (comment) (I don't blame you, looking through old, closed, stale issues to check for comments probably isn't a thing many people do), I'll just repost it. It may seem like a trivial issue, and it is, but quite an annoying one for the handful of people who care.
crash-2021-08-23_17.23.53-server.txt
Either I'm missing something or this isn't fixed.
Kubejs version is kubejs-forge-1605.3.15-build.90
This is the (relevant) code I use:
event.create(food.id).texture(food.texture).food(f => {
f.hunger(food.hunger);
f.saturation(food.saturation);
f.effect('ars_noveau:mana_regen', 60, 0, 1.0);
f.alwaysEdible();
})
It works fine with vanilla potion effects, but if I use that one, it crashes the game.
crash-2021-08-23_17.23.53-server.txt
Either I'm missing something or this isn't fixed.Kubejs version is kubejs-forge-1605.3.15-build.90
This is the (relevant) code I use:
event.create(food.id).texture(food.texture).food(f => { f.hunger(food.hunger); f.saturation(food.saturation); f.effect('ars_noveau:mana_regen', 60, 0, 1.0); f.alwaysEdible(); })
It works fine with vanilla potion effects, but if I use that one, it crashes the game.
When testing this again. Make sure that its ars_nouveau:mana_regen
and not ars_noveau:mana_regen
.
Damnit, might have to double-check this works on recent versions, @lythowastaken any ideas maybe?
Damnit, might have to double-check this works on recent versions, @lythowastaken any ideas maybe?
Seems like I misstest something there.
public FoodBuilder effect(MobEffect mobEffect, int duration, int amplifier, float probability)
When type wrapping the String
to MobEffect
it does not find a MobEffect
and returns null. The mob effects don't exist at this point.
The method should take ResourceLocation
instead of MobEffect
and get the effect while eating. Which makes sense why it is a supplier >.> fak
I would go with this?:
private static class EffectSupplier implements Supplier<MobEffectInstance> {
private final ResourceLocation id;
private final int duration;
private final int amplifier;
private MobEffect cachedEffect;
public EffectSupplier(ResourceLocation id, int duration, int amplifier) {
this.id = id;
this.duration = duration;
this.amplifier = amplifier;
}
@Override
public MobEffectInstance get() {
if(cachedEffect == null) {
cachedEffect = KubeJSRegistries.mobEffects().get(id);
if(cachedEffect == null) {
throw new RuntimeException(String.format("Missing effect '%s'. Check spelling or maybe potion id was used instead of effect id", id));
}
}
return new MobEffectInstance(cachedEffect, duration, amplifier);
}
}
public FoodBuilder effect(ResourceLocation mobEffectId, int duration, int amplifier, float probability) {
effects.add(Pair.of(new EffectSupplier(mobEffectId, duration, amplifier), probability));
return this;
}
Fixed with 9178615 ^^