Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
        public void BlockTest_1_8_3_debug()
        {
            NbtWorld world = NbtWorld.Open(@"..\..\Data\1_8_3-debug\");

            Assert.IsNotNull(world);

            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);
                    Assert.IsTrue(blockInfo.TestData(blockRef.Data), "Data value '0x{0:X4}' not recognised for block '{1}' at {2},{3}", blockRef.Data, blockInfo.Name, x, z);
                }
            }
        }
Ejemplo n.º 5
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.º 6
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("You must specify a target directory");
                return;
            }
            string dest = args[0];

            // 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.º 7
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.º 8
0
        public override void Run()
        {
            NbtWorld             world = NbtWorld.Open(opt.OPT_WORLD);
            IChunkManager        cm    = world.GetChunkManager(opt.OPT_DIM);
            FilteredChunkManager fcm   = new FilteredChunkManager(cm, opt.GetChunkFilter());

            if (opt.OPT_V)
            {
                Console.WriteLine("Clearing existing chunk lighting...");
            }

            int affectedChunks = 0;

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

                if (opt.HeightMap)
                {
                    chunk.Blocks.RebuildHeightMap();
                }
                if (opt.BlockLight)
                {
                    chunk.Blocks.ResetBlockLight();
                }
                if (opt.SkyLight)
                {
                    chunk.Blocks.ResetSkyLight();
                }
                fcm.Save();

                affectedChunks++;
            }

            if (opt.OPT_V)
            {
                Console.WriteLine("Rebuilding chunk lighting...");
            }

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

                if (opt.BlockLight)
                {
                    chunk.Blocks.RebuildBlockLight();
                }
                if (opt.SkyLight)
                {
                    chunk.Blocks.RebuildSkyLight();
                }
                fcm.Save();
            }

            if (opt.OPT_V)
            {
                Console.WriteLine("Reconciling chunk edges...");
            }

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

                if (opt.BlockLight)
                {
                    chunk.Blocks.StitchBlockLight();
                }
                if (opt.SkyLight)
                {
                    chunk.Blocks.StitchSkyLight();
                }
                fcm.Save();
            }

            Console.WriteLine("Relit Chunks: " + affectedChunks);
        }
Ejemplo n.º 9
0
        public static void Run(string sourcePath, string outputPath, bool console)
        {
            string playerPath = Path.Combine(outputPath, "players");

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

            NbtWorld world = NbtWorld.Open(sourcePath);

            if (Directory.Exists(Path.Combine(outputPath, world.Level.LevelName)))
            {
                if (console)
                {
                    Console.WriteLine("World folder already exists, stopping.");
                }
                else
                {
                    MessageBox.Show("World folder exists already, stopping.");
                }

                return;
            }
            else
            {
                Directory.CreateDirectory(Path.Combine(outputPath, world.Level.LevelName));
            }

            DirectoryCopy(sourcePath, Path.Combine(outputPath, world.Level.LevelName), true);


            INIFile iniFile = new INIFile(Path.Combine(outputPath, world.Level.LevelName, "world.ini"));

            iniFile.SetValue("General", "Gamemode", (int)world.Level.GameType);
            iniFile.SetValue("General", "TimeInTicks", world.Level.Time);
            iniFile.SetValue("SpawnPosition", "X", world.Level.Spawn.X);
            iniFile.SetValue("SpawnPosition", "Y", world.Level.Spawn.Y);
            iniFile.SetValue("SpawnPosition", "Z", world.Level.Spawn.Z);
            iniFile.SetValue("Seed", "Seed", world.Level.RandomSeed);

            if (File.Exists(Path.Combine(Directory.GetParent(sourcePath).FullName, "server.properties")))
            {
                IDictionary <string, string> serverProperties = ReadDictionaryFile(Path.Combine(Directory.GetParent(sourcePath).FullName, "server.properties"));
                iniFile.SetValue("Mechanics", "CommandBlocksEnabled", serverProperties["enable-command-block"] == "true" ? 1 : 0);
                iniFile.SetValue("Mechanics", "PVPEnabled", serverProperties["pvp"] == "true" ? 1 : 0);
                iniFile.SetValue("SpawnPosition", "MaxViewDistance", serverProperties["view-distance"]);
                iniFile.SetValue("SpawnProtect", "ProtectRadius", serverProperties["spawn-protection"]);
                iniFile.SetValue("Difficulty", "WorldDifficulty", serverProperties["difficulty"]);
            }

            iniFile.Flush();

            PlayerManager playerManager = (PlayerManager)world.GetPlayerManager();

            foreach (Player player in playerManager)
            {
                JObject rootObject = new JObject();
                rootObject.Add("SpawnX", player.Spawn.X == 0 ? world.Level.Spawn.X : player.Spawn.X);
                rootObject.Add("SpawnY", player.Spawn.Y == 0 ? world.Level.Spawn.Y : player.Spawn.Y);
                rootObject.Add("SpawnZ", player.Spawn.Z == 0 ? world.Level.Spawn.Z : player.Spawn.Z);
                rootObject.Add("air", player.Air);
                rootObject.Add("enderchestinventory", convertInventory(player.EnderItems, 27));
                rootObject.Add("food", player.HungerLevel);
                rootObject.Add("foodExhaustion", player.HungerExhaustionLevel);
                rootObject.Add("foodSaturation", player.HungerSaturationLevel);
                rootObject.Add("foodTickTimer", player.HungerTimer);
                rootObject.Add("gamemode", (int)player.GameType);
                rootObject.Add("health", player.Health);
                rootObject.Add("inventory", convertPlayerInventory(player.Items));
                rootObject.Add("isflying", player.Air);
                rootObject.Add("position", new JArray(player.Position.X, player.Position.Y, player.Position.Z));
                rootObject.Add("rotation", new JArray(player.Rotation.Yaw, player.Rotation.Pitch, 0.0));
                rootObject.Add("world", player.World);
                rootObject.Add("xpCurrent", player.XPLevel);
                rootObject.Add("xpTotal", player.XPTotal);

                string uuidPrefix = player.Name.Substring(0, 2);
                string outputFile = Path.Combine(playerPath, uuidPrefix, player.Name.Substring(2) + ".json");

                if (!Directory.Exists(Path.Combine(playerPath, uuidPrefix)))
                {
                    Directory.CreateDirectory(Path.Combine(playerPath, uuidPrefix));
                }

                StreamWriter writer = new StreamWriter(outputFile);
                writer.Write(rootObject.ToString());
                writer.Flush();
                writer.Close();
            }

            if (console)
            {
                Console.WriteLine("Done!");
            }
            else
            {
                MessageBox.Show("Done!");
            }
        }
Ejemplo n.º 10
0
        public void OpenTest_1_9_2_debug()
        {
            NbtWorld world = NbtWorld.Open(@"..\..\Data\1_9_2-debug\");

            Assert.IsNotNull(world);
        }
Ejemplo n.º 11
0
        public void OpenTest_1_8_7_survival()
        {
            NbtWorld world = NbtWorld.Open(@"..\..\Data\1_8_7-survival\");

            Assert.IsNotNull(world);
        }
Ejemplo n.º 12
0
        public override void Run()
        {
            NbtWorld             world = NbtWorld.Open(opt.OPT_WORLD);
            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(",");
                }

                IChunk c = chunk.GetChunkRef();

                NbtTree tree = null;
                if (c is AnvilChunk)
                {
                    tree = (c as AnvilChunk).Tree;
                }
                else if (c is AlphaChunk)
                {
                    tree = (c as AlphaChunk).Tree;
                }

                if (tree == null || tree.Root == null)
                {
                    continue;
                }

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

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

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

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

                first = false;
            }

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

            fstr.Close();
        }