package net.minecraft.client.renderer;

import org.apache.logging.log4j.LogManager;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.item.BoneMealItem;
import net.minecraft.world.level.block.Block;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.client.particle.Particle;
import net.minecraft.ReportedException;
import net.minecraft.CrashReportCategory;
import net.minecraft.core.Registry;
import net.minecraft.CrashReport;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.RecordItem;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.border.WorldBorder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.math.Vector3f;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import java.util.Iterator;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import com.mojang.blaze3d.vertex.VertexMultiConsumer;
import com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.LivingEntity;
import com.mojang.blaze3d.platform.Lighting;
import net.minecraft.client.Option;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import java.util.List;
import java.util.Queue;
import java.util.Collection;
import java.util.Comparator;
import net.minecraft.core.Vec3i;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
import net.minecraft.world.entity.Entity;
import net.minecraft.Util;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.Options;
import net.minecraft.client.GraphicsStatus;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.LevelReader;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.tags.Tag;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.client.ParticleStatus;
import net.minecraft.client.Camera;
import com.mojang.blaze3d.vertex.BufferBuilder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.BlockAndTintGetter;
import java.util.Random;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.biome.Biome;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.Tesselator;
import net.minecraft.util.Mth;
import com.google.common.collect.Maps;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import com.google.common.collect.Sets;
import com.mojang.math.Vector3d;
import com.mojang.math.Vector4f;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.CloudStatus;
import net.minecraft.world.phys.Vec3;
import com.mojang.blaze3d.pipeline.RenderTarget;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.core.BlockPos;
import java.util.Map;
import java.util.SortedSet;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.minecraft.server.level.BlockDestructionProgress;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import javax.annotation.Nullable;
import com.mojang.blaze3d.vertex.VertexBuffer;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.world.level.block.entity.BlockEntity;
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import java.util.Set;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.Logger;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;

public class LevelRenderer implements ResourceManagerReloadListener, AutoCloseable {
    private static final Logger LOGGER;
    private static final ResourceLocation MOON_LOCATION;
    private static final ResourceLocation SUN_LOCATION;
    private static final ResourceLocation CLOUDS_LOCATION;
    private static final ResourceLocation END_SKY_LOCATION;
    private static final ResourceLocation FORCEFIELD_LOCATION;
    private static final ResourceLocation RAIN_LOCATION;
    private static final ResourceLocation SNOW_LOCATION;
    public static final Direction[] DIRECTIONS;
    private final Minecraft minecraft;
    private final TextureManager textureManager;
    private final EntityRenderDispatcher entityRenderDispatcher;
    private final RenderBuffers renderBuffers;
    private ClientLevel level;
    private Set<ChunkRenderDispatcher.RenderChunk> chunksToCompile;
    private final ObjectList<RenderChunkInfo> renderChunks;
    private final Set<BlockEntity> globalBlockEntities;
    private ViewArea viewArea;
    private final VertexFormat skyFormat;
    @Nullable
    private VertexBuffer starBuffer;
    @Nullable
    private VertexBuffer skyBuffer;
    @Nullable
    private VertexBuffer darkBuffer;
    private boolean generateClouds;
    @Nullable
    private VertexBuffer cloudBuffer;
    private final RunningTrimmedMean frameTimes;
    private int ticks;
    private final Int2ObjectMap<BlockDestructionProgress> destroyingBlocks;
    private final Long2ObjectMap<SortedSet<BlockDestructionProgress>> destructionProgress;
    private final Map<BlockPos, SoundInstance> playingRecords;
    @Nullable
    private RenderTarget entityTarget;
    @Nullable
    private PostChain entityEffect;
    @Nullable
    private RenderTarget translucentTarget;
    @Nullable
    private RenderTarget itemEntityTarget;
    @Nullable
    private RenderTarget particlesTarget;
    @Nullable
    private RenderTarget weatherTarget;
    @Nullable
    private RenderTarget cloudsTarget;
    @Nullable
    private PostChain transparencyChain;
    private double lastCameraX;
    private double lastCameraY;
    private double lastCameraZ;
    private int lastCameraChunkX;
    private int lastCameraChunkY;
    private int lastCameraChunkZ;
    private double prevCamX;
    private double prevCamY;
    private double prevCamZ;
    private double prevCamRotX;
    private double prevCamRotY;
    private int prevCloudX;
    private int prevCloudY;
    private int prevCloudZ;
    private Vec3 prevCloudColor;
    private CloudStatus prevCloudsType;
    private ChunkRenderDispatcher chunkRenderDispatcher;
    private final VertexFormat format;
    private int lastViewDistance;
    private int renderedEntities;
    private int culledEntities;
    private boolean captureFrustum;
    @Nullable
    private Frustum capturedFrustum;
    private final Vector4f[] frustumPoints;
    private final Vector3d frustumPos;
    private double xTransparentOld;
    private double yTransparentOld;
    private double zTransparentOld;
    private boolean needsUpdate;
    private int frameId;
    private int rainSoundTime;
    private final float[] rainSizeX;
    private final float[] rainSizeZ;
    
    public LevelRenderer(final Minecraft dlx, final RenderBuffers ecf) {
        this.chunksToCompile = Sets.newLinkedHashSet();
        this.renderChunks = (ObjectList<RenderChunkInfo>)new ObjectArrayList(69696);
        this.globalBlockEntities = Sets.newHashSet();
        this.skyFormat = DefaultVertexFormat.POSITION;
        this.generateClouds = true;
        this.frameTimes = new RunningTrimmedMean(100);
        this.destroyingBlocks = (Int2ObjectMap<BlockDestructionProgress>)new Int2ObjectOpenHashMap();
        this.destructionProgress = (Long2ObjectMap<SortedSet<BlockDestructionProgress>>)new Long2ObjectOpenHashMap();
        this.playingRecords = Maps.newHashMap();
        this.lastCameraX = Double.MIN_VALUE;
        this.lastCameraY = Double.MIN_VALUE;
        this.lastCameraZ = Double.MIN_VALUE;
        this.lastCameraChunkX = Integer.MIN_VALUE;
        this.lastCameraChunkY = Integer.MIN_VALUE;
        this.lastCameraChunkZ = Integer.MIN_VALUE;
        this.prevCamX = Double.MIN_VALUE;
        this.prevCamY = Double.MIN_VALUE;
        this.prevCamZ = Double.MIN_VALUE;
        this.prevCamRotX = Double.MIN_VALUE;
        this.prevCamRotY = Double.MIN_VALUE;
        this.prevCloudX = Integer.MIN_VALUE;
        this.prevCloudY = Integer.MIN_VALUE;
        this.prevCloudZ = Integer.MIN_VALUE;
        this.prevCloudColor = Vec3.ZERO;
        this.format = DefaultVertexFormat.BLOCK;
        this.lastViewDistance = -1;
        this.frustumPoints = new Vector4f[8];
        this.frustumPos = new Vector3d(0.0, 0.0, 0.0);
        this.needsUpdate = true;
        this.rainSizeX = new float[1024];
        this.rainSizeZ = new float[1024];
        this.minecraft = dlx;
        this.entityRenderDispatcher = dlx.getEntityRenderDispatcher();
        this.renderBuffers = ecf;
        this.textureManager = dlx.getTextureManager();
        for (int integer4 = 0; integer4 < 32; ++integer4) {
            for (int integer5 = 0; integer5 < 32; ++integer5) {
                final float float6 = (float)(integer5 - 16);
                final float float7 = (float)(integer4 - 16);
                final float float8 = Mth.sqrt(float6 * float6 + float7 * float7);
                this.rainSizeX[integer4 << 5 | integer5] = -float7 / float8;
                this.rainSizeZ[integer4 << 5 | integer5] = float6 / float8;
            }
        }
        this.createStars();
        this.createLightSky();
        this.createDarkSky();
    }
    
    private void renderSnowAndRain(final LightTexture eby, final float float2, final double double3, final double double4, final double double5) {
        final float float3 = this.minecraft.level.getRainLevel(float2);
        if (float3 <= 0.0f) {
            return;
        }
        eby.turnOnLightLayer();
        final Level bqb11 = this.minecraft.level;
        final int integer12 = Mth.floor(double3);
        final int integer13 = Mth.floor(double4);
        final int integer14 = Mth.floor(double5);
        final Tesselator dhn15 = Tesselator.getInstance();
        final BufferBuilder dhg16 = dhn15.getBuilder();
        RenderSystem.enableAlphaTest();
        RenderSystem.disableCull();
        RenderSystem.normal3f(0.0f, 1.0f, 0.0f);
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.defaultAlphaFunc();
        RenderSystem.enableDepthTest();
        int integer15 = 5;
        if (Minecraft.useFancyGraphics()) {
            integer15 = 10;
        }
        RenderSystem.depthMask(Minecraft.useShaderTransparency());
        int integer16 = -1;
        final float float4 = this.ticks + float2;
        RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
        final BlockPos.MutableBlockPos a20 = new BlockPos.MutableBlockPos();
        for (int integer17 = integer14 - integer15; integer17 <= integer14 + integer15; ++integer17) {
            for (int integer18 = integer12 - integer15; integer18 <= integer12 + integer15; ++integer18) {
                final int integer19 = (integer17 - integer14 + 16) * 32 + integer18 - integer12 + 16;
                final double double6 = this.rainSizeX[integer19] * 0.5;
                final double double7 = this.rainSizeZ[integer19] * 0.5;
                a20.set(integer18, 0, integer17);
                final Biome bre28 = bqb11.getBiome(a20);
                if (bre28.getPrecipitation() != Biome.Precipitation.NONE) {
                    final int integer20 = bqb11.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, a20).getY();
                    int integer21 = integer13 - integer15;
                    int integer22 = integer13 + integer15;
                    if (integer21 < integer20) {
                        integer21 = integer20;
                    }
                    if (integer22 < integer20) {
                        integer22 = integer20;
                    }
                    int integer23 = integer20;
                    if (integer23 < integer13) {
                        integer23 = integer13;
                    }
                    if (integer21 != integer22) {
                        final Random random33 = new Random(integer18 * integer18 * 3121 + integer18 * 45238971 ^ integer17 * integer17 * 418711 + integer17 * 13761);
                        a20.set(integer18, integer21, integer17);
                        final float float5 = bre28.getTemperature(a20);
                        if (float5 >= 0.15f) {
                            if (integer16 != 0) {
                                if (integer16 >= 0) {
                                    dhn15.end();
                                }
                                integer16 = 0;
                                this.minecraft.getTextureManager().bind(LevelRenderer.RAIN_LOCATION);
                                dhg16.begin(7, DefaultVertexFormat.PARTICLE);
                            }
                            final int integer24 = this.ticks + integer18 * integer18 * 3121 + integer18 * 45238971 + integer17 * integer17 * 418711 + integer17 * 13761 & 0x1F;
                            final float float6 = -(integer24 + float2) / 32.0f * (3.0f + random33.nextFloat());
                            final double double8 = integer18 + 0.5f - double3;
                            final double double9 = integer17 + 0.5f - double5;
                            final float float7 = Mth.sqrt(double8 * double8 + double9 * double9) / integer15;
                            final float float8 = ((1.0f - float7 * float7) * 0.5f + 0.5f) * float3;
                            a20.set(integer18, integer23, integer17);
                            final int integer25 = getLightColor(bqb11, a20);
                            dhg16.vertex(integer18 - double3 - double6 + 0.5, integer22 - double4, integer17 - double5 - double7 + 0.5).uv(0.0f, integer21 * 0.25f + float6).color(1.0f, 1.0f, 1.0f, float8).uv2(integer25).endVertex();
                            dhg16.vertex(integer18 - double3 + double6 + 0.5, integer22 - double4, integer17 - double5 + double7 + 0.5).uv(1.0f, integer21 * 0.25f + float6).color(1.0f, 1.0f, 1.0f, float8).uv2(integer25).endVertex();
                            dhg16.vertex(integer18 - double3 + double6 + 0.5, integer21 - double4, integer17 - double5 + double7 + 0.5).uv(1.0f, integer22 * 0.25f + float6).color(1.0f, 1.0f, 1.0f, float8).uv2(integer25).endVertex();
                            dhg16.vertex(integer18 - double3 - double6 + 0.5, integer21 - double4, integer17 - double5 - double7 + 0.5).uv(0.0f, integer22 * 0.25f + float6).color(1.0f, 1.0f, 1.0f, float8).uv2(integer25).endVertex();
                        }
                        else {
                            if (integer16 != 1) {
                                if (integer16 >= 0) {
                                    dhn15.end();
                                }
                                integer16 = 1;
                                this.minecraft.getTextureManager().bind(LevelRenderer.SNOW_LOCATION);
                                dhg16.begin(7, DefaultVertexFormat.PARTICLE);
                            }
                            final float float9 = -((this.ticks & 0x1FF) + float2) / 512.0f;
                            final float float6 = (float)(random33.nextDouble() + float4 * 0.01 * (float)random33.nextGaussian());
                            final float float10 = (float)(random33.nextDouble() + float4 * (float)random33.nextGaussian() * 0.001);
                            final double double10 = integer18 + 0.5f - double3;
                            final double double11 = integer17 + 0.5f - double5;
                            final float float8 = Mth.sqrt(double10 * double10 + double11 * double11) / integer15;
                            final float float11 = ((1.0f - float8 * float8) * 0.3f + 0.5f) * float3;
                            a20.set(integer18, integer23, integer17);
                            final int integer26 = getLightColor(bqb11, a20);
                            final int integer27 = integer26 >> 16 & 0xFFFF;
                            final int integer28 = (integer26 & 0xFFFF) * 3;
                            final int integer29 = (integer27 * 3 + 240) / 4;
                            final int integer30 = (integer28 * 3 + 240) / 4;
                            dhg16.vertex(integer18 - double3 - double6 + 0.5, integer22 - double4, integer17 - double5 - double7 + 0.5).uv(0.0f + float6, integer21 * 0.25f + float9 + float10).color(1.0f, 1.0f, 1.0f, float11).uv2(integer30, integer29).endVertex();
                            dhg16.vertex(integer18 - double3 + double6 + 0.5, integer22 - double4, integer17 - double5 + double7 + 0.5).uv(1.0f + float6, integer21 * 0.25f + float9 + float10).color(1.0f, 1.0f, 1.0f, float11).uv2(integer30, integer29).endVertex();
                            dhg16.vertex(integer18 - double3 + double6 + 0.5, integer21 - double4, integer17 - double5 + double7 + 0.5).uv(1.0f + float6, integer22 * 0.25f + float9 + float10).color(1.0f, 1.0f, 1.0f, float11).uv2(integer30, integer29).endVertex();
                            dhg16.vertex(integer18 - double3 - double6 + 0.5, integer21 - double4, integer17 - double5 - double7 + 0.5).uv(0.0f + float6, integer22 * 0.25f + float9 + float10).color(1.0f, 1.0f, 1.0f, float11).uv2(integer30, integer29).endVertex();
                        }
                    }
                }
            }
        }
        if (integer16 >= 0) {
            dhn15.end();
        }
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
        RenderSystem.defaultAlphaFunc();
        RenderSystem.disableAlphaTest();
        eby.turnOffLightLayer();
    }
    
    public void tickRain(final Camera dlj) {
        final float float3 = this.minecraft.level.getRainLevel(1.0f) / (Minecraft.useFancyGraphics() ? 1.0f : 2.0f);
        if (float3 <= 0.0f) {
            return;
        }
        final Random random4 = new Random(this.ticks * 312987231L);
        final LevelReader bqd5 = this.minecraft.level;
        final BlockPos fu6 = new BlockPos(dlj.getPosition());
        BlockPos fu7 = null;
        for (int integer8 = (int)(100.0f * float3 * float3) / ((this.minecraft.options.particles == ParticleStatus.DECREASED) ? 2 : 1), integer9 = 0; integer9 < integer8; ++integer9) {
            final int integer10 = random4.nextInt(21) - 10;
            final int integer11 = random4.nextInt(21) - 10;
            final BlockPos fu8 = bqd5.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, fu6.offset(integer10, 0, integer11)).below();
            final Biome bre13 = bqd5.getBiome(fu8);
            if (fu8.getY() > 0 && fu8.getY() <= fu6.getY() + 10 && fu8.getY() >= fu6.getY() - 10 && bre13.getPrecipitation() == Biome.Precipitation.RAIN && bre13.getTemperature(fu8) >= 0.15f) {
                fu7 = fu8;
                if (this.minecraft.options.particles == ParticleStatus.MINIMAL) {
                    break;
                }
                final double double14 = random4.nextDouble();
                final double double15 = random4.nextDouble();
                final BlockState cfj18 = bqd5.getBlockState(fu7);
                final FluidState cxa19 = bqd5.getFluidState(fu7);
                final VoxelShape dfg20 = cfj18.getCollisionShape(bqd5, fu7);
                final double double16 = dfg20.max(Direction.Axis.Y, double14, double15);
                final double double17 = cxa19.getHeight(bqd5, fu7);
                final double double18 = Math.max(double16, double17);
                final ParticleOptions hf27 = (cxa19.is(FluidTags.LAVA) || cfj18.is(Blocks.MAGMA_BLOCK) || CampfireBlock.isLitCampfire(cfj18)) ? ParticleTypes.SMOKE : ParticleTypes.RAIN;
                this.minecraft.level.addParticle(hf27, fu7.getX() + double14, fu7.getY() + double18, fu7.getZ() + double15, 0.0, 0.0, 0.0);
            }
        }
        if (fu7 != null && random4.nextInt(3) < this.rainSoundTime++) {
            this.rainSoundTime = 0;
            if (fu7.getY() > fu6.getY() + 1 && bqd5.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, fu6).getY() > Mth.floor((float)fu6.getY())) {
                this.minecraft.level.playLocalSound(fu7, SoundEvents.WEATHER_RAIN_ABOVE, SoundSource.WEATHER, 0.1f, 0.5f, false);
            }
            else {
                this.minecraft.level.playLocalSound(fu7, SoundEvents.WEATHER_RAIN, SoundSource.WEATHER, 0.2f, 1.0f, false);
            }
        }
    }
    
    @Override
    public void close() {
        if (this.entityEffect != null) {
            this.entityEffect.close();
        }
        if (this.transparencyChain != null) {
            this.transparencyChain.close();
        }
    }
    
    @Override
    public void onResourceManagerReload(final ResourceManager abc) {
        this.textureManager.bind(LevelRenderer.FORCEFIELD_LOCATION);
        RenderSystem.texParameter(3553, 10242, 10497);
        RenderSystem.texParameter(3553, 10243, 10497);
        RenderSystem.bindTexture(0);
        this.initOutline();
        if (Minecraft.useShaderTransparency()) {
            this.initTransparency();
        }
    }
    
    public void initOutline() {
        if (this.entityEffect != null) {
            this.entityEffect.close();
        }
        final ResourceLocation uh2 = new ResourceLocation("shaders/post/entity_outline.json");
        try {
            (this.entityEffect = new PostChain(this.minecraft.getTextureManager(), this.minecraft.getResourceManager(), this.minecraft.getMainRenderTarget(), uh2)).resize(this.minecraft.getWindow().getWidth(), this.minecraft.getWindow().getHeight());
            this.entityTarget = this.entityEffect.getTempTarget("final");
        }
        catch (IOException iOException3) {
            LevelRenderer.LOGGER.warn("Failed to load shader: {}", uh2, iOException3);
            this.entityEffect = null;
            this.entityTarget = null;
        }
        catch (JsonSyntaxException jsonSyntaxException3) {
            LevelRenderer.LOGGER.warn("Failed to parse shader: {}", uh2, jsonSyntaxException3);
            this.entityEffect = null;
            this.entityTarget = null;
        }
    }
    
    private void initTransparency() {
        this.deinitTransparency();
        final ResourceLocation uh2 = new ResourceLocation("shaders/post/transparency.json");
        try {
            final PostChain ecc3 = new PostChain(this.minecraft.getTextureManager(), this.minecraft.getResourceManager(), this.minecraft.getMainRenderTarget(), uh2);
            ecc3.resize(this.minecraft.getWindow().getWidth(), this.minecraft.getWindow().getHeight());
            final RenderTarget dgf4 = ecc3.getTempTarget("translucent");
            final RenderTarget dgf5 = ecc3.getTempTarget("itemEntity");
            final RenderTarget dgf6 = ecc3.getTempTarget("particles");
            final RenderTarget dgf7 = ecc3.getTempTarget("weather");
            final RenderTarget dgf8 = ecc3.getTempTarget("clouds");
            this.transparencyChain = ecc3;
            this.translucentTarget = dgf4;
            this.itemEntityTarget = dgf5;
            this.particlesTarget = dgf6;
            this.weatherTarget = dgf7;
            this.cloudsTarget = dgf8;
        }
        catch (Exception exception3) {
            final String string4 = (exception3 instanceof JsonSyntaxException) ? "parse" : "load";
            final Options dmb5 = Minecraft.getInstance().options;
            dmb5.graphicsMode = GraphicsStatus.FANCY;
            dmb5.save();
            throw new TranparencyShaderException("Failed to " + string4 + " shader: " + uh2, exception3);
        }
    }
    
    private void deinitTransparency() {
        if (this.transparencyChain != null) {
            this.transparencyChain.close();
            this.translucentTarget.destroyBuffers();
            this.itemEntityTarget.destroyBuffers();
            this.particlesTarget.destroyBuffers();
            this.weatherTarget.destroyBuffers();
            this.cloudsTarget.destroyBuffers();
            this.transparencyChain = null;
            this.translucentTarget = null;
            this.itemEntityTarget = null;
            this.particlesTarget = null;
            this.weatherTarget = null;
            this.cloudsTarget = null;
        }
    }
    
    public void doEntityOutline() {
        if (this.shouldShowEntityOutlines()) {
            RenderSystem.enableBlend();
            RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
            this.entityTarget.blitToScreen(this.minecraft.getWindow().getWidth(), this.minecraft.getWindow().getHeight(), false);
            RenderSystem.disableBlend();
        }
    }
    
    protected boolean shouldShowEntityOutlines() {
        return this.entityTarget != null && this.entityEffect != null && this.minecraft.player != null;
    }
    
    private void createDarkSky() {
        final Tesselator dhn2 = Tesselator.getInstance();
        final BufferBuilder dhg3 = dhn2.getBuilder();
        if (this.darkBuffer != null) {
            this.darkBuffer.close();
        }
        this.darkBuffer = new VertexBuffer(this.skyFormat);
        this.drawSkyHemisphere(dhg3, -16.0f, true);
        dhg3.end();
        this.darkBuffer.upload(dhg3);
    }
    
    private void createLightSky() {
        final Tesselator dhn2 = Tesselator.getInstance();
        final BufferBuilder dhg3 = dhn2.getBuilder();
        if (this.skyBuffer != null) {
            this.skyBuffer.close();
        }
        this.skyBuffer = new VertexBuffer(this.skyFormat);
        this.drawSkyHemisphere(dhg3, 16.0f, false);
        dhg3.end();
        this.skyBuffer.upload(dhg3);
    }
    
    private void drawSkyHemisphere(final BufferBuilder dhg, final float float2, final boolean boolean3) {
        final int integer5 = 64;
        final int integer6 = 6;
        dhg.begin(7, DefaultVertexFormat.POSITION);
        for (int integer7 = -384; integer7 <= 384; integer7 += 64) {
            for (int integer8 = -384; integer8 <= 384; integer8 += 64) {
                float float3 = (float)integer7;
                float float4 = (float)(integer7 + 64);
                if (boolean3) {
                    float4 = (float)integer7;
                    float3 = (float)(integer7 + 64);
                }
                dhg.vertex(float3, float2, integer8).endVertex();
                dhg.vertex(float4, float2, integer8).endVertex();
                dhg.vertex(float4, float2, integer8 + 64).endVertex();
                dhg.vertex(float3, float2, integer8 + 64).endVertex();
            }
        }
    }
    
    private void createStars() {
        final Tesselator dhn2 = Tesselator.getInstance();
        final BufferBuilder dhg3 = dhn2.getBuilder();
        if (this.starBuffer != null) {
            this.starBuffer.close();
        }
        this.starBuffer = new VertexBuffer(this.skyFormat);
        this.drawStars(dhg3);
        dhg3.end();
        this.starBuffer.upload(dhg3);
    }
    
    private void drawStars(final BufferBuilder dhg) {
        final Random random3 = new Random(10842L);
        dhg.begin(7, DefaultVertexFormat.POSITION);
        for (int integer4 = 0; integer4 < 1500; ++integer4) {
            double double5 = random3.nextFloat() * 2.0f - 1.0f;
            double double6 = random3.nextFloat() * 2.0f - 1.0f;
            double double7 = random3.nextFloat() * 2.0f - 1.0f;
            final double double8 = 0.15f + random3.nextFloat() * 0.1f;
            double double9 = double5 * double5 + double6 * double6 + double7 * double7;
            if (double9 < 1.0 && double9 > 0.01) {
                double9 = 1.0 / Math.sqrt(double9);
                double5 *= double9;
                double6 *= double9;
                double7 *= double9;
                final double double10 = double5 * 100.0;
                final double double11 = double6 * 100.0;
                final double double12 = double7 * 100.0;
                final double double13 = Math.atan2(double5, double7);
                final double double14 = Math.sin(double13);
                final double double15 = Math.cos(double13);
                final double double16 = Math.atan2(Math.sqrt(double5 * double5 + double7 * double7), double6);
                final double double17 = Math.sin(double16);
                final double double18 = Math.cos(double16);
                final double double19 = random3.nextDouble() * 3.141592653589793 * 2.0;
                final double double20 = Math.sin(double19);
                final double double21 = Math.cos(double19);
                for (int integer5 = 0; integer5 < 4; ++integer5) {
                    final double double22 = 0.0;
                    final double double23 = ((integer5 & 0x2) - 1) * double8;
                    final double double24 = ((integer5 + 1 & 0x2) - 1) * double8;
                    final double double25 = 0.0;
                    final double double26 = double23 * double21 - double24 * double20;
                    final double double28;
                    final double double27 = double28 = double24 * double21 + double23 * double20;
                    final double double29 = double26 * double17 + 0.0 * double18;
                    final double double30 = 0.0 * double17 - double26 * double18;
                    final double double31 = double30 * double14 - double28 * double15;
                    final double double32 = double29;
                    final double double33 = double28 * double14 + double30 * double15;
                    dhg.vertex(double10 + double31, double11 + double32, double12 + double33).endVertex();
                }
            }
        }
    }
    
    public void setLevel(@Nullable final ClientLevel dym) {
        this.lastCameraX = Double.MIN_VALUE;
        this.lastCameraY = Double.MIN_VALUE;
        this.lastCameraZ = Double.MIN_VALUE;
        this.lastCameraChunkX = Integer.MIN_VALUE;
        this.lastCameraChunkY = Integer.MIN_VALUE;
        this.lastCameraChunkZ = Integer.MIN_VALUE;
        this.entityRenderDispatcher.setLevel(dym);
        this.level = dym;
        if (dym != null) {
            this.allChanged();
        }
        else {
            this.chunksToCompile.clear();
            this.renderChunks.clear();
            if (this.viewArea != null) {
                this.viewArea.releaseAllBuffers();
                this.viewArea = null;
            }
            if (this.chunkRenderDispatcher != null) {
                this.chunkRenderDispatcher.dispose();
            }
            this.chunkRenderDispatcher = null;
            this.globalBlockEntities.clear();
        }
    }
    
    public void allChanged() {
        if (this.level == null) {
            return;
        }
        if (Minecraft.useShaderTransparency()) {
            this.initTransparency();
        }
        else {
            this.deinitTransparency();
        }
        this.level.clearTintCaches();
        if (this.chunkRenderDispatcher == null) {
            this.chunkRenderDispatcher = new ChunkRenderDispatcher(this.level, this, Util.backgroundExecutor(), this.minecraft.is64Bit(), this.renderBuffers.fixedBufferPack());
        }
        else {
            this.chunkRenderDispatcher.setLevel(this.level);
        }
        this.needsUpdate = true;
        this.generateClouds = true;
        ItemBlockRenderTypes.setFancy(Minecraft.useFancyGraphics());
        this.lastViewDistance = this.minecraft.options.renderDistance;
        if (this.viewArea != null) {
            this.viewArea.releaseAllBuffers();
        }
        this.resetChunksToCompile();
        synchronized (this.globalBlockEntities) {
            this.globalBlockEntities.clear();
        }
        this.viewArea = new ViewArea(this.chunkRenderDispatcher, this.level, this.minecraft.options.renderDistance, this);
        if (this.level != null) {
            final Entity aom2 = this.minecraft.getCameraEntity();
            if (aom2 != null) {
                this.viewArea.repositionCamera(aom2.getX(), aom2.getZ());
            }
        }
    }
    
    protected void resetChunksToCompile() {
        this.chunksToCompile.clear();
        this.chunkRenderDispatcher.blockUntilClear();
    }
    
    public void resize(final int integer1, final int integer2) {
        this.needsUpdate();
        if (this.entityEffect != null) {
            this.entityEffect.resize(integer1, integer2);
        }
        if (this.transparencyChain != null) {
            this.transparencyChain.resize(integer1, integer2);
        }
    }
    
    public String getChunkStatistics() {
        final int integer2 = this.viewArea.chunks.length;
        final int integer3 = this.countRenderedChunks();
        return String.format("C: %d/%d %sD: %d, %s", integer3, integer2, this.minecraft.smartCull ? "(s) " : "", this.lastViewDistance, (this.chunkRenderDispatcher == null) ? "null" : this.chunkRenderDispatcher.getStats());
    }
    
    protected int countRenderedChunks() {
        int integer2 = 0;
        for (final RenderChunkInfo a4 : this.renderChunks) {
            if (!a4.chunk.getCompiledChunk().hasNoRenderableLayers()) {
                ++integer2;
            }
        }
        return integer2;
    }
    
    public String getEntityStatistics() {
        return "E: " + this.renderedEntities + "/" + this.level.getEntityCount() + ", B: " + this.culledEntities;
    }
    
    private void setupRender(final Camera dlj, final Frustum ees, final boolean boolean3, final int integer, final boolean boolean5) {
        final Vec3 dem7 = dlj.getPosition();
        if (this.minecraft.options.renderDistance != this.lastViewDistance) {
            this.allChanged();
        }
        this.level.getProfiler().push("camera");
        final double double8 = this.minecraft.player.getX() - this.lastCameraX;
        final double double9 = this.minecraft.player.getY() - this.lastCameraY;
        final double double10 = this.minecraft.player.getZ() - this.lastCameraZ;
        if (this.lastCameraChunkX != this.minecraft.player.xChunk || this.lastCameraChunkY != this.minecraft.player.yChunk || this.lastCameraChunkZ != this.minecraft.player.zChunk || double8 * double8 + double9 * double9 + double10 * double10 > 16.0) {
            this.lastCameraX = this.minecraft.player.getX();
            this.lastCameraY = this.minecraft.player.getY();
            this.lastCameraZ = this.minecraft.player.getZ();
            this.lastCameraChunkX = this.minecraft.player.xChunk;
            this.lastCameraChunkY = this.minecraft.player.yChunk;
            this.lastCameraChunkZ = this.minecraft.player.zChunk;
            this.viewArea.repositionCamera(this.minecraft.player.getX(), this.minecraft.player.getZ());
        }
        this.chunkRenderDispatcher.setCamera(dem7);
        this.level.getProfiler().popPush("cull");
        this.minecraft.getProfiler().popPush("culling");
        final BlockPos fu14 = dlj.getBlockPosition();
        final ChunkRenderDispatcher.RenderChunk c15 = this.viewArea.getRenderChunkAt(fu14);
        final int integer2 = 16;
        final BlockPos fu15 = new BlockPos(Mth.floor(dem7.x / 16.0) * 16, Mth.floor(dem7.y / 16.0) * 16, Mth.floor(dem7.z / 16.0) * 16);
        final float float18 = dlj.getXRot();
        final float float19 = dlj.getYRot();
        this.needsUpdate = (this.needsUpdate || !this.chunksToCompile.isEmpty() || dem7.x != this.prevCamX || dem7.y != this.prevCamY || dem7.z != this.prevCamZ || float18 != this.prevCamRotX || float19 != this.prevCamRotY);
        this.prevCamX = dem7.x;
        this.prevCamY = dem7.y;
        this.prevCamZ = dem7.z;
        this.prevCamRotX = float18;
        this.prevCamRotY = float19;
        this.minecraft.getProfiler().popPush("update");
        if (!boolean3 && this.needsUpdate) {
            this.needsUpdate = false;
            this.renderChunks.clear();
            final Queue<RenderChunkInfo> queue20 = Queues.newArrayDeque();
            Entity.setViewScale(Mth.clamp(this.minecraft.options.renderDistance / 8.0, 1.0, 2.5) * this.minecraft.options.entityDistanceScaling);
            boolean boolean6 = this.minecraft.smartCull;
            if (c15 == null) {
                final int integer3 = (fu14.getY() > 0) ? 248 : 8;
                final int integer4 = Mth.floor(dem7.x / 16.0) * 16;
                final int integer5 = Mth.floor(dem7.z / 16.0) * 16;
                final List<RenderChunkInfo> list25 = Lists.newArrayList();
                for (int integer6 = -this.lastViewDistance; integer6 <= this.lastViewDistance; ++integer6) {
                    for (int integer7 = -this.lastViewDistance; integer7 <= this.lastViewDistance; ++integer7) {
                        final ChunkRenderDispatcher.RenderChunk c16 = this.viewArea.getRenderChunkAt(new BlockPos(integer4 + (integer6 << 4) + 8, integer3, integer5 + (integer7 << 4) + 8));
                        if (c16 != null && ees.isVisible(c16.bb)) {
                            c16.setFrame(integer);
                            list25.add(new RenderChunkInfo(c16, (Direction)null, 0));
                        }
                    }
                }
                list25.sort(Comparator.comparingDouble(a -> fu14.distSqr(a.chunk.getOrigin().offset(8, 8, 8))));
                queue20.addAll(list25);
            }
            else {
                if (boolean5 && this.level.getBlockState(fu14).isSolidRender(this.level, fu14)) {
                    boolean6 = false;
                }
                c15.setFrame(integer);
                queue20.add(new RenderChunkInfo(c15, (Direction)null, 0));
            }
            this.minecraft.getProfiler().push("iteration");
            while (!queue20.isEmpty()) {
                final RenderChunkInfo a2 = queue20.poll();
                final ChunkRenderDispatcher.RenderChunk c17 = a2.chunk;
                final Direction fz24 = a2.sourceDirection;
                this.renderChunks.add(a2);
                for (final Direction fz25 : LevelRenderer.DIRECTIONS) {
                    final ChunkRenderDispatcher.RenderChunk c18 = this.getRelativeFrom(fu15, c17, fz25);
                    if (!boolean6 || !a2.hasDirection(fz25.getOpposite())) {
                        if (!boolean6 || fz24 == null || c17.getCompiledChunk().facesCanSeeEachother(fz24.getOpposite(), fz25)) {
                            if (c18 != null) {
                                if (c18.hasAllNeighbors()) {
                                    if (c18.setFrame(integer)) {
                                        if (ees.isVisible(c18.bb)) {
                                            final RenderChunkInfo a3 = new RenderChunkInfo(c18, fz25, a2.step + 1);
                                            a3.setDirections(a2.directions, fz25);
                                            queue20.add(a3);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.minecraft.getProfiler().pop();
        }
        this.minecraft.getProfiler().popPush("rebuildNear");
        final Set<ChunkRenderDispatcher.RenderChunk> set20 = this.chunksToCompile;
        this.chunksToCompile = Sets.newLinkedHashSet();
        final ObjectListIterator iterator = this.renderChunks.iterator();
        while (((Iterator)iterator).hasNext()) {
            final RenderChunkInfo a2 = ((Iterator<RenderChunkInfo>)iterator).next();
            final ChunkRenderDispatcher.RenderChunk c17 = a2.chunk;
            if (c17.isDirty() || set20.contains(c17)) {
                this.needsUpdate = true;
                final BlockPos fu16 = c17.getOrigin().offset(8, 8, 8);
                final boolean boolean7 = fu16.distSqr(fu14) < 768.0;
                if (c17.isDirtyFromPlayer() || boolean7) {
                    this.minecraft.getProfiler().push("build near");
                    this.chunkRenderDispatcher.rebuildChunkSync(c17);
                    c17.setNotDirty();
                    this.minecraft.getProfiler().pop();
                }
                else {
                    this.chunksToCompile.add(c17);
                }
            }
        }
        this.chunksToCompile.addAll(set20);
        this.minecraft.getProfiler().pop();
    }
    
    @Nullable
    private ChunkRenderDispatcher.RenderChunk getRelativeFrom(final BlockPos fu, final ChunkRenderDispatcher.RenderChunk c, final Direction fz) {
        final BlockPos fu2 = c.getRelativeOrigin(fz);
        if (Mth.abs(fu.getX() - fu2.getX()) > this.lastViewDistance * 16) {
            return null;
        }
        if (fu2.getY() < 0 || fu2.getY() >= 256) {
            return null;
        }
        if (Mth.abs(fu.getZ() - fu2.getZ()) > this.lastViewDistance * 16) {
            return null;
        }
        return this.viewArea.getRenderChunkAt(fu2);
    }
    
    private void captureFrustum(final Matrix4f b1, final Matrix4f b2, final double double3, final double double4, final double double5, final Frustum ees) {
        this.capturedFrustum = ees;
        final Matrix4f b3 = b2.copy();
        b3.multiply(b1);
        b3.invert();
        this.frustumPos.x = double3;
        this.frustumPos.y = double4;
        this.frustumPos.z = double5;
        this.frustumPoints[0] = new Vector4f(-1.0f, -1.0f, -1.0f, 1.0f);
        this.frustumPoints[1] = new Vector4f(1.0f, -1.0f, -1.0f, 1.0f);
        this.frustumPoints[2] = new Vector4f(1.0f, 1.0f, -1.0f, 1.0f);
        this.frustumPoints[3] = new Vector4f(-1.0f, 1.0f, -1.0f, 1.0f);
        this.frustumPoints[4] = new Vector4f(-1.0f, -1.0f, 1.0f, 1.0f);
        this.frustumPoints[5] = new Vector4f(1.0f, -1.0f, 1.0f, 1.0f);
        this.frustumPoints[6] = new Vector4f(1.0f, 1.0f, 1.0f, 1.0f);
        this.frustumPoints[7] = new Vector4f(-1.0f, 1.0f, 1.0f, 1.0f);
        for (int integer12 = 0; integer12 < 8; ++integer12) {
            this.frustumPoints[integer12].transform(b3);
            this.frustumPoints[integer12].perspectiveDivide();
        }
    }
    
    public void renderLevel(final PoseStack dhl, final float float2, final long long3, final boolean boolean4, final Camera dlj, final GameRenderer ebs, final LightTexture eby, final Matrix4f b) {
        BlockEntityRenderDispatcher.instance.prepare(this.level, this.minecraft.getTextureManager(), this.minecraft.font, dlj, this.minecraft.hitResult);
        this.entityRenderDispatcher.prepare(this.level, dlj, this.minecraft.crosshairPickEntity);
        final ProfilerFiller ami11 = this.level.getProfiler();
        ami11.popPush("light_updates");
        this.minecraft.level.getChunkSource().getLightEngine().runUpdates(Integer.MAX_VALUE, true, true);
        final Vec3 dem12 = dlj.getPosition();
        final double double13 = dem12.x();
        final double double14 = dem12.y();
        final double double15 = dem12.z();
        final Matrix4f b2 = dhl.last().pose();
        ami11.popPush("culling");
        final boolean boolean5 = this.capturedFrustum != null;
        Frustum ees21;
        if (boolean5) {
            ees21 = this.capturedFrustum;
            ees21.prepare(this.frustumPos.x, this.frustumPos.y, this.frustumPos.z);
        }
        else {
            ees21 = new Frustum(b2, b);
            ees21.prepare(double13, double14, double15);
        }
        this.minecraft.getProfiler().popPush("captureFrustum");
        if (this.captureFrustum) {
            this.captureFrustum(b2, b, dem12.x, dem12.y, dem12.z, boolean5 ? new Frustum(b2, b) : ees21);
            this.captureFrustum = false;
        }
        ami11.popPush("clear");
        FogRenderer.setupColor(dlj, float2, this.minecraft.level, this.minecraft.options.renderDistance, ebs.getDarkenWorldAmount(float2));
        RenderSystem.clear(16640, Minecraft.ON_OSX);
        final float float3 = ebs.getRenderDistance();
        final boolean boolean6 = this.minecraft.level.effects().isFoggyAt(Mth.floor(double13), Mth.floor(double14)) || this.minecraft.gui.getBossOverlay().shouldCreateWorldFog();
        if (this.minecraft.options.renderDistance >= 4) {
            FogRenderer.setupFog(dlj, FogRenderer.FogMode.FOG_SKY, float3, boolean6);
            ami11.popPush("sky");
            this.renderSky(dhl, float2);
        }
        ami11.popPush("fog");
        FogRenderer.setupFog(dlj, FogRenderer.FogMode.FOG_TERRAIN, Math.max(float3 - 16.0f, 32.0f), boolean6);
        ami11.popPush("terrain_setup");
        this.setupRender(dlj, ees21, boolean5, this.frameId++, this.minecraft.player.isSpectator());
        ami11.popPush("updatechunks");
        final int integer24 = 30;
        final int integer25 = this.minecraft.options.framerateLimit;
        final long long4 = 33333333L;
        long long5;
        if (integer25 == Option.FRAMERATE_LIMIT.getMaxValue()) {
            long5 = 0L;
        }
        else {
            long5 = 1000000000 / integer25;
        }
        final long long6 = Util.getNanos() - long3;
        final long long7 = this.frameTimes.registerValueAndGetMean(long6);
        final long long8 = long7 * 3L / 2L;
        final long long9 = Mth.clamp(long8, long5, 33333333L);
        this.compileChunksUntil(long3 + long9);
        ami11.popPush("terrain");
        this.renderChunkLayer(RenderType.solid(), dhl, double13, double14, double15);
        this.renderChunkLayer(RenderType.cutoutMipped(), dhl, double13, double14, double15);
        this.renderChunkLayer(RenderType.cutout(), dhl, double13, double14, double15);
        if (this.level.effects().constantAmbientLight()) {
            Lighting.setupNetherLevel(dhl.last().pose());
        }
        else {
            Lighting.setupLevel(dhl.last().pose());
        }
        ami11.popPush("entities");
        ami11.push("prepare");
        this.renderedEntities = 0;
        this.culledEntities = 0;
        ami11.popPush("entities");
        if (this.itemEntityTarget != null) {
            this.itemEntityTarget.clear(Minecraft.ON_OSX);
            this.itemEntityTarget.copyDepthFrom(this.minecraft.getMainRenderTarget());
            this.minecraft.getMainRenderTarget().bindWrite(false);
        }
        if (this.weatherTarget != null) {
            this.weatherTarget.clear(Minecraft.ON_OSX);
        }
        if (this.shouldShowEntityOutlines()) {
            this.entityTarget.clear(Minecraft.ON_OSX);
            this.minecraft.getMainRenderTarget().bindWrite(false);
        }
        boolean boolean7 = false;
        final MultiBufferSource.BufferSource a39 = this.renderBuffers.bufferSource();
        for (final Entity aom41 : this.level.entitiesForRendering()) {
            if (!this.entityRenderDispatcher.<Entity>shouldRender(aom41, ees21, double13, double14, double15) && !aom41.hasIndirectPassenger(this.minecraft.player)) {
                continue;
            }
            if (aom41 == dlj.getEntity() && !dlj.isDetached()) {
                if (!(dlj.getEntity() instanceof LivingEntity)) {
                    continue;
                }
                if (!((LivingEntity)dlj.getEntity()).isSleeping()) {
                    continue;
                }
            }
            if (aom41 instanceof LocalPlayer && dlj.getEntity() != aom41) {
                continue;
            }
            ++this.renderedEntities;
            if (aom41.tickCount == 0) {
                aom41.xOld = aom41.getX();
                aom41.yOld = aom41.getY();
                aom41.zOld = aom41.getZ();
            }
            MultiBufferSource ebz42;
            if (this.shouldShowEntityOutlines() && this.minecraft.shouldEntityAppearGlowing(aom41)) {
                boolean7 = true;
                final OutlineBufferSource eca43 = (OutlineBufferSource)(ebz42 = this.renderBuffers.outlineBufferSource());
                final int integer26 = aom41.getTeamColor();
                final int integer27 = 255;
                final int integer28 = integer26 >> 16 & 0xFF;
                final int integer29 = integer26 >> 8 & 0xFF;
                final int integer30 = integer26 & 0xFF;
                eca43.setColor(integer28, integer29, integer30, 255);
            }
            else {
                ebz42 = a39;
            }
            this.renderEntity(aom41, double13, double14, double15, float2, dhl, ebz42);
        }
        this.checkPoseStack(dhl);
        a39.endBatch(RenderType.entitySolid(TextureAtlas.LOCATION_BLOCKS));
        a39.endBatch(RenderType.entityCutout(TextureAtlas.LOCATION_BLOCKS));
        a39.endBatch(RenderType.entityCutoutNoCull(TextureAtlas.LOCATION_BLOCKS));
        a39.endBatch(RenderType.entitySmoothCutout(TextureAtlas.LOCATION_BLOCKS));
        ami11.popPush("blockentities");
        for (final RenderChunkInfo a40 : this.renderChunks) {
            final List<BlockEntity> list42 = a40.chunk.getCompiledChunk().getRenderableBlockEntities();
            if (list42.isEmpty()) {
                continue;
            }
            for (final BlockEntity cdl44 : list42) {
                final BlockPos fu45 = cdl44.getBlockPos();
                MultiBufferSource ebz43 = a39;
                dhl.pushPose();
                dhl.translate(fu45.getX() - double13, fu45.getY() - double14, fu45.getZ() - double15);
                final SortedSet<BlockDestructionProgress> sortedSet47 = (SortedSet<BlockDestructionProgress>)this.destructionProgress.get(fu45.asLong());
                if (sortedSet47 != null && !sortedSet47.isEmpty()) {
                    final int integer30 = sortedSet47.last().getProgress();
                    if (integer30 >= 0) {
                        final PoseStack.Pose a41 = dhl.last();
                        final VertexConsumer dhp50 = new SheetedDecalTextureGenerator(this.renderBuffers.crumblingBufferSource().getBuffer(ModelBakery.DESTROY_TYPES.get(integer30)), a41.pose(), a41.normal());
                        final MultiBufferSource.BufferSource bufferSource;
                        final VertexConsumer dhp51;
                        final VertexConsumer dhp54;
                        ebz43 = (ech -> {
                            dhp51 = bufferSource.getBuffer(ech);
                            if (ech.affectsCrumbling()) {
                                return VertexMultiConsumer.create(dhp54, dhp51);
                            }
                            else {
                                return dhp51;
                            }
                        });
                    }
                }
                BlockEntityRenderDispatcher.instance.<BlockEntity>render(cdl44, float2, dhl, ebz43);
                dhl.popPose();
            }
        }
        synchronized (this.globalBlockEntities) {
            for (final BlockEntity cdl45 : this.globalBlockEntities) {
                final BlockPos fu46 = cdl45.getBlockPos();
                dhl.pushPose();
                dhl.translate(fu46.getX() - double13, fu46.getY() - double14, fu46.getZ() - double15);
                BlockEntityRenderDispatcher.instance.<BlockEntity>render(cdl45, float2, dhl, a39);
                dhl.popPose();
            }
        }
        this.checkPoseStack(dhl);
        a39.endBatch(RenderType.solid());
        a39.endBatch(Sheets.solidBlockSheet());
        a39.endBatch(Sheets.cutoutBlockSheet());
        a39.endBatch(Sheets.bedSheet());
        a39.endBatch(Sheets.shulkerBoxSheet());
        a39.endBatch(Sheets.signSheet());
        a39.endBatch(Sheets.chestSheet());
        this.renderBuffers.outlineBufferSource().endOutlineBatch();
        if (boolean7) {
            this.entityEffect.process(float2);
            this.minecraft.getMainRenderTarget().bindWrite(false);
        }
        ami11.popPush("destroyProgress");
        for (final Long2ObjectMap.Entry<SortedSet<BlockDestructionProgress>> entry41 : this.destructionProgress.long2ObjectEntrySet()) {
            final BlockPos fu47 = BlockPos.of(entry41.getLongKey());
            final double double16 = fu47.getX() - double13;
            final double double17 = fu47.getY() - double14;
            final double double18 = fu47.getZ() - double15;
            if (double16 * double16 + double17 * double17 + double18 * double18 > 1024.0) {
                continue;
            }
            final SortedSet<BlockDestructionProgress> sortedSet48 = (SortedSet<BlockDestructionProgress>)entry41.getValue();
            if (sortedSet48 == null) {
                continue;
            }
            if (sortedSet48.isEmpty()) {
                continue;
            }
            final int integer31 = sortedSet48.last().getProgress();
            dhl.pushPose();
            dhl.translate(fu47.getX() - double13, fu47.getY() - double14, fu47.getZ() - double15);
            final PoseStack.Pose a42 = dhl.last();
            final VertexConsumer dhp52 = new SheetedDecalTextureGenerator(this.renderBuffers.crumblingBufferSource().getBuffer(ModelBakery.DESTROY_TYPES.get(integer31)), a42.pose(), a42.normal());
            this.minecraft.getBlockRenderer().renderBreakingTexture(this.level.getBlockState(fu47), fu47, this.level, dhl, dhp52);
            dhl.popPose();
        }
        this.checkPoseStack(dhl);
        ami11.pop();
        final HitResult dej40 = this.minecraft.hitResult;
        if (boolean4 && dej40 != null && dej40.getType() == HitResult.Type.BLOCK) {
            ami11.popPush("outline");
            final BlockPos fu48 = ((BlockHitResult)dej40).getBlockPos();
            final BlockState cfj42 = this.level.getBlockState(fu48);
            if (!cfj42.isAir() && this.level.getWorldBorder().isWithinBounds(fu48)) {
                final VertexConsumer dhp53 = a39.getBuffer(RenderType.lines());
                this.renderHitOutline(dhl, dhp53, dlj.getEntity(), double13, double14, double15, fu48, cfj42);
            }
        }
        RenderSystem.pushMatrix();
        RenderSystem.multMatrix(dhl.last().pose());
        this.minecraft.debugRenderer.render(dhl, a39, double13, double14, double15);
        RenderSystem.popMatrix();
        a39.endBatch(Sheets.translucentCullBlockSheet());
        a39.endBatch(Sheets.bannerSheet());
        a39.endBatch(Sheets.shieldSheet());
        a39.endBatch(RenderType.armorGlint());
        a39.endBatch(RenderType.armorEntityGlint());
        a39.endBatch(RenderType.glint());
        a39.endBatch(RenderType.entityGlint());
        a39.endBatch(RenderType.waterMask());
        this.renderBuffers.crumblingBufferSource().endBatch();
        a39.endBatch(RenderType.lines());
        a39.endBatch();
        if (this.transparencyChain != null) {
            this.translucentTarget.clear(Minecraft.ON_OSX);
            this.translucentTarget.copyDepthFrom(this.minecraft.getMainRenderTarget());
            ami11.popPush("translucent");
            this.renderChunkLayer(RenderType.translucent(), dhl, double13, double14, double15);
            ami11.popPush("string");
            this.renderChunkLayer(RenderType.tripwire(), dhl, double13, double14, double15);
            this.particlesTarget.clear(Minecraft.ON_OSX);
            this.particlesTarget.copyDepthFrom(this.minecraft.getMainRenderTarget());
            RenderStateShard.PARTICLES_TARGET.setupRenderState();
            ami11.popPush("particles");
            this.minecraft.particleEngine.render(dhl, a39, eby, dlj, float2);
            RenderStateShard.PARTICLES_TARGET.clearRenderState();
        }
        else {
            ami11.popPush("translucent");
            this.renderChunkLayer(RenderType.translucent(), dhl, double13, double14, double15);
            ami11.popPush("string");
            this.renderChunkLayer(RenderType.tripwire(), dhl, double13, double14, double15);
            ami11.popPush("particles");
            this.minecraft.particleEngine.render(dhl, a39, eby, dlj, float2);
        }
        RenderSystem.pushMatrix();
        RenderSystem.multMatrix(dhl.last().pose());
        if (this.minecraft.options.getCloudsType() != CloudStatus.OFF) {
            if (this.transparencyChain != null) {
                this.cloudsTarget.clear(Minecraft.ON_OSX);
                RenderStateShard.CLOUDS_TARGET.setupRenderState();
                ami11.popPush("clouds");
                this.renderClouds(dhl, float2, double13, double14, double15);
                RenderStateShard.CLOUDS_TARGET.clearRenderState();
            }
            else {
                ami11.popPush("clouds");
                this.renderClouds(dhl, float2, double13, double14, double15);
            }
        }
        if (this.transparencyChain != null) {
            RenderStateShard.WEATHER_TARGET.setupRenderState();
            ami11.popPush("weather");
            this.renderSnowAndRain(eby, float2, double13, double14, double15);
            this.renderWorldBounds(dlj);
            RenderStateShard.WEATHER_TARGET.clearRenderState();
            this.transparencyChain.process(float2);
            this.minecraft.getMainRenderTarget().bindWrite(false);
        }
        else {
            RenderSystem.depthMask(false);
            ami11.popPush("weather");
            this.renderSnowAndRain(eby, float2, double13, double14, double15);
            this.renderWorldBounds(dlj);
            RenderSystem.depthMask(true);
        }
        this.renderDebug(dlj);
        RenderSystem.shadeModel(7424);
        RenderSystem.depthMask(true);
        RenderSystem.disableBlend();
        RenderSystem.popMatrix();
        FogRenderer.setupNoFog();
    }
    
    private void checkPoseStack(final PoseStack dhl) {
        if (!dhl.clear()) {
            throw new IllegalStateException("Pose stack not empty");
        }
    }
    
    private void renderEntity(final Entity aom, final double double2, final double double3, final double double4, final float float5, final PoseStack dhl, final MultiBufferSource ebz) {
        final double double5 = Mth.lerp(float5, aom.xOld, aom.getX());
        final double double6 = Mth.lerp(float5, aom.yOld, aom.getY());
        final double double7 = Mth.lerp(float5, aom.zOld, aom.getZ());
        final float float6 = Mth.lerp(float5, aom.yRotO, aom.yRot);
        this.entityRenderDispatcher.<Entity>render(aom, double5 - double2, double6 - double3, double7 - double4, float6, float5, dhl, ebz, this.entityRenderDispatcher.<Entity>getPackedLightCoords(aom, float5));
    }
    
    private void renderChunkLayer(final RenderType ech, final PoseStack dhl, final double double3, final double double4, final double double5) {
        ech.setupRenderState();
        if (ech == RenderType.translucent()) {
            this.minecraft.getProfiler().push("translucent_sort");
            final double double6 = double3 - this.xTransparentOld;
            final double double7 = double4 - this.yTransparentOld;
            final double double8 = double5 - this.zTransparentOld;
            if (double6 * double6 + double7 * double7 + double8 * double8 > 1.0) {
                this.xTransparentOld = double3;
                this.yTransparentOld = double4;
                this.zTransparentOld = double5;
                int integer16 = 0;
                for (final RenderChunkInfo a18 : this.renderChunks) {
                    if (integer16 < 15 && a18.chunk.resortTransparency(ech, this.chunkRenderDispatcher)) {
                        ++integer16;
                    }
                }
            }
            this.minecraft.getProfiler().pop();
        }
        this.minecraft.getProfiler().push("filterempty");
        this.minecraft.getProfiler().popPush(() -> "render_" + ech);
        final boolean boolean10 = ech != RenderType.translucent();
        final ObjectListIterator<RenderChunkInfo> objectListIterator11 = (ObjectListIterator<RenderChunkInfo>)this.renderChunks.listIterator(boolean10 ? 0 : this.renderChunks.size());
        while (true) {
            if (boolean10) {
                if (!objectListIterator11.hasNext()) {
                    break;
                }
            }
            else if (!objectListIterator11.hasPrevious()) {
                break;
            }
            final RenderChunkInfo a19 = (RenderChunkInfo)(boolean10 ? objectListIterator11.next() : ((RenderChunkInfo)objectListIterator11.previous()));
            final ChunkRenderDispatcher.RenderChunk c13 = a19.chunk;
            if (c13.getCompiledChunk().isEmpty(ech)) {
                continue;
            }
            final VertexBuffer dho14 = c13.getBuffer(ech);
            dhl.pushPose();
            final BlockPos fu15 = c13.getOrigin();
            dhl.translate(fu15.getX() - double3, fu15.getY() - double4, fu15.getZ() - double5);
            dho14.bind();
            this.format.setupBufferState(0L);
            dho14.draw(dhl.last().pose(), 7);
            dhl.popPose();
        }
        VertexBuffer.unbind();
        RenderSystem.clearCurrentColor();
        this.format.clearBufferState();
        this.minecraft.getProfiler().pop();
        ech.clearRenderState();
    }
    
    private void renderDebug(final Camera dlj) {
        final Tesselator dhn3 = Tesselator.getInstance();
        final BufferBuilder dhg4 = dhn3.getBuilder();
        if (this.minecraft.chunkPath || this.minecraft.chunkVisibility) {
            final double double5 = dlj.getPosition().x();
            final double double6 = dlj.getPosition().y();
            final double double7 = dlj.getPosition().z();
            RenderSystem.depthMask(true);
            RenderSystem.disableCull();
            RenderSystem.enableBlend();
            RenderSystem.defaultBlendFunc();
            RenderSystem.disableTexture();
            for (final RenderChunkInfo a12 : this.renderChunks) {
                final ChunkRenderDispatcher.RenderChunk c13 = a12.chunk;
                RenderSystem.pushMatrix();
                final BlockPos fu14 = c13.getOrigin();
                RenderSystem.translated(fu14.getX() - double5, fu14.getY() - double6, fu14.getZ() - double7);
                if (this.minecraft.chunkPath) {
                    dhg4.begin(1, DefaultVertexFormat.POSITION_COLOR);
                    RenderSystem.lineWidth(10.0f);
                    final int integer15 = (a12.step == 0) ? 0 : Mth.hsvToRgb(a12.step / 50.0f, 0.9f, 0.9f);
                    final int integer16 = integer15 >> 16 & 0xFF;
                    final int integer17 = integer15 >> 8 & 0xFF;
                    final int integer18 = integer15 & 0xFF;
                    final Direction fz19 = a12.sourceDirection;
                    if (fz19 != null) {
                        dhg4.vertex(8.0, 8.0, 8.0).color(integer16, integer17, integer18, 255).endVertex();
                        dhg4.vertex(8 - 16 * fz19.getStepX(), 8 - 16 * fz19.getStepY(), 8 - 16 * fz19.getStepZ()).color(integer16, integer17, integer18, 255).endVertex();
                    }
                    dhn3.end();
                    RenderSystem.lineWidth(1.0f);
                }
                if (this.minecraft.chunkVisibility && !c13.getCompiledChunk().hasNoRenderableLayers()) {
                    dhg4.begin(1, DefaultVertexFormat.POSITION_COLOR);
                    RenderSystem.lineWidth(10.0f);
                    int integer15 = 0;
                    for (final Direction fz19 : LevelRenderer.DIRECTIONS) {
                        for (final Direction fz20 : LevelRenderer.DIRECTIONS) {
                            final boolean boolean24 = c13.getCompiledChunk().facesCanSeeEachother(fz19, fz20);
                            if (!boolean24) {
                                ++integer15;
                                dhg4.vertex(8 + 8 * fz19.getStepX(), 8 + 8 * fz19.getStepY(), 8 + 8 * fz19.getStepZ()).color(1, 0, 0, 1).endVertex();
                                dhg4.vertex(8 + 8 * fz20.getStepX(), 8 + 8 * fz20.getStepY(), 8 + 8 * fz20.getStepZ()).color(1, 0, 0, 1).endVertex();
                            }
                        }
                    }
                    dhn3.end();
                    RenderSystem.lineWidth(1.0f);
                    if (integer15 > 0) {
                        dhg4.begin(7, DefaultVertexFormat.POSITION_COLOR);
                        final float float16 = 0.5f;
                        final float float17 = 0.2f;
                        dhg4.vertex(0.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(15.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhg4.vertex(0.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        dhn3.end();
                    }
                }
                RenderSystem.popMatrix();
            }
            RenderSystem.depthMask(true);
            RenderSystem.disableBlend();
            RenderSystem.enableCull();
            RenderSystem.enableTexture();
        }
        if (this.capturedFrustum != null) {
            RenderSystem.disableCull();
            RenderSystem.disableTexture();
            RenderSystem.enableBlend();
            RenderSystem.defaultBlendFunc();
            RenderSystem.lineWidth(10.0f);
            RenderSystem.pushMatrix();
            RenderSystem.translatef((float)(this.frustumPos.x - dlj.getPosition().x), (float)(this.frustumPos.y - dlj.getPosition().y), (float)(this.frustumPos.z - dlj.getPosition().z));
            RenderSystem.depthMask(true);
            dhg4.begin(7, DefaultVertexFormat.POSITION_COLOR);
            this.addFrustumQuad(dhg4, 0, 1, 2, 3, 0, 1, 1);
            this.addFrustumQuad(dhg4, 4, 5, 6, 7, 1, 0, 0);
            this.addFrustumQuad(dhg4, 0, 1, 5, 4, 1, 1, 0);
            this.addFrustumQuad(dhg4, 2, 3, 7, 6, 0, 0, 1);
            this.addFrustumQuad(dhg4, 0, 4, 7, 3, 0, 1, 0);
            this.addFrustumQuad(dhg4, 1, 5, 6, 2, 1, 0, 1);
            dhn3.end();
            RenderSystem.depthMask(false);
            dhg4.begin(1, DefaultVertexFormat.POSITION);
            RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
            this.addFrustumVertex(dhg4, 0);
            this.addFrustumVertex(dhg4, 1);
            this.addFrustumVertex(dhg4, 1);
            this.addFrustumVertex(dhg4, 2);
            this.addFrustumVertex(dhg4, 2);
            this.addFrustumVertex(dhg4, 3);
            this.addFrustumVertex(dhg4, 3);
            this.addFrustumVertex(dhg4, 0);
            this.addFrustumVertex(dhg4, 4);
            this.addFrustumVertex(dhg4, 5);
            this.addFrustumVertex(dhg4, 5);
            this.addFrustumVertex(dhg4, 6);
            this.addFrustumVertex(dhg4, 6);
            this.addFrustumVertex(dhg4, 7);
            this.addFrustumVertex(dhg4, 7);
            this.addFrustumVertex(dhg4, 4);
            this.addFrustumVertex(dhg4, 0);
            this.addFrustumVertex(dhg4, 4);
            this.addFrustumVertex(dhg4, 1);
            this.addFrustumVertex(dhg4, 5);
            this.addFrustumVertex(dhg4, 2);
            this.addFrustumVertex(dhg4, 6);
            this.addFrustumVertex(dhg4, 3);
            this.addFrustumVertex(dhg4, 7);
            dhn3.end();
            RenderSystem.popMatrix();
            RenderSystem.depthMask(true);
            RenderSystem.disableBlend();
            RenderSystem.enableCull();
            RenderSystem.enableTexture();
            RenderSystem.lineWidth(1.0f);
        }
    }
    
    private void addFrustumVertex(final VertexConsumer dhp, final int integer) {
        dhp.vertex(this.frustumPoints[integer].x(), this.frustumPoints[integer].y(), this.frustumPoints[integer].z()).endVertex();
    }
    
    private void addFrustumQuad(final VertexConsumer dhp, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6, final int integer7, final int integer8) {
        final float float10 = 0.25f;
        dhp.vertex(this.frustumPoints[integer2].x(), this.frustumPoints[integer2].y(), this.frustumPoints[integer2].z()).color((float)integer6, (float)integer7, (float)integer8, 0.25f).endVertex();
        dhp.vertex(this.frustumPoints[integer3].x(), this.frustumPoints[integer3].y(), this.frustumPoints[integer3].z()).color((float)integer6, (float)integer7, (float)integer8, 0.25f).endVertex();
        dhp.vertex(this.frustumPoints[integer4].x(), this.frustumPoints[integer4].y(), this.frustumPoints[integer4].z()).color((float)integer6, (float)integer7, (float)integer8, 0.25f).endVertex();
        dhp.vertex(this.frustumPoints[integer5].x(), this.frustumPoints[integer5].y(), this.frustumPoints[integer5].z()).color((float)integer6, (float)integer7, (float)integer8, 0.25f).endVertex();
    }
    
    public void tick() {
        ++this.ticks;
        if (this.ticks % 20 != 0) {
            return;
        }
        final Iterator<BlockDestructionProgress> iterator2 = (Iterator<BlockDestructionProgress>)this.destroyingBlocks.values().iterator();
        while (iterator2.hasNext()) {
            final BlockDestructionProgress yn3 = iterator2.next();
            final int integer4 = yn3.getUpdatedRenderTick();
            if (this.ticks - integer4 > 400) {
                iterator2.remove();
                this.removeProgress(yn3);
            }
        }
    }
    
    private void removeProgress(final BlockDestructionProgress yn) {
        final long long3 = yn.getPos().asLong();
        final Set<BlockDestructionProgress> set5 = (Set<BlockDestructionProgress>)this.destructionProgress.get(long3);
        set5.remove(yn);
        if (set5.isEmpty()) {
            this.destructionProgress.remove(long3);
        }
    }
    
    private void renderEndSky(final PoseStack dhl) {
        RenderSystem.disableAlphaTest();
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.depthMask(false);
        this.textureManager.bind(LevelRenderer.END_SKY_LOCATION);
        final Tesselator dhn3 = Tesselator.getInstance();
        final BufferBuilder dhg4 = dhn3.getBuilder();
        for (int integer5 = 0; integer5 < 6; ++integer5) {
            dhl.pushPose();
            if (integer5 == 1) {
                dhl.mulPose(Vector3f.XP.rotationDegrees(90.0f));
            }
            if (integer5 == 2) {
                dhl.mulPose(Vector3f.XP.rotationDegrees(-90.0f));
            }
            if (integer5 == 3) {
                dhl.mulPose(Vector3f.XP.rotationDegrees(180.0f));
            }
            if (integer5 == 4) {
                dhl.mulPose(Vector3f.ZP.rotationDegrees(90.0f));
            }
            if (integer5 == 5) {
                dhl.mulPose(Vector3f.ZP.rotationDegrees(-90.0f));
            }
            final Matrix4f b6 = dhl.last().pose();
            dhg4.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR);
            dhg4.vertex(b6, -100.0f, -100.0f, -100.0f).uv(0.0f, 0.0f).color(40, 40, 40, 255).endVertex();
            dhg4.vertex(b6, -100.0f, -100.0f, 100.0f).uv(0.0f, 16.0f).color(40, 40, 40, 255).endVertex();
            dhg4.vertex(b6, 100.0f, -100.0f, 100.0f).uv(16.0f, 16.0f).color(40, 40, 40, 255).endVertex();
            dhg4.vertex(b6, 100.0f, -100.0f, -100.0f).uv(16.0f, 0.0f).color(40, 40, 40, 255).endVertex();
            dhn3.end();
            dhl.popPose();
        }
        RenderSystem.depthMask(true);
        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
        RenderSystem.enableAlphaTest();
    }
    
    public void renderSky(final PoseStack dhl, final float float2) {
        if (this.minecraft.level.effects().skyType() == DimensionSpecialEffects.SkyType.END) {
            this.renderEndSky(dhl);
            return;
        }
        if (this.minecraft.level.effects().skyType() != DimensionSpecialEffects.SkyType.NORMAL) {
            return;
        }
        RenderSystem.disableTexture();
        final Vec3 dem4 = this.level.getSkyColor(this.minecraft.gameRenderer.getMainCamera().getBlockPosition(), float2);
        final float float3 = (float)dem4.x;
        final float float4 = (float)dem4.y;
        final float float5 = (float)dem4.z;
        FogRenderer.levelFogColor();
        final BufferBuilder dhg8 = Tesselator.getInstance().getBuilder();
        RenderSystem.depthMask(false);
        RenderSystem.enableFog();
        RenderSystem.color3f(float3, float4, float5);
        this.skyBuffer.bind();
        this.skyFormat.setupBufferState(0L);
        this.skyBuffer.draw(dhl.last().pose(), 7);
        VertexBuffer.unbind();
        this.skyFormat.clearBufferState();
        RenderSystem.disableFog();
        RenderSystem.disableAlphaTest();
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        final float[] arr9 = this.level.effects().getSunriseColor(this.level.getTimeOfDay(float2), float2);
        if (arr9 != null) {
            RenderSystem.disableTexture();
            RenderSystem.shadeModel(7425);
            dhl.pushPose();
            dhl.mulPose(Vector3f.XP.rotationDegrees(90.0f));
            final float float6 = (Mth.sin(this.level.getSunAngle(float2)) < 0.0f) ? 180.0f : 0.0f;
            dhl.mulPose(Vector3f.ZP.rotationDegrees(float6));
            dhl.mulPose(Vector3f.ZP.rotationDegrees(90.0f));
            final float float7 = arr9[0];
            final float float8 = arr9[1];
            final float float9 = arr9[2];
            final Matrix4f b14 = dhl.last().pose();
            dhg8.begin(6, DefaultVertexFormat.POSITION_COLOR);
            dhg8.vertex(b14, 0.0f, 100.0f, 0.0f).color(float7, float8, float9, arr9[3]).endVertex();
            final int integer15 = 16;
            for (int integer16 = 0; integer16 <= 16; ++integer16) {
                final float float10 = integer16 * 6.2831855f / 16.0f;
                final float float11 = Mth.sin(float10);
                final float float12 = Mth.cos(float10);
                dhg8.vertex(b14, float11 * 120.0f, float12 * 120.0f, -float12 * 40.0f * arr9[3]).color(arr9[0], arr9[1], arr9[2], 0.0f).endVertex();
            }
            dhg8.end();
            BufferUploader.end(dhg8);
            dhl.popPose();
            RenderSystem.shadeModel(7424);
        }
        RenderSystem.enableTexture();
        RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
        dhl.pushPose();
        final float float6 = 1.0f - this.level.getRainLevel(float2);
        RenderSystem.color4f(1.0f, 1.0f, 1.0f, float6);
        dhl.mulPose(Vector3f.YP.rotationDegrees(-90.0f));
        dhl.mulPose(Vector3f.XP.rotationDegrees(this.level.getTimeOfDay(float2) * 360.0f));
        final Matrix4f b15 = dhl.last().pose();
        float float8 = 30.0f;
        this.textureManager.bind(LevelRenderer.SUN_LOCATION);
        dhg8.begin(7, DefaultVertexFormat.POSITION_TEX);
        dhg8.vertex(b15, -float8, 100.0f, -float8).uv(0.0f, 0.0f).endVertex();
        dhg8.vertex(b15, float8, 100.0f, -float8).uv(1.0f, 0.0f).endVertex();
        dhg8.vertex(b15, float8, 100.0f, float8).uv(1.0f, 1.0f).endVertex();
        dhg8.vertex(b15, -float8, 100.0f, float8).uv(0.0f, 1.0f).endVertex();
        dhg8.end();
        BufferUploader.end(dhg8);
        float8 = 20.0f;
        this.textureManager.bind(LevelRenderer.MOON_LOCATION);
        final int integer17 = this.level.getMoonPhase();
        final int integer18 = integer17 % 4;
        final int integer15 = integer17 / 4 % 2;
        final float float13 = (integer18 + 0) / 4.0f;
        final float float10 = (integer15 + 0) / 2.0f;
        final float float11 = (integer18 + 1) / 4.0f;
        final float float12 = (integer15 + 1) / 2.0f;
        dhg8.begin(7, DefaultVertexFormat.POSITION_TEX);
        dhg8.vertex(b15, -float8, -100.0f, float8).uv(float11, float12).endVertex();
        dhg8.vertex(b15, float8, -100.0f, float8).uv(float13, float12).endVertex();
        dhg8.vertex(b15, float8, -100.0f, -float8).uv(float13, float10).endVertex();
        dhg8.vertex(b15, -float8, -100.0f, -float8).uv(float11, float10).endVertex();
        dhg8.end();
        BufferUploader.end(dhg8);
        RenderSystem.disableTexture();
        final float float14 = this.level.getStarBrightness(float2) * float6;
        if (float14 > 0.0f) {
            RenderSystem.color4f(float14, float14, float14, float14);
            this.starBuffer.bind();
            this.skyFormat.setupBufferState(0L);
            this.starBuffer.draw(dhl.last().pose(), 7);
            VertexBuffer.unbind();
            this.skyFormat.clearBufferState();
        }
        RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.disableBlend();
        RenderSystem.enableAlphaTest();
        RenderSystem.enableFog();
        dhl.popPose();
        RenderSystem.disableTexture();
        RenderSystem.color3f(0.0f, 0.0f, 0.0f);
        final double double10 = this.minecraft.player.getEyePosition(float2).y - this.level.getLevelData().getHorizonHeight();
        if (double10 < 0.0) {
            dhl.pushPose();
            dhl.translate(0.0, 12.0, 0.0);
            this.darkBuffer.bind();
            this.skyFormat.setupBufferState(0L);
            this.darkBuffer.draw(dhl.last().pose(), 7);
            VertexBuffer.unbind();
            this.skyFormat.clearBufferState();
            dhl.popPose();
        }
        if (this.level.effects().hasGround()) {
            RenderSystem.color3f(float3 * 0.2f + 0.04f, float4 * 0.2f + 0.04f, float5 * 0.6f + 0.1f);
        }
        else {
            RenderSystem.color3f(float3, float4, float5);
        }
        RenderSystem.enableTexture();
        RenderSystem.depthMask(true);
        RenderSystem.disableFog();
    }
    
    public void renderClouds(final PoseStack dhl, final float float2, final double double3, final double double4, final double double5) {
        final float float3 = this.level.effects().getCloudHeight();
        if (Float.isNaN(float3)) {
            return;
        }
        RenderSystem.disableCull();
        RenderSystem.enableBlend();
        RenderSystem.enableAlphaTest();
        RenderSystem.enableDepthTest();
        RenderSystem.defaultAlphaFunc();
        RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        RenderSystem.enableFog();
        RenderSystem.depthMask(true);
        final float float4 = 12.0f;
        final float float5 = 4.0f;
        final double double6 = 2.0E-4;
        final double double7 = (this.ticks + float2) * 0.03f;
        double double8 = (double3 + double7) / 12.0;
        final double double9 = float3 - (float)double4 + 0.33f;
        double double10 = double5 / 12.0 + 0.33000001311302185;
        double8 -= Mth.floor(double8 / 2048.0) * 2048;
        double10 -= Mth.floor(double10 / 2048.0) * 2048;
        final float float6 = (float)(double8 - Mth.floor(double8));
        final float float7 = (float)(double9 / 4.0 - Mth.floor(double9 / 4.0)) * 4.0f;
        final float float8 = (float)(double10 - Mth.floor(double10));
        final Vec3 dem26 = this.level.getCloudColor(float2);
        final int integer27 = (int)Math.floor(double8);
        final int integer28 = (int)Math.floor(double9 / 4.0);
        final int integer29 = (int)Math.floor(double10);
        if (integer27 != this.prevCloudX || integer28 != this.prevCloudY || integer29 != this.prevCloudZ || this.minecraft.options.getCloudsType() != this.prevCloudsType || this.prevCloudColor.distanceToSqr(dem26) > 2.0E-4) {
            this.prevCloudX = integer27;
            this.prevCloudY = integer28;
            this.prevCloudZ = integer29;
            this.prevCloudColor = dem26;
            this.prevCloudsType = this.minecraft.options.getCloudsType();
            this.generateClouds = true;
        }
        if (this.generateClouds) {
            this.generateClouds = false;
            final BufferBuilder dhg30 = Tesselator.getInstance().getBuilder();
            if (this.cloudBuffer != null) {
                this.cloudBuffer.close();
            }
            this.cloudBuffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL);
            this.buildClouds(dhg30, double8, double9, double10, dem26);
            dhg30.end();
            this.cloudBuffer.upload(dhg30);
        }
        this.textureManager.bind(LevelRenderer.CLOUDS_LOCATION);
        dhl.pushPose();
        dhl.scale(12.0f, 1.0f, 12.0f);
        dhl.translate(-float6, float7, -float8);
        if (this.cloudBuffer != null) {
            this.cloudBuffer.bind();
            DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL.setupBufferState(0L);
            int integer31;
            for (int integer30 = integer31 = ((this.prevCloudsType != CloudStatus.FANCY) ? 1 : 0); integer31 < 2; ++integer31) {
                if (integer31 == 0) {
                    RenderSystem.colorMask(false, false, false, false);
                }
                else {
                    RenderSystem.colorMask(true, true, true, true);
                }
                this.cloudBuffer.draw(dhl.last().pose(), 7);
            }
            VertexBuffer.unbind();
            DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL.clearBufferState();
        }
        dhl.popPose();
        RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.disableAlphaTest();
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
        RenderSystem.disableFog();
    }
    
    private void buildClouds(final BufferBuilder dhg, final double double2, final double double3, final double double4, final Vec3 dem) {
        final float float10 = 4.0f;
        final float float11 = 0.00390625f;
        final int integer12 = 8;
        final int integer13 = 4;
        final float float12 = 9.765625E-4f;
        final float float13 = Mth.floor(double2) * 0.00390625f;
        final float float14 = Mth.floor(double4) * 0.00390625f;
        final float float15 = (float)dem.x;
        final float float16 = (float)dem.y;
        final float float17 = (float)dem.z;
        final float float18 = float15 * 0.9f;
        final float float19 = float16 * 0.9f;
        final float float20 = float17 * 0.9f;
        final float float21 = float15 * 0.7f;
        final float float22 = float16 * 0.7f;
        final float float23 = float17 * 0.7f;
        final float float24 = float15 * 0.8f;
        final float float25 = float16 * 0.8f;
        final float float26 = float17 * 0.8f;
        dhg.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL);
        final float float27 = (float)Math.floor(double3 / 4.0) * 4.0f;
        if (this.prevCloudsType == CloudStatus.FANCY) {
            for (int integer14 = -3; integer14 <= 4; ++integer14) {
                for (int integer15 = -3; integer15 <= 4; ++integer15) {
                    final float float28 = (float)(integer14 * 8);
                    final float float29 = (float)(integer15 * 8);
                    if (float27 > -5.0f) {
                        dhg.vertex(float28 + 0.0f, float27 + 0.0f, float29 + 8.0f).uv((float28 + 0.0f) * 0.00390625f + float13, (float29 + 8.0f) * 0.00390625f + float14).color(float21, float22, float23, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
                        dhg.vertex(float28 + 8.0f, float27 + 0.0f, float29 + 8.0f).uv((float28 + 8.0f) * 0.00390625f + float13, (float29 + 8.0f) * 0.00390625f + float14).color(float21, float22, float23, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
                        dhg.vertex(float28 + 8.0f, float27 + 0.0f, float29 + 0.0f).uv((float28 + 8.0f) * 0.00390625f + float13, (float29 + 0.0f) * 0.00390625f + float14).color(float21, float22, float23, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
                        dhg.vertex(float28 + 0.0f, float27 + 0.0f, float29 + 0.0f).uv((float28 + 0.0f) * 0.00390625f + float13, (float29 + 0.0f) * 0.00390625f + float14).color(float21, float22, float23, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
                    }
                    if (float27 <= 5.0f) {
                        dhg.vertex(float28 + 0.0f, float27 + 4.0f - 9.765625E-4f, float29 + 8.0f).uv((float28 + 0.0f) * 0.00390625f + float13, (float29 + 8.0f) * 0.00390625f + float14).color(float15, float16, float17, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
                        dhg.vertex(float28 + 8.0f, float27 + 4.0f - 9.765625E-4f, float29 + 8.0f).uv((float28 + 8.0f) * 0.00390625f + float13, (float29 + 8.0f) * 0.00390625f + float14).color(float15, float16, float17, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
                        dhg.vertex(float28 + 8.0f, float27 + 4.0f - 9.765625E-4f, float29 + 0.0f).uv((float28 + 8.0f) * 0.00390625f + float13, (float29 + 0.0f) * 0.00390625f + float14).color(float15, float16, float17, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
                        dhg.vertex(float28 + 0.0f, float27 + 4.0f - 9.765625E-4f, float29 + 0.0f).uv((float28 + 0.0f) * 0.00390625f + float13, (float29 + 0.0f) * 0.00390625f + float14).color(float15, float16, float17, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
                    }
                    if (integer14 > -1) {
                        for (int integer16 = 0; integer16 < 8; ++integer16) {
                            dhg.vertex(float28 + integer16 + 0.0f, float27 + 0.0f, float29 + 8.0f).uv((float28 + integer16 + 0.5f) * 0.00390625f + float13, (float29 + 8.0f) * 0.00390625f + float14).color(float18, float19, float20, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
                            dhg.vertex(float28 + integer16 + 0.0f, float27 + 4.0f, float29 + 8.0f).uv((float28 + integer16 + 0.5f) * 0.00390625f + float13, (float29 + 8.0f) * 0.00390625f + float14).color(float18, float19, float20, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
                            dhg.vertex(float28 + integer16 + 0.0f, float27 + 4.0f, float29 + 0.0f).uv((float28 + integer16 + 0.5f) * 0.00390625f + float13, (float29 + 0.0f) * 0.00390625f + float14).color(float18, float19, float20, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
                            dhg.vertex(float28 + integer16 + 0.0f, float27 + 0.0f, float29 + 0.0f).uv((float28 + integer16 + 0.5f) * 0.00390625f + float13, (float29 + 0.0f) * 0.00390625f + float14).color(float18, float19, float20, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
                        }
                    }
                    if (integer14 <= 1) {
                        for (int integer16 = 0; integer16 < 8; ++integer16) {
                            dhg.vertex(float28 + integer16 + 1.0f - 9.765625E-4f, float27 + 0.0f, float29 + 8.0f).uv((float28 + integer16 + 0.5f) * 0.00390625f + float13, (float29 + 8.0f) * 0.00390625f + float14).color(float18, float19, float20, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
                            dhg.vertex(float28 + integer16 + 1.0f - 9.765625E-4f, float27 + 4.0f, float29 + 8.0f).uv((float28 + integer16 + 0.5f) * 0.00390625f + float13, (float29 + 8.0f) * 0.00390625f + float14).color(float18, float19, float20, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
                            dhg.vertex(float28 + integer16 + 1.0f - 9.765625E-4f, float27 + 4.0f, float29 + 0.0f).uv((float28 + integer16 + 0.5f) * 0.00390625f + float13, (float29 + 0.0f) * 0.00390625f + float14).color(float18, float19, float20, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
                            dhg.vertex(float28 + integer16 + 1.0f - 9.765625E-4f, float27 + 0.0f, float29 + 0.0f).uv((float28 + integer16 + 0.5f) * 0.00390625f + float13, (float29 + 0.0f) * 0.00390625f + float14).color(float18, float19, float20, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
                        }
                    }
                    if (integer15 > -1) {
                        for (int integer16 = 0; integer16 < 8; ++integer16) {
                            dhg.vertex(float28 + 0.0f, float27 + 4.0f, float29 + integer16 + 0.0f).uv((float28 + 0.0f) * 0.00390625f + float13, (float29 + integer16 + 0.5f) * 0.00390625f + float14).color(float24, float25, float26, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
                            dhg.vertex(float28 + 8.0f, float27 + 4.0f, float29 + integer16 + 0.0f).uv((float28 + 8.0f) * 0.00390625f + float13, (float29 + integer16 + 0.5f) * 0.00390625f + float14).color(float24, float25, float26, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
                            dhg.vertex(float28 + 8.0f, float27 + 0.0f, float29 + integer16 + 0.0f).uv((float28 + 8.0f) * 0.00390625f + float13, (float29 + integer16 + 0.5f) * 0.00390625f + float14).color(float24, float25, float26, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
                            dhg.vertex(float28 + 0.0f, float27 + 0.0f, float29 + integer16 + 0.0f).uv((float28 + 0.0f) * 0.00390625f + float13, (float29 + integer16 + 0.5f) * 0.00390625f + float14).color(float24, float25, float26, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
                        }
                    }
                    if (integer15 <= 1) {
                        for (int integer16 = 0; integer16 < 8; ++integer16) {
                            dhg.vertex(float28 + 0.0f, float27 + 4.0f, float29 + integer16 + 1.0f - 9.765625E-4f).uv((float28 + 0.0f) * 0.00390625f + float13, (float29 + integer16 + 0.5f) * 0.00390625f + float14).color(float24, float25, float26, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
                            dhg.vertex(float28 + 8.0f, float27 + 4.0f, float29 + integer16 + 1.0f - 9.765625E-4f).uv((float28 + 8.0f) * 0.00390625f + float13, (float29 + integer16 + 0.5f) * 0.00390625f + float14).color(float24, float25, float26, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
                            dhg.vertex(float28 + 8.0f, float27 + 0.0f, float29 + integer16 + 1.0f - 9.765625E-4f).uv((float28 + 8.0f) * 0.00390625f + float13, (float29 + integer16 + 0.5f) * 0.00390625f + float14).color(float24, float25, float26, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
                            dhg.vertex(float28 + 0.0f, float27 + 0.0f, float29 + integer16 + 1.0f - 9.765625E-4f).uv((float28 + 0.0f) * 0.00390625f + float13, (float29 + integer16 + 0.5f) * 0.00390625f + float14).color(float24, float25, float26, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
                        }
                    }
                }
            }
        }
        else {
            final int integer14 = 1;
            final int integer15 = 32;
            for (int integer17 = -32; integer17 < 32; integer17 += 32) {
                for (int integer18 = -32; integer18 < 32; integer18 += 32) {
                    dhg.vertex(integer17 + 0, float27, integer18 + 32).uv((integer17 + 0) * 0.00390625f + float13, (integer18 + 32) * 0.00390625f + float14).color(float15, float16, float17, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
                    dhg.vertex(integer17 + 32, float27, integer18 + 32).uv((integer17 + 32) * 0.00390625f + float13, (integer18 + 32) * 0.00390625f + float14).color(float15, float16, float17, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
                    dhg.vertex(integer17 + 32, float27, integer18 + 0).uv((integer17 + 32) * 0.00390625f + float13, (integer18 + 0) * 0.00390625f + float14).color(float15, float16, float17, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
                    dhg.vertex(integer17 + 0, float27, integer18 + 0).uv((integer17 + 0) * 0.00390625f + float13, (integer18 + 0) * 0.00390625f + float14).color(float15, float16, float17, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
                }
            }
        }
    }
    
    private void compileChunksUntil(final long long1) {
        this.needsUpdate |= this.chunkRenderDispatcher.uploadAllPendingUploads();
        final long long2 = Util.getNanos();
        int integer6 = 0;
        if (!this.chunksToCompile.isEmpty()) {
            final Iterator<ChunkRenderDispatcher.RenderChunk> iterator7 = this.chunksToCompile.iterator();
            while (iterator7.hasNext()) {
                final ChunkRenderDispatcher.RenderChunk c8 = iterator7.next();
                if (c8.isDirtyFromPlayer()) {
                    this.chunkRenderDispatcher.rebuildChunkSync(c8);
                }
                else {
                    c8.rebuildChunkAsync(this.chunkRenderDispatcher);
                }
                c8.setNotDirty();
                iterator7.remove();
                ++integer6;
                final long long3 = Util.getNanos();
                final long long4 = long3 - long2;
                final long long5 = long4 / integer6;
                final long long6 = long1 - long3;
                if (long6 < long5) {
                    break;
                }
            }
        }
    }
    
    private void renderWorldBounds(final Camera dlj) {
        final BufferBuilder dhg3 = Tesselator.getInstance().getBuilder();
        final WorldBorder cgw4 = this.level.getWorldBorder();
        final double double5 = this.minecraft.options.renderDistance * 16;
        if (dlj.getPosition().x < cgw4.getMaxX() - double5 && dlj.getPosition().x > cgw4.getMinX() + double5 && dlj.getPosition().z < cgw4.getMaxZ() - double5 && dlj.getPosition().z > cgw4.getMinZ() + double5) {
            return;
        }
        double double6 = 1.0 - cgw4.getDistanceToBorder(dlj.getPosition().x, dlj.getPosition().z) / double5;
        double6 = Math.pow(double6, 4.0);
        final double double7 = dlj.getPosition().x;
        final double double8 = dlj.getPosition().y;
        final double double9 = dlj.getPosition().z;
        RenderSystem.enableBlend();
        RenderSystem.enableDepthTest();
        RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
        this.textureManager.bind(LevelRenderer.FORCEFIELD_LOCATION);
        RenderSystem.depthMask(Minecraft.useShaderTransparency());
        RenderSystem.pushMatrix();
        final int integer15 = cgw4.getStatus().getColor();
        final float float16 = (integer15 >> 16 & 0xFF) / 255.0f;
        final float float17 = (integer15 >> 8 & 0xFF) / 255.0f;
        final float float18 = (integer15 & 0xFF) / 255.0f;
        RenderSystem.color4f(float16, float17, float18, (float)double6);
        RenderSystem.polygonOffset(-3.0f, -3.0f);
        RenderSystem.enablePolygonOffset();
        RenderSystem.defaultAlphaFunc();
        RenderSystem.enableAlphaTest();
        RenderSystem.disableCull();
        final float float19 = Util.getMillis() % 3000L / 3000.0f;
        final float float20 = 0.0f;
        final float float21 = 0.0f;
        final float float22 = 128.0f;
        dhg3.begin(7, DefaultVertexFormat.POSITION_TEX);
        double double10 = Math.max(Mth.floor(double9 - double5), cgw4.getMinZ());
        double double11 = Math.min(Mth.ceil(double9 + double5), cgw4.getMaxZ());
        if (double7 > cgw4.getMaxX() - double5) {
            float float23 = 0.0f;
            for (double double12 = double10; double12 < double11; ++double12, float23 += 0.5f) {
                final double double13 = Math.min(1.0, double11 - double12);
                final float float24 = (float)double13 * 0.5f;
                this.vertex(dhg3, double7, double8, double9, cgw4.getMaxX(), 256, double12, float19 + float23, float19 + 0.0f);
                this.vertex(dhg3, double7, double8, double9, cgw4.getMaxX(), 256, double12 + double13, float19 + float24 + float23, float19 + 0.0f);
                this.vertex(dhg3, double7, double8, double9, cgw4.getMaxX(), 0, double12 + double13, float19 + float24 + float23, float19 + 128.0f);
                this.vertex(dhg3, double7, double8, double9, cgw4.getMaxX(), 0, double12, float19 + float23, float19 + 128.0f);
            }
        }
        if (double7 < cgw4.getMinX() + double5) {
            float float23 = 0.0f;
            for (double double12 = double10; double12 < double11; ++double12, float23 += 0.5f) {
                final double double13 = Math.min(1.0, double11 - double12);
                final float float24 = (float)double13 * 0.5f;
                this.vertex(dhg3, double7, double8, double9, cgw4.getMinX(), 256, double12, float19 + float23, float19 + 0.0f);
                this.vertex(dhg3, double7, double8, double9, cgw4.getMinX(), 256, double12 + double13, float19 + float24 + float23, float19 + 0.0f);
                this.vertex(dhg3, double7, double8, double9, cgw4.getMinX(), 0, double12 + double13, float19 + float24 + float23, float19 + 128.0f);
                this.vertex(dhg3, double7, double8, double9, cgw4.getMinX(), 0, double12, float19 + float23, float19 + 128.0f);
            }
        }
        double10 = Math.max(Mth.floor(double7 - double5), cgw4.getMinX());
        double11 = Math.min(Mth.ceil(double7 + double5), cgw4.getMaxX());
        if (double9 > cgw4.getMaxZ() - double5) {
            float float23 = 0.0f;
            for (double double12 = double10; double12 < double11; ++double12, float23 += 0.5f) {
                final double double13 = Math.min(1.0, double11 - double12);
                final float float24 = (float)double13 * 0.5f;
                this.vertex(dhg3, double7, double8, double9, double12, 256, cgw4.getMaxZ(), float19 + float23, float19 + 0.0f);
                this.vertex(dhg3, double7, double8, double9, double12 + double13, 256, cgw4.getMaxZ(), float19 + float24 + float23, float19 + 0.0f);
                this.vertex(dhg3, double7, double8, double9, double12 + double13, 0, cgw4.getMaxZ(), float19 + float24 + float23, float19 + 128.0f);
                this.vertex(dhg3, double7, double8, double9, double12, 0, cgw4.getMaxZ(), float19 + float23, float19 + 128.0f);
            }
        }
        if (double9 < cgw4.getMinZ() + double5) {
            float float23 = 0.0f;
            for (double double12 = double10; double12 < double11; ++double12, float23 += 0.5f) {
                final double double13 = Math.min(1.0, double11 - double12);
                final float float24 = (float)double13 * 0.5f;
                this.vertex(dhg3, double7, double8, double9, double12, 256, cgw4.getMinZ(), float19 + float23, float19 + 0.0f);
                this.vertex(dhg3, double7, double8, double9, double12 + double13, 256, cgw4.getMinZ(), float19 + float24 + float23, float19 + 0.0f);
                this.vertex(dhg3, double7, double8, double9, double12 + double13, 0, cgw4.getMinZ(), float19 + float24 + float23, float19 + 128.0f);
                this.vertex(dhg3, double7, double8, double9, double12, 0, cgw4.getMinZ(), float19 + float23, float19 + 128.0f);
            }
        }
        dhg3.end();
        BufferUploader.end(dhg3);
        RenderSystem.enableCull();
        RenderSystem.disableAlphaTest();
        RenderSystem.polygonOffset(0.0f, 0.0f);
        RenderSystem.disablePolygonOffset();
        RenderSystem.enableAlphaTest();
        RenderSystem.disableBlend();
        RenderSystem.popMatrix();
        RenderSystem.depthMask(true);
    }
    
    private void vertex(final BufferBuilder dhg, final double double2, final double double3, final double double4, final double double5, final int integer, final double double7, final float float8, final float float9) {
        dhg.vertex(double5 - double2, integer - double3, double7 - double4).uv(float8, float9).endVertex();
    }
    
    private void renderHitOutline(final PoseStack dhl, final VertexConsumer dhp, final Entity aom, final double double4, final double double5, final double double6, final BlockPos fu, final BlockState cfj) {
        renderShape(dhl, dhp, cfj.getShape(this.level, fu, CollisionContext.of(aom)), fu.getX() - double4, fu.getY() - double5, fu.getZ() - double6, 0.0f, 0.0f, 0.0f, 0.4f);
    }
    
    public static void renderVoxelShape(final PoseStack dhl, final VertexConsumer dhp, final VoxelShape dfg, final double double4, final double double5, final double double6, final float float7, final float float8, final float float9, final float float10) {
        final List<AABB> list14 = dfg.toAabbs();
        final int integer15 = Mth.ceil(list14.size() / 3.0);
        for (int integer16 = 0; integer16 < list14.size(); ++integer16) {
            final AABB deg17 = list14.get(integer16);
            final float float11 = (integer16 % (float)integer15 + 1.0f) / integer15;
            final float float12 = (float)(integer16 / integer15);
            final float float13 = float11 * ((float12 == 0.0f) ? 1 : 0);
            final float float14 = float11 * ((float12 == 1.0f) ? 1 : 0);
            final float float15 = float11 * ((float12 == 2.0f) ? 1 : 0);
            renderShape(dhl, dhp, Shapes.create(deg17.move(0.0, 0.0, 0.0)), double4, double5, double6, float13, float14, float15, 1.0f);
        }
    }
    
    private static void renderShape(final PoseStack dhl, final VertexConsumer dhp, final VoxelShape dfg, final double double4, final double double5, final double double6, final float float7, final float float8, final float float9, final float float10) {
        final Matrix4f b14 = dhl.last().pose();
        final Matrix4f matrix4f;
        dfg.forAllEdges((double10, double11, double12, double13, double14, double15) -> {
            dhp.vertex(matrix4f, (float)(double10 + double4), (float)(double11 + double5), (float)(double12 + double6)).color(float7, float8, float9, float10).endVertex();
            dhp.vertex(matrix4f, (float)(double13 + double4), (float)(double14 + double5), (float)(double15 + double6)).color(float7, float8, float9, float10).endVertex();
        });
    }
    
    public static void renderLineBox(final PoseStack dhl, final VertexConsumer dhp, final AABB deg, final float float4, final float float5, final float float6, final float float7) {
        renderLineBox(dhl, dhp, deg.minX, deg.minY, deg.minZ, deg.maxX, deg.maxY, deg.maxZ, float4, float5, float6, float7, float4, float5, float6);
    }
    
    public static void renderLineBox(final PoseStack dhl, final VertexConsumer dhp, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8, final float float9, final float float10, final float float11, final float float12) {
        renderLineBox(dhl, dhp, double3, double4, double5, double6, double7, double8, float9, float10, float11, float12, float9, float10, float11);
    }
    
    public static void renderLineBox(final PoseStack dhl, final VertexConsumer dhp, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8, final float float9, final float float10, final float float11, final float float12, final float float13, final float float14, final float float15) {
        final Matrix4f b22 = dhl.last().pose();
        final float float16 = (float)double3;
        final float float17 = (float)double4;
        final float float18 = (float)double5;
        final float float19 = (float)double6;
        final float float20 = (float)double7;
        final float float21 = (float)double8;
        dhp.vertex(b22, float16, float17, float18).color(float9, float14, float15, float12).endVertex();
        dhp.vertex(b22, float19, float17, float18).color(float9, float14, float15, float12).endVertex();
        dhp.vertex(b22, float16, float17, float18).color(float13, float10, float15, float12).endVertex();
        dhp.vertex(b22, float16, float20, float18).color(float13, float10, float15, float12).endVertex();
        dhp.vertex(b22, float16, float17, float18).color(float13, float14, float11, float12).endVertex();
        dhp.vertex(b22, float16, float17, float21).color(float13, float14, float11, float12).endVertex();
        dhp.vertex(b22, float19, float17, float18).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float20, float18).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float20, float18).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float16, float20, float18).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float16, float20, float18).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float16, float20, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float16, float20, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float16, float17, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float16, float17, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float17, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float17, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float17, float18).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float16, float20, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float20, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float17, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float20, float21).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float20, float18).color(float9, float10, float11, float12).endVertex();
        dhp.vertex(b22, float19, float20, float21).color(float9, float10, float11, float12).endVertex();
    }
    
    public static void addChainedFilledBoxVertices(final BufferBuilder dhg, final double double2, final double double3, final double double4, final double double5, final double double6, final double double7, final float float8, final float float9, final float float10, final float float11) {
        dhg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double3, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double6, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double6, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double6, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double3, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double3, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double3, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double3, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double6, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double6, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double3, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double6, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double3, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double3, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double3, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double3, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double6, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double6, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double2, double6, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double6, double4).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
        dhg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
    }
    
    public void blockChanged(final BlockGetter bpg, final BlockPos fu, final BlockState cfj3, final BlockState cfj4, final int integer) {
        this.setBlockDirty(fu, (integer & 0x8) != 0x0);
    }
    
    private void setBlockDirty(final BlockPos fu, final boolean boolean2) {
        for (int integer4 = fu.getZ() - 1; integer4 <= fu.getZ() + 1; ++integer4) {
            for (int integer5 = fu.getX() - 1; integer5 <= fu.getX() + 1; ++integer5) {
                for (int integer6 = fu.getY() - 1; integer6 <= fu.getY() + 1; ++integer6) {
                    this.setSectionDirty(integer5 >> 4, integer6 >> 4, integer4 >> 4, boolean2);
                }
            }
        }
    }
    
    public void setBlocksDirty(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6) {
        for (int integer7 = integer3 - 1; integer7 <= integer6 + 1; ++integer7) {
            for (int integer8 = integer1 - 1; integer8 <= integer4 + 1; ++integer8) {
                for (int integer9 = integer2 - 1; integer9 <= integer5 + 1; ++integer9) {
                    this.setSectionDirty(integer8 >> 4, integer9 >> 4, integer7 >> 4);
                }
            }
        }
    }
    
    public void setBlockDirty(final BlockPos fu, final BlockState cfj2, final BlockState cfj3) {
        if (this.minecraft.getModelManager().requiresRender(cfj2, cfj3)) {
            this.setBlocksDirty(fu.getX(), fu.getY(), fu.getZ(), fu.getX(), fu.getY(), fu.getZ());
        }
    }
    
    public void setSectionDirtyWithNeighbors(final int integer1, final int integer2, final int integer3) {
        for (int integer4 = integer3 - 1; integer4 <= integer3 + 1; ++integer4) {
            for (int integer5 = integer1 - 1; integer5 <= integer1 + 1; ++integer5) {
                for (int integer6 = integer2 - 1; integer6 <= integer2 + 1; ++integer6) {
                    this.setSectionDirty(integer5, integer6, integer4);
                }
            }
        }
    }
    
    public void setSectionDirty(final int integer1, final int integer2, final int integer3) {
        this.setSectionDirty(integer1, integer2, integer3, false);
    }
    
    private void setSectionDirty(final int integer1, final int integer2, final int integer3, final boolean boolean4) {
        this.viewArea.setDirty(integer1, integer2, integer3, boolean4);
    }
    
    public void playStreamingMusic(@Nullable final SoundEvent ack, final BlockPos fu) {
        SoundInstance eom4 = this.playingRecords.get(fu);
        if (eom4 != null) {
            this.minecraft.getSoundManager().stop(eom4);
            this.playingRecords.remove(fu);
        }
        if (ack != null) {
            final RecordItem bkx5 = RecordItem.getBySound(ack);
            if (bkx5 != null) {
                this.minecraft.gui.setNowPlaying(bkx5.getDisplayName());
            }
            eom4 = SimpleSoundInstance.forRecord(ack, fu.getX(), fu.getY(), fu.getZ());
            this.playingRecords.put(fu, eom4);
            this.minecraft.getSoundManager().play(eom4);
        }
        this.notifyNearbyEntities(this.level, fu, ack != null);
    }
    
    private void notifyNearbyEntities(final Level bqb, final BlockPos fu, final boolean boolean3) {
        final List<LivingEntity> list5 = bqb.<LivingEntity>getEntitiesOfClass(LivingEntity.class, new AABB(fu).inflate(3.0));
        for (final LivingEntity aoy7 : list5) {
            aoy7.setRecordPlayingNearby(fu, boolean3);
        }
    }
    
    public void addParticle(final ParticleOptions hf, final boolean boolean2, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
        this.addParticle(hf, boolean2, false, double3, double4, double5, double6, double7, double8);
    }
    
    public void addParticle(final ParticleOptions hf, final boolean boolean2, final boolean boolean3, final double double4, final double double5, final double double6, final double double7, final double double8, final double double9) {
        try {
            this.addParticleInternal(hf, boolean2, boolean3, double4, double5, double6, double7, double8, double9);
        }
        catch (Throwable throwable17) {
            final CrashReport j18 = CrashReport.forThrowable(throwable17, "Exception while adding particle");
            final CrashReportCategory k19 = j18.addCategory("Particle being added");
            k19.setDetail("ID", Registry.PARTICLE_TYPE.getKey(hf.getType()));
            k19.setDetail("Parameters", hf.writeToString());
            k19.setDetail("Position", () -> CrashReportCategory.formatLocation(double4, double5, double6));
            throw new ReportedException(j18);
        }
    }
    
    private <T extends ParticleOptions> void addParticle(final T hf, final double double2, final double double3, final double double4, final double double5, final double double6, final double double7) {
        this.addParticle(hf, hf.getType().getOverrideLimiter(), double2, double3, double4, double5, double6, double7);
    }
    
    @Nullable
    private Particle addParticleInternal(final ParticleOptions hf, final boolean boolean2, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
        return this.addParticleInternal(hf, boolean2, false, double3, double4, double5, double6, double7, double8);
    }
    
    @Nullable
    private Particle addParticleInternal(final ParticleOptions hf, final boolean boolean2, final boolean boolean3, final double double4, final double double5, final double double6, final double double7, final double double8, final double double9) {
        final Camera dlj17 = this.minecraft.gameRenderer.getMainCamera();
        if (this.minecraft == null || !dlj17.isInitialized() || this.minecraft.particleEngine == null) {
            return null;
        }
        final ParticleStatus dmc18 = this.calculateParticleLevel(boolean3);
        if (boolean2) {
            return this.minecraft.particleEngine.createParticle(hf, double4, double5, double6, double7, double8, double9);
        }
        if (dlj17.getPosition().distanceToSqr(double4, double5, double6) > 1024.0) {
            return null;
        }
        if (dmc18 == ParticleStatus.MINIMAL) {
            return null;
        }
        return this.minecraft.particleEngine.createParticle(hf, double4, double5, double6, double7, double8, double9);
    }
    
    private ParticleStatus calculateParticleLevel(final boolean boolean1) {
        ParticleStatus dmc3 = this.minecraft.options.particles;
        if (boolean1 && dmc3 == ParticleStatus.MINIMAL && this.level.random.nextInt(10) == 0) {
            dmc3 = ParticleStatus.DECREASED;
        }
        if (dmc3 == ParticleStatus.DECREASED && this.level.random.nextInt(3) == 0) {
            dmc3 = ParticleStatus.MINIMAL;
        }
        return dmc3;
    }
    
    public void clear() {
    }
    
    public void globalLevelEvent(final int integer1, final BlockPos fu, final int integer3) {
        switch (integer1) {
            case 1023:
            case 1028:
            case 1038: {
                final Camera dlj5 = this.minecraft.gameRenderer.getMainCamera();
                if (!dlj5.isInitialized()) {
                    break;
                }
                final double double6 = fu.getX() - dlj5.getPosition().x;
                final double double7 = fu.getY() - dlj5.getPosition().y;
                final double double8 = fu.getZ() - dlj5.getPosition().z;
                final double double9 = Math.sqrt(double6 * double6 + double7 * double7 + double8 * double8);
                double double10 = dlj5.getPosition().x;
                double double11 = dlj5.getPosition().y;
                double double12 = dlj5.getPosition().z;
                if (double9 > 0.0) {
                    double10 += double6 / double9 * 2.0;
                    double11 += double7 / double9 * 2.0;
                    double12 += double8 / double9 * 2.0;
                }
                if (integer1 == 1023) {
                    this.level.playLocalSound(double10, double11, double12, SoundEvents.WITHER_SPAWN, SoundSource.HOSTILE, 1.0f, 1.0f, false);
                    break;
                }
                if (integer1 == 1038) {
                    this.level.playLocalSound(double10, double11, double12, SoundEvents.END_PORTAL_SPAWN, SoundSource.HOSTILE, 1.0f, 1.0f, false);
                    break;
                }
                this.level.playLocalSound(double10, double11, double12, SoundEvents.ENDER_DRAGON_DEATH, SoundSource.HOSTILE, 5.0f, 1.0f, false);
                break;
            }
        }
    }
    
    public void levelEvent(final Player bec, final int integer2, final BlockPos fu, final int integer4) {
        final Random random6 = this.level.random;
        switch (integer2) {
            case 1035: {
                this.level.playLocalSound(fu, SoundEvents.BREWING_STAND_BREW, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                break;
            }
            case 1033: {
                this.level.playLocalSound(fu, SoundEvents.CHORUS_FLOWER_GROW, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                break;
            }
            case 1034: {
                this.level.playLocalSound(fu, SoundEvents.CHORUS_FLOWER_DEATH, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                break;
            }
            case 1032: {
                this.minecraft.getSoundManager().play(SimpleSoundInstance.forLocalAmbience(SoundEvents.PORTAL_TRAVEL, random6.nextFloat() * 0.4f + 0.8f, 0.25f));
                break;
            }
            case 1001: {
                this.level.playLocalSound(fu, SoundEvents.DISPENSER_FAIL, SoundSource.BLOCKS, 1.0f, 1.2f, false);
                break;
            }
            case 1000: {
                this.level.playLocalSound(fu, SoundEvents.DISPENSER_DISPENSE, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                break;
            }
            case 1003: {
                this.level.playLocalSound(fu, SoundEvents.ENDER_EYE_LAUNCH, SoundSource.NEUTRAL, 1.0f, 1.2f, false);
                break;
            }
            case 1004: {
                this.level.playLocalSound(fu, SoundEvents.FIREWORK_ROCKET_SHOOT, SoundSource.NEUTRAL, 1.0f, 1.2f, false);
                break;
            }
            case 1002: {
                this.level.playLocalSound(fu, SoundEvents.DISPENSER_LAUNCH, SoundSource.BLOCKS, 1.0f, 1.2f, false);
                break;
            }
            case 2000: {
                final Direction fz7 = Direction.from3DDataValue(integer4);
                final int integer5 = fz7.getStepX();
                final int integer6 = fz7.getStepY();
                final int integer7 = fz7.getStepZ();
                final double double11 = fu.getX() + integer5 * 0.6 + 0.5;
                final double double12 = fu.getY() + integer6 * 0.6 + 0.5;
                final double double13 = fu.getZ() + integer7 * 0.6 + 0.5;
                for (int integer8 = 0; integer8 < 10; ++integer8) {
                    final double double14 = random6.nextDouble() * 0.2 + 0.01;
                    final double double15 = double11 + integer5 * 0.01 + (random6.nextDouble() - 0.5) * integer7 * 0.5;
                    final double double16 = double12 + integer6 * 0.01 + (random6.nextDouble() - 0.5) * integer6 * 0.5;
                    final double double17 = double13 + integer7 * 0.01 + (random6.nextDouble() - 0.5) * integer5 * 0.5;
                    final double double18 = integer5 * double14 + random6.nextGaussian() * 0.01;
                    final double double19 = integer6 * double14 + random6.nextGaussian() * 0.01;
                    final double double20 = integer7 * double14 + random6.nextGaussian() * 0.01;
                    this.<SimpleParticleType>addParticle(ParticleTypes.SMOKE, double15, double16, double17, double18, double19, double20);
                }
                break;
            }
            case 2003: {
                final double double21 = fu.getX() + 0.5;
                final double double22 = fu.getY();
                final double double11 = fu.getZ() + 0.5;
                for (int integer9 = 0; integer9 < 8; ++integer9) {
                    this.<ItemParticleOption>addParticle(new ItemParticleOption(ParticleTypes.ITEM, new ItemStack(Items.ENDER_EYE)), double21, double22, double11, random6.nextGaussian() * 0.15, random6.nextDouble() * 0.2, random6.nextGaussian() * 0.15);
                }
                for (double double12 = 0.0; double12 < 6.283185307179586; double12 += 0.15707963267948966) {
                    this.<SimpleParticleType>addParticle(ParticleTypes.PORTAL, double21 + Math.cos(double12) * 5.0, double22 - 0.4, double11 + Math.sin(double12) * 5.0, Math.cos(double12) * -5.0, 0.0, Math.sin(double12) * -5.0);
                    this.<SimpleParticleType>addParticle(ParticleTypes.PORTAL, double21 + Math.cos(double12) * 5.0, double22 - 0.4, double11 + Math.sin(double12) * 5.0, Math.cos(double12) * -7.0, 0.0, Math.sin(double12) * -7.0);
                }
                break;
            }
            case 2002:
            case 2007: {
                final Vec3 dem7 = Vec3.atBottomCenterOf(fu);
                for (int integer5 = 0; integer5 < 8; ++integer5) {
                    this.<ItemParticleOption>addParticle(new ItemParticleOption(ParticleTypes.ITEM, new ItemStack(Items.SPLASH_POTION)), dem7.x, dem7.y, dem7.z, random6.nextGaussian() * 0.15, random6.nextDouble() * 0.2, random6.nextGaussian() * 0.15);
                }
                final float float8 = (integer4 >> 16 & 0xFF) / 255.0f;
                final float float9 = (integer4 >> 8 & 0xFF) / 255.0f;
                final float float10 = (integer4 >> 0 & 0xFF) / 255.0f;
                final ParticleOptions hf11 = (integer2 == 2007) ? ParticleTypes.INSTANT_EFFECT : ParticleTypes.EFFECT;
                for (int integer10 = 0; integer10 < 100; ++integer10) {
                    final double double12 = random6.nextDouble() * 4.0;
                    final double double13 = random6.nextDouble() * 3.141592653589793 * 2.0;
                    final double double23 = Math.cos(double13) * double12;
                    final double double24 = 0.01 + random6.nextDouble() * 0.5;
                    final double double25 = Math.sin(double13) * double12;
                    final Particle dzz23 = this.addParticleInternal(hf11, hf11.getType().getOverrideLimiter(), dem7.x + double23 * 0.1, dem7.y + 0.3, dem7.z + double25 * 0.1, double23, double24, double25);
                    if (dzz23 != null) {
                        final float float11 = 0.75f + random6.nextFloat() * 0.25f;
                        dzz23.setColor(float8 * float11, float9 * float11, float10 * float11);
                        dzz23.setPower((float)double12);
                    }
                }
                this.level.playLocalSound(fu, SoundEvents.SPLASH_POTION_BREAK, SoundSource.NEUTRAL, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 2001: {
                final BlockState cfj7 = Block.stateById(integer4);
                if (!cfj7.isAir()) {
                    final SoundType cbh8 = cfj7.getSoundType();
                    this.level.playLocalSound(fu, cbh8.getBreakSound(), SoundSource.BLOCKS, (cbh8.getVolume() + 1.0f) / 2.0f, cbh8.getPitch() * 0.8f, false);
                }
                this.minecraft.particleEngine.destroy(fu, cfj7);
                break;
            }
            case 2004: {
                for (int integer5 = 0; integer5 < 20; ++integer5) {
                    final double double22 = fu.getX() + 0.5 + (random6.nextDouble() - 0.5) * 2.0;
                    final double double11 = fu.getY() + 0.5 + (random6.nextDouble() - 0.5) * 2.0;
                    final double double12 = fu.getZ() + 0.5 + (random6.nextDouble() - 0.5) * 2.0;
                    this.level.addParticle(ParticleTypes.SMOKE, double22, double11, double12, 0.0, 0.0, 0.0);
                    this.level.addParticle(ParticleTypes.FLAME, double22, double11, double12, 0.0, 0.0, 0.0);
                }
                break;
            }
            case 2005: {
                BoneMealItem.addGrowthParticles(this.level, fu, integer4);
                break;
            }
            case 2008: {
                this.level.addParticle(ParticleTypes.EXPLOSION, fu.getX() + 0.5, fu.getY() + 0.5, fu.getZ() + 0.5, 0.0, 0.0, 0.0);
                break;
            }
            case 1500: {
                ComposterBlock.handleFill(this.level, fu, integer4 > 0);
                break;
            }
            case 1501: {
                this.level.playLocalSound(fu, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.5f, 2.6f + (random6.nextFloat() - random6.nextFloat()) * 0.8f, false);
                for (int integer5 = 0; integer5 < 8; ++integer5) {
                    this.level.addParticle(ParticleTypes.LARGE_SMOKE, fu.getX() + random6.nextDouble(), fu.getY() + 1.2, fu.getZ() + random6.nextDouble(), 0.0, 0.0, 0.0);
                }
                break;
            }
            case 1502: {
                this.level.playLocalSound(fu, SoundEvents.REDSTONE_TORCH_BURNOUT, SoundSource.BLOCKS, 0.5f, 2.6f + (random6.nextFloat() - random6.nextFloat()) * 0.8f, false);
                for (int integer5 = 0; integer5 < 5; ++integer5) {
                    final double double22 = fu.getX() + random6.nextDouble() * 0.6 + 0.2;
                    final double double11 = fu.getY() + random6.nextDouble() * 0.6 + 0.2;
                    final double double12 = fu.getZ() + random6.nextDouble() * 0.6 + 0.2;
                    this.level.addParticle(ParticleTypes.SMOKE, double22, double11, double12, 0.0, 0.0, 0.0);
                }
                break;
            }
            case 1503: {
                this.level.playLocalSound(fu, SoundEvents.END_PORTAL_FRAME_FILL, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                for (int integer5 = 0; integer5 < 16; ++integer5) {
                    final double double22 = fu.getX() + (5.0 + random6.nextDouble() * 6.0) / 16.0;
                    final double double11 = fu.getY() + 0.8125;
                    final double double12 = fu.getZ() + (5.0 + random6.nextDouble() * 6.0) / 16.0;
                    this.level.addParticle(ParticleTypes.SMOKE, double22, double11, double12, 0.0, 0.0, 0.0);
                }
                break;
            }
            case 2006: {
                for (int integer5 = 0; integer5 < 200; ++integer5) {
                    final float float9 = random6.nextFloat() * 4.0f;
                    final float float10 = random6.nextFloat() * 6.2831855f;
                    final double double11 = Mth.cos(float10) * float9;
                    final double double12 = 0.01 + random6.nextDouble() * 0.5;
                    final double double13 = Mth.sin(float10) * float9;
                    final Particle dzz24 = this.addParticleInternal(ParticleTypes.DRAGON_BREATH, false, fu.getX() + double11 * 0.1, fu.getY() + 0.3, fu.getZ() + double13 * 0.1, double11, double12, double13);
                    if (dzz24 != null) {
                        dzz24.setPower(float9);
                    }
                }
                if (integer4 == 1) {
                    this.level.playLocalSound(fu, SoundEvents.DRAGON_FIREBALL_EXPLODE, SoundSource.HOSTILE, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                    break;
                }
                break;
            }
            case 2009: {
                for (int integer5 = 0; integer5 < 8; ++integer5) {
                    this.level.addParticle(ParticleTypes.CLOUD, fu.getX() + random6.nextDouble(), fu.getY() + 1.2, fu.getZ() + random6.nextDouble(), 0.0, 0.0, 0.0);
                }
                break;
            }
            case 1012: {
                this.level.playLocalSound(fu, SoundEvents.WOODEN_DOOR_CLOSE, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1036: {
                this.level.playLocalSound(fu, SoundEvents.IRON_TRAPDOOR_CLOSE, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1013: {
                this.level.playLocalSound(fu, SoundEvents.WOODEN_TRAPDOOR_CLOSE, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1014: {
                this.level.playLocalSound(fu, SoundEvents.FENCE_GATE_CLOSE, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1011: {
                this.level.playLocalSound(fu, SoundEvents.IRON_DOOR_CLOSE, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1006: {
                this.level.playLocalSound(fu, SoundEvents.WOODEN_DOOR_OPEN, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1007: {
                this.level.playLocalSound(fu, SoundEvents.WOODEN_TRAPDOOR_OPEN, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1037: {
                this.level.playLocalSound(fu, SoundEvents.IRON_TRAPDOOR_OPEN, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1008: {
                this.level.playLocalSound(fu, SoundEvents.FENCE_GATE_OPEN, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1005: {
                this.level.playLocalSound(fu, SoundEvents.IRON_DOOR_OPEN, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1009: {
                this.level.playLocalSound(fu, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5f, 2.6f + (random6.nextFloat() - random6.nextFloat()) * 0.8f, false);
                break;
            }
            case 1029: {
                this.level.playLocalSound(fu, SoundEvents.ANVIL_DESTROY, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1030: {
                this.level.playLocalSound(fu, SoundEvents.ANVIL_USE, SoundSource.BLOCKS, 1.0f, random6.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1044: {
                this.level.playLocalSound(fu, SoundEvents.SMITHING_TABLE_USE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1031: {
                this.level.playLocalSound(fu, SoundEvents.ANVIL_LAND, SoundSource.BLOCKS, 0.3f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1039: {
                this.level.playLocalSound(fu, SoundEvents.PHANTOM_BITE, SoundSource.HOSTILE, 0.3f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1010: {
                if (Item.byId(integer4) instanceof RecordItem) {
                    this.playStreamingMusic(((RecordItem)Item.byId(integer4)).getSound(), fu);
                    break;
                }
                this.playStreamingMusic(null, fu);
                break;
            }
            case 1015: {
                this.level.playLocalSound(fu, SoundEvents.GHAST_WARN, SoundSource.HOSTILE, 10.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1017: {
                this.level.playLocalSound(fu, SoundEvents.ENDER_DRAGON_SHOOT, SoundSource.HOSTILE, 10.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1016: {
                this.level.playLocalSound(fu, SoundEvents.GHAST_SHOOT, SoundSource.HOSTILE, 10.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1019: {
                this.level.playLocalSound(fu, SoundEvents.ZOMBIE_ATTACK_WOODEN_DOOR, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1022: {
                this.level.playLocalSound(fu, SoundEvents.WITHER_BREAK_BLOCK, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1021: {
                this.level.playLocalSound(fu, SoundEvents.ZOMBIE_BREAK_WOODEN_DOOR, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1020: {
                this.level.playLocalSound(fu, SoundEvents.ZOMBIE_ATTACK_IRON_DOOR, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1018: {
                this.level.playLocalSound(fu, SoundEvents.BLAZE_SHOOT, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1024: {
                this.level.playLocalSound(fu, SoundEvents.WITHER_SHOOT, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1026: {
                this.level.playLocalSound(fu, SoundEvents.ZOMBIE_INFECT, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1027: {
                this.level.playLocalSound(fu, SoundEvents.ZOMBIE_VILLAGER_CONVERTED, SoundSource.NEUTRAL, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1040: {
                this.level.playLocalSound(fu, SoundEvents.ZOMBIE_CONVERTED_TO_DROWNED, SoundSource.NEUTRAL, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1041: {
                this.level.playLocalSound(fu, SoundEvents.HUSK_CONVERTED_TO_ZOMBIE, SoundSource.NEUTRAL, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1025: {
                this.level.playLocalSound(fu, SoundEvents.BAT_TAKEOFF, SoundSource.NEUTRAL, 0.05f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1042: {
                this.level.playLocalSound(fu, SoundEvents.GRINDSTONE_USE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1043: {
                this.level.playLocalSound(fu, SoundEvents.BOOK_PAGE_TURN, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 3000: {
                this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, true, fu.getX() + 0.5, fu.getY() + 0.5, fu.getZ() + 0.5, 0.0, 0.0, 0.0);
                this.level.playLocalSound(fu, SoundEvents.END_GATEWAY_SPAWN, SoundSource.BLOCKS, 10.0f, (1.0f + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2f) * 0.7f, false);
                break;
            }
            case 3001: {
                this.level.playLocalSound(fu, SoundEvents.ENDER_DRAGON_GROWL, SoundSource.HOSTILE, 64.0f, 0.8f + this.level.random.nextFloat() * 0.3f, false);
                break;
            }
        }
    }
    
    public void destroyBlockProgress(final int integer1, final BlockPos fu, final int integer3) {
        if (integer3 < 0 || integer3 >= 10) {
            final BlockDestructionProgress yn5 = (BlockDestructionProgress)this.destroyingBlocks.remove(integer1);
            if (yn5 != null) {
                this.removeProgress(yn5);
            }
        }
        else {
            BlockDestructionProgress yn5 = (BlockDestructionProgress)this.destroyingBlocks.get(integer1);
            if (yn5 != null) {
                this.removeProgress(yn5);
            }
            if (yn5 == null || yn5.getPos().getX() != fu.getX() || yn5.getPos().getY() != fu.getY() || yn5.getPos().getZ() != fu.getZ()) {
                yn5 = new BlockDestructionProgress(integer1, fu);
                this.destroyingBlocks.put(integer1, yn5);
            }
            yn5.setProgress(integer3);
            yn5.updateTick(this.ticks);
            ((SortedSet)this.destructionProgress.computeIfAbsent(yn5.getPos().asLong(), long1 -> Sets.<Comparable>newTreeSet())).add(yn5);
        }
    }
    
    public boolean hasRenderedAllChunks() {
        return this.chunksToCompile.isEmpty() && this.chunkRenderDispatcher.isQueueEmpty();
    }
    
    public void needsUpdate() {
        this.needsUpdate = true;
        this.generateClouds = true;
    }
    
    public void updateGlobalBlockEntities(final Collection<BlockEntity> collection1, final Collection<BlockEntity> collection2) {
        synchronized (this.globalBlockEntities) {
            this.globalBlockEntities.removeAll(collection1);
            this.globalBlockEntities.addAll(collection2);
        }
    }
    
    public static int getLightColor(final BlockAndTintGetter bpe, final BlockPos fu) {
        return getLightColor(bpe, bpe.getBlockState(fu), fu);
    }
    
    public static int getLightColor(final BlockAndTintGetter bpe, final BlockState cfj, final BlockPos fu) {
        if (cfj.emissiveRendering(bpe, fu)) {
            return 15728880;
        }
        final int integer4 = bpe.getBrightness(LightLayer.SKY, fu);
        int integer5 = bpe.getBrightness(LightLayer.BLOCK, fu);
        final int integer6 = cfj.getLightEmission();
        if (integer5 < integer6) {
            integer5 = integer6;
        }
        return integer4 << 20 | integer5 << 4;
    }
    
    @Nullable
    public RenderTarget entityTarget() {
        return this.entityTarget;
    }
    
    @Nullable
    public RenderTarget getTranslucentTarget() {
        return this.translucentTarget;
    }
    
    @Nullable
    public RenderTarget getItemEntityTarget() {
        return this.itemEntityTarget;
    }
    
    @Nullable
    public RenderTarget getParticlesTarget() {
        return this.particlesTarget;
    }
    
    @Nullable
    public RenderTarget getWeatherTarget() {
        return this.weatherTarget;
    }
    
    @Nullable
    public RenderTarget getCloudsTarget() {
        return this.cloudsTarget;
    }
    
    static {
        LOGGER = LogManager.getLogger();
        MOON_LOCATION = new ResourceLocation("textures/environment/moon_phases.png");
        SUN_LOCATION = new ResourceLocation("textures/environment/sun.png");
        CLOUDS_LOCATION = new ResourceLocation("textures/environment/clouds.png");
        END_SKY_LOCATION = new ResourceLocation("textures/environment/end_sky.png");
        FORCEFIELD_LOCATION = new ResourceLocation("textures/misc/forcefield.png");
        RAIN_LOCATION = new ResourceLocation("textures/environment/rain.png");
        SNOW_LOCATION = new ResourceLocation("textures/environment/snow.png");
        DIRECTIONS = Direction.values();
    }
    
    class RenderChunkInfo {
        private final ChunkRenderDispatcher.RenderChunk chunk;
        private final Direction sourceDirection;
        private byte directions;
        private final int step;
        
        private RenderChunkInfo(final ChunkRenderDispatcher.RenderChunk c, @Nullable final Direction fz, final int integer) {
            this.chunk = c;
            this.sourceDirection = fz;
            this.step = integer;
        }
        
        public void setDirections(final byte byte1, final Direction fz) {
            this.directions |= (byte)(byte1 | 1 << fz.ordinal());
        }
        
        public boolean hasDirection(final Direction fz) {
            return (this.directions & 1 << fz.ordinal()) > 0;
        }
    }
    
    public static class TranparencyShaderException extends RuntimeException {
        public TranparencyShaderException(final String string, final Throwable throwable) {
            super(string, throwable);
        }
    }
}
