Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap bm = new Bitmap(2048, 2176);

            NbtWorld world = NbtWorld.Open(@"E:\games\Curse\Instances\Modern Skyblock 2\saves\Kekimuro");

            // The chunk manager is more efficient than the block manager for
            // this purpose, since we'll inspect every block
            Substrate.Core.IChunkManager rcm = world.GetChunkManager();

            foreach (ChunkRef chunk in rcm)
            {
                // You could hardcode your dimensions, but maybe some day they
                // won't always be 16.  Also the CLR is a bit stupid and has
                // trouble optimizing repeated calls to Chunk.Blocks.xx, so we
                // cache them in locals
                int xdim = chunk.Blocks.XDim;
                int ydim = chunk.Blocks.YDim;
                int zdim = chunk.Blocks.ZDim;
                AnvilBiomeCollection chunkBiome = chunk.Biomes;

                // x, z, y is the most efficient order to scan blocks (not that
                // you should care about internal detail)
                for (int x = 0; x < xdim; x++)
                {
                    for (int z = 0; z < zdim; z++)
                    {
                        int biome = chunkBiome.GetBiome(x, z);
                        bm.SetPixel(chunk.X * xdim + x, chunk.Z * zdim + z, Biomes.id2color(biome));
                    }
                }
            }
            pictureBox1.Image = bm;
        }
Ejemplo n.º 2
0
        public void BlockTest_1_9_2_debug()
        {
            NbtWorld world = NbtWorld.Open(@"..\..\Data\1_9_2-debug\");

            Assert.IsNotNull(world);

            bool dataError = false;

            for (int x = DebugWorld.MinX; x < DebugWorld.MaxX; x += 2)
            {
                for (int z = DebugWorld.MinZ; z < DebugWorld.MaxZ; z += 2)
                {
                    var blockRef  = world.GetBlockManager().GetBlockRef(x, DebugWorld.Y, z);
                    var blockInfo = BlockInfo.BlockTable[blockRef.ID];

                    Debug.WriteLine(string.Format("ID:{0} ({1}), Data:{2}", blockRef.ID, blockInfo.Name, blockRef.Data));

                    Assert.IsTrue(blockInfo.Registered, "Block ID {0} has not been registered", blockRef.ID);
                    if (!blockInfo.TestData(blockRef.Data))
                    {
                        dataError = true;
                        Debug.WriteLine("Data value '0x{0:X4}' not recognised for block '{1}' at {2},{3}", blockRef.Data, blockInfo.Name, x, z);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Usage: MoveSpawn <world> <x> <y> <z>");
                return;
            }

            string dest = args[0];
            int    x    = Convert.ToInt32(args[1]);
            int    y    = Convert.ToInt32(args[2]);
            int    z    = Convert.ToInt32(args[3]);

            // Open our world
            NbtWorld world = NbtWorld.Open(dest);

            // Set the level's spawn
            // Note: Players do not have separate spawns by default
            // If you wanted to change a player's spawn, you must set all
            // 3 coordinates for it to stick.  It will not take the level's defaults.
            world.Level.Spawn = new SpawnPoint(x, y, z);

            // Save the changes
            world.Save();
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            TileEntityFactory.Register(TileEntityBrewingStand.TypeId, typeof(TileEntityBrewingStand));
            TileEntityFactory.Register(TileEntityChest.TypeId, typeof(TileEntityChest));
            TileEntityFactory.Register(TileEntityTrap.TypeId, typeof(TileEntityTrap));
            TileEntityFactory.Register(TileEntityMobSpawner.TypeId, typeof(TileEntityMobSpawner));

            string   path  = args.Length == 0 ? "." : string.Join(" ", args);
            NbtWorld world = NbtWorld.Open(path);

            if (world == null)
            {
                Dialog.WorldInvalidDialog();
                return;
            }
            Console.WriteLine("Working with world: {0}", world.Level.LevelName);
            fixPotions  = Dialog.FixPotionsDialog();
            fixSpawners = Dialog.FixSpawnersDialog();
            DateTime startTime = DateTime.Now;

            LoopChunks(world, Dimension.DEFAULT);
            LoopChunks(world, Dimension.NETHER);
            LoopChunks(world, Dimension.THE_END);
            TimeSpan time = DateTime.Now.Subtract(startTime);

            Console.Write("Finished searching {0} in {1}. Fixed:", world.Level.LevelName, time.ToString(@"h\:mm\:ss"));
            Console.Write(" [{0} chest{1}]", fixedIssues["chest"], fixedIssues["chest"] == 1 ? "" : "s");
            Console.Write(" [{0} potion{1}]", fixedIssues["potion"], fixedIssues["potion"] == 1 ? "" : "s");
            Console.Write(" [{0} spawner{1}]", fixedIssues["spawner"], fixedIssues["spawner"] == 1 ? "" : "s");
            Console.WriteLine();
            Dialog.NewDialog();
        }
Ejemplo n.º 5
0
        public override void Run()
        {
            NbtWorld             world = GetWorld(opt);
            IChunkManager        cm    = world.GetChunkManager(opt.OPT_DIM);
            FilteredChunkManager fcm   = new FilteredChunkManager(cm, opt.GetChunkFilter());

            int affectedChunks = 0;

            foreach (ChunkRef chunk in fcm)
            {
                if (chunk == null || !chunk.IsTerrainPopulated)
                {
                    continue;
                }

                if (opt.OPT_V)
                {
                    Console.WriteLine("Processing Chunk (" + chunk.X + "," + chunk.Z + ")");
                }

                affectedChunks++;

                ApplyChunk(world, chunk);

                fcm.Save();
            }

            Console.WriteLine("Affected Chunks: " + affectedChunks);
        }
Ejemplo n.º 6
0
        public override void Run()
        {
            NbtWorld             world = GetWorld(opt);
            IChunkManager        cm    = world.GetChunkManager(opt.OPT_DIM);
            FilteredChunkManager fcm   = new FilteredChunkManager(cm, opt.GetChunkFilter());

            StreamWriter fstr;

            try {
                fstr = new StreamWriter(opt._outFile, false);
            }
            catch (IOException e) {
                Console.WriteLine(e.Message);
                return;
            }

            fstr.WriteLine("[");

            bool first = true;

            foreach (ChunkRef chunk in fcm)
            {
                if (!first)
                {
                    fstr.Write(",");
                }

                Chunk c = chunk.GetChunkRef();

                if (!opt._dumpBlocks)
                {
                    c.Tree.Root["Level"].ToTagCompound().Remove("Blocks");
                    c.Tree.Root["Level"].ToTagCompound().Remove("Data");
                    c.Tree.Root["Level"].ToTagCompound().Remove("BlockLight");
                    c.Tree.Root["Level"].ToTagCompound().Remove("SkyLight");
                    c.Tree.Root["Level"].ToTagCompound().Remove("HeightMap");
                }

                if (!opt._dumpEntities)
                {
                    c.Tree.Root["Level"].ToTagCompound().Remove("Entities");
                }

                if (!opt._dumpTileEntities)
                {
                    c.Tree.Root["Level"].ToTagCompound().Remove("TileEntities");
                }

                string s = JSONSerializer.Serialize(c.Tree.Root["Level"], 1);
                fstr.Write(s);

                first = false;
            }

            fstr.WriteLine();
            fstr.WriteLine("]");

            fstr.Close();
        }
Ejemplo n.º 7
0
        private World([NotNull] NbtWorld world)
        {
            if (world == null)
            {
                throw new ArgumentNullException("world");
            }

            _nbtWorld  = world;
            _directory = new DirectoryInfo(world.Path);
        }
Ejemplo n.º 8
0
 public mapReader(string mapFilePath)
 {
     nbtWorld        = NbtWorld.Open(mapFilePath);
     chunkManager    = nbtWorld.GetChunkManager();
     chunkEnumerator = chunkManager.GetEnumerator();
     chunkEnumerator.MoveNext();
     CurrentChunk  = chunkEnumerator.Current;
     CurrentHeight = 0;
     readASlice();
 }
Ejemplo n.º 9
0
        public void initializeMinecraftWorld()
        {
            currentWorld = AnvilWorld.Create(Settings.Default.outputPath);

            // We can set different world parameters
            currentWorld.Level.LevelName     = Settings.Default.levelName;
            currentWorld.Level.Spawn         = new SpawnPoint(20, 255, 20);
            currentWorld.Level.GameType      = GameType.CREATIVE;
            currentWorld.Level.AllowCommands = true;
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Usage: BlockReplace <world> <before-id> <after-id>");
                return;
            }

            string dest   = args[0];
            int    before = Convert.ToInt32(args[1]);
            int    after  = Convert.ToInt32(args[2]);

            // Open our world
            NbtWorld world = NbtWorld.Open(dest);

            // The chunk manager is more efficient than the block manager for
            // this purpose, since we'll inspect every block
            IChunkManager cm = world.GetChunkManager();

            foreach (ChunkRef chunk in cm)
            {
                // You could hardcode your dimensions, but maybe some day they
                // won't always be 16.  Also the CLR is a bit stupid and has
                // trouble optimizing repeated calls to Chunk.Blocks.xx, so we
                // cache them in locals
                int xdim = chunk.Blocks.XDim;
                int ydim = chunk.Blocks.YDim;
                int zdim = chunk.Blocks.ZDim;

                // x, z, y is the most efficient order to scan blocks (not that
                // you should care about internal detail)
                for (int x = 0; x < xdim; x++)
                {
                    for (int z = 0; z < zdim; z++)
                    {
                        for (int y = 0; y < ydim; y++)
                        {
                            // Replace the block with after if it matches before
                            if (chunk.Blocks.GetID(x, y, z) == before)
                            {
                                chunk.Blocks.SetData(x, y, z, 0);
                                chunk.Blocks.SetID(x, y, z, after);
                            }
                        }
                    }
                }

                // Save the chunk
                cm.Save();

                Console.WriteLine("Processed Chunk {0},{1}", chunk.X, chunk.Z);
            }
        }
Ejemplo n.º 11
0
        public static World Open(string path)
        {
            var world = NbtWorld.Open(path);

            if (world == null)
            {
                return(null);
            }

            var mcfire = new World(world);

            return(mcfire);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Loads the Mincraft world files into a Nbt file using Substrate
        /// </summary>
        /// <param name="inputPath">Location of Minecraft saved wold files</param>
        /// <returns>True if successfully loaded world</returns>
        public static bool LoadWorld(string inputPath)
        {
            importedWorld = NbtWorld.Open(inputPath);

            if (importedWorld != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: GoodyChest <world> <prob>");
                return;
            }

            string dest = args[0];
            double p    = Convert.ToDouble(args[1]);

            rand = new Random();

            // Open our world
            NbtWorld      world = NbtWorld.Open(dest);
            IChunkManager cm    = world.GetChunkManager();

            int added = 0;

            // Iterate through every chunk in the world
            // With proability p, pick a random location
            // inside the chunk to place a chest, above the
            // first solid block
            foreach (ChunkRef chunk in cm)
            {
                if (rand.NextDouble() < p)
                {
                    int x = rand.Next(chunk.Blocks.XDim);
                    int z = rand.Next(chunk.Blocks.ZDim);
                    int y = chunk.Blocks.GetHeight(x, z);

                    // Can't build this high (-2 to account for new MC 1.6 height limitation)
                    if (y >= chunk.Blocks.YDim - 2)
                    {
                        continue;
                    }

                    // Get a block object, then assign it to the chunk
                    AlphaBlock block = BuildChest();
                    chunk.Blocks.SetBlock(x, y + 1, z, block);

                    // Save the chunk
                    cm.Save();

                    added++;
                }
            }

            // And we're done
            Console.WriteLine("Added {0} goody chests to world", added);
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Usage: Convert <world> <dest> <alpha|beta|anvil>");
                return;
            }

            string src     = args[0];
            string dst     = args[1];
            string srctype = args[2];

            if (!Directory.Exists(dst))
            {
                Directory.CreateDirectory(dst);
            }

            // Open source and destrination worlds depending on conversion type
            NbtWorld srcWorld = NbtWorld.Open(src);
            NbtWorld dstWorld;

            switch (srctype)
            {
            case "alpha": dstWorld = AlphaWorld.Create(dst); break;

            case "beta": dstWorld = BetaWorld.Create(dst); break;

            case "anvil": dstWorld = AnvilWorld.Create(dst); break;

            default: throw new Exception("Invalid conversion type");
            }

            // Grab chunk managers to copy chunks
            IChunkManager cmsrc = srcWorld.GetChunkManager();
            IChunkManager cmdst = dstWorld.GetChunkManager();

            // Copy each chunk from source to dest
            foreach (ChunkRef chunk in cmsrc)
            {
                cmdst.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef());
                Console.WriteLine("Copying chunk: {0}, {1}", chunk.X, chunk.Z);
            }

            // Copy level data from source to dest
            dstWorld.Level.LoadTreeSafe(srcWorld.Level.BuildTree());

            // Save level.dat
            dstWorld.Level.Save();
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("You must specify a target directory");
                return;
            }
            string dest = args[0];

            NbtVerifier.InvalidTagType += (e) => {
                throw new Exception("Invalid Tag Type: " + e.TagName + " [" + e.Tag + "]");
            };
            NbtVerifier.InvalidTagValue += (e) => {
                throw new Exception("Invalid Tag Value: " + e.TagName + " [" + e.Tag + "]");
            };
            NbtVerifier.MissingTag += (e) => {
                throw new Exception("Missing Tag: " + e.TagName);
            };

            // Opening an NbtWorld will try to autodetect if a world is Alpha-style or Beta-style
            NbtWorld world = NbtWorld.Open(dest);

            // Grab a generic chunk manager reference
            IChunkManager cm = world.GetChunkManager();

            // First blank out all of the lighting in all of the chunks
            foreach (ChunkRef chunk in cm)
            {
                chunk.Blocks.RebuildHeightMap();
                chunk.Blocks.ResetBlockLight();
                chunk.Blocks.ResetSkyLight();

                cm.Save();

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

            // In a separate pass, reconstruct the light
            foreach (ChunkRef chunk in cm)
            {
                chunk.Blocks.RebuildBlockLight();
                chunk.Blocks.RebuildSkyLight();

                // Save the chunk to disk so it doesn't hang around in RAM
                cm.Save();

                Console.WriteLine("Lit Chunk {0},{1}", chunk.X, chunk.Z);
            }
        }
Ejemplo n.º 16
0
        protected override void SetWorld()
        {
            // Open MCA world
            m_MCAWorld = NbtWorld.Open(MCAPath);
            //m_cm = m_MCAWorld.GetChunkManager();

            // Sanity check
            //int tmp = 0;
            //foreach(ChunkRef ch in m_cm)
            //{
            //    tmp++;
            //    if(tmp > 100) { break; }
            //    if(ch.Blocks == null) { continue; }
            //    Debug.Log($"Good chunk at {ch.X}, {ch.Z}");
            //}
        }
Ejemplo n.º 17
0
        public override void Run()
        {
            NbtWorld             world = GetWorld(opt);
            IChunkManager        cm    = world.GetChunkManager(opt.OPT_DIM);
            FilteredChunkManager fcm   = new FilteredChunkManager(cm, opt.GetChunkFilter());

            int affectedChunks = 0;

            foreach (ChunkRef chunk in fcm)
            {
                affectedChunks++;
                fcm.DeleteChunk(chunk.X, chunk.Z);
            }

            Console.WriteLine("Purged Chunks: " + affectedChunks);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: CustomBlock <world>");
                return;
            }

            string dest = args[0];

            // Open our world
            NbtWorld world = NbtWorld.Open(dest);

            // The chunk manager is more efficient than the block manager for
            // this purpose, since we'll inspect every block
            IChunkManager cm = world.GetChunkManager();

            foreach (ChunkRef chunk in cm)
            {
                // You could hardcode your dimensions, but maybe some day they
                // won't always be 16.  Also the CLR is a bit stupid and has
                // trouble optimizing repeated calls to Chunk.Blocks.xx, so we
                // cache them in locals
                int xdim = chunk.Blocks.XDim;
                int ydim = chunk.Blocks.YDim;
                int zdim = chunk.Blocks.ZDim;

                chunk.Blocks.AutoFluid = true;

                // x, z, y is the most efficient order to scan blocks (not that
                // you should care about internal detail)
                for (int x = 0; x < xdim; x++)
                {
                    for (int z = 0; z < zdim; z++)
                    {
                        for (int y = 0; y < ydim; y++)
                        {
                            BlockInfo info = chunk.Blocks.GetInfo(x, y, z);
                            if (info.ID == BlockInfoM.LightSensor.ID)
                            {
                                Console.WriteLine("Found custom block '{0}' at {1}", info.Name, new BlockKey(x, y, z));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            // Process arguments
            if (args.Length != 2 && args.Length != 6)
            {
                Console.WriteLine("Usage: PurgeEntities <world> <entityID> [<x1> <z1> <x2> <z2>]");
                return;
            }
            string dest = args[0];
            string eid  = args[1];

            // Our initial bounding box is "infinite"
            int x1 = BlockManager.MIN_X;
            int x2 = BlockManager.MAX_X;
            int z1 = BlockManager.MIN_Z;
            int z2 = BlockManager.MAX_Z;

            // If we have all coordinate parameters, set the bounding box
            if (args.Length == 6)
            {
                x1 = Convert.ToInt32(args[2]);
                z1 = Convert.ToInt32(args[3]);
                x2 = Convert.ToInt32(args[4]);
                z2 = Convert.ToInt32(args[5]);
            }

            // Load world
            NbtWorld      world = NbtWorld.Open(dest);
            IChunkManager cm    = world.GetChunkManager();

            // Remove entities
            foreach (ChunkRef chunk in cm)
            {
                // Skip chunks that don't cover our selected area
                if (((chunk.X + 1) * chunk.Blocks.XDim < x1) ||
                    (chunk.X * chunk.Blocks.XDim >= x2) ||
                    ((chunk.Z + 1) * chunk.Blocks.ZDim < z1) ||
                    (chunk.Z * chunk.Blocks.ZDim >= z2))
                {
                    continue;
                }

                // Delete the specified entities
                chunk.Entities.RemoveAll(eid);
                cm.Save();
            }
        }
Ejemplo n.º 20
0
        //NbtWorld nbtWorld;

        public MCALoaderChunkGeneratorJob(bool useID, NbtWorld nbtWorld, string savePath, int x, int ySize, int z, List <Chunk> chunksFromYBottomToTop) : base(chunksFromYBottomToTop)
        {
            this.useID = useID;
            this.x     = x;
            this.ySize = ySize;
            this.z     = z;
            //this.nbtWorld = nbtWorld;
            if (cmPool == null)
            {
                cmPool = new Matryoshka.Utils.PerThreadPool <IChunkManager>(() =>
                {
                    //return NbtWorld.Open(savePath).GetChunkManager();
                    return(nbtWorld.GetChunkManager());
                });
            }
            this.isUnique = false;
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Usage: GiveItem <world> <player> <item-id> <cnt>");
                return;
            }

            string dest   = args[0];
            string player = args[1];
            int    itemid = Convert.ToInt32(args[2]);
            int    count  = Convert.ToInt32(args[3]);

            // Open the world and grab its player manager
            NbtWorld       world = NbtWorld.Open(dest);
            IPlayerManager pm    = world.GetPlayerManager();

            // Check that the named player exists
            if (!pm.PlayerExists(player))
            {
                Console.WriteLine("No such player {0}!", player);
                return;
            }

            // Get player (returned object is independent of the playermanager)
            Player p = pm.GetPlayer(player);

            // Find first slot to place item
            for (int i = 0; i < p.Items.Capacity; i++)
            {
                if (!p.Items.ItemExists(i))
                {
                    // Create the item and set its stack count
                    Item item = new Item(itemid);
                    item.Count = count;
                    p.Items[i] = item;

                    // Don't keep adding items
                    break;
                }
            }

            // Save the player
            pm.SetPlayer(player, p);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates a new <see cref="Map"/> object with copied data.
        /// </summary>
        /// <param name="p">A <see cref="Map"/> to copy data from.</param>
        protected Map(Map p)
        {
            _world = p._world;
            _id    = p._id;

            _scale     = p._scale;
            _dimension = p._dimension;
            _height    = p._height;
            _width     = p._width;
            _x         = p._x;
            _z         = p._z;

            _colors = new byte[_width * _height];
            if (p._colors != null)
            {
                p._colors.CopyTo(_colors, 0);
            }
        }
Ejemplo n.º 23
0
        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: BlockReplace <world> <blockids>");
                return;
            }

            var sw = Stopwatch.StartNew();

            var dest = args[0];

            var blockIds = args.Skip(1).Select(arg => new BlockType(arg)).ToList();

            new ChunkProcessor(NbtWorld.Open(dest), blockIds).Run();

            Console.WriteLine("Elapsed time: {0}", sw.Elapsed);
        }
Ejemplo n.º 24
0
        public ChunkProcessor(NbtWorld world, List <BlockType> blockArgs)
        {
            _world    = world;
            _blockIds = new Dictionary <int, Dictionary <int, BlockType> >();
            foreach (var blockArg in blockArgs)
            {
                if (_blockIds.ContainsKey(blockArg.Id))
                {
                    _blockIds[blockArg.Id][blockArg.Data] = blockArg;
                    continue;
                }
                _blockIds[blockArg.Id] = new Dictionary <int, BlockType>();
                _blockIds[blockArg.Id][blockArg.Data] = blockArg;
            }


            _blockArgs = blockArgs;
        }
Ejemplo n.º 25
0
        public override void Run()
        {
            NbtWorld world = GetWorld(opt);
            IChunkManager cm = world.GetChunkManager(opt.OPT_DIM);
            FilteredChunkManager fcm = new FilteredChunkManager(cm, opt.GetChunkFilter());

            int affectedChunks = 0;
            foreach (ChunkRef chunk in fcm) {
                if (opt.OPT_V) {
                    Console.WriteLine("Processing chunk {0},{1}...", chunk.X, chunk.Z);
                }

                ApplyChunk(world, chunk);

                affectedChunks += fcm.Save() > 0 ? 1 : 0;
            }

            Console.WriteLine("Affected Chunks: " + affectedChunks);
        }
Ejemplo n.º 26
0
        ReaderWriterObjectLock <IChunk> GetChunkLock(ChunkPositionDimension pos)
        {
            lock (_chunkAccessLock)
            {
                ReaderWriterObjectLock <IChunk> chunkLock;
                if (_chunkAccess.TryGetValue(pos, out chunkLock))
                {
                    return(chunkLock);
                }

                // create a new chunkLock
                if (NbtWorld == null)
                {
                    return(_chunkAccess[pos] = new ReaderWriterObjectLock <IChunk>(null));
                }
                var chunk = NbtWorld.GetChunkManager(pos.Dimension).GetChunk(pos.ChunkX, pos.ChunkZ);
                return(_chunkAccess[pos] = new ReaderWriterObjectLock <IChunk>(chunk));
            }
        }
Ejemplo n.º 27
0
        public NbtWorld GetWorld(TKOptions opt)
        {
            NbtWorld world = null;

            try {
                if (opt.OPT_ALPHA)
                {
                    world = AlphaWorld.Open(opt.OPT_WORLD);
                }
                else
                {
                    world = BetaWorld.Open(opt.OPT_WORLD);
                }
            }
            catch (Exception ex) {
                Console.WriteLine("Error: " + ex.Message);
                Environment.Exit(1);
            }

            return(world);
        }
Ejemplo n.º 28
0
        public override void Run()
        {
            if (!Directory.Exists(opt.OPT_WORLD) && !File.Exists(opt.OPT_WORLD))
            {
                Console.WriteLine("Error: Could not locate path: " + opt.OPT_WORLD);
                return;
            }

            NbtWorld             world = null;
            IChunkManager        cm    = null;
            FilteredChunkManager fcm   = null;

            try {
                world = NbtWorld.Open(opt.OPT_WORLD);
                cm    = world.GetChunkManager(opt.OPT_DIM);
                fcm   = new FilteredChunkManager(cm, opt.GetChunkFilter());
            }
            catch (Exception e) {
                Console.WriteLine("Error: Failed to open world: " + opt.OPT_WORLD);
                Console.WriteLine("Exception: " + e.Message);
                Console.WriteLine(e.StackTrace);
                return;
            }

            int affectedChunks = 0;

            foreach (ChunkRef chunk in fcm)
            {
                if (opt.OPT_V)
                {
                    Console.WriteLine("Processing chunk {0},{1}...", chunk.X, chunk.Z);
                }

                ApplyChunk(world, chunk);

                affectedChunks += fcm.Save() > 0 ? 1 : 0;
            }

            Console.WriteLine("Affected Chunks: " + affectedChunks);
        }
Ejemplo n.º 29
0
        public static void SetBiomeData(string dest)
        {
            NbtWorld      world = NbtWorld.Open(dest);
            IChunkManager cm    = world.GetChunkManager();

            foreach (ChunkRef chunk in cm)
            {
                AnvilChunk       anvil_chunk = chunk.GetChunkRef() as AnvilChunk;
                TagNodeByteArray biomeNode   = anvil_chunk.Tree.Root["Level"].ToTagCompound()["Biomes"].ToTagByteArray();
                ZXByteArray      biomeData   = new ZXByteArray(16, 16, biomeNode.Data);
                for (int x = 0; x <= 15; x++)
                {
                    for (int y = 0; y <= 15; y++)
                    {
                        biomeData[x, y] = biomes[chunk.X + "." + chunk.Z];
                    }
                }
                chunk.SetChunkRef(anvil_chunk);
                cm.Save();
            }
            world.Save();
        }
Ejemplo n.º 30
0
        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);
            }
        }