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.Entity;
import net.minecraft.world.entity.animal.chicken.Chicken;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
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(Entity.class)
public abstract class EntityMixin {
	@Inject(method = "interact", at = @At("HEAD"), cancellable = true)
	private void ibelievechickenfly$pickUpChickenAt(Player player, InteractionHand hand, Vec3 hitPos, CallbackInfoReturnable<InteractionResult> cir) {
		Entity self = (Entity) (Object) this;
		if (!(self instanceof Chicken)) {
			return;
		}

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

	@Inject(method = "isPushable", at = @At("HEAD"), cancellable = true)
	private void ibelievechickenfly$disablePush(CallbackInfoReturnable<Boolean> cir) {
		if (ChickenCarryController.isChickenCarried((Entity) (Object) this)) {
			cir.setReturnValue(false);
		}
	}

	@Inject(method = "isPickable", at = @At("HEAD"), cancellable = true)
	private void ibelievechickenfly$disablePick(CallbackInfoReturnable<Boolean> cir) {
		if (ChickenCarryController.isChickenCarried((Entity) (Object) this)) {
			cir.setReturnValue(false);
		}
	}

	@Inject(method = "canCollideWith", at = @At("HEAD"), cancellable = true)
	private void ibelievechickenfly$disableEntityCollision(Entity entity, CallbackInfoReturnable<Boolean> cir) {
		if (ChickenCarryController.isChickenCarried((Entity) (Object) this)) {
			cir.setReturnValue(false);
		}
	}
}
