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 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 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.network.Connection;
import net.minecraft.world.phys.BlockHitResult;
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 net.minecraft.world.level.dimension.DimensionType;
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 net.minecraft.core.BlockPos;
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 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 dbn) {
        this.minecraft = dbn;
        this.font = dbn.font;
    }
    
    public void clearChunkCache() {
        this.serverChunk = null;
        this.clientChunk = null;
    }
    
    public void render() {
        this.minecraft.getProfiler().push("debug");
        RenderSystem.pushMatrix();
        final Entity akq2 = this.minecraft.getCameraEntity();
        this.block = akq2.pick(20.0, 0.0f, false);
        this.liquid = akq2.pick(20.0, 0.0f, true);
        this.drawGameInformation();
        this.drawSystemInformation();
        RenderSystem.popMatrix();
        if (this.minecraft.options.renderFpsChart) {
            final int integer3 = this.minecraft.getWindow().getGuiScaledWidth();
            this.drawChart(this.minecraft.getFrameTimer(), 0, integer3 / 2, true);
            final IntegratedServer edm4 = this.minecraft.getSingleplayerServer();
            if (edm4 != null) {
                this.drawChart(edm4.getFrameTimer(), integer3 - Math.min(integer3 / 2, 240), integer3 / 2, false);
            }
        }
        this.minecraft.getProfiler().pop();
    }
    
    protected void drawGameInformation() {
        final List<String> list2 = this.getGameInformation();
        list2.add("");
        final boolean boolean3 = this.minecraft.getSingleplayerServer() != null;
        list2.add("Debug: Pie [shift]: " + (this.minecraft.options.renderDebugCharts ? "visible" : "hidden") + (boolean3 ? " FPS + TPS" : " FPS") + " [alt]: " + (this.minecraft.options.renderFpsChart ? "visible" : "hidden"));
        list2.add("For help: press F3 + Q");
        for (int integer4 = 0; integer4 < list2.size(); ++integer4) {
            final String string5 = list2.get(integer4);
            if (!Strings.isNullOrEmpty(string5)) {
                this.font.getClass();
                final int integer5 = 9;
                final int integer6 = this.font.width(string5);
                final int integer7 = 2;
                final int integer8 = 2 + integer5 * integer4;
                GuiComponent.fill(1, integer8 - 1, 2 + integer6 + 1, integer8 + integer5 - 1, -1873784752);
                this.font.draw(string5, 2.0f, (float)integer8, 14737632);
            }
        }
    }
    
    protected void drawSystemInformation() {
        final List<String> list2 = this.getSystemInformation();
        for (int integer3 = 0; integer3 < list2.size(); ++integer3) {
            final String string4 = list2.get(integer3);
            if (!Strings.isNullOrEmpty(string4)) {
                this.font.getClass();
                final int integer4 = 9;
                final int integer5 = this.font.width(string4);
                final int integer6 = this.minecraft.getWindow().getGuiScaledWidth() - 2 - integer5;
                final int integer7 = 2 + integer4 * integer3;
                GuiComponent.fill(integer6 - 1, integer7 - 1, integer6 + integer5 + 1, integer7 + integer4 - 1, -1873784752);
                this.font.draw(string4, (float)integer6, (float)integer7, 14737632);
            }
        }
    }
    
    protected List<String> getGameInformation() {
        final IntegratedServer edm3 = this.minecraft.getSingleplayerServer();
        final Connection kt4 = this.minecraft.getConnection().getConnection();
        final float float5 = kt4.getAverageSentPackets();
        final float float6 = kt4.getAverageReceivedPackets();
        String string2;
        if (edm3 != null) {
            string2 = String.format("Integrated server @ %.0f ms ticks, %.0f tx, %.0f rx", edm3.getAverageTickTime(), float5, float6);
        }
        else {
            string2 = String.format("\"%s\" server, %.0f tx, %.0f rx", this.minecraft.player.getServerBrand(), float5, float6);
        }
        final BlockPos fk7 = new BlockPos(this.minecraft.getCameraEntity());
        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", fk7.getX() & 0xF, fk7.getY() & 0xF, fk7.getZ() & 0xF));
        }
        final Entity akq8 = this.minecraft.getCameraEntity();
        final Direction fp9 = akq8.getDirection();
        String string3 = null;
        switch (fp9) {
            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 bjh11 = new ChunkPos(fk7);
        if (!Objects.equals(this.lastPos, bjh11)) {
            this.lastPos = bjh11;
            this.clearChunkCache();
        }
        final Level bjw12 = this.getLevel();
        final LongSet longSet13 = (bjw12 instanceof ServerLevel) ? ((ServerLevel)bjw12).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(DimensionType.getName(this.minecraft.level.dimension.getType()).toString() + " FC: " + Integer.toString(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", fk7.getX(), fk7.getY(), fk7.getZ()));
        list14.add(String.format("Chunk: %d %d %d in %d %d %d", fk7.getX() & 0xF, fk7.getY() & 0xF, fk7.getZ() & 0xF, fk7.getX() >> 4, fk7.getY() >> 4, fk7.getZ() >> 4));
        list14.add(String.format(Locale.ROOT, "Facing: %s (%s) (%.1f / %.1f)", fp9, string3, Mth.wrapDegrees(akq8.yRot), Mth.wrapDegrees(akq8.xRot)));
        if (this.minecraft.level != null) {
            if (this.minecraft.level.hasChunkAt(fk7)) {
                final LevelChunk cal16 = this.getClientChunk();
                if (cal16.isEmpty()) {
                    list14.add("Waiting for chunk...");
                }
                else {
                    final int integer17 = this.minecraft.level.getChunkSource().getLightEngine().getRawBrightness(fk7, 0);
                    final int integer18 = this.minecraft.level.getBrightness(LightLayer.SKY, fk7);
                    final int integer19 = this.minecraft.level.getBrightness(LightLayer.BLOCK, fk7);
                    list14.add("Client Light: " + integer17 + " (" + integer18 + " sky, " + integer19 + " block)");
                    final LevelChunk cal17 = this.getServerChunk();
                    if (cal17 != null) {
                        final LevelLightEngine coa21 = bjw12.getChunkSource().getLightEngine();
                        list14.add("Server Light: (" + coa21.getLayerListener(LightLayer.SKY).getLightValue(fk7) + " sky, " + coa21.getLayerListener(LightLayer.BLOCK).getLightValue(fk7) + " 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(cal16.getHeight(a25, fk7.getX(), fk7.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 (cal17 != null) {
                                stringBuilder21.append(cal17.getHeight(a25, fk7.getX(), fk7.getZ()));
                            }
                            else {
                                stringBuilder21.append("??");
                            }
                        }
                    }
                    list14.add(stringBuilder21.toString());
                    if (fk7.getY() >= 0 && fk7.getY() < 256) {
                        list14.add("Biome: " + Registry.BIOME.getKey(this.minecraft.level.getBiome(fk7)));
                        long long22 = 0L;
                        float float7 = 0.0f;
                        if (cal17 != null) {
                            float7 = bjw12.getMoonBrightness();
                            long22 = cal17.getInhabitedTime();
                        }
                        final DifficultyInstance ajj25 = new DifficultyInstance(bjw12.getDifficulty(), bjw12.getDayTime(), long22, float7);
                        list14.add(String.format(Locale.ROOT, "Local Difficulty: %.2f // %.2f (Day %d)", ajj25.getEffectiveDifficulty(), ajj25.getSpecialMultiplier(), this.minecraft.level.getDayTime() / 24000L));
                    }
                }
            }
            else {
                list14.add("Outside of world...");
            }
        }
        else {
            list14.add("Outside of world...");
        }
        final PostChain dqw16 = this.minecraft.gameRenderer.currentEffect();
        if (dqw16 != null) {
            list14.add("Shader: " + dqw16.getName());
        }
        if (this.block.getType() == HitResult.Type.BLOCK) {
            final BlockPos fk8 = ((BlockHitResult)this.block).getBlockPos();
            list14.add(String.format("Looking at block: %d %d %d", fk8.getX(), fk8.getY(), fk8.getZ()));
        }
        if (this.liquid.getType() == HitResult.Type.BLOCK) {
            final BlockPos fk8 = ((BlockHitResult)this.liquid).getBlockPos();
            list14.add(String.format("Looking at liquid: %d %d %d", fk8.getX(), fk8.getY(), fk8.getZ()));
        }
        list14.add(this.minecraft.getSoundManager().getDebugString());
        return list14;
    }
    
    @Nullable
    private String getServerChunkStats() {
        final IntegratedServer edm2 = this.minecraft.getSingleplayerServer();
        if (edm2 != null) {
            final ServerLevel xd3 = edm2.getLevel(this.minecraft.level.getDimension().getType());
            if (xd3 != null) {
                return xd3.gatherChunkSourceStats();
            }
        }
        return null;
    }
    
    private Level getLevel() {
        return (Level)DataFixUtils.orElse((Optional)Optional.<IntegratedServer>ofNullable(this.minecraft.getSingleplayerServer()).map(edm -> edm.getLevel(this.minecraft.level.dimension.getType())), this.minecraft.level);
    }
    
    @Nullable
    private LevelChunk getServerChunk() {
        if (this.serverChunk == null) {
            final IntegratedServer edm2 = this.minecraft.getSingleplayerServer();
            if (edm2 != null) {
                final ServerLevel xd3 = edm2.getLevel(this.minecraft.level.dimension.getType());
                if (xd3 != null) {
                    this.serverChunk = xd3.getChunkSource().getChunkFuture(this.lastPos.x, this.lastPos.z, ChunkStatus.FULL, false).<LevelChunk>thenApply(either -> (LevelChunk)either.map(bzy -> bzy, 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 fk11 = ((BlockHitResult)this.block).getBlockPos();
            final BlockState byj12 = this.minecraft.level.getBlockState(fk11);
            list10.add("");
            list10.add(ChatFormatting.UNDERLINE + "Targeted Block");
            list10.add(String.valueOf(Registry.BLOCK.getKey(byj12.getBlock())));
            for (final Map.Entry<Property<?>, Comparable<?>> entry14 : byj12.getValues().entrySet()) {
                list10.add(this.getPropertyValueString(entry14));
            }
            for (final ResourceLocation sm14 : this.minecraft.getConnection().getTags().getBlocks().getMatchingTags(byj12.getBlock())) {
                list10.add("#" + sm14);
            }
        }
        if (this.liquid.getType() == HitResult.Type.BLOCK) {
            final BlockPos fk11 = ((BlockHitResult)this.liquid).getBlockPos();
            final FluidState coj12 = this.minecraft.level.getFluidState(fk11);
            list10.add("");
            list10.add(ChatFormatting.UNDERLINE + "Targeted Fluid");
            list10.add(String.valueOf(Registry.FLUID.getKey(coj12.getType())));
            for (final Map.Entry<Property<?>, Comparable<?>> entry14 : coj12.getValues().entrySet()) {
                list10.add(this.getPropertyValueString(entry14));
            }
            for (final ResourceLocation sm14 : this.minecraft.getConnection().getTags().getFluids().getMatchingTags(coj12.getType())) {
                list10.add("#" + sm14);
            }
        }
        final Entity akq11 = this.minecraft.crosshairPickEntity;
        if (akq11 != null) {
            list10.add("");
            list10.add(ChatFormatting.UNDERLINE + "Targeted Entity");
            list10.add(String.valueOf(Registry.ENTITY_TYPE.getKey(akq11.getType())));
        }
        return list10;
    }
    
    private String getPropertyValueString(final Map.Entry<Property<?>, Comparable<?>> entry) {
        final Property<?> bzm3 = entry.getKey();
        final Comparable<?> comparable4 = entry.getValue();
        String string5 = Util.getPropertyName(bzm3, comparable4);
        if (Boolean.TRUE.equals(comparable4)) {
            string5 = ChatFormatting.GREEN + string5;
        }
        else if (Boolean.FALSE.equals(comparable4)) {
            string5 = ChatFormatting.RED + string5;
        }
        return bzm3.getName() + ": " + string5;
    }
    
    private void drawChart(final FrameTimer abj, final int integer2, final int integer3, final boolean boolean4) {
        RenderSystem.disableDepthTest();
        final int integer4 = abj.getLogStart();
        final int integer5 = abj.getLogEnd();
        final long[] arr8 = abj.getLog();
        int integer6 = integer4;
        int integer7 = integer2;
        final int integer8 = Math.max(0, arr8.length - integer3);
        final int integer9 = arr8.length - integer8;
        integer6 = abj.wrapIndex(integer6 + integer8);
        long long13 = 0L;
        int integer10 = Integer.MAX_VALUE;
        int integer11 = Integer.MIN_VALUE;
        for (int integer12 = 0; integer12 < integer9; ++integer12) {
            final int integer13 = (int)(arr8[abj.wrapIndex(integer6 + integer12)] / 1000000L);
            integer10 = Math.min(integer10, integer13);
            integer11 = Math.max(integer11, integer13);
            long13 += integer13;
        }
        int integer12 = this.minecraft.getWindow().getGuiScaledHeight();
        GuiComponent.fill(integer2, integer12 - 60, integer2 + integer9, integer12, -1873784752);
        final BufferBuilder cyg18 = Tesselator.getInstance().getBuilder();
        RenderSystem.enableBlend();
        RenderSystem.disableTexture();
        RenderSystem.defaultBlendFunc();
        cyg18.begin(7, DefaultVertexFormat.POSITION_COLOR);
        final Matrix4f b19 = Transformation.identity().getMatrix();
        while (integer6 != integer5) {
            final int integer14 = abj.scaleSampleTo(arr8[integer6], boolean4 ? 30 : 60, boolean4 ? 60 : 20);
            final int integer15 = boolean4 ? 100 : 60;
            final int integer16 = this.getSampleColor(Mth.clamp(integer14, 0, integer15), 0, integer15 / 2, integer15);
            final int integer17 = integer16 >> 24 & 0xFF;
            final int integer18 = integer16 >> 16 & 0xFF;
            final int integer19 = integer16 >> 8 & 0xFF;
            final int integer20 = integer16 & 0xFF;
            cyg18.vertex(b19, (float)(integer7 + 1), (float)integer12, 0.0f).color(integer18, integer19, integer20, integer17).endVertex();
            cyg18.vertex(b19, (float)integer7, (float)integer12, 0.0f).color(integer18, integer19, integer20, integer17).endVertex();
            cyg18.vertex(b19, (float)integer7, (float)(integer12 - integer14 + 1), 0.0f).color(integer18, integer19, integer20, integer17).endVertex();
            cyg18.vertex(b19, (float)(integer7 + 1), (float)(integer12 - integer14 + 1), 0.0f).color(integer18, integer19, integer20, integer17).endVertex();
            ++integer7;
            integer6 = abj.wrapIndex(integer6 + 1);
        }
        cyg18.end();
        BufferUploader.end(cyg18);
        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
        if (boolean4) {
            GuiComponent.fill(integer2 + 1, integer12 - 30 + 1, integer2 + 14, integer12 - 30 + 10, -1873784752);
            this.font.draw("60 FPS", (float)(integer2 + 2), (float)(integer12 - 30 + 2), 14737632);
            this.hLine(integer2, integer2 + integer9 - 1, integer12 - 30, -1);
            GuiComponent.fill(integer2 + 1, integer12 - 60 + 1, integer2 + 14, integer12 - 60 + 10, -1873784752);
            this.font.draw("30 FPS", (float)(integer2 + 2), (float)(integer12 - 60 + 2), 14737632);
            this.hLine(integer2, integer2 + integer9 - 1, integer12 - 60, -1);
        }
        else {
            GuiComponent.fill(integer2 + 1, integer12 - 60 + 1, integer2 + 14, integer12 - 60 + 10, -1873784752);
            this.font.draw("20 TPS", (float)(integer2 + 2), (float)(integer12 - 60 + 2), 14737632);
            this.hLine(integer2, integer2 + integer9 - 1, integer12 - 60, -1);
        }
        this.hLine(integer2, integer2 + integer9 - 1, integer12 - 1, -1);
        this.vLine(integer2, integer12 - 60, integer12, -1);
        this.vLine(integer2 + integer9 - 1, integer12 - 60, integer12, -1);
        if (boolean4 && this.minecraft.options.framerateLimit > 0 && this.minecraft.options.framerateLimit <= 250) {
            this.hLine(integer2, integer2 + integer9 - 1, integer12 - 1 - (int)(1800.0 / this.minecraft.options.framerateLimit), -16711681);
        }
        final String string20 = integer10 + " ms min";
        final String string21 = long13 / integer9 + " ms avg";
        final String string22 = integer11 + " ms max";
        final Font font = this.font;
        final String string23 = string20;
        final float float2 = (float)(integer2 + 2);
        final int n = integer12 - 60;
        this.font.getClass();
        font.drawShadow(string23, float2, (float)(n - 9), 14737632);
        final Font font2 = this.font;
        final String string24 = string21;
        final float float3 = (float)(integer2 + integer9 / 2 - this.font.width(string21) / 2);
        final int n2 = integer12 - 60;
        this.font.getClass();
        font2.drawShadow(string24, float3, (float)(n2 - 9), 14737632);
        final Font font3 = this.font;
        final String string25 = string22;
        final float float4 = (float)(integer2 + integer9 - this.font.width(string22));
        final int n3 = integer12 - 60;
        this.font.getClass();
        font3.drawShadow(string25, float4, (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");
        });
    }
}
