package xyz.tbvns.rogue_block.mixin;

import net.minecraft.advancement.AdvancementRewards;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xyz.tbvns.rogue_block.Managers.DataManager;

@Mixin(AdvancementRewards.class)
public class MixinAchievementReward {
    @Inject(method = "apply", at = @At("HEAD"))
    public void apply(ServerPlayerEntity player, CallbackInfo ci) {
        AdvancementRewards advancementRewards = ((AdvancementRewards) ((Object) this));
        int point = advancementRewards.experience() / 10;
        if (point == 0) return;
        DataManager.getPlayerState(player).addPoints(point);
        player.sendMessage(Text.of("§aReceived §b§l" + point + "§r§a points for completing an achievement."));
    }
}
