package carpetfixes.mixins.entityFixes;

import carpetfixes.CFSettings;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.entity.mob.ZombieVillagerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
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.CallbackInfoReturnable;

/**
 * Fixes being able to start the conversion of zombie villagers while they are already converting
 */

@Mixin(ZombieVillagerEntity.class)
public abstract class ZombieVillagerEntity_convertingMixin extends ZombieEntity {

    public ZombieVillagerEntity_convertingMixin(EntityType<? extends ZombieEntity> entityType, World world) {
        super(entityType, world);
    }


    @Shadow
    public abstract boolean isConverting();


    @Inject(
            method = "interactMob",
            at = @At("HEAD"),
            cancellable = true
    )
    private void cf$interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
        if (CFSettings.convertConvertingZombieVillagersFix && this.isConverting()) {
            cir.setReturnValue(super.interactMob(player, hand));
        }
    }
}
