package dev.crucifixbeta.mod.gui;

import dev.crucifixbeta.api.utils.render.Render2DUtil;
import java.awt.Color;
import java.util.Random;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;

@Environment(EnvType.CLIENT)
public class Snow {
   private static final Random RAND = new Random();
   private int x;
   private int y;
   private int fallingSpeed;
   private int size;

   public Snow(int x, int y, int fallingSpeed, int size) {
      this.x = x;
      this.y = y;
      this.fallingSpeed = fallingSpeed;
      this.size = size;
   }

   public int getX() {
      return this.x;
   }

   public void setX(int x) {
      this.x = x;
   }

   public int getY() {
      return this.y;
   }

   public void setY(int _y) {
      this.y = _y;
   }

   public void drawSnow(DrawContext drawContext) {
      Render2DUtil.drawRect(drawContext.getMatrices(), (float)this.getX(), (float)this.getY(), (float)this.size, (float)this.size, -1714829883);
      this.setY(this.getY() + this.fallingSpeed);
   }

   public void drawSnow(DrawContext drawContext, int screenWidth, int screenHeight, float speed, float sizeScale, float wind, int alpha, boolean star) {
      int var9 = Math.max(0, Math.min(255, alpha));
      int var10 = Math.max(1, Math.round((float)this.size * Math.max(0.4F, sizeScale)));
      Color var11 = new Color(255, 255, 255, var9);
      if (star) {
         float var12 = (float)this.x + (float)var10 * 0.5F;
         float var13 = (float)this.y + (float)var10 * 0.5F;
         Render2DUtil.drawLine(drawContext.getMatrices(), var12 - (float)var10, var13, var12 + (float)var10, var13, var11.getRGB());
         Render2DUtil.drawLine(drawContext.getMatrices(), var12, var13 - (float)var10, var12, var13 + (float)var10, var11.getRGB());
      } else {
         Render2DUtil.drawCircle(drawContext.getMatrices(), (float)this.x, (float)this.y, (float)var10, var11, 12);
      }

      float var14 = Math.max(0.05F, speed / 20.0F);
      this.y = this.y + Math.max(1, Math.round((float)this.fallingSpeed * var14));
      this.x = this.x + Math.round(wind / 20.0F);
      if (this.y > screenHeight + 10 || this.y < -30 || this.x < -30 || this.x > screenWidth + 30) {
         this.y = -10 - RAND.nextInt(30);
         this.x = RAND.nextInt(Math.max(1, screenWidth));
         this.fallingSpeed = RAND.nextInt(5) + 1;
         this.size = RAND.nextInt(3) + 1;
      }
   }
}
