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); }
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!"); } }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: eina_to_nbt <source> <dest>"); return; } String dest = args[1]; System.Console.WriteLine("Creating EINA map..."); if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } NbtWorld world = AnvilWorld.Create(dest); world.Level.LevelName = "EINA"; world.Level.Spawn = new SpawnPoint(292, 70, 270); world.Level.GameType = GameType.CREATIVE; world.Level.Initialized = true; Player p = new Player(); p.Position.X = 292; p.Position.Y = 130; p.Position.Z = 292; IPlayerManager pm = world.GetPlayerManager(); pm.SetPlayer("Player", p); IChunkManager cm = world.GetChunkManager(); string[] lines = System.IO.File.ReadAllLines(args[0]); string[] words; ChunkRef chunk; words = lines[0].Split(' '); int minx = Int32.Parse(words[0]); int maxx = Int32.Parse(words[0]); int miny = Int32.Parse(words[0]); int maxy = Int32.Parse(words[0]); for (int i = 0; i < lines.Length; i++) { words = lines[i].Split(' '); //System.Console.WriteLine(lines[i]); int x = Int32.Parse(words[0]); int y = Int32.Parse(words[1]); int z = Int32.Parse(words[2]); int color = Int32.Parse(words[3]); string text = ""; if (words.Length > 4) { text = words[4]; for (int j = 5; j < words.Length; j++) { text += ' ' + words[j]; } } else { text = ""; } int xLocal = x / 16; int yLocal = y / 16; if (xLocal < minx) { minx = xLocal; } if (xLocal > maxx) { maxx = xLocal; } if (yLocal < miny) { miny = yLocal; } if (yLocal > maxy) { maxy = yLocal; } if (!cm.ChunkExists(xLocal, yLocal)) { //System.Console.WriteLine(xLocal+" "+yLocal); cm.CreateChunk(xLocal, yLocal); } chunk = cm.GetChunkRef(xLocal, yLocal); //System.Console.WriteLine(x+" "+y+" "+z); //System.Console.WriteLine(xLocal+" "+yLocal); if (!chunk.IsDirty) { chunk.IsTerrainPopulated = true; chunk.Blocks.AutoLight = false; //FlatChunk(chunk, 64); chunk.Blocks.RebuildHeightMap(); chunk.Blocks.RebuildBlockLight(); chunk.Blocks.RebuildSkyLight(); //System.Console.WriteLine(chunk.IsDirty); for (int i2 = 0; i2 < 16; i2++) { for (int j = 0; j < 16; j++) { setBlock(chunk, i2, 64, j, 16, ""); } } if (((xLocal % 8) == 0) & ((yLocal % 8) == 0)) { cm.Save(); } setBlock(chunk, x % 16, z + 64, y % 16, color, text); } else { setBlock(chunk, x % 16, z + 64, y % 16, color, text); //System.Console.WriteLine("hola"); } if ((i + 1) % 500000 == 0) { System.Console.WriteLine("Guardando"); world.Save(); //System.Console.WriteLine("Hecho"); } } world.Save(); }