MineViewer.SMPInterface.GetChunk C# (CSharp) Method

GetChunk() public static method

public static GetChunk ( Cubia pos, bool trans ) : MinecraftLevel.Chunk
pos Cubia
trans bool
return MinecraftLevel.Chunk
        public static MinecraftLevel.Chunk GetChunk(Cubia.Point<int> pos, bool trans)
        {
            MinecraftLevel.Chunk c;
            if (!trans)
                Chunks.TryGetValue(pos, out c);
            else
                TransChunks.TryGetValue(pos, out c);
            return c;
        }

Usage Example

示例#1
0
        /// <summary>
        /// Tries loading the chunk at the specified position. This is done automatically
        /// when an area is requested.
        /// </summary>
        public Chunk?LoadChunk(Point <int> Pos)
        {
            Chunk?chunk;

            if (SMPInterface.IsSMP)
            {
                chunk = SMPInterface.GetChunk(Pos, this._Trans);
            }
            else if (!this._Chunks.TryGetValue(Pos, out chunk))
            {
                long   regionX = (long)Math.Floor((decimal)Pos.X / 32);
                long   regionZ = (long)Math.Floor((decimal)Pos.Y / 32);
                string file    = this._Source + Path.DirectorySeparatorChar + "region" + Path.DirectorySeparatorChar + "r." +
                                 Convert.ToString(regionX) + "." + Convert.ToString(regionZ) + ".mca";

                if (File.Exists(file))
                {
                    try
                    {
                        using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) //File.OpenRead(file))
                        {
                            NBTNamedTag <INBTData> dat   = NBT.ReadChunk(fs, Pos);
                            NBTCompound            level = (NBTCompound)(((NBTCompound)dat.Data).Data["Level"]).Data;
                            this._Chunks.Add(Pos,
                                             chunk = ParseChunkFromNBT(level)
                                             );
                        }
                    }
                    catch
                    {
                        this._Chunks.Add(Pos, null);
                    }
                }
                else
                {
                    this._Chunks.Add(Pos, null);
                }
            }
            return(chunk);
        }