package com.leisuretimedock.blasttravelreborn.mixin;

import com.leisuretimedock.blasttravelreborn.content.entity.CannonEntity;
import com.leisuretimedock.blasttravelreborn.util.PlayerEntityDuck;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.Input;
import net.minecraft.client.player.LocalPlayer;
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.CallbackInfo;

@Mixin(LocalPlayer.class)
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayer implements PlayerEntityDuck {
	@Shadow public Input input;

	public ClientPlayerEntityMixin(ClientLevel world, GameProfile profile) {
		super(world, profile);
	}

	@Inject(method = "rideTick", at = @At("TAIL"))
	private void blasttravel$handleCannonInput(CallbackInfo ci) {
		if (this.getVehicle() instanceof CannonEntity cannon) {
			cannon.handleInput(this.input.jumping);
		}
	}

	@Inject(method = "serverAiStep", at = @At("TAIL"))
	private void blasttravel$preserveHSpeedInFlight(CallbackInfo ci) {
		if (this.blasttravel$inCannonFlight()) {
			var self = this;
			self.xxa = 0;
			self.zza = 0;
		}
	}
}
