package com.thebrokenrail.gestus.mixin;

import com.thebrokenrail.gestus.entity.FakePlayerEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.network.packet.s2c.play.MobSpawnS2CPacket;
import net.minecraft.util.registry.Registry;
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(MobSpawnS2CPacket.class)
public class MixinMobSpawnS2CPacket {
    @Shadow
    private int entityTypeId;

    @Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/entity/LivingEntity;)V")
    public void init(LivingEntity entity, CallbackInfo info) {
        if (entity instanceof FakePlayerEntity) {
            entityTypeId = Registry.ENTITY_TYPE.getRawId(EntityType.ARMOR_STAND);
        }
    }
}
