package com.tiedup.remake.mixin.client;

import com.tiedup.remake.client.state.PetBedClientState;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
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.CallbackInfoReturnable;

/**
 * Client-side mixin: prevent vanilla sleeping visuals (laying flat) for
 * players on a pet bed in SLEEP mode. Server-side isSleeping() is unaffected,
 * so night skip still works.
 */
@Mixin(LivingEntity.class)
public abstract class MixinLivingEntitySleeping {

    @Inject(method = "isSleeping", at = @At("HEAD"), cancellable = true)
    private void tiedup$hidePetBedSleeping(
        CallbackInfoReturnable<Boolean> cir
    ) {
        LivingEntity self = (LivingEntity) (Object) this;
        if (self.level().isClientSide() && self instanceof Player player) {
            if (PetBedClientState.get(player.getUUID()) == 2) {
                cir.setReturnValue(false);
            }
        }
    }
}
