package com.thebrokenrail.gestus;

import com.thebrokenrail.gestus.command.EmoteCommand;
import com.thebrokenrail.gestus.entity.FakePlayerEntity;
import com.thebrokenrail.gestus.util.ServerPlayerEntityExtension;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class Gestus implements ModInitializer {
    public static final String NAMESPACE = "gestus";

    public static final EntityType<FakePlayerEntity> FAKE_PLAYER_ENTITY_TYPE = FabricEntityTypeBuilder.create(SpawnGroup.MISC, (EntityType.EntityFactory<FakePlayerEntity>) FakePlayerEntity::new).disableSaving().disableSummon().dimensions(EntityDimensions.fixed(0f, 0f)).fireImmune().build();

    @Override
    public void onInitialize() {
        Registry.register(Registry.ENTITY_TYPE, new Identifier(NAMESPACE, "fake_player"), FAKE_PLAYER_ENTITY_TYPE);
        FabricDefaultAttributeRegistry.register(FAKE_PLAYER_ENTITY_TYPE, LivingEntity.createLivingAttributes());

        CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> EmoteCommand.register(dispatcher));
    }

    /**
     * Play Custom Emote
     * @param player Player
     * @param emote Emote ID
     */
    public static void playCustomEmote(ServerPlayerEntity player, Identifier emote) {
        ((ServerPlayerEntityExtension) player).getShadow().playCustomEmote(emote);
    }
}
