Beispiel #1
0
 public ChunkRef GetChunk(NbtWorld World, int X, int Z)
 {
     ChunkRef tr;
     lock (World) {
         if (World.GetChunkManager ().ChunkExists (X, Z)) {
             World.GetChunkManager ().DeleteChunk (X, Z); //Delete the chunk if it exists.
         }
         tr = World.GetChunkManager ().CreateChunk (X, Z);
         Populate (tr);
         return tr;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Save changes to a modified Minecraft world.
        /// </summary>
        /// <param name="world">The world to be saved. The world will be written back to the location it was opened from.</param>
        /// <returns name="world">The world to be saved</returns>
        public static NbtWorld SaveWorld(NbtWorld world)
        {
            RegionChunkManager rcm = (RegionChunkManager)world.GetChunkManager();
            rcm.RelightDirtyChunks();

            world.Save();

            return world;
        }
        public void ApplyChunk (NbtWorld world, ChunkRef chunk)
        {
            if (opt.OPT_V) {
                Console.WriteLine("Generating {0} size {1} deposits of {2} between {3} and {4}",
                    opt.OPT_ROUNDS, opt.OPT_SIZE, opt.OPT_ID, opt.OPT_MIN, opt.OPT_MAX);
            }

            IGenerator generator;
            if (opt.OPT_DATA == null) {
                generator = new NativeGenOre((int)opt.OPT_ID, (int)opt.OPT_SIZE);
                ((NativeGenOre)generator).MathFix = opt.OPT_MATHFIX;
            }
            else {
                generator = new NativeGenOre((int)opt.OPT_ID, (int)opt.OPT_DATA, (int)opt.OPT_SIZE);
                ((NativeGenOre)generator).MathFix = opt.OPT_MATHFIX;
            }

            IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
            IBlockManager bm = new GenOreBlockManager(cm, opt);

            for (int i = 0; i < opt.OPT_ROUNDS; i++) {
                if (opt.OPT_VV) {
                    Console.WriteLine("Generating round {0}...", i);
                }

                int x = chunk.X * chunk.Blocks.XDim + rand.Next(chunk.Blocks.XDim);
                int y = (int)opt.OPT_MIN + rand.Next((int)opt.OPT_MAX - (int)opt.OPT_MIN);
                int z = chunk.Z * chunk.Blocks.ZDim + rand.Next(chunk.Blocks.ZDim);

                generator.Generate(bm, rand, x, y, z);
            }
        }
        private IEnumerable<ChunkRef> CreateWorld(NbtWorld world)
        {
            var cm = world.GetChunkManager();
            var radius = 10;
            int xmin = -radius;
            int xmax = radius;
            int zmin = -radius;
            int zmaz = radius;

            world.Level.AllowCommands = true;
            world.Level.LevelName = "MineDefined";
            world.Level.Spawn = new SpawnPoint(-5, -5, 9);

            world.Level.SetDefaultPlayer();
            world.Level.Player.GameType= PlayerGameType.Creative;
            world.Level.Player.Position = new Vector3() {
                X = -5,
                Y = 9,
                Z = -5
            };
            world.Level.Player.IsOnGround = false;
            var chunks = new List<ChunkRef>();

            // We'll create chunks at chunk coordinates xmin,zmin to xmax,zmax
            for (int xi = xmin; xi < xmax; xi++)
            {
                for (int zi = zmin; zi < zmaz; zi++)
                {
                    // This line will create a default empty chunk, and create a
                    // backing region file if necessary (which will immediately be
                    // written to disk)
                    ChunkRef chunk = cm.CreateChunk(xi, zi);
                    chunks.Add(chunk);

                    // This will suppress generating caves, ores, and all those
                    // other goodies.
                    chunk.IsTerrainPopulated = true;

                    // Auto light recalculation is horrifically bad for creating
                    // chunks from scratch, because we're placing thousands
                    // of blocks.  Turn it off.
                    chunk.Blocks.AutoLight = false;

                    // Set the blocks
                    FlatChunk(chunk, 8);

                    //Console.WriteLine("Built Chunk {0},{1}", chunk.X, chunk.Z);

                    // Save the chunk to disk so it doesn't hang around in RAM
                }
            }
            return chunks;
        }