package fr.koka99cab.ibelievechickenfly.mixin;

import fr.koka99cab.ibelievechickenfly.chickenfly.ChickenCarryController;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.chicken.Chicken;
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;

@Mixin(Animal.class)
public abstract class AnimalEntityMixin {
	@Inject(method = "mobInteract", at = @At("HEAD"), cancellable = true)
	private void ibelievechickenfly$pickUpChicken(Player player, InteractionHand hand, CallbackInfoReturnable<InteractionResult> cir) {
		Animal self = (Animal) (Object) this;
		if (!(self instanceof Chicken)) {
			return;
		}

		InteractionResult result = ChickenCarryController.tryPickUpChicken(player, self.level(), hand, self);
		if (result != InteractionResult.PASS) {
			cir.setReturnValue(result);
		}
	}
}
