package xyz.tbvns.rogue_block.mixin;

import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
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;
import xyz.tbvns.rogue_block.Managers.DataManager;
import xyz.tbvns.rogue_block.Managers.WorldManager;

@Mixin(ServerPlayerEntity.class)
public abstract class MixinPlayerDeath {
    @Shadow public abstract Entity getCameraEntity();

    @Inject(method = "onDeath", at = @At("HEAD"), cancellable = true)
    public void onDeath(DamageSource damageSource, CallbackInfo ci) {
        ServerPlayerEntity entity = ((ServerPlayerEntity) (Object) this);
        entity.setHealth(20);

        WorldManager.teleportToLobbyWorld(((ServerPlayerEntity) (Object) this));

        System.out.println(DataManager.getPlayerState(((ServerPlayerEntity) (Object) this)).addPoints(10));

        ci.cancel();
    }
}
