package net.minecraft.client.gui.components;

import java.util.EnumMap;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.server.level.ChunkHolder;
import com.mojang.datafixers.util.Either;
import com.mojang.math.Matrix4f;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.math.Transformation;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import net.minecraft.util.FrameTimer;
import net.minecraft.Util;
import net.minecraft.world.level.material.FluidState;
import java.util.Iterator;
import com.google.common.collect.UnmodifiableIterator;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.ChatFormatting;
import net.minecraft.world.phys.BlockHitResult;
import com.mojang.blaze3d.platform.GlUtil;
import net.minecraft.world.level.chunk.ChunkStatus;
import com.mojang.datafixers.DataFixUtils;
import java.util.Optional;
import net.minecraft.client.renderer.PostChain;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.world.level.NaturalSpawner;
import net.minecraft.world.level.lighting.LevelLightEngine;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.world.level.Level;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.network.Connection;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.core.Registry;
import net.minecraft.world.level.LightLayer;
import net.minecraft.util.Mth;
import java.util.Locale;
import it.unimi.dsi.fastutil.longs.LongSets;
import net.minecraft.server.level.ServerLevel;
import java.util.Objects;
import com.google.common.collect.Lists;
import net.minecraft.client.ClientBrandRetriever;
import net.minecraft.SharedConstants;
import java.util.List;
import com.google.common.base.Strings;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.world.entity.Entity;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import java.util.concurrent.CompletableFuture;
import net.minecraft.world.level.chunk.LevelChunk;
import javax.annotation.Nullable;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.phys.HitResult;
import net.minecraft.client.gui.Font;
import net.minecraft.client.Minecraft;
import net.minecraft.world.level.levelgen.Heightmap;
import java.util.Map;
import net.minecraft.client.gui.GuiComponent;

public class DebugScreenOverlay extends GuiComponent {
    private static final Map<Heightmap.Types, String> HEIGHTMAP_NAMES;
    private final Minecraft minecraft;
    private final Font font;
    private HitResult block;
    private HitResult liquid;
    @Nullable
    private ChunkPos lastPos;
    @Nullable
    private LevelChunk clientChunk;
    @Nullable
    private CompletableFuture<LevelChunk> serverChunk;
    
    public DebugScreenOverlay(final Minecraft dlx) {
        this.minecraft = dlx;
        this.font = dlx.font;
    }
    
    public void clearChunkCache() {
        this.serverChunk = null;
        this.clientChunk = null;
    }
    
    public void render(final PoseStack dhl) {
        this.minecraft.getProfiler().push("debug");
        RenderSystem.pushMatrix();
        final Entity aom3 = this.minecraft.getCameraEntity();
        this.block = aom3.pick(20.0, 0.0f, false);
        this.liquid = aom3.pick(20.0, 0.0f, true);
        this.drawGameInformation(dhl);
        this.drawSystemInformation(dhl);
        RenderSystem.popMatrix();
        if (this.minecraft.options.renderFpsChart) {
            final int integer4 = this.minecraft.getWindow().getGuiScaledWidth();
            this.drawChart(dhl, this.minecraft.getFrameTimer(), 0, integer4 / 2, true);
            final IntegratedServer eoz5 = this.minecraft.getSingleplayerServer();
            if (eoz5 != null) {
                this.drawChart(dhl, eoz5.getFrameTimer(), integer4 - Math.min(integer4 / 2, 240), integer4 / 2, false);
            }
        }
        this.minecraft.getProfiler().pop();
    }
    
    protected void drawGameInformation(final PoseStack dhl) {
        final List<String> list3 = this.getGameInformation();
        list3.add("");
        final boolean boolean4 = this.minecraft.getSingleplayerServer() != null;
        list3.add("Debug: Pie [shift]: " + (this.minecraft.options.renderDebugCharts ? "visible" : "hidden") + (boolean4 ? " FPS + TPS" : " FPS") + " [alt]: " + (this.minecraft.options.renderFpsChart ? "visible" : "hidden"));
        list3.add("For help: press F3 + Q");
        for (int integer5 = 0; integer5 < list3.size(); ++integer5) {
            final String string6 = list3.get(integer5);
            if (!Strings.isNullOrEmpty(string6)) {
                this.font.getClass();
                final int integer6 = 9;
                final int integer7 = this.font.width(string6);
                final int integer8 = 2;
                final int integer9 = 2 + integer6 * integer5;
                GuiComponent.fill(dhl, 1, integer9 - 1, 2 + integer7 + 1, integer9 + integer6 - 1, -1873784752);
                this.font.draw(dhl, string6, 2.0f, (float)integer9, 14737632);
            }
        }
    }
    
    protected void drawSystemInformation(final PoseStack dhl) {
        final List<String> list3 = this.getSystemInformation();
        for (int integer4 = 0; integer4 < list3.size(); ++integer4) {
            final String string5 = list3.get(integer4);
            if (!Strings.isNullOrEmpty(string5)) {
                this.font.getClass();
                final int integer5 = 9;
                final int integer6 = this.font.width(string5);
                final int integer7 = this.minecraft.getWindow().getGuiScaledWidth() - 2 - integer6;
                final int integer8 = 2 + integer5 * integer4;
                GuiComponent.fill(dhl, integer7 - 1, integer8 - 1, integer7 + integer6 + 1, integer8 + integer5 - 1, -1873784752);
                this.font.draw(dhl, string5, (float)integer7, (float)integer8, 14737632);
            }
        }
    }
    
    protected List<String> getGameInformation() {
        final IntegratedServer eoz3 = this.minecraft.getSingleplayerServer();
        final Connection me4 = this.minecraft.getConnection().getConnection();
        final float float5 = me4.getAverageSentPackets();
        final float float6 = me4.getAverageReceivedPackets();
        String string2;
        if (eoz3 != null) {
            string2 = String.format("Integrated server @ %.0f ms ticks, %.0f tx, %.0f rx", eoz3.getAverageTickTime(), float5, float6);
        }
        else {
            string2 = String.format("\"%s\" server, %.0f tx, %.0f rx", this.minecraft.player.getServerBrand(), float5, float6);
        }
        final BlockPos fu7 = this.minecraft.getCameraEntity().blockPosition();
        if (this.minecraft.showOnlyReducedInfo()) {
            return Lists.<String>newArrayList("Minecraft " + SharedConstants.getCurrentVersion().getName() + " (" + this.minecraft.getLaunchedVersion() + "/" + ClientBrandRetriever.getClientModName() + ")", this.minecraft.fpsString, string2, this.minecraft.levelRenderer.getChunkStatistics(), this.minecraft.levelRenderer.getEntityStatistics(), "P: " + this.minecraft.particleEngine.countParticles() + ". T: " + this.minecraft.level.getEntityCount(), this.minecraft.level.gatherChunkSourceStats(), "", String.format("Chunk-relative: %d %d %d", fu7.getX() & 0xF, fu7.getY() & 0xF, fu7.getZ() & 0xF));
        }
        final Entity aom8 = this.minecraft.getCameraEntity();
        final Direction fz9 = aom8.getDirection();
        String string3 = null;
        switch (fz9) {
            case NORTH: {
                string3 = "Towards negative Z";
                break;
            }
            case SOUTH: {
                string3 = "Towards positive Z";
                break;
            }
            case WEST: {
                string3 = "Towards negative X";
                break;
            }
            case EAST: {
                string3 = "Towards positive X";
                break;
            }
            default: {
                string3 = "Invalid";
                break;
            }
        }
        final ChunkPos bph11 = new ChunkPos(fu7);
        if (!Objects.equals(this.lastPos, bph11)) {
            this.lastPos = bph11;
            this.clearChunkCache();
        }
        final Level bqb12 = this.getLevel();
        final LongSet longSet13 = (bqb12 instanceof ServerLevel) ? ((ServerLevel)bqb12).getForcedChunks() : LongSets.EMPTY_SET;
        final List<String> list14 = Lists.<String>newArrayList("Minecraft " + SharedConstants.getCurrentVersion().getName() + " (" + this.minecraft.getLaunchedVersion() + "/" + ClientBrandRetriever.getClientModName() + ("release".equalsIgnoreCase(this.minecraft.getVersionType()) ? "" : ("/" + this.minecraft.getVersionType())) + ")", this.minecraft.fpsString, string2, this.minecraft.levelRenderer.getChunkStatistics(), this.minecraft.levelRenderer.getEntityStatistics(), "P: " + this.minecraft.particleEngine.countParticles() + ". T: " + this.minecraft.level.getEntityCount(), this.minecraft.level.gatherChunkSourceStats());
        final String string4 = this.getServerChunkStats();
        if (string4 != null) {
            list14.add(string4);
        }
        list14.add(this.minecraft.level.dimension().location() + " FC: " + longSet13.size());
        list14.add("");
        list14.add(String.format(Locale.ROOT, "XYZ: %.3f / %.5f / %.3f", this.minecraft.getCameraEntity().getX(), this.minecraft.getCameraEntity().getY(), this.minecraft.getCameraEntity().getZ()));
        list14.add(String.format("Block: %d %d %d", fu7.getX(), fu7.getY(), fu7.getZ()));
        list14.add(String.format("Chunk: %d %d %d in %d %d %d", fu7.getX() & 0xF, fu7.getY() & 0xF, fu7.getZ() & 0xF, fu7.getX() >> 4, fu7.getY() >> 4, fu7.getZ() >> 4));
        list14.add(String.format(Locale.ROOT, "Facing: %s (%s) (%.1f / %.1f)", fz9, string3, Mth.wrapDegrees(aom8.yRot), Mth.wrapDegrees(aom8.xRot)));
        if (this.minecraft.level != null) {
            if (this.minecraft.level.hasChunkAt(fu7)) {
                final LevelChunk chj16 = this.getClientChunk();
                if (chj16.isEmpty()) {
                    list14.add("Waiting for chunk...");
                }
                else {
                    final int integer17 = this.minecraft.level.getChunkSource().getLightEngine().getRawBrightness(fu7, 0);
                    final int integer18 = this.minecraft.level.getBrightness(LightLayer.SKY, fu7);
                    final int integer19 = this.minecraft.level.getBrightness(LightLayer.BLOCK, fu7);
                    list14.add("Client Light: " + integer17 + " (" + integer18 + " sky, " + integer19 + " block)");
                    final LevelChunk chj17 = this.getServerChunk();
                    if (chj17 != null) {
                        final LevelLightEngine cwr21 = bqb12.getChunkSource().getLightEngine();
                        list14.add("Server Light: (" + cwr21.getLayerListener(LightLayer.SKY).getLightValue(fu7) + " sky, " + cwr21.getLayerListener(LightLayer.BLOCK).getLightValue(fu7) + " block)");
                    }
                    else {
                        list14.add("Server Light: (?? sky, ?? block)");
                    }
                    final StringBuilder stringBuilder21 = new StringBuilder("CH");
                    for (final Heightmap.Types a25 : Heightmap.Types.values()) {
                        if (a25.sendToClient()) {
                            stringBuilder21.append(" ").append(DebugScreenOverlay.HEIGHTMAP_NAMES.get(a25)).append(": ").append(chj16.getHeight(a25, fu7.getX(), fu7.getZ()));
                        }
                    }
                    list14.add(stringBuilder21.toString());
                    stringBuilder21.setLength(0);
                    stringBuilder21.append("SH");
                    for (final Heightmap.Types a25 : Heightmap.Types.values()) {
                        if (a25.keepAfterWorldgen()) {
                            stringBuilder21.append(" ").append(DebugScreenOverlay.HEIGHTMAP_NAMES.get(a25)).append(": ");
                            if (chj17 != null) {
                                stringBuilder21.append(chj17.getHeight(a25, fu7.getX(), fu7.getZ()));
                            }
                            else {
                                stringBuilder21.append("??");
                            }
                        }
                    }
                    list14.add(stringBuilder21.toString());
                    if (fu7.getY() >= 0 && fu7.getY() < 256) {
                        list14.add("Biome: " + Registry.BIOME.getKey(this.minecraft.level.getBiome(fu7)));
                        long long22 = 0L;
                        float float7 = 0.0f;
                        if (chj17 != null) {
                            float7 = bqb12.getMoonBrightness();
                            long22 = chj17.getInhabitedTime();
                        }
                        final DifficultyInstance ane25 = new DifficultyInstance(bqb12.getDifficulty(), bqb12.getDayTime(), long22, float7);
                        list14.add(String.format(Locale.ROOT, "Local Difficulty: %.2f // %.2f (Day %d)", ane25.getEffectiveDifficulty(), ane25.getSpecialMultiplier(), this.minecraft.level.getDayTime() / 24000L));
                    }
                }
            }
            else {
                list14.add("Outside of world...");
            }
        }
        else {
            list14.add("Outside of world...");
        }
        final ServerLevel zd16 = this.getServerLevel();
        if (zd16 != null) {
            final NaturalSpawner.SpawnState d17 = zd16.getChunkSource().getLastSpawnState();
            if (d17 != null) {
                final Object2IntMap<MobCategory> object2IntMap18 = d17.getMobCategoryCounts();
                final int integer19 = d17.getSpawnableChunkCount();
                list14.add("SC: " + integer19 + ", " + Stream.<MobCategory>of(MobCategory.values()).map(apa -> Character.toUpperCase(apa.getName().charAt(0)) + ": " + object2IntMap18.getInt(apa)).collect(Collectors.joining(", ")));
            }
            else {
                list14.add("SC: N/A");
            }
        }
        final PostChain ecc17 = this.minecraft.gameRenderer.currentEffect();
        if (ecc17 != null) {
            list14.add("Shader: " + ecc17.getName());
        }
        list14.add(this.minecraft.getSoundManager().getDebugString() + String.format(" (Mood %d%%)", Math.round(this.minecraft.player.getCurrentMood() * 100.0f)));
        return list14;
    }
    
    @Nullable
    private ServerLevel getServerLevel() {
        final IntegratedServer eoz2 = this.minecraft.getSingleplayerServer();
        if (eoz2 != null) {
            return eoz2.getLevel(this.minecraft.level.dimension());
        }
        return null;
    }
    
    @Nullable
    private String getServerChunkStats() {
        final ServerLevel zd2 = this.getServerLevel();
        if (zd2 != null) {
            return zd2.gatherChunkSourceStats();
        }
        return null;
    }
    
    private Level getLevel() {
        return (Level)DataFixUtils.orElse((Optional)Optional.<IntegratedServer>ofNullable(this.minecraft.getSingleplayerServer()).flatMap(eoz -> Optional.<ServerLevel>ofNullable(eoz.getLevel(this.minecraft.level.dimension()))), this.minecraft.level);
    }
    
    @Nullable
    private LevelChunk getServerChunk() {
        if (this.serverChunk == null) {
            final ServerLevel zd2 = this.getServerLevel();
            if (zd2 != null) {
                this.serverChunk = zd2.getChunkSource().getChunkFuture(this.lastPos.x, this.lastPos.z, ChunkStatus.FULL, false).<LevelChunk>thenApply(either -> (LevelChunk)either.map(cgy -> cgy, a -> null));
            }
            if (this.serverChunk == null) {
                this.serverChunk = CompletableFuture.<LevelChunk>completedFuture(this.getClientChunk());
            }
        }
        return this.serverChunk.getNow(null);
    }
    
    private LevelChunk getClientChunk() {
        if (this.clientChunk == null) {
            this.clientChunk = this.minecraft.level.getChunk(this.lastPos.x, this.lastPos.z);
        }
        return this.clientChunk;
    }
    
    protected List<String> getSystemInformation() {
        final long long2 = Runtime.getRuntime().maxMemory();
        final long long3 = Runtime.getRuntime().totalMemory();
        final long long4 = Runtime.getRuntime().freeMemory();
        final long long5 = long3 - long4;
        final List<String> list10 = Lists.<String>newArrayList(String.format("Java: %s %dbit", System.getProperty("java.version"), this.minecraft.is64Bit() ? 64 : 32), String.format("Mem: % 2d%% %03d/%03dMB", long5 * 100L / long2, bytesToMegabytes(long5), bytesToMegabytes(long2)), String.format("Allocated: % 2d%% %03dMB", long3 * 100L / long2, bytesToMegabytes(long3)), "", String.format("CPU: %s", GlUtil.getCpuInfo()), "", String.format("Display: %dx%d (%s)", Minecraft.getInstance().getWindow().getWidth(), Minecraft.getInstance().getWindow().getHeight(), GlUtil.getVendor()), GlUtil.getRenderer(), GlUtil.getOpenGLVersion());
        if (this.minecraft.showOnlyReducedInfo()) {
            return list10;
        }
        if (this.block.getType() == HitResult.Type.BLOCK) {
            final BlockPos fu11 = ((BlockHitResult)this.block).getBlockPos();
            final BlockState cfj12 = this.minecraft.level.getBlockState(fu11);
            list10.add("");
            list10.add(ChatFormatting.UNDERLINE + "Targeted Block: " + fu11.getX() + ", " + fu11.getY() + ", " + fu11.getZ());
            list10.add(String.valueOf(Registry.BLOCK.getKey(cfj12.getBlock())));
            for (final Map.Entry<Property<?>, Comparable<?>> entry14 : cfj12.getValues().entrySet()) {
                list10.add(this.getPropertyValueString(entry14));
            }
            for (final ResourceLocation uh14 : this.minecraft.getConnection().getTags().getBlocks().getMatchingTags(cfj12.getBlock())) {
                list10.add("#" + uh14);
            }
        }
        if (this.liquid.getType() == HitResult.Type.BLOCK) {
            final BlockPos fu11 = ((BlockHitResult)this.liquid).getBlockPos();
            final FluidState cxa12 = this.minecraft.level.getFluidState(fu11);
            list10.add("");
            list10.add(ChatFormatting.UNDERLINE + "Targeted Fluid: " + fu11.getX() + ", " + fu11.getY() + ", " + fu11.getZ());
            list10.add(String.valueOf(Registry.FLUID.getKey(cxa12.getType())));
            for (final Map.Entry<Property<?>, Comparable<?>> entry14 : cxa12.getValues().entrySet()) {
                list10.add(this.getPropertyValueString(entry14));
            }
            for (final ResourceLocation uh14 : this.minecraft.getConnection().getTags().getFluids().getMatchingTags(cxa12.getType())) {
                list10.add("#" + uh14);
            }
        }
        final Entity aom11 = this.minecraft.crosshairPickEntity;
        if (aom11 != null) {
            list10.add("");
            list10.add(ChatFormatting.UNDERLINE + "Targeted Entity");
            list10.add(String.valueOf(Registry.ENTITY_TYPE.getKey(aom11.getType())));
        }
        return list10;
    }
    
    private String getPropertyValueString(final Map.Entry<Property<?>, Comparable<?>> entry) {
        final Property<?> cgl3 = entry.getKey();
        final Comparable<?> comparable4 = entry.getValue();
        String string5 = Util.getPropertyName(cgl3, comparable4);
        if (Boolean.TRUE.equals(comparable4)) {
            string5 = ChatFormatting.GREEN + string5;
        }
        else if (Boolean.FALSE.equals(comparable4)) {
            string5 = ChatFormatting.RED + string5;
        }
        return cgl3.getName() + ": " + string5;
    }
    
    private void drawChart(final PoseStack dhl, final FrameTimer ads, final int integer3, final int integer4, final boolean boolean5) {
        RenderSystem.disableDepthTest();
        final int integer5 = ads.getLogStart();
        final int integer6 = ads.getLogEnd();
        final long[] arr9 = ads.getLog();
        int integer7 = integer5;
        int integer8 = integer3;
        final int integer9 = Math.max(0, arr9.length - integer4);
        final int integer10 = arr9.length - integer9;
        integer7 = ads.wrapIndex(integer7 + integer9);
        long long14 = 0L;
        int integer11 = Integer.MAX_VALUE;
        int integer12 = Integer.MIN_VALUE;
        for (int integer13 = 0; integer13 < integer10; ++integer13) {
            final int integer14 = (int)(arr9[ads.wrapIndex(integer7 + integer13)] / 1000000L);
            integer11 = Math.min(integer11, integer14);
            integer12 = Math.max(integer12, integer14);
            long14 += integer14;
        }
        int integer13 = this.minecraft.getWindow().getGuiScaledHeight();
        GuiComponent.fill(dhl, integer3, integer13 - 60, integer3 + integer10, integer13, -1873784752);
        final BufferBuilder dhg19 = Tesselator.getInstance().getBuilder();
        RenderSystem.enableBlend();
        RenderSystem.disableTexture();
        RenderSystem.defaultBlendFunc();
        dhg19.begin(7, DefaultVertexFormat.POSITION_COLOR);
        final Matrix4f b20 = Transformation.identity().getMatrix();
        while (integer7 != integer6) {
            final int integer15 = ads.scaleSampleTo(arr9[integer7], boolean5 ? 30 : 60, boolean5 ? 60 : 20);
            final int integer16 = boolean5 ? 100 : 60;
            final int integer17 = this.getSampleColor(Mth.clamp(integer15, 0, integer16), 0, integer16 / 2, integer16);
            final int integer18 = integer17 >> 24 & 0xFF;
            final int integer19 = integer17 >> 16 & 0xFF;
            final int integer20 = integer17 >> 8 & 0xFF;
            final int integer21 = integer17 & 0xFF;
            dhg19.vertex(b20, (float)(integer8 + 1), (float)integer13, 0.0f).color(integer19, integer20, integer21, integer18).endVertex();
            dhg19.vertex(b20, (float)(integer8 + 1), (float)(integer13 - integer15 + 1), 0.0f).color(integer19, integer20, integer21, integer18).endVertex();
            dhg19.vertex(b20, (float)integer8, (float)(integer13 - integer15 + 1), 0.0f).color(integer19, integer20, integer21, integer18).endVertex();
            dhg19.vertex(b20, (float)integer8, (float)integer13, 0.0f).color(integer19, integer20, integer21, integer18).endVertex();
            ++integer8;
            integer7 = ads.wrapIndex(integer7 + 1);
        }
        dhg19.end();
        BufferUploader.end(dhg19);
        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
        if (boolean5) {
            GuiComponent.fill(dhl, integer3 + 1, integer13 - 30 + 1, integer3 + 14, integer13 - 30 + 10, -1873784752);
            this.font.draw(dhl, "60 FPS", (float)(integer3 + 2), (float)(integer13 - 30 + 2), 14737632);
            this.hLine(dhl, integer3, integer3 + integer10 - 1, integer13 - 30, -1);
            GuiComponent.fill(dhl, integer3 + 1, integer13 - 60 + 1, integer3 + 14, integer13 - 60 + 10, -1873784752);
            this.font.draw(dhl, "30 FPS", (float)(integer3 + 2), (float)(integer13 - 60 + 2), 14737632);
            this.hLine(dhl, integer3, integer3 + integer10 - 1, integer13 - 60, -1);
        }
        else {
            GuiComponent.fill(dhl, integer3 + 1, integer13 - 60 + 1, integer3 + 14, integer13 - 60 + 10, -1873784752);
            this.font.draw(dhl, "20 TPS", (float)(integer3 + 2), (float)(integer13 - 60 + 2), 14737632);
            this.hLine(dhl, integer3, integer3 + integer10 - 1, integer13 - 60, -1);
        }
        this.hLine(dhl, integer3, integer3 + integer10 - 1, integer13 - 1, -1);
        this.vLine(dhl, integer3, integer13 - 60, integer13, -1);
        this.vLine(dhl, integer3 + integer10 - 1, integer13 - 60, integer13, -1);
        if (boolean5 && this.minecraft.options.framerateLimit > 0 && this.minecraft.options.framerateLimit <= 250) {
            this.hLine(dhl, integer3, integer3 + integer10 - 1, integer13 - 1 - (int)(1800.0 / this.minecraft.options.framerateLimit), -16711681);
        }
        final String string21 = integer11 + " ms min";
        final String string22 = long14 / integer10 + " ms avg";
        final String string23 = integer12 + " ms max";
        final Font font = this.font;
        final String string24 = string21;
        final float float3 = (float)(integer3 + 2);
        final int n = integer13 - 60;
        this.font.getClass();
        font.drawShadow(dhl, string24, float3, (float)(n - 9), 14737632);
        final Font font2 = this.font;
        final String string25 = string22;
        final float float4 = (float)(integer3 + integer10 / 2 - this.font.width(string22) / 2);
        final int n2 = integer13 - 60;
        this.font.getClass();
        font2.drawShadow(dhl, string25, float4, (float)(n2 - 9), 14737632);
        final Font font3 = this.font;
        final String string26 = string23;
        final float float5 = (float)(integer3 + integer10 - this.font.width(string23));
        final int n3 = integer13 - 60;
        this.font.getClass();
        font3.drawShadow(dhl, string26, float5, (float)(n3 - 9), 14737632);
        RenderSystem.enableDepthTest();
    }
    
    private int getSampleColor(final int integer1, final int integer2, final int integer3, final int integer4) {
        if (integer1 < integer3) {
            return this.colorLerp(-16711936, -256, integer1 / (float)integer3);
        }
        return this.colorLerp(-256, -65536, (integer1 - integer3) / (float)(integer4 - integer3));
    }
    
    private int colorLerp(final int integer1, final int integer2, final float float3) {
        final int integer3 = integer1 >> 24 & 0xFF;
        final int integer4 = integer1 >> 16 & 0xFF;
        final int integer5 = integer1 >> 8 & 0xFF;
        final int integer6 = integer1 & 0xFF;
        final int integer7 = integer2 >> 24 & 0xFF;
        final int integer8 = integer2 >> 16 & 0xFF;
        final int integer9 = integer2 >> 8 & 0xFF;
        final int integer10 = integer2 & 0xFF;
        final int integer11 = Mth.clamp((int)Mth.lerp(float3, (float)integer3, (float)integer7), 0, 255);
        final int integer12 = Mth.clamp((int)Mth.lerp(float3, (float)integer4, (float)integer8), 0, 255);
        final int integer13 = Mth.clamp((int)Mth.lerp(float3, (float)integer5, (float)integer9), 0, 255);
        final int integer14 = Mth.clamp((int)Mth.lerp(float3, (float)integer6, (float)integer10), 0, 255);
        return integer11 << 24 | integer12 << 16 | integer13 << 8 | integer14;
    }
    
    private static long bytesToMegabytes(final long long1) {
        return long1 / 1024L / 1024L;
    }
    
    static {
        HEIGHTMAP_NAMES = Util.<EnumMap<Heightmap.Types, String>>make(new EnumMap<Heightmap.Types, String>(Heightmap.Types.class), enumMap -> {
            enumMap.put(Heightmap.Types.WORLD_SURFACE_WG, "SW");
            enumMap.put(Heightmap.Types.WORLD_SURFACE, "S");
            enumMap.put(Heightmap.Types.OCEAN_FLOOR_WG, "OW");
            enumMap.put(Heightmap.Types.OCEAN_FLOOR, "O");
            enumMap.put(Heightmap.Types.MOTION_BLOCKING, "M");
            enumMap.put(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, "ML");
        });
    }
}
