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.particles.ParticleType;
import net.minecraft.core.Registry;
import net.minecraft.CrashReport;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
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 net.minecraft.world.level.dimension.DimensionType;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import com.mojang.blaze3d.vertex.VertexConsumer;
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.BreakingTextureGenerator;
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.Iterator;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.client.renderer.chunk.VisGraph;
import com.mojang.math.Vector3f;
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 com.google.gson.JsonSyntaxException;
import java.io.IOException;
import net.minecraft.server.packs.resources.ResourceManager;
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.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.level.block.Blocks;
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 AutoCloseable, ResourceManagerReloadListener {
    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 RunningTrimmedMean frameTimes;
    private int ticks;
    private final Int2ObjectMap<BlockDestructionProgress> destroyingBlocks;
    private final Long2ObjectMap<SortedSet<BlockDestructionProgress>> destructionProgress;
    private final Map<BlockPos, SoundInstance> playingRecords;
    private RenderTarget entityTarget;
    private PostChain entityEffect;
    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 dbn, final RenderBuffers dqz) {
        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 = dbn;
        this.entityRenderDispatcher = dbn.getEntityRenderDispatcher();
        this.renderBuffers = dqz;
        this.textureManager = dbn.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 dqs, 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;
        }
        dqs.turnOnLightLayer();
        final Level bjw11 = this.minecraft.level;
        final int integer12 = Mth.floor(double3);
        final int integer13 = Mth.floor(double4);
        final int integer14 = Mth.floor(double5);
        final Tesselator cym15 = Tesselator.getInstance();
        final BufferBuilder cyg16 = cym15.getBuilder();
        RenderSystem.disableCull();
        RenderSystem.normal3f(0.0f, 1.0f, 0.0f);
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.defaultAlphaFunc();
        int integer15 = 5;
        if (this.minecraft.options.fancyGraphics) {
            integer15 = 10;
        }
        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 bkt28 = bjw11.getBiome(a20);
                if (bkt28.getPrecipitation() != Biome.Precipitation.NONE) {
                    final int integer20 = bjw11.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 = bkt28.getTemperature(a20);
                        if (float5 >= 0.15f) {
                            if (integer16 != 0) {
                                if (integer16 >= 0) {
                                    cym15.end();
                                }
                                integer16 = 0;
                                this.minecraft.getTextureManager().bind(LevelRenderer.RAIN_LOCATION);
                                cyg16.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(bjw11, a20);
                            cyg16.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();
                            cyg16.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();
                            cyg16.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();
                            cyg16.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) {
                                    cym15.end();
                                }
                                integer16 = 1;
                                this.minecraft.getTextureManager().bind(LevelRenderer.SNOW_LOCATION);
                                cyg16.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(bjw11, 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;
                            cyg16.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();
                            cyg16.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();
                            cyg16.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();
                            cyg16.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) {
            cym15.end();
        }
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
        RenderSystem.defaultAlphaFunc();
        dqs.turnOffLightLayer();
    }
    
    public void tickRain(final Camera dbb) {
        float float3 = this.minecraft.level.getRainLevel(1.0f);
        if (!this.minecraft.options.fancyGraphics) {
            float3 /= 2.0f;
        }
        if (float3 == 0.0f) {
            return;
        }
        final Random random4 = new Random(this.ticks * 312987231L);
        final LevelReader bjz5 = this.minecraft.level;
        final BlockPos fk6 = new BlockPos(dbb.getPosition());
        final int integer7 = 10;
        double double8 = 0.0;
        double double9 = 0.0;
        double double10 = 0.0;
        int integer8 = 0;
        int integer9 = (int)(100.0f * float3 * float3);
        if (this.minecraft.options.particles == ParticleStatus.DECREASED) {
            integer9 >>= 1;
        }
        else if (this.minecraft.options.particles == ParticleStatus.MINIMAL) {
            integer9 = 0;
        }
        for (int integer10 = 0; integer10 < integer9; ++integer10) {
            final BlockPos fk7 = bjz5.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, fk6.offset(random4.nextInt(10) - random4.nextInt(10), 0, random4.nextInt(10) - random4.nextInt(10)));
            final Biome bkt18 = bjz5.getBiome(fk7);
            final BlockPos fk8 = fk7.below();
            if (fk7.getY() <= fk6.getY() + 10 && fk7.getY() >= fk6.getY() - 10 && bkt18.getPrecipitation() == Biome.Precipitation.RAIN && bkt18.getTemperature(fk7) >= 0.15f) {
                final double double11 = random4.nextDouble();
                final double double12 = random4.nextDouble();
                final BlockState byj24 = bjz5.getBlockState(fk8);
                final FluidState coj25 = bjz5.getFluidState(fk7);
                final VoxelShape cwf26 = byj24.getCollisionShape(bjz5, fk8);
                final double double13 = cwf26.max(Direction.Axis.Y, double11, double12);
                final double double14 = coj25.getHeight(bjz5, fk7);
                double double15;
                double double16;
                if (double13 >= double14) {
                    double15 = double13;
                    double16 = cwf26.min(Direction.Axis.Y, double11, double12);
                }
                else {
                    double15 = 0.0;
                    double16 = 0.0;
                }
                if (double15 > -1.7976931348623157E308) {
                    if (coj25.is(FluidTags.LAVA) || byj24.getBlock() == Blocks.MAGMA_BLOCK || (byj24.getBlock() == Blocks.CAMPFIRE && byj24.<Boolean>getValue((Property<Boolean>)CampfireBlock.LIT))) {
                        this.minecraft.level.addParticle(ParticleTypes.SMOKE, fk7.getX() + double11, fk7.getY() + 0.1f - double16, fk7.getZ() + double12, 0.0, 0.0, 0.0);
                    }
                    else {
                        if (random4.nextInt(++integer8) == 0) {
                            double8 = fk8.getX() + double11;
                            double9 = fk8.getY() + 0.1f + double15 - 1.0;
                            double10 = fk8.getZ() + double12;
                        }
                        this.minecraft.level.addParticle(ParticleTypes.RAIN, fk8.getX() + double11, fk8.getY() + 0.1f + double15, fk8.getZ() + double12, 0.0, 0.0, 0.0);
                    }
                }
            }
        }
        if (integer8 > 0 && random4.nextInt(3) < this.rainSoundTime++) {
            this.rainSoundTime = 0;
            if (double9 > fk6.getY() + 1 && bjz5.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, fk6).getY() > Mth.floor((float)fk6.getY())) {
                this.minecraft.level.playLocalSound(double8, double9, double10, SoundEvents.WEATHER_RAIN_ABOVE, SoundSource.WEATHER, 0.1f, 0.5f, false);
            }
            else {
                this.minecraft.level.playLocalSound(double8, double9, double10, SoundEvents.WEATHER_RAIN, SoundSource.WEATHER, 0.2f, 1.0f, false);
            }
        }
    }
    
    @Override
    public void close() {
        if (this.entityEffect != null) {
            this.entityEffect.close();
        }
    }
    
    @Override
    public void onResourceManagerReload(final ResourceManager zb) {
        this.textureManager.bind(LevelRenderer.FORCEFIELD_LOCATION);
        RenderSystem.texParameter(3553, 10242, 10497);
        RenderSystem.texParameter(3553, 10243, 10497);
        RenderSystem.bindTexture(0);
        this.initOutline();
    }
    
    public void initOutline() {
        if (this.entityEffect != null) {
            this.entityEffect.close();
        }
        final ResourceLocation sm2 = new ResourceLocation("shaders/post/entity_outline.json");
        try {
            (this.entityEffect = new PostChain(this.minecraft.getTextureManager(), this.minecraft.getResourceManager(), this.minecraft.getMainRenderTarget(), sm2)).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: {}", sm2, iOException3);
            this.entityEffect = null;
            this.entityTarget = null;
        }
        catch (JsonSyntaxException jsonSyntaxException3) {
            LevelRenderer.LOGGER.warn("Failed to load shader: {}", sm2, jsonSyntaxException3);
            this.entityEffect = null;
            this.entityTarget = 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 cym2 = Tesselator.getInstance();
        final BufferBuilder cyg3 = cym2.getBuilder();
        if (this.darkBuffer != null) {
            this.darkBuffer.close();
        }
        this.darkBuffer = new VertexBuffer(this.skyFormat);
        this.drawSkyHemisphere(cyg3, -16.0f, true);
        cyg3.end();
        this.darkBuffer.upload(cyg3);
    }
    
    private void createLightSky() {
        final Tesselator cym2 = Tesselator.getInstance();
        final BufferBuilder cyg3 = cym2.getBuilder();
        if (this.skyBuffer != null) {
            this.skyBuffer.close();
        }
        this.skyBuffer = new VertexBuffer(this.skyFormat);
        this.drawSkyHemisphere(cyg3, 16.0f, false);
        cyg3.end();
        this.skyBuffer.upload(cyg3);
    }
    
    private void drawSkyHemisphere(final BufferBuilder cyg, final float float2, final boolean boolean3) {
        final int integer5 = 64;
        final int integer6 = 6;
        cyg.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);
                }
                cyg.vertex(float3, float2, integer8).endVertex();
                cyg.vertex(float4, float2, integer8).endVertex();
                cyg.vertex(float4, float2, integer8 + 64).endVertex();
                cyg.vertex(float3, float2, integer8 + 64).endVertex();
            }
        }
    }
    
    private void createStars() {
        final Tesselator cym2 = Tesselator.getInstance();
        final BufferBuilder cyg3 = cym2.getBuilder();
        if (this.starBuffer != null) {
            this.starBuffer.close();
        }
        this.starBuffer = new VertexBuffer(this.skyFormat);
        this.drawStars(cyg3);
        cyg3.end();
        this.starBuffer.upload(cyg3);
    }
    
    private void drawStars(final BufferBuilder cyg) {
        final Random random3 = new Random(10842L);
        cyg.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;
                    cyg.vertex(double10 + double31, double11 + double32, double12 + double33).endVertex();
                }
            }
        }
    }
    
    public void setLevel(@Nullable final ClientLevel dno) {
        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(dno);
        this.level = dno;
        if (dno != 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;
        }
        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(this.minecraft.options.fancyGraphics);
        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 akq2 = this.minecraft.getCameraEntity();
            if (akq2 != null) {
                this.viewArea.repositionCamera(akq2.getX(), akq2.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);
        }
    }
    
    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 dbb, final Frustum dtm, final boolean boolean3, final int integer, final boolean boolean5) {
        final Vec3 cvl7 = dbb.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(cvl7);
        this.level.getProfiler().popPush("cull");
        this.minecraft.getProfiler().popPush("culling");
        final BlockPos fk14 = dbb.getBlockPosition();
        final ChunkRenderDispatcher.RenderChunk c15 = this.viewArea.getRenderChunkAt(fk14);
        final int integer2 = 16;
        final BlockPos fk15 = new BlockPos(Mth.floor(cvl7.x / 16.0) * 16, Mth.floor(cvl7.y / 16.0) * 16, Mth.floor(cvl7.z / 16.0) * 16);
        final float float18 = dbb.getXRot();
        final float float19 = dbb.getYRot();
        this.needsUpdate = (this.needsUpdate || !this.chunksToCompile.isEmpty() || cvl7.x != this.prevCamX || cvl7.y != this.prevCamY || cvl7.z != this.prevCamZ || float18 != this.prevCamRotX || float19 != this.prevCamRotY);
        this.prevCamX = cvl7.x;
        this.prevCamY = cvl7.y;
        this.prevCamZ = cvl7.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));
            boolean boolean6 = this.minecraft.smartCull;
            if (c15 == null) {
                final int integer3 = (fk14.getY() > 0) ? 248 : 8;
                final int integer4 = Mth.floor(cvl7.x / 16.0) * 16;
                final int integer5 = Mth.floor(cvl7.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 && dtm.isVisible(c16.bb)) {
                            c16.setFrame(integer);
                            list25.add(new RenderChunkInfo(c16, (Direction)null, 0));
                        }
                    }
                }
                list25.sort(Comparator.comparingDouble(a -> fk14.distSqr(a.chunk.getOrigin().offset(8, 8, 8))));
                queue20.addAll(list25);
            }
            else {
                boolean boolean7 = false;
                final RenderChunkInfo a2 = new RenderChunkInfo(c15, (Direction)null, 0);
                final Set<Direction> set24 = this.getVisibleDirections(fk14);
                if (set24.size() == 1) {
                    final Vector3f e25 = dbb.getLookVector();
                    final Direction fp26 = Direction.getNearest(e25.x(), e25.y(), e25.z()).getOpposite();
                    set24.remove(fp26);
                }
                if (set24.isEmpty()) {
                    boolean7 = true;
                }
                if (!boolean7 || boolean5) {
                    if (boolean5 && this.level.getBlockState(fk14).isSolidRender(this.level, fk14)) {
                        boolean6 = false;
                    }
                    c15.setFrame(integer);
                    queue20.add(a2);
                }
                else {
                    this.renderChunks.add(a2);
                }
            }
            this.minecraft.getProfiler().push("iteration");
            while (!queue20.isEmpty()) {
                final RenderChunkInfo a3 = queue20.poll();
                final ChunkRenderDispatcher.RenderChunk c17 = a3.chunk;
                final Direction fp27 = a3.sourceDirection;
                this.renderChunks.add(a3);
                for (final Direction fp28 : LevelRenderer.DIRECTIONS) {
                    final ChunkRenderDispatcher.RenderChunk c18 = this.getRelativeFrom(fk15, c17, fp28);
                    if (!boolean6 || !a3.hasDirection(fp28.getOpposite())) {
                        if (!boolean6 || fp27 == null || c17.getCompiledChunk().facesCanSeeEachother(fp27.getOpposite(), fp28)) {
                            if (c18 != null) {
                                if (c18.hasAllNeighbors()) {
                                    if (c18.setFrame(integer)) {
                                        if (dtm.isVisible(c18.bb)) {
                                            final RenderChunkInfo a4 = new RenderChunkInfo(c18, fp28, a3.step + 1);
                                            a4.setDirections(a3.directions, fp28);
                                            queue20.add(a4);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.minecraft.getProfiler().pop();
        }
        this.minecraft.getProfiler().popPush("rebuildNear");
        final Set<ChunkRenderDispatcher.RenderChunk> set25 = this.chunksToCompile;
        this.chunksToCompile = Sets.newLinkedHashSet();
        final ObjectListIterator iterator = this.renderChunks.iterator();
        while (((Iterator)iterator).hasNext()) {
            final RenderChunkInfo a3 = ((Iterator<RenderChunkInfo>)iterator).next();
            final ChunkRenderDispatcher.RenderChunk c17 = a3.chunk;
            if (c17.isDirty() || set25.contains(c17)) {
                this.needsUpdate = true;
                final BlockPos fk16 = c17.getOrigin().offset(8, 8, 8);
                final boolean boolean8 = fk16.distSqr(fk14) < 768.0;
                if (c17.isDirtyFromPlayer() || boolean8) {
                    this.minecraft.getProfiler().push("build near");
                    this.chunkRenderDispatcher.rebuildChunkSync(c17);
                    c17.setNotDirty();
                    this.minecraft.getProfiler().pop();
                }
                else {
                    this.chunksToCompile.add(c17);
                }
            }
        }
        this.chunksToCompile.addAll(set25);
        this.minecraft.getProfiler().pop();
    }
    
    private Set<Direction> getVisibleDirections(final BlockPos fk) {
        final VisGraph dtj3 = new VisGraph();
        final BlockPos fk2 = new BlockPos(fk.getX() >> 4 << 4, fk.getY() >> 4 << 4, fk.getZ() >> 4 << 4);
        final LevelChunk cal5 = this.level.getChunkAt(fk2);
        for (final BlockPos fk3 : BlockPos.betweenClosed(fk2, fk2.offset(15, 15, 15))) {
            if (cal5.getBlockState(fk3).isSolidRender(this.level, fk3)) {
                dtj3.setOpaque(fk3);
            }
        }
        return dtj3.floodFill(fk);
    }
    
    @Nullable
    private ChunkRenderDispatcher.RenderChunk getRelativeFrom(final BlockPos fk, final ChunkRenderDispatcher.RenderChunk c, final Direction fp) {
        final BlockPos fk2 = c.getRelativeOrigin(fp);
        if (Mth.abs(fk.getX() - fk2.getX()) > this.lastViewDistance * 16) {
            return null;
        }
        if (fk2.getY() < 0 || fk2.getY() >= 256) {
            return null;
        }
        if (Mth.abs(fk.getZ() - fk2.getZ()) > this.lastViewDistance * 16) {
            return null;
        }
        return this.viewArea.getRenderChunkAt(fk2);
    }
    
    private void captureFrustum(final Matrix4f b1, final Matrix4f b2, final double double3, final double double4, final double double5, final Frustum dtm) {
        this.capturedFrustum = dtm;
        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 cyl, final float float2, final long long3, final boolean boolean4, final Camera dbb, final GameRenderer dqn, final LightTexture dqs, final Matrix4f b) {
        BlockEntityRenderDispatcher.instance.prepare(this.level, this.minecraft.getTextureManager(), this.minecraft.font, dbb, this.minecraft.hitResult);
        this.entityRenderDispatcher.prepare(this.level, dbb, this.minecraft.crosshairPickEntity);
        final ProfilerFiller aio11 = this.level.getProfiler();
        aio11.popPush("light_updates");
        this.minecraft.level.getChunkSource().getLightEngine().runUpdates(Integer.MAX_VALUE, true, true);
        final Vec3 cvl12 = dbb.getPosition();
        final double double13 = cvl12.x();
        final double double14 = cvl12.y();
        final double double15 = cvl12.z();
        final Matrix4f b2 = cyl.last().pose();
        aio11.popPush("culling");
        final boolean boolean5 = this.capturedFrustum != null;
        Frustum dtm21;
        if (boolean5) {
            dtm21 = this.capturedFrustum;
            dtm21.prepare(this.frustumPos.x, this.frustumPos.y, this.frustumPos.z);
        }
        else {
            dtm21 = new Frustum(b2, b);
            dtm21.prepare(double13, double14, double15);
        }
        this.minecraft.getProfiler().popPush("captureFrustum");
        if (this.captureFrustum) {
            this.captureFrustum(b2, b, cvl12.x, cvl12.y, cvl12.z, boolean5 ? new Frustum(b2, b) : dtm21);
            this.captureFrustum = false;
        }
        aio11.popPush("clear");
        FogRenderer.setupColor(dbb, float2, this.minecraft.level, this.minecraft.options.renderDistance, dqn.getDarkenWorldAmount(float2));
        RenderSystem.clear(16640, Minecraft.ON_OSX);
        final float float3 = dqn.getRenderDistance();
        final boolean boolean6 = this.minecraft.level.dimension.isFoggyAt(Mth.floor(double13), Mth.floor(double14)) || this.minecraft.gui.getBossOverlay().shouldCreateWorldFog();
        if (this.minecraft.options.renderDistance >= 4) {
            FogRenderer.setupFog(dbb, FogRenderer.FogMode.FOG_SKY, float3, boolean6);
            aio11.popPush("sky");
            this.renderSky(cyl, float2);
        }
        aio11.popPush("fog");
        FogRenderer.setupFog(dbb, FogRenderer.FogMode.FOG_TERRAIN, Math.max(float3 - 16.0f, 32.0f), boolean6);
        aio11.popPush("terrain_setup");
        this.setupRender(dbb, dtm21, boolean5, this.frameId++, this.minecraft.player.isSpectator());
        aio11.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);
        aio11.popPush("terrain");
        this.renderChunkLayer(RenderType.solid(), cyl, double13, double14, double15);
        this.renderChunkLayer(RenderType.cutoutMipped(), cyl, double13, double14, double15);
        this.renderChunkLayer(RenderType.cutout(), cyl, double13, double14, double15);
        Lighting.setupLevel(cyl.last().pose());
        aio11.popPush("entities");
        aio11.push("prepare");
        this.renderedEntities = 0;
        this.culledEntities = 0;
        aio11.popPush("entities");
        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 akq41 : this.level.entitiesForRendering()) {
            if (!this.entityRenderDispatcher.<Entity>shouldRender(akq41, dtm21, double13, double14, double15) && !akq41.hasIndirectPassenger(this.minecraft.player)) {
                continue;
            }
            if (akq41 == dbb.getEntity() && !dbb.isDetached()) {
                if (!(dbb.getEntity() instanceof LivingEntity)) {
                    continue;
                }
                if (!((LivingEntity)dbb.getEntity()).isSleeping()) {
                    continue;
                }
            }
            if (akq41 instanceof LocalPlayer && dbb.getEntity() != akq41) {
                continue;
            }
            ++this.renderedEntities;
            if (akq41.tickCount == 0) {
                akq41.xOld = akq41.getX();
                akq41.yOld = akq41.getY();
                akq41.zOld = akq41.getZ();
            }
            MultiBufferSource dqt42;
            if (this.shouldShowEntityOutlines() && akq41.isGlowing()) {
                boolean7 = true;
                final OutlineBufferSource dqu43 = (OutlineBufferSource)(dqt42 = this.renderBuffers.outlineBufferSource());
                final int integer26 = akq41.getTeamColor();
                final int integer27 = 255;
                final int integer28 = integer26 >> 16 & 0xFF;
                final int integer29 = integer26 >> 8 & 0xFF;
                final int integer30 = integer26 & 0xFF;
                dqu43.setColor(integer28, integer29, integer30, 255);
            }
            else {
                dqt42 = a39;
            }
            this.renderEntity(akq41, double13, double14, double15, float2, cyl, dqt42);
        }
        this.checkPoseStack(cyl);
        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));
        aio11.popPush("blockentities");
        for (final RenderChunkInfo a40 : this.renderChunks) {
            final List<BlockEntity> list42 = a40.chunk.getCompiledChunk().getRenderableBlockEntities();
            if (list42.isEmpty()) {
                continue;
            }
            for (final BlockEntity bwl44 : list42) {
                final BlockPos fk45 = bwl44.getBlockPos();
                MultiBufferSource dqt43 = a39;
                cyl.pushPose();
                cyl.translate(fk45.getX() - double13, fk45.getY() - double14, fk45.getZ() - double15);
                final SortedSet<BlockDestructionProgress> sortedSet47 = (SortedSet<BlockDestructionProgress>)this.destructionProgress.get(fk45.asLong());
                if (sortedSet47 != null && !sortedSet47.isEmpty()) {
                    final int integer30 = sortedSet47.last().getProgress();
                    if (integer30 >= 0) {
                        final VertexConsumer cyo49 = new BreakingTextureGenerator(this.renderBuffers.crumblingBufferSource().getBuffer(ModelBakery.DESTROY_TYPES.get(integer30)), cyl.last());
                        final MultiBufferSource.BufferSource bufferSource;
                        final VertexConsumer cyo50;
                        final VertexConsumer cyo53;
                        dqt43 = (drb -> {
                            cyo50 = bufferSource.getBuffer(drb);
                            if (drb.affectsCrumbling()) {
                                return VertexMultiConsumer.create(cyo53, cyo50);
                            }
                            else {
                                return cyo50;
                            }
                        });
                    }
                }
                BlockEntityRenderDispatcher.instance.<BlockEntity>render(bwl44, float2, cyl, dqt43);
                cyl.popPose();
            }
        }
        synchronized (this.globalBlockEntities) {
            for (final BlockEntity bwl45 : this.globalBlockEntities) {
                final BlockPos fk46 = bwl45.getBlockPos();
                cyl.pushPose();
                cyl.translate(fk46.getX() - double13, fk46.getY() - double14, fk46.getZ() - double15);
                BlockEntityRenderDispatcher.instance.<BlockEntity>render(bwl45, float2, cyl, a39);
                cyl.popPose();
            }
        }
        this.checkPoseStack(cyl);
        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);
        }
        aio11.popPush("destroyProgress");
        for (final Long2ObjectMap.Entry<SortedSet<BlockDestructionProgress>> entry41 : this.destructionProgress.long2ObjectEntrySet()) {
            final BlockPos fk47 = BlockPos.of(entry41.getLongKey());
            final double double16 = fk47.getX() - double13;
            final double double17 = fk47.getY() - double14;
            final double double18 = fk47.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();
            cyl.pushPose();
            cyl.translate(fk47.getX() - double13, fk47.getY() - double14, fk47.getZ() - double15);
            final VertexConsumer cyo51 = new BreakingTextureGenerator(this.renderBuffers.crumblingBufferSource().getBuffer(ModelBakery.DESTROY_TYPES.get(integer31)), cyl.last());
            this.minecraft.getBlockRenderer().renderBreakingTexture(this.level.getBlockState(fk47), fk47, this.level, cyl, cyo51);
            cyl.popPose();
        }
        this.checkPoseStack(cyl);
        aio11.pop();
        final HitResult cvi40 = this.minecraft.hitResult;
        if (boolean4 && cvi40 != null && cvi40.getType() == HitResult.Type.BLOCK) {
            aio11.popPush("outline");
            final BlockPos fk48 = ((BlockHitResult)cvi40).getBlockPos();
            final BlockState byj42 = this.level.getBlockState(fk48);
            if (!byj42.isAir() && this.level.getWorldBorder().isWithinBounds(fk48)) {
                final VertexConsumer cyo52 = a39.getBuffer(RenderType.lines());
                this.renderHitOutline(cyl, cyo52, dbb.getEntity(), double13, double14, double15, fk48, byj42);
            }
        }
        RenderSystem.pushMatrix();
        RenderSystem.multMatrix(cyl.last().pose());
        this.minecraft.debugRenderer.render(cyl, a39, double13, double14, double15);
        this.renderWorldBounds(dbb);
        RenderSystem.popMatrix();
        a39.endBatch(Sheets.translucentBlockSheet());
        a39.endBatch(Sheets.bannerSheet());
        a39.endBatch(Sheets.shieldSheet());
        a39.endBatch(RenderType.glint());
        a39.endBatch(RenderType.entityGlint());
        a39.endBatch(RenderType.waterMask());
        this.renderBuffers.crumblingBufferSource().endBatch();
        a39.endBatch(RenderType.lines());
        a39.endBatch();
        aio11.popPush("translucent");
        this.renderChunkLayer(RenderType.translucent(), cyl, double13, double14, double15);
        aio11.popPush("particles");
        this.minecraft.particleEngine.render(cyl, a39, dqs, dbb, float2);
        RenderSystem.pushMatrix();
        RenderSystem.multMatrix(cyl.last().pose());
        aio11.popPush("cloudsLayers");
        if (this.minecraft.options.getCloudsType() != CloudStatus.OFF) {
            aio11.popPush("clouds");
            this.renderClouds(cyl, float2, double13, double14, double15);
        }
        RenderSystem.depthMask(false);
        aio11.popPush("weather");
        this.renderSnowAndRain(dqs, float2, double13, double14, double15);
        RenderSystem.depthMask(true);
        this.renderDebug(dbb);
        RenderSystem.shadeModel(7424);
        RenderSystem.depthMask(true);
        RenderSystem.disableBlend();
        RenderSystem.popMatrix();
        FogRenderer.setupNoFog();
    }
    
    private void checkPoseStack(final PoseStack cyl) {
        if (!cyl.clear()) {
            throw new IllegalStateException("Pose stack not empty");
        }
    }
    
    private void renderEntity(final Entity akq, final double double2, final double double3, final double double4, final float float5, final PoseStack cyl, final MultiBufferSource dqt) {
        final double double5 = Mth.lerp(float5, akq.xOld, akq.getX());
        final double double6 = Mth.lerp(float5, akq.yOld, akq.getY());
        final double double7 = Mth.lerp(float5, akq.zOld, akq.getZ());
        final float float6 = Mth.lerp(float5, akq.yRotO, akq.yRot);
        this.entityRenderDispatcher.<Entity>render(akq, double5 - double2, double6 - double3, double7 - double4, float6, float5, cyl, dqt, this.entityRenderDispatcher.<Entity>getPackedLightCoords(akq, float5));
    }
    
    private void renderChunkLayer(final RenderType drb, final PoseStack cyl, final double double3, final double double4, final double double5) {
        drb.setupRenderState();
        if (drb == 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(drb, this.chunkRenderDispatcher)) {
                        ++integer16;
                    }
                }
            }
            this.minecraft.getProfiler().pop();
        }
        this.minecraft.getProfiler().push("filterempty");
        this.minecraft.getProfiler().popPush(() -> "render_" + drb);
        final boolean boolean10 = drb != 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(drb)) {
                continue;
            }
            final VertexBuffer cyn14 = c13.getBuffer(drb);
            cyl.pushPose();
            final BlockPos fk15 = c13.getOrigin();
            cyl.translate(fk15.getX() - double3, fk15.getY() - double4, fk15.getZ() - double5);
            cyn14.bind();
            this.format.setupBufferState(0L);
            cyn14.draw(cyl.last().pose(), 7);
            cyl.popPose();
        }
        VertexBuffer.unbind();
        RenderSystem.clearCurrentColor();
        this.format.clearBufferState();
        this.minecraft.getProfiler().pop();
        drb.clearRenderState();
    }
    
    private void renderDebug(final Camera dbb) {
        final Tesselator cym3 = Tesselator.getInstance();
        final BufferBuilder cyg4 = cym3.getBuilder();
        if (this.minecraft.chunkPath || this.minecraft.chunkVisibility) {
            final double double5 = dbb.getPosition().x();
            final double double6 = dbb.getPosition().y();
            final double double7 = dbb.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 fk14 = c13.getOrigin();
                RenderSystem.translated(fk14.getX() - double5, fk14.getY() - double6, fk14.getZ() - double7);
                if (this.minecraft.chunkPath) {
                    cyg4.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 fp19 = a12.sourceDirection;
                    if (fp19 != null) {
                        cyg4.vertex(8.0, 8.0, 8.0).color(integer16, integer17, integer18, 255).endVertex();
                        cyg4.vertex(8 - 16 * fp19.getStepX(), 8 - 16 * fp19.getStepY(), 8 - 16 * fp19.getStepZ()).color(integer16, integer17, integer18, 255).endVertex();
                    }
                    cym3.end();
                    RenderSystem.lineWidth(1.0f);
                }
                if (this.minecraft.chunkVisibility && !c13.getCompiledChunk().hasNoRenderableLayers()) {
                    cyg4.begin(1, DefaultVertexFormat.POSITION_COLOR);
                    RenderSystem.lineWidth(10.0f);
                    int integer15 = 0;
                    for (final Direction fp19 : Direction.values()) {
                        for (final Direction fp20 : Direction.values()) {
                            final boolean boolean24 = c13.getCompiledChunk().facesCanSeeEachother(fp19, fp20);
                            if (!boolean24) {
                                ++integer15;
                                cyg4.vertex(8 + 8 * fp19.getStepX(), 8 + 8 * fp19.getStepY(), 8 + 8 * fp19.getStepZ()).color(1, 0, 0, 1).endVertex();
                                cyg4.vertex(8 + 8 * fp20.getStepX(), 8 + 8 * fp20.getStepY(), 8 + 8 * fp20.getStepZ()).color(1, 0, 0, 1).endVertex();
                            }
                        }
                    }
                    cym3.end();
                    RenderSystem.lineWidth(1.0f);
                    if (integer15 > 0) {
                        cyg4.begin(7, DefaultVertexFormat.POSITION_COLOR);
                        final float float16 = 0.5f;
                        final float float17 = 0.2f;
                        cyg4.vertex(0.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 0.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 15.5, 0.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 15.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(15.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cyg4.vertex(0.5, 0.5, 15.5).color(0.9f, 0.9f, 0.0f, 0.2f).endVertex();
                        cym3.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 - dbb.getPosition().x), (float)(this.frustumPos.y - dbb.getPosition().y), (float)(this.frustumPos.z - dbb.getPosition().z));
            RenderSystem.depthMask(true);
            cyg4.begin(7, DefaultVertexFormat.POSITION_COLOR);
            this.addFrustumQuad(cyg4, 0, 1, 2, 3, 0, 1, 1);
            this.addFrustumQuad(cyg4, 4, 5, 6, 7, 1, 0, 0);
            this.addFrustumQuad(cyg4, 0, 1, 5, 4, 1, 1, 0);
            this.addFrustumQuad(cyg4, 2, 3, 7, 6, 0, 0, 1);
            this.addFrustumQuad(cyg4, 0, 4, 7, 3, 0, 1, 0);
            this.addFrustumQuad(cyg4, 1, 5, 6, 2, 1, 0, 1);
            cym3.end();
            RenderSystem.depthMask(false);
            cyg4.begin(1, DefaultVertexFormat.POSITION);
            RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
            this.addFrustumVertex(cyg4, 0);
            this.addFrustumVertex(cyg4, 1);
            this.addFrustumVertex(cyg4, 1);
            this.addFrustumVertex(cyg4, 2);
            this.addFrustumVertex(cyg4, 2);
            this.addFrustumVertex(cyg4, 3);
            this.addFrustumVertex(cyg4, 3);
            this.addFrustumVertex(cyg4, 0);
            this.addFrustumVertex(cyg4, 4);
            this.addFrustumVertex(cyg4, 5);
            this.addFrustumVertex(cyg4, 5);
            this.addFrustumVertex(cyg4, 6);
            this.addFrustumVertex(cyg4, 6);
            this.addFrustumVertex(cyg4, 7);
            this.addFrustumVertex(cyg4, 7);
            this.addFrustumVertex(cyg4, 4);
            this.addFrustumVertex(cyg4, 0);
            this.addFrustumVertex(cyg4, 4);
            this.addFrustumVertex(cyg4, 1);
            this.addFrustumVertex(cyg4, 5);
            this.addFrustumVertex(cyg4, 2);
            this.addFrustumVertex(cyg4, 6);
            this.addFrustumVertex(cyg4, 3);
            this.addFrustumVertex(cyg4, 7);
            cym3.end();
            RenderSystem.popMatrix();
            RenderSystem.depthMask(true);
            RenderSystem.disableBlend();
            RenderSystem.enableCull();
            RenderSystem.enableTexture();
            RenderSystem.lineWidth(1.0f);
        }
    }
    
    private void addFrustumVertex(final VertexConsumer cyo, final int integer) {
        cyo.vertex(this.frustumPoints[integer].x(), this.frustumPoints[integer].y(), this.frustumPoints[integer].z()).endVertex();
    }
    
    private void addFrustumQuad(final VertexConsumer cyo, 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;
        cyo.vertex(this.frustumPoints[integer2].x(), this.frustumPoints[integer2].y(), this.frustumPoints[integer2].z()).color((float)integer6, (float)integer7, (float)integer8, 0.25f).endVertex();
        cyo.vertex(this.frustumPoints[integer3].x(), this.frustumPoints[integer3].y(), this.frustumPoints[integer3].z()).color((float)integer6, (float)integer7, (float)integer8, 0.25f).endVertex();
        cyo.vertex(this.frustumPoints[integer4].x(), this.frustumPoints[integer4].y(), this.frustumPoints[integer4].z()).color((float)integer6, (float)integer7, (float)integer8, 0.25f).endVertex();
        cyo.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 wn3 = iterator2.next();
            final int integer4 = wn3.getUpdatedRenderTick();
            if (this.ticks - integer4 > 400) {
                iterator2.remove();
                this.removeProgress(wn3);
            }
        }
    }
    
    private void removeProgress(final BlockDestructionProgress wn) {
        final long long3 = wn.getPos().asLong();
        final Set<BlockDestructionProgress> set5 = (Set<BlockDestructionProgress>)this.destructionProgress.get(long3);
        set5.remove(wn);
        if (set5.isEmpty()) {
            this.destructionProgress.remove(long3);
        }
    }
    
    private void renderEndSky(final PoseStack cyl) {
        RenderSystem.disableAlphaTest();
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.depthMask(false);
        this.textureManager.bind(LevelRenderer.END_SKY_LOCATION);
        final Tesselator cym3 = Tesselator.getInstance();
        final BufferBuilder cyg4 = cym3.getBuilder();
        for (int integer5 = 0; integer5 < 6; ++integer5) {
            cyl.pushPose();
            if (integer5 == 1) {
                cyl.mulPose(Vector3f.XP.rotationDegrees(90.0f));
            }
            if (integer5 == 2) {
                cyl.mulPose(Vector3f.XP.rotationDegrees(-90.0f));
            }
            if (integer5 == 3) {
                cyl.mulPose(Vector3f.XP.rotationDegrees(180.0f));
            }
            if (integer5 == 4) {
                cyl.mulPose(Vector3f.ZP.rotationDegrees(90.0f));
            }
            if (integer5 == 5) {
                cyl.mulPose(Vector3f.ZP.rotationDegrees(-90.0f));
            }
            final Matrix4f b6 = cyl.last().pose();
            cyg4.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR);
            cyg4.vertex(b6, -100.0f, -100.0f, -100.0f).uv(0.0f, 0.0f).color(40, 40, 40, 255).endVertex();
            cyg4.vertex(b6, -100.0f, -100.0f, 100.0f).uv(0.0f, 16.0f).color(40, 40, 40, 255).endVertex();
            cyg4.vertex(b6, 100.0f, -100.0f, 100.0f).uv(16.0f, 16.0f).color(40, 40, 40, 255).endVertex();
            cyg4.vertex(b6, 100.0f, -100.0f, -100.0f).uv(16.0f, 0.0f).color(40, 40, 40, 255).endVertex();
            cym3.end();
            cyl.popPose();
        }
        RenderSystem.depthMask(true);
        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
        RenderSystem.enableAlphaTest();
    }
    
    public void renderSky(final PoseStack cyl, final float float2) {
        if (this.minecraft.level.dimension.getType() == DimensionType.THE_END) {
            this.renderEndSky(cyl);
            return;
        }
        if (!this.minecraft.level.dimension.isNaturalDimension()) {
            return;
        }
        RenderSystem.disableTexture();
        final Vec3 cvl4 = this.level.getSkyColor(this.minecraft.gameRenderer.getMainCamera().getBlockPosition(), float2);
        final float float3 = (float)cvl4.x;
        final float float4 = (float)cvl4.y;
        final float float5 = (float)cvl4.z;
        FogRenderer.levelFogColor();
        final BufferBuilder cyg8 = Tesselator.getInstance().getBuilder();
        RenderSystem.depthMask(false);
        RenderSystem.enableFog();
        RenderSystem.color3f(float3, float4, float5);
        this.skyBuffer.bind();
        this.skyFormat.setupBufferState(0L);
        this.skyBuffer.draw(cyl.last().pose(), 7);
        VertexBuffer.unbind();
        this.skyFormat.clearBufferState();
        RenderSystem.disableFog();
        RenderSystem.disableAlphaTest();
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        final float[] arr9 = this.level.dimension.getSunriseColor(this.level.getTimeOfDay(float2), float2);
        if (arr9 != null) {
            RenderSystem.disableTexture();
            RenderSystem.shadeModel(7425);
            cyl.pushPose();
            cyl.mulPose(Vector3f.XP.rotationDegrees(90.0f));
            final float float6 = (Mth.sin(this.level.getSunAngle(float2)) < 0.0f) ? 180.0f : 0.0f;
            cyl.mulPose(Vector3f.ZP.rotationDegrees(float6));
            cyl.mulPose(Vector3f.ZP.rotationDegrees(90.0f));
            final float float7 = arr9[0];
            final float float8 = arr9[1];
            final float float9 = arr9[2];
            final Matrix4f b14 = cyl.last().pose();
            cyg8.begin(6, DefaultVertexFormat.POSITION_COLOR);
            cyg8.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);
                cyg8.vertex(b14, float11 * 120.0f, float12 * 120.0f, -float12 * 40.0f * arr9[3]).color(arr9[0], arr9[1], arr9[2], 0.0f).endVertex();
            }
            cyg8.end();
            BufferUploader.end(cyg8);
            cyl.popPose();
            RenderSystem.shadeModel(7424);
        }
        RenderSystem.enableTexture();
        RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
        cyl.pushPose();
        final float float6 = 1.0f - this.level.getRainLevel(float2);
        RenderSystem.color4f(1.0f, 1.0f, 1.0f, float6);
        cyl.mulPose(Vector3f.YP.rotationDegrees(-90.0f));
        cyl.mulPose(Vector3f.XP.rotationDegrees(this.level.getTimeOfDay(float2) * 360.0f));
        final Matrix4f b15 = cyl.last().pose();
        float float8 = 30.0f;
        this.textureManager.bind(LevelRenderer.SUN_LOCATION);
        cyg8.begin(7, DefaultVertexFormat.POSITION_TEX);
        cyg8.vertex(b15, -float8, 100.0f, -float8).uv(0.0f, 0.0f).endVertex();
        cyg8.vertex(b15, float8, 100.0f, -float8).uv(1.0f, 0.0f).endVertex();
        cyg8.vertex(b15, float8, 100.0f, float8).uv(1.0f, 1.0f).endVertex();
        cyg8.vertex(b15, -float8, 100.0f, float8).uv(0.0f, 1.0f).endVertex();
        cyg8.end();
        BufferUploader.end(cyg8);
        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;
        cyg8.begin(7, DefaultVertexFormat.POSITION_TEX);
        cyg8.vertex(b15, -float8, -100.0f, float8).uv(float11, float12).endVertex();
        cyg8.vertex(b15, float8, -100.0f, float8).uv(float13, float12).endVertex();
        cyg8.vertex(b15, float8, -100.0f, -float8).uv(float13, float10).endVertex();
        cyg8.vertex(b15, -float8, -100.0f, -float8).uv(float11, float10).endVertex();
        cyg8.end();
        BufferUploader.end(cyg8);
        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(cyl.last().pose(), 7);
            VertexBuffer.unbind();
            this.skyFormat.clearBufferState();
        }
        RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.disableBlend();
        RenderSystem.enableAlphaTest();
        RenderSystem.enableFog();
        cyl.popPose();
        RenderSystem.disableTexture();
        RenderSystem.color3f(0.0f, 0.0f, 0.0f);
        final double double10 = this.minecraft.player.getEyePosition(float2).y - this.level.getHorizonHeight();
        if (double10 < 0.0) {
            cyl.pushPose();
            cyl.translate(0.0, 12.0, 0.0);
            this.darkBuffer.bind();
            this.skyFormat.setupBufferState(0L);
            this.darkBuffer.draw(cyl.last().pose(), 7);
            VertexBuffer.unbind();
            this.skyFormat.clearBufferState();
            cyl.popPose();
        }
        if (this.level.dimension.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 cyl, final float float2, final double double3, final double double4, final double double5) {
        if (!this.minecraft.level.dimension.isNaturalDimension()) {
            return;
        }
        RenderSystem.disableCull();
        RenderSystem.enableBlend();
        RenderSystem.enableAlphaTest();
        RenderSystem.enableDepthTest();
        RenderSystem.defaultAlphaFunc();
        RenderSystem.defaultBlendFunc();
        RenderSystem.enableFog();
        final float float3 = 12.0f;
        final float float4 = 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 = this.level.dimension.getCloudHeight() - (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 float5 = (float)(double8 - Mth.floor(double8));
        final float float6 = (float)(double9 / 4.0 - Mth.floor(double9 / 4.0)) * 4.0f;
        final float float7 = (float)(double10 - Mth.floor(double10));
        final Vec3 cvl25 = this.level.getCloudColor(float2);
        final int integer26 = (int)Math.floor(double8);
        final int integer27 = (int)Math.floor(double9 / 4.0);
        final int integer28 = (int)Math.floor(double10);
        if (integer26 != this.prevCloudX || integer27 != this.prevCloudY || integer28 != this.prevCloudZ || this.minecraft.options.getCloudsType() != this.prevCloudsType || this.prevCloudColor.distanceToSqr(cvl25) > 2.0E-4) {
            this.prevCloudX = integer26;
            this.prevCloudY = integer27;
            this.prevCloudZ = integer28;
            this.prevCloudColor = cvl25;
            this.prevCloudsType = this.minecraft.options.getCloudsType();
            this.generateClouds = true;
        }
        if (this.generateClouds) {
            this.generateClouds = false;
            final BufferBuilder cyg29 = Tesselator.getInstance().getBuilder();
            if (this.cloudBuffer != null) {
                this.cloudBuffer.close();
            }
            this.cloudBuffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL);
            this.buildClouds(cyg29, double8, double9, double10, cvl25);
            cyg29.end();
            this.cloudBuffer.upload(cyg29);
        }
        this.textureManager.bind(LevelRenderer.CLOUDS_LOCATION);
        cyl.pushPose();
        cyl.scale(12.0f, 1.0f, 12.0f);
        cyl.translate(-float5, float6, -float7);
        if (this.cloudBuffer != null) {
            this.cloudBuffer.bind();
            DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL.setupBufferState(0L);
            int integer30;
            for (int integer29 = integer30 = ((this.prevCloudsType != CloudStatus.FANCY) ? 1 : 0); integer30 < 2; ++integer30) {
                if (integer30 == 0) {
                    RenderSystem.colorMask(false, false, false, false);
                }
                else {
                    RenderSystem.colorMask(true, true, true, true);
                }
                this.cloudBuffer.draw(cyl.last().pose(), 7);
            }
            VertexBuffer.unbind();
            DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL.clearBufferState();
        }
        cyl.popPose();
        RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.disableAlphaTest();
        RenderSystem.enableCull();
        RenderSystem.disableBlend();
        RenderSystem.disableFog();
    }
    
    private void buildClouds(final BufferBuilder cyg, final double double2, final double double3, final double double4, final Vec3 cvl) {
        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)cvl.x;
        final float float16 = (float)cvl.y;
        final float float17 = (float)cvl.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;
        cyg.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) {
                        cyg.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();
                        cyg.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();
                        cyg.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();
                        cyg.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) {
                        cyg.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();
                        cyg.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();
                        cyg.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();
                        cyg.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) {
                            cyg.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();
                            cyg.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();
                            cyg.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();
                            cyg.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) {
                            cyg.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();
                            cyg.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();
                            cyg.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();
                            cyg.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) {
                            cyg.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();
                            cyg.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();
                            cyg.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();
                            cyg.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) {
                            cyg.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();
                            cyg.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();
                            cyg.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();
                            cyg.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) {
                    cyg.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();
                    cyg.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();
                    cyg.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();
                    cyg.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 dbb) {
        final BufferBuilder cyg3 = Tesselator.getInstance().getBuilder();
        final WorldBorder bzw4 = this.level.getWorldBorder();
        final double double5 = this.minecraft.options.renderDistance * 16;
        if (dbb.getPosition().x < bzw4.getMaxX() - double5 && dbb.getPosition().x > bzw4.getMinX() + double5 && dbb.getPosition().z < bzw4.getMaxZ() - double5 && dbb.getPosition().z > bzw4.getMinZ() + double5) {
            return;
        }
        double double6 = 1.0 - bzw4.getDistanceToBorder(dbb.getPosition().x, dbb.getPosition().z) / double5;
        double6 = Math.pow(double6, 4.0);
        final double double7 = dbb.getPosition().x;
        final double double8 = dbb.getPosition().y;
        final double double9 = dbb.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(false);
        RenderSystem.pushMatrix();
        final int integer15 = bzw4.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;
        cyg3.begin(7, DefaultVertexFormat.POSITION_TEX);
        double double10 = Math.max(Mth.floor(double9 - double5), bzw4.getMinZ());
        double double11 = Math.min(Mth.ceil(double9 + double5), bzw4.getMaxZ());
        if (double7 > bzw4.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(cyg3, double7, double8, double9, bzw4.getMaxX(), 256, double12, float19 + float23, float19 + 0.0f);
                this.vertex(cyg3, double7, double8, double9, bzw4.getMaxX(), 256, double12 + double13, float19 + float24 + float23, float19 + 0.0f);
                this.vertex(cyg3, double7, double8, double9, bzw4.getMaxX(), 0, double12 + double13, float19 + float24 + float23, float19 + 128.0f);
                this.vertex(cyg3, double7, double8, double9, bzw4.getMaxX(), 0, double12, float19 + float23, float19 + 128.0f);
            }
        }
        if (double7 < bzw4.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(cyg3, double7, double8, double9, bzw4.getMinX(), 256, double12, float19 + float23, float19 + 0.0f);
                this.vertex(cyg3, double7, double8, double9, bzw4.getMinX(), 256, double12 + double13, float19 + float24 + float23, float19 + 0.0f);
                this.vertex(cyg3, double7, double8, double9, bzw4.getMinX(), 0, double12 + double13, float19 + float24 + float23, float19 + 128.0f);
                this.vertex(cyg3, double7, double8, double9, bzw4.getMinX(), 0, double12, float19 + float23, float19 + 128.0f);
            }
        }
        double10 = Math.max(Mth.floor(double7 - double5), bzw4.getMinX());
        double11 = Math.min(Mth.ceil(double7 + double5), bzw4.getMaxX());
        if (double9 > bzw4.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(cyg3, double7, double8, double9, double12, 256, bzw4.getMaxZ(), float19 + float23, float19 + 0.0f);
                this.vertex(cyg3, double7, double8, double9, double12 + double13, 256, bzw4.getMaxZ(), float19 + float24 + float23, float19 + 0.0f);
                this.vertex(cyg3, double7, double8, double9, double12 + double13, 0, bzw4.getMaxZ(), float19 + float24 + float23, float19 + 128.0f);
                this.vertex(cyg3, double7, double8, double9, double12, 0, bzw4.getMaxZ(), float19 + float23, float19 + 128.0f);
            }
        }
        if (double9 < bzw4.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(cyg3, double7, double8, double9, double12, 256, bzw4.getMinZ(), float19 + float23, float19 + 0.0f);
                this.vertex(cyg3, double7, double8, double9, double12 + double13, 256, bzw4.getMinZ(), float19 + float24 + float23, float19 + 0.0f);
                this.vertex(cyg3, double7, double8, double9, double12 + double13, 0, bzw4.getMinZ(), float19 + float24 + float23, float19 + 128.0f);
                this.vertex(cyg3, double7, double8, double9, double12, 0, bzw4.getMinZ(), float19 + float23, float19 + 128.0f);
            }
        }
        cyg3.end();
        BufferUploader.end(cyg3);
        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 cyg, final double double2, final double double3, final double double4, final double double5, final int integer, final double double7, final float float8, final float float9) {
        cyg.vertex(double5 - double2, integer - double3, double7 - double4).uv(float8, float9).endVertex();
    }
    
    private void renderHitOutline(final PoseStack cyl, final VertexConsumer cyo, final Entity akq, final double double4, final double double5, final double double6, final BlockPos fk, final BlockState byj) {
        renderShape(cyl, cyo, byj.getShape(this.level, fk, CollisionContext.of(akq)), fk.getX() - double4, fk.getY() - double5, fk.getZ() - double6, 0.0f, 0.0f, 0.0f, 0.4f);
    }
    
    public static void renderVoxelShape(final PoseStack cyl, final VertexConsumer cyo, final VoxelShape cwf, 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 = cwf.toAabbs();
        final int integer15 = Mth.ceil(list14.size() / 3.0);
        for (int integer16 = 0; integer16 < list14.size(); ++integer16) {
            final AABB cvf17 = 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(cyl, cyo, Shapes.create(cvf17.move(0.0, 0.0, 0.0)), double4, double5, double6, float13, float14, float15, 1.0f);
        }
    }
    
    private static void renderShape(final PoseStack cyl, final VertexConsumer cyo, final VoxelShape cwf, final double double4, final double double5, final double double6, final float float7, final float float8, final float float9, final float float10) {
        final Matrix4f b14 = cyl.last().pose();
        final Matrix4f matrix4f;
        cwf.forAllEdges((double10, double11, double12, double13, double14, double15) -> {
            cyo.vertex(matrix4f, (float)(double10 + double4), (float)(double11 + double5), (float)(double12 + double6)).color(float7, float8, float9, float10).endVertex();
            cyo.vertex(matrix4f, (float)(double13 + double4), (float)(double14 + double5), (float)(double15 + double6)).color(float7, float8, float9, float10).endVertex();
        });
    }
    
    public static void renderLineBox(final VertexConsumer cyo, 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) {
        renderLineBox(new PoseStack(), cyo, double2, double3, double4, double5, double6, double7, float8, float9, float10, float11, float8, float9, float10);
    }
    
    public static void renderLineBox(final PoseStack cyl, final VertexConsumer cyo, final AABB cvf, final float float4, final float float5, final float float6, final float float7) {
        renderLineBox(cyl, cyo, cvf.minX, cvf.minY, cvf.minZ, cvf.maxX, cvf.maxY, cvf.maxZ, float4, float5, float6, float7, float4, float5, float6);
    }
    
    public static void renderLineBox(final PoseStack cyl, final VertexConsumer cyo, 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(cyl, cyo, double3, double4, double5, double6, double7, double8, float9, float10, float11, float12, float9, float10, float11);
    }
    
    public static void renderLineBox(final PoseStack cyl, final VertexConsumer cyo, 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 = cyl.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;
        cyo.vertex(b22, float16, float17, float18).color(float9, float14, float15, float12).endVertex();
        cyo.vertex(b22, float19, float17, float18).color(float9, float14, float15, float12).endVertex();
        cyo.vertex(b22, float16, float17, float18).color(float13, float10, float15, float12).endVertex();
        cyo.vertex(b22, float16, float20, float18).color(float13, float10, float15, float12).endVertex();
        cyo.vertex(b22, float16, float17, float18).color(float13, float14, float11, float12).endVertex();
        cyo.vertex(b22, float16, float17, float21).color(float13, float14, float11, float12).endVertex();
        cyo.vertex(b22, float19, float17, float18).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float20, float18).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float20, float18).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float16, float20, float18).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float16, float20, float18).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float16, float20, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float16, float20, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float16, float17, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float16, float17, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float17, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float17, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float17, float18).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float16, float20, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float20, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float17, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float20, float21).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float20, float18).color(float9, float10, float11, float12).endVertex();
        cyo.vertex(b22, float19, float20, float21).color(float9, float10, float11, float12).endVertex();
    }
    
    public static void addChainedFilledBoxVertices(final BufferBuilder cyg, 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) {
        cyg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double3, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double6, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double6, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double6, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double3, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double3, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double3, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double3, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double6, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double6, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double3, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double6, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double3, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double3, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double3, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double3, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double3, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double6, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double6, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double2, double6, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double6, double4).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
        cyg.vertex(double5, double6, double7).color(float8, float9, float10, float11).endVertex();
    }
    
    public void blockChanged(final BlockGetter bjg, final BlockPos fk, final BlockState byj3, final BlockState byj4, final int integer) {
        this.setBlockDirty(fk, (integer & 0x8) != 0x0);
    }
    
    private void setBlockDirty(final BlockPos fk, final boolean boolean2) {
        for (int integer4 = fk.getZ() - 1; integer4 <= fk.getZ() + 1; ++integer4) {
            for (int integer5 = fk.getX() - 1; integer5 <= fk.getX() + 1; ++integer5) {
                for (int integer6 = fk.getY() - 1; integer6 <= fk.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 fk, final BlockState byj2, final BlockState byj3) {
        if (this.minecraft.getModelManager().requiresRender(byj2, byj3)) {
            this.setBlocksDirty(fk.getX(), fk.getY(), fk.getZ(), fk.getX(), fk.getY(), fk.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 aah, final BlockPos fk) {
        SoundInstance ecz4 = this.playingRecords.get(fk);
        if (ecz4 != null) {
            this.minecraft.getSoundManager().stop(ecz4);
            this.playingRecords.remove(fk);
        }
        if (aah != null) {
            final RecordItem bfb5 = RecordItem.getBySound(aah);
            if (bfb5 != null) {
                this.minecraft.gui.setNowPlaying(bfb5.getDisplayName().getColoredString());
            }
            ecz4 = SimpleSoundInstance.forRecord(aah, (float)fk.getX(), (float)fk.getY(), (float)fk.getZ());
            this.playingRecords.put(fk, ecz4);
            this.minecraft.getSoundManager().play(ecz4);
        }
        this.notifyNearbyEntities(this.level, fk, aah != null);
    }
    
    private void notifyNearbyEntities(final Level bjw, final BlockPos fk, final boolean boolean3) {
        final List<LivingEntity> list5 = bjw.<LivingEntity>getEntitiesOfClass(LivingEntity.class, new AABB(fk).inflate(3.0));
        for (final LivingEntity akz7 : list5) {
            akz7.setRecordPlayingNearby(fk, boolean3);
        }
    }
    
    public void addParticle(final ParticleOptions gt, final boolean boolean2, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
        this.addParticle(gt, boolean2, false, double3, double4, double5, double6, double7, double8);
    }
    
    public void addParticle(final ParticleOptions gt, 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(gt, boolean2, boolean3, double4, double5, double6, double7, double8, double9);
        }
        catch (Throwable throwable17) {
            final CrashReport h18 = CrashReport.forThrowable(throwable17, "Exception while adding particle");
            final CrashReportCategory i19 = h18.addCategory("Particle being added");
            i19.setDetail("ID", Registry.PARTICLE_TYPE.getKey(gt.getType()));
            i19.setDetail("Parameters", gt.writeToString());
            i19.setDetail("Position", () -> CrashReportCategory.formatLocation(double4, double5, double6));
            throw new ReportedException(h18);
        }
    }
    
    private <T extends ParticleOptions> void addParticle(final T gt, final double double2, final double double3, final double double4, final double double5, final double double6, final double double7) {
        this.addParticle(gt, gt.getType().getOverrideLimiter(), double2, double3, double4, double5, double6, double7);
    }
    
    @Nullable
    private Particle addParticleInternal(final ParticleOptions gt, final boolean boolean2, final double double3, final double double4, final double double5, final double double6, final double double7, final double double8) {
        return this.addParticleInternal(gt, boolean2, false, double3, double4, double5, double6, double7, double8);
    }
    
    @Nullable
    private Particle addParticleInternal(final ParticleOptions gt, 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 dbb17 = this.minecraft.gameRenderer.getMainCamera();
        if (this.minecraft == null || !dbb17.isInitialized() || this.minecraft.particleEngine == null) {
            return null;
        }
        final ParticleStatus dbs18 = this.calculateParticleLevel(boolean3);
        if (boolean2) {
            return this.minecraft.particleEngine.createParticle(gt, double4, double5, double6, double7, double8, double9);
        }
        if (dbb17.getPosition().distanceToSqr(double4, double5, double6) > 1024.0) {
            return null;
        }
        if (dbs18 == ParticleStatus.MINIMAL) {
            return null;
        }
        return this.minecraft.particleEngine.createParticle(gt, double4, double5, double6, double7, double8, double9);
    }
    
    private ParticleStatus calculateParticleLevel(final boolean boolean1) {
        ParticleStatus dbs3 = this.minecraft.options.particles;
        if (boolean1 && dbs3 == ParticleStatus.MINIMAL && this.level.random.nextInt(10) == 0) {
            dbs3 = ParticleStatus.DECREASED;
        }
        if (dbs3 == ParticleStatus.DECREASED && this.level.random.nextInt(3) == 0) {
            dbs3 = ParticleStatus.MINIMAL;
        }
        return dbs3;
    }
    
    public void clear() {
    }
    
    public void globalLevelEvent(final int integer1, final BlockPos fk, final int integer3) {
        switch (integer1) {
            case 1023:
            case 1028:
            case 1038: {
                final Camera dbb5 = this.minecraft.gameRenderer.getMainCamera();
                if (!dbb5.isInitialized()) {
                    break;
                }
                final double double6 = fk.getX() - dbb5.getPosition().x;
                final double double7 = fk.getY() - dbb5.getPosition().y;
                final double double8 = fk.getZ() - dbb5.getPosition().z;
                final double double9 = Math.sqrt(double6 * double6 + double7 * double7 + double8 * double8);
                double double10 = dbb5.getPosition().x;
                double double11 = dbb5.getPosition().y;
                double double12 = dbb5.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 ayj, final int integer2, final BlockPos fk, final int integer4) {
        final Random random6 = this.level.random;
        switch (integer2) {
            case 1035: {
                this.level.playLocalSound(fk, SoundEvents.BREWING_STAND_BREW, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                break;
            }
            case 1033: {
                this.level.playLocalSound(fk, SoundEvents.CHORUS_FLOWER_GROW, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                break;
            }
            case 1034: {
                this.level.playLocalSound(fk, SoundEvents.CHORUS_FLOWER_DEATH, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                break;
            }
            case 1032: {
                this.minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.PORTAL_TRAVEL, random6.nextFloat() * 0.4f + 0.8f));
                break;
            }
            case 1001: {
                this.level.playLocalSound(fk, SoundEvents.DISPENSER_FAIL, SoundSource.BLOCKS, 1.0f, 1.2f, false);
                break;
            }
            case 1000: {
                this.level.playLocalSound(fk, SoundEvents.DISPENSER_DISPENSE, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                break;
            }
            case 1003: {
                this.level.playLocalSound(fk, SoundEvents.ENDER_EYE_LAUNCH, SoundSource.NEUTRAL, 1.0f, 1.2f, false);
                break;
            }
            case 1004: {
                this.level.playLocalSound(fk, SoundEvents.FIREWORK_ROCKET_SHOOT, SoundSource.NEUTRAL, 1.0f, 1.2f, false);
                break;
            }
            case 1002: {
                this.level.playLocalSound(fk, SoundEvents.DISPENSER_LAUNCH, SoundSource.BLOCKS, 1.0f, 1.2f, false);
                break;
            }
            case 2000: {
                final Direction fp7 = Direction.from3DDataValue(integer4);
                final int integer5 = fp7.getStepX();
                final int integer6 = fp7.getStepY();
                final int integer7 = fp7.getStepZ();
                final double double11 = fk.getX() + integer5 * 0.6 + 0.5;
                final double double12 = fk.getY() + integer6 * 0.6 + 0.5;
                final double double13 = fk.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 = fk.getX() + 0.5;
                final double double22 = fk.getY();
                final double double11 = fk.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 double double21 = fk.getX();
                final double double22 = fk.getY();
                final double double11 = fk.getZ();
                for (int integer9 = 0; integer9 < 8; ++integer9) {
                    this.<ItemParticleOption>addParticle(new ItemParticleOption(ParticleTypes.ITEM, new ItemStack(Items.SPLASH_POTION)), double21, double22, double11, random6.nextGaussian() * 0.15, random6.nextDouble() * 0.2, random6.nextGaussian() * 0.15);
                }
                final float float13 = (integer4 >> 16 & 0xFF) / 255.0f;
                final float float14 = (integer4 >> 8 & 0xFF) / 255.0f;
                final float float15 = (integer4 >> 0 & 0xFF) / 255.0f;
                final ParticleOptions gt16 = (integer2 == 2007) ? ParticleTypes.INSTANT_EFFECT : ParticleTypes.EFFECT;
                for (int integer8 = 0; integer8 < 100; ++integer8) {
                    final double double14 = random6.nextDouble() * 4.0;
                    final double double15 = random6.nextDouble() * 3.141592653589793 * 2.0;
                    final double double16 = Math.cos(double15) * double14;
                    final double double17 = 0.01 + random6.nextDouble() * 0.5;
                    final double double18 = Math.sin(double15) * double14;
                    final Particle doz28 = this.addParticleInternal(gt16, gt16.getType().getOverrideLimiter(), double21 + double16 * 0.1, double22 + 0.3, double11 + double18 * 0.1, double16, double17, double18);
                    if (doz28 != null) {
                        final float float16 = 0.75f + random6.nextFloat() * 0.25f;
                        doz28.setColor(float13 * float16, float14 * float16, float15 * float16);
                        doz28.setPower((float)double14);
                    }
                }
                this.level.playLocalSound(fk, SoundEvents.SPLASH_POTION_BREAK, SoundSource.NEUTRAL, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 2001: {
                final BlockState byj7 = Block.stateById(integer4);
                if (!byj7.isAir()) {
                    final SoundType bum8 = byj7.getSoundType();
                    this.level.playLocalSound(fk, bum8.getBreakSound(), SoundSource.BLOCKS, (bum8.getVolume() + 1.0f) / 2.0f, bum8.getPitch() * 0.8f, false);
                }
                this.minecraft.particleEngine.destroy(fk, byj7);
                break;
            }
            case 2004: {
                for (int integer5 = 0; integer5 < 20; ++integer5) {
                    final double double22 = fk.getX() + 0.5 + (this.level.random.nextFloat() - 0.5) * 2.0;
                    final double double11 = fk.getY() + 0.5 + (this.level.random.nextFloat() - 0.5) * 2.0;
                    final double double12 = fk.getZ() + 0.5 + (this.level.random.nextFloat() - 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, fk, integer4);
                break;
            }
            case 2008: {
                this.level.addParticle(ParticleTypes.EXPLOSION, fk.getX() + 0.5, fk.getY() + 0.5, fk.getZ() + 0.5, 0.0, 0.0, 0.0);
                break;
            }
            case 1500: {
                ComposterBlock.handleFill(this.level, fk, integer4 > 0);
                break;
            }
            case 1501: {
                this.level.playLocalSound(fk, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.5f, 2.6f + (this.level.getRandom().nextFloat() - this.level.getRandom().nextFloat()) * 0.8f, false);
                for (int integer5 = 0; integer5 < 8; ++integer5) {
                    this.level.addParticle(ParticleTypes.LARGE_SMOKE, fk.getX() + Math.random(), fk.getY() + 1.2, fk.getZ() + Math.random(), 0.0, 0.0, 0.0);
                }
                break;
            }
            case 1502: {
                this.level.playLocalSound(fk, SoundEvents.REDSTONE_TORCH_BURNOUT, SoundSource.BLOCKS, 0.5f, 2.6f + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.8f, false);
                for (int integer5 = 0; integer5 < 5; ++integer5) {
                    final double double22 = fk.getX() + random6.nextDouble() * 0.6 + 0.2;
                    final double double11 = fk.getY() + random6.nextDouble() * 0.6 + 0.2;
                    final double double12 = fk.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(fk, SoundEvents.END_PORTAL_FRAME_FILL, SoundSource.BLOCKS, 1.0f, 1.0f, false);
                for (int integer5 = 0; integer5 < 16; ++integer5) {
                    final double double22 = fk.getX() + (5.0f + random6.nextFloat() * 6.0f) / 16.0f;
                    final double double11 = fk.getY() + 0.8125f;
                    final double double12 = fk.getZ() + (5.0f + random6.nextFloat() * 6.0f) / 16.0f;
                    final double double13 = 0.0;
                    final double double23 = 0.0;
                    final double double24 = 0.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 float17 = random6.nextFloat() * 4.0f;
                    final float float18 = random6.nextFloat() * 6.2831855f;
                    final double double11 = Mth.cos(float18) * float17;
                    final double double12 = 0.01 + random6.nextDouble() * 0.5;
                    final double double13 = Mth.sin(float18) * float17;
                    final Particle doz29 = this.addParticleInternal(ParticleTypes.DRAGON_BREATH, false, fk.getX() + double11 * 0.1, fk.getY() + 0.3, fk.getZ() + double13 * 0.1, double11, double12, double13);
                    if (doz29 != null) {
                        doz29.setPower(float17);
                    }
                }
                this.level.playLocalSound(fk, SoundEvents.DRAGON_FIREBALL_EXPLODE, SoundSource.HOSTILE, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 2009: {
                for (int integer5 = 0; integer5 < 8; ++integer5) {
                    this.level.addParticle(ParticleTypes.CLOUD, fk.getX() + Math.random(), fk.getY() + 1.2, fk.getZ() + Math.random(), 0.0, 0.0, 0.0);
                }
                break;
            }
            case 1012: {
                this.level.playLocalSound(fk, SoundEvents.WOODEN_DOOR_CLOSE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1036: {
                this.level.playLocalSound(fk, SoundEvents.IRON_TRAPDOOR_CLOSE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1013: {
                this.level.playLocalSound(fk, SoundEvents.WOODEN_TRAPDOOR_CLOSE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1014: {
                this.level.playLocalSound(fk, SoundEvents.FENCE_GATE_CLOSE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1011: {
                this.level.playLocalSound(fk, SoundEvents.IRON_DOOR_CLOSE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1006: {
                this.level.playLocalSound(fk, SoundEvents.WOODEN_DOOR_OPEN, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1007: {
                this.level.playLocalSound(fk, SoundEvents.WOODEN_TRAPDOOR_OPEN, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1037: {
                this.level.playLocalSound(fk, SoundEvents.IRON_TRAPDOOR_OPEN, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1008: {
                this.level.playLocalSound(fk, SoundEvents.FENCE_GATE_OPEN, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1005: {
                this.level.playLocalSound(fk, SoundEvents.IRON_DOOR_OPEN, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1009: {
                this.level.playLocalSound(fk, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5f, 2.6f + (random6.nextFloat() - random6.nextFloat()) * 0.8f, false);
                break;
            }
            case 1029: {
                this.level.playLocalSound(fk, SoundEvents.ANVIL_DESTROY, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1030: {
                this.level.playLocalSound(fk, SoundEvents.ANVIL_USE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1031: {
                this.level.playLocalSound(fk, SoundEvents.ANVIL_LAND, SoundSource.BLOCKS, 0.3f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1039: {
                this.level.playLocalSound(fk, 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(), fk);
                    break;
                }
                this.playStreamingMusic(null, fk);
                break;
            }
            case 1015: {
                this.level.playLocalSound(fk, SoundEvents.GHAST_WARN, SoundSource.HOSTILE, 10.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1017: {
                this.level.playLocalSound(fk, SoundEvents.ENDER_DRAGON_SHOOT, SoundSource.HOSTILE, 10.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1016: {
                this.level.playLocalSound(fk, SoundEvents.GHAST_SHOOT, SoundSource.HOSTILE, 10.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1019: {
                this.level.playLocalSound(fk, SoundEvents.ZOMBIE_ATTACK_WOODEN_DOOR, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1022: {
                this.level.playLocalSound(fk, SoundEvents.WITHER_BREAK_BLOCK, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1021: {
                this.level.playLocalSound(fk, SoundEvents.ZOMBIE_BREAK_WOODEN_DOOR, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1020: {
                this.level.playLocalSound(fk, SoundEvents.ZOMBIE_ATTACK_IRON_DOOR, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1018: {
                this.level.playLocalSound(fk, SoundEvents.BLAZE_SHOOT, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1024: {
                this.level.playLocalSound(fk, SoundEvents.WITHER_SHOOT, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1026: {
                this.level.playLocalSound(fk, SoundEvents.ZOMBIE_INFECT, SoundSource.HOSTILE, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1027: {
                this.level.playLocalSound(fk, SoundEvents.ZOMBIE_VILLAGER_CONVERTED, SoundSource.NEUTRAL, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1040: {
                this.level.playLocalSound(fk, SoundEvents.ZOMBIE_CONVERTED_TO_DROWNED, SoundSource.NEUTRAL, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1041: {
                this.level.playLocalSound(fk, SoundEvents.HUSK_CONVERTED_TO_ZOMBIE, SoundSource.NEUTRAL, 2.0f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1025: {
                this.level.playLocalSound(fk, SoundEvents.BAT_TAKEOFF, SoundSource.NEUTRAL, 0.05f, (random6.nextFloat() - random6.nextFloat()) * 0.2f + 1.0f, false);
                break;
            }
            case 1042: {
                this.level.playLocalSound(fk, SoundEvents.GRINDSTONE_USE, SoundSource.BLOCKS, 1.0f, this.level.random.nextFloat() * 0.1f + 0.9f, false);
                break;
            }
            case 1043: {
                this.level.playLocalSound(fk, 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, fk.getX() + 0.5, fk.getY() + 0.5, fk.getZ() + 0.5, 0.0, 0.0, 0.0);
                this.level.playLocalSound(fk, 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(fk, 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 fk, final int integer3) {
        if (integer3 < 0 || integer3 >= 10) {
            final BlockDestructionProgress wn5 = (BlockDestructionProgress)this.destroyingBlocks.remove(integer1);
            if (wn5 != null) {
                this.removeProgress(wn5);
            }
        }
        else {
            BlockDestructionProgress wn5 = (BlockDestructionProgress)this.destroyingBlocks.get(integer1);
            if (wn5 != null) {
                this.removeProgress(wn5);
            }
            if (wn5 == null || wn5.getPos().getX() != fk.getX() || wn5.getPos().getY() != fk.getY() || wn5.getPos().getZ() != fk.getZ()) {
                wn5 = new BlockDestructionProgress(integer1, fk);
                this.destroyingBlocks.put(integer1, wn5);
            }
            wn5.setProgress(integer3);
            wn5.updateTick(this.ticks);
            ((SortedSet)this.destructionProgress.computeIfAbsent(wn5.getPos().asLong(), long1 -> Sets.<Comparable>newTreeSet())).add(wn5);
        }
    }
    
    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 bje, final BlockPos fk) {
        return getLightColor(bje, bje.getBlockState(fk), fk);
    }
    
    public static int getLightColor(final BlockAndTintGetter bje, final BlockState byj, final BlockPos fk) {
        if (byj.emissiveRendering()) {
            return 15728880;
        }
        final int integer4 = bje.getBrightness(LightLayer.SKY, fk);
        int integer5 = bje.getBrightness(LightLayer.BLOCK, fk);
        final int integer6 = byj.getLightEmission();
        if (integer5 < integer6) {
            integer5 = integer6;
        }
        return integer4 << 20 | integer5 << 4;
    }
    
    public RenderTarget entityTarget() {
        return this.entityTarget;
    }
    
    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 fp, final int integer) {
            this.chunk = c;
            this.sourceDirection = fp;
            this.step = integer;
        }
        
        public void setDirections(final byte byte1, final Direction fp) {
            this.directions |= (byte)(byte1 | 1 << fp.ordinal());
        }
        
        public boolean hasDirection(final Direction fp) {
            return (this.directions & 1 << fp.ordinal()) > 0;
        }
    }
}
