package asm.mixins;

import dev.crucifixbeta.CrucifixBeta;
import dev.crucifixbeta.api.events.impl.TotemParticleEvent;
import java.awt.Color;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.particle.TotemParticle;
import net.minecraft.client.world.ClientWorld;
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.CallbackInfo;

@Environment(EnvType.CLIENT)
@Mixin({TotemParticle.class})
public abstract class MixinTotemParticle extends MixinParticle {
   @Inject(
      method = {"<init>"},
      at = {@At("TAIL")}
   )
   private void hookInit(
      ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ, SpriteProvider spriteProvider, CallbackInfo ci
   ) {
      TotemParticleEvent var16 = TotemParticleEvent.get(velocityX, velocityY, velocityZ);
      CrucifixBeta.EVENT_BUS.post(var16);
      if (var16.isCancelled()) {
         this.velocityX = var16.velocityX;
         this.velocityY = var16.velocityY;
         this.velocityZ = var16.velocityZ;
         Color var17 = var16.color;
         if (var17 != null) {
            this.setColor((float)var17.getRed() / 255.0F, (float)var17.getGreen() / 255.0F, (float)var17.getBlue() / 255.0F);
            this.setAlpha((float)var17.getAlpha() / 255.0F);
         }
      }
   }
}
