package ru.dbotthepony.mc.otm.mixin;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
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;
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability;

@Mixin(Player.class)
public class MixinPatchProjectileFinder {
	@Inject(
		method = "getProjectile(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;",
		at = @At(
			value = "INVOKE",
			target = "net.minecraftforge.common.ForgeHooks.getProjectile(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;",
			ordinal = 2,
			shift = At.Shift.BEFORE,
			remap = false
		),
		cancellable = true)
	private void exosuitGetProjectileHook(ItemStack weaponItem, CallbackInfoReturnable<ItemStack> hook) {
		ItemStack result = MatteryPlayerCapability.getProjectileHook((Player) ((Object) this), weaponItem);

		if (result != null) {
			hook.setReturnValue(result);
		}
	}
}
