package carpetfixes.mixins.itemFixes;

import carpetfixes.CFSettings;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ChorusFruitItem;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
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;

/**
 * Fix chorus fruit not removing fall damage when teleporting you down.
 */

@Mixin(ChorusFruitItem.class)
public class ChorusFruitItem_fallDamageMixin {


    @Inject(
            method = "finishUsing",
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/world/World;emitGameEvent(Lnet/minecraft/world/event/GameEvent;" +
                            "Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/world/event/GameEvent$Emitter;)V"
            )
    )
    private void cf$finishUsing(ItemStack stack, World world, LivingEntity user,
                                CallbackInfoReturnable<ItemStack> cir) {
        if (CFSettings.chorusFruitFallDamageFix) {
            user.onLanding();
        }
    }
}
