示例#1
0
        public int GetBiome(int x, int y, int z)
        {
            if (y < 0 || y >= ChunkManager.H)
            {
                return(127);
            }
            int cx = x >> 4;
            int cz = z >> 4;

            ChunkManager chunk = GetChunk(cx, cz, false);

            if ((object)chunk == null)
            {
                return(127);
            }

            int          cy      = y >> 4;
            ChunkSection section = chunk.Sections[cy];

            if ((object)section == null)
            {
                return(127);
            }

            int bx = x & 0x000F;
            int bz = z & 0x000F;

            return(section.Chunk.BlockBiomeArray[bz * 16 | bx]);
        }
示例#2
0
        public int GetBlock(int x, int y, int z)
        {
            if (y < 0 || y >= ChunkManager.H)
            {
                return(0);
            }
            int cx = x >> 4;
            int cz = z >> 4;

            ChunkManager chunk = GetChunk(cx, cz, false);

            if ((object)chunk == null)
            {
                return(0);
            }

            int          cy      = y >> 4;
            ChunkSection section = chunk.Sections[cy];

            if ((object)section == null)
            {
                return(0);
            }

            int bx = x & 0x000F;
            int by = y & 0x000F;
            int bz = z & 0x000F;

            return(section.Data[bx, by, bz]);
        }
示例#3
0
        public void GetLight(int x, int y, int z, out float block, out float sky)
        {
            if (y < 0 || y >= ChunkManager.H)
            {
                block = sky = 15;
                return;
            }
            int cx = x >> 4;
            int cz = z >> 4;

            ChunkManager chunk = GetChunk(cx, cz, false);

            if ((object)chunk == null)
            {
                block = sky = 15;
                return;
            }

            int          cy      = y >> 4;
            ChunkSection section = chunk.Sections[cy];

            if ((object)section == null)
            {
                block = sky = 15;
                return;
            }

            int bx = x & 0x000F;
            int by = y & 0x000F;
            int bz = z & 0x000F;

            block = section.BlocklightArray[bx, by, bz];
            sky   = section.SkylightArray[bx, by, bz];

            // For better AO
            int blockId = section.Data[bx, by, bz];

            if (blockId != 0 && GameSession.Palette[blockId].ClassicBlock)
            {
                block -= 2;
                sky   -= 2;
            }
        }
示例#4
0
        private ChunkSection CreateSection(int y)
        {
            GameObject sectionObj = new GameObject();

            sectionObj.transform.parent = this.transform;
            var coll = sectionObj.AddComponent <MeshCollider>();
            //coll.cookingOptions = MeshColliderCookingOptions.;
            MeshRenderer renderer = sectionObj.AddComponent <MeshRenderer>();

            renderer.reflectionProbeUsage       = UnityEngine.Rendering.ReflectionProbeUsage.Off;
            renderer.shadowCastingMode          = UnityEngine.Rendering.ShadowCastingMode.Off;
            renderer.receiveShadows             = false;
            renderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
            renderer.lightProbeUsage            = UnityEngine.Rendering.LightProbeUsage.Off;
            renderer.sharedMaterials            = World.Materials;
            sectionObj.AddComponent <MeshFilter>();
            ChunkSection section = sectionObj.AddComponent <ChunkSection>();

            section.Init(this, y);
            sectionObj.transform.localPosition = new Vector3(0, section.WorldY);
            return(section);
        }
示例#5
0
        public void FillChunk(MemoryStream ms, int primaryBitMask, bool groundUpContinuous)
        {
            for (int i = 0; i < Sections.Length; i++)
            {
                ChunkSection section = Sections[i];

                if ((primaryBitMask & 1 << i) == 0)
                {
                    if (groundUpContinuous)
                    {
                        Sections[i] = null;
                    }
                }
                else
                {
                    if (section == null)
                    {
                        Sections[i] = section = CreateSection(i);
                    }

                    section.FillSection(ms);
                    ms.Read(section.BlocklightArray.Data);

                    if (World.Overworld)
                    {
                        ms.Read(section.SkylightArray.Data);
                    }
                    section.Rend();
                }
            }

            if (groundUpContinuous)
            {
                ms.Read(BlockBiomeArray);
            }
        }
示例#6
0
        public void TryRendFromQueue(int centerX, int centerY, int centerZ)
        {
            ChunkSection bestSection = null;

            ChunkSection[] bestSectionSides = new ChunkSection[6];
            float          bestDistance     = 999999;

            foreach (ChunkSection section in RenderQueue)
            {
                ChunkManager chunkLeft = GetChunk(section.Chunk.Position.Left(), false);
                if (chunkLeft == null)
                {
                    continue;
                }
                ChunkManager chunkRight = GetChunk(section.Chunk.Position.Right(), false);
                if (chunkRight == null)
                {
                    continue;
                }
                ChunkManager chunkFront = GetChunk(section.Chunk.Position.Front(), false);
                if (chunkFront == null)
                {
                    continue;
                }
                ChunkManager chunkBack = GetChunk(section.Chunk.Position.Back(), false);
                if (chunkBack == null)
                {
                    continue;
                }

                float distance = Vector3.Distance(new Vector3(centerX, 0, centerZ),
                                                  section.Chunk.Position);

                int yDist = Math.Abs(centerY - section.Y);
                if (yDist > 2)
                {
                    yDist *= 4;
                }

                distance += yDist;

                if (distance < bestDistance)
                {
                    bestDistance        = distance;
                    bestSection         = section;
                    bestSectionSides[0] = chunkLeft.Sections[section.Y];
                    bestSectionSides[1] = chunkRight.Sections[section.Y];
                    bestSectionSides[2] = chunkFront.Sections[section.Y];
                    bestSectionSides[3] = chunkBack.Sections[section.Y];
                    if (section.Y > 0)
                    {
                        bestSectionSides[4] = section.Chunk.Sections[section.Y - 1];
                    }
                    else
                    {
                        bestSectionSides[4] = null;
                    }
                    if (section.Y < 15)
                    {
                        bestSectionSides[5] = section.Chunk.Sections[section.Y + 1];
                    }
                    else
                    {
                        bestSectionSides[5] = null;
                    }
                }
            }
            if (bestSection != null)
            {
                foreach (ChunkSection sectionSide in bestSectionSides)
                {
                    sectionSide?.DecodeLongs();
                }
                bestSection.DecodeLongs();
                bestSection.Rend(true);
                RenderQueue.Remove(bestSection);
            }
        }