#How can I add the ".snack()" value to a vanilla item?

3 messages · Page 1 of 1 (latest)

tough hearth
#

Basically I want to add the .snack() line to the vanilla sweet berries using mixins.

So currently the latest code I tried was:

package net.offtop1a.hungering.mixin;

import net.minecraft.component.type.FoodComponent;
import net.minecraft.component.type.FoodComponents;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(FoodComponents.class)
public class HungeringFoodAdjustmentMixin {
    @Shadow
    public static FoodComponent SWEET_BERRIES;

    @Inject(method = "<clinit>", at = @At("TAIL"))
    private static void adjustSweetBerries(CallbackInfo ci) {
        SWEET_BERRIES = new FoodComponent.Builder().nutrition(2).saturationModifier(0.1f).snack().build();
    }
}

the code Is giving an illegal access error when it tries to modify the line, how should I fix this? (crash report should be provided as a .txt file)

sand holly
#

You either need to annotate SWEET_BERRIES with @Mutable or you should @ModifyExpressionValue of the origional assignment