/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  meteordevelopment.orbit.EventHandler
 *  net.minecraft.class_1657
 *  net.minecraft.class_3532
 */
package meteordevelopment.meteorclient.systems.modules.render;

import java.util.Objects;
import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.renderer.ShapeMode;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.ColorSetting;
import meteordevelopment.meteorclient.settings.DoubleSetting;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.friends.Friends;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.class_1657;
import net.minecraft.class_3532;

public class CreeperOrbit
extends Module {
    private final SettingGroup sgGeneral;
    private final SettingGroup sgFriends;
    private final Setting<Integer> creeperCount;
    private final Setting<Double> orbitSpeed;
    private final Setting<Double> radius;
    private final Setting<SettingColor> color;
    private final Setting<Double> bobbingHeight;
    private final Setting<Double> size;
    private final Setting<Boolean> friendColorEnabled;
    private final Setting<SettingColor> friendColor;

    public CreeperOrbit() {
        super(Categories.Render, "creeper-orbit", "Miniature creeper ghosts orbiting around players.");
        this.sgGeneral = this.settings.getDefaultGroup();
        this.sgFriends = this.settings.createGroup("Friends");
        this.creeperCount = this.sgGeneral.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("creeper-count")).description("Number of creeper ghosts orbiting each player.")).defaultValue(3)).min(1).sliderMax(10).build());
        this.orbitSpeed = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("speed")).description("Speed of the orbiting creepers.")).defaultValue(2.0).min(0.1).sliderMax(10.0).build());
        this.radius = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("radius")).description("Orbit radius around players.")).defaultValue(1.5).min(0.5).sliderMax(4.0).build());
        this.color = this.sgGeneral.add(((ColorSetting.Builder)((ColorSetting.Builder)new ColorSetting.Builder().name("color")).description("Color of the creeper ghosts.")).defaultValue(new SettingColor(0, 255, 100, 150)).build());
        this.bobbingHeight = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("bobbing-height")).description("How much the creepers bob up and down.")).defaultValue(0.3).min(0.0).sliderMax(1.0).build());
        this.size = this.sgGeneral.add(((DoubleSetting.Builder)((DoubleSetting.Builder)new DoubleSetting.Builder().name("size")).description("Size of the creeper ghosts.")).defaultValue(0.12).min(0.05).sliderMax(0.3).build());
        this.friendColorEnabled = this.sgFriends.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("use-friend-color")).description("Use a different color for friends.")).defaultValue(true)).build());
        SettingGroup var10001 = this.sgFriends;
        ColorSetting.Builder var10002 = ((ColorSetting.Builder)((ColorSetting.Builder)new ColorSetting.Builder().name("friend-color")).description("Color for friends' creeper ghosts.")).defaultValue(new SettingColor(0, 150, 255, 150));
        Setting<Boolean> var10003 = this.friendColorEnabled;
        Objects.requireNonNull(var10003);
        this.friendColor = var10001.add(((ColorSetting.Builder)var10002.visible(var10003::get)).build());
    }

    /*
     * Unable to fully structure code
     */
    @EventHandler
    private void onRender(Render3DEvent event) {
        if (this.mc.field_1687 != null) {
            var2 = this.mc.field_1687.method_18456().iterator();
            block0: while (true) {
                if (!var2.hasNext()) {
                    return;
                }
                player = (class_1657)var2.next();
                if (player == this.mc.field_1724) continue;
                creeperColor = this.color.get();
                if (this.friendColorEnabled.get().booleanValue() && Friends.get().isFriend(player)) {
                    creeperColor = this.friendColor.get();
                }
                tickDelta = event.tickDelta;
                posX = class_3532.method_16436((double)tickDelta, (double)player.field_6014, (double)player.method_23317());
                posY = class_3532.method_16436((double)tickDelta, (double)player.field_6036, (double)player.method_23318());
                posZ = class_3532.method_16436((double)tickDelta, (double)player.field_5969, (double)player.method_23321());
                time = (double)System.currentTimeMillis() / 1000.0 * this.orbitSpeed.get();
                i = 0;
                while (true) {
                    if (i < this.creeperCount.get()) ** break;
                    continue block0;
                    angle = time + 6.283185307179586 / (double)this.creeperCount.get().intValue() * (double)i;
                    x = posX + Math.cos(angle) * this.radius.get();
                    z = posZ + Math.sin(angle) * this.radius.get();
                    y = posY + (double)(player.method_18381(player.method_18376()) / 2.0f) + Math.sin(angle) * this.bobbingHeight.get();
                    this.renderCreeperGhost(event, x, y, z, angle, creeperColor);
                    ++i;
                }
                break;
            }
        }
    }

    private void renderCreeperGhost(Render3DEvent event, double x, double y, double z, double angle, Color c) {
        Color black = new Color(0, 0, 0, 255);
        double headSize = this.size.get();
        event.renderer.box(x - headSize, y, z - headSize, x + headSize, y + headSize * 2.0, z + headSize, c, c, ShapeMode.Both, 0);
        double bodyWidth = headSize * 0.67;
        double bodyHeight = headSize * 1.5;
        event.renderer.box(x - bodyWidth, y - bodyHeight, z - bodyWidth, x + bodyWidth, y, z + bodyWidth, c, c, ShapeMode.Both, 0);
        double lookX = Math.cos(angle + Math.PI);
        double lookZ = Math.sin(angle + Math.PI);
        this.renderFacePixel(event, x, y, z, lookX, lookZ, 0.05, 0.16, 0.02, black);
        this.renderFacePixel(event, x, y, z, lookX, lookZ, -0.05, 0.16, 0.02, black);
        this.renderFacePixel(event, x, y, z, lookX, lookZ, 0.0, 0.08, 0.03, black);
        this.renderFacePixel(event, x, y, z, lookX, lookZ, 0.03, 0.06, 0.02, black);
        this.renderFacePixel(event, x, y, z, lookX, lookZ, -0.03, 0.06, 0.02, black);
    }

    private void renderFacePixel(Render3DEvent event, double x, double y, double z, double lx, double lz, double lateralOffset, double vertOffset, double pixelSize, Color color) {
        double px = x + lx * 0.125 + -lz * lateralOffset;
        double pz = z + lz * 0.125 + lx * lateralOffset;
        double py = y + vertOffset;
        event.renderer.box(px - pixelSize, py - pixelSize, pz - pixelSize, px + pixelSize, py + pixelSize, pz + pixelSize, color, color, ShapeMode.Both, 0);
    }
}

