diff --git a/SubstrateCS/Examples/BlockReplace/BlockReplace.csproj b/SubstrateCS/Examples/BlockReplace/BlockReplace.csproj index ee51215..c720072 100644 --- a/SubstrateCS/Examples/BlockReplace/BlockReplace.csproj +++ b/SubstrateCS/Examples/BlockReplace/BlockReplace.csproj @@ -36,7 +36,8 @@ 4 - + + False ..\..\bin\Release\NET2\Substrate.dll diff --git a/SubstrateCS/Examples/BlockReplace/Program.cs b/SubstrateCS/Examples/BlockReplace/Program.cs index 3392dff..694dd1b 100644 --- a/SubstrateCS/Examples/BlockReplace/Program.cs +++ b/SubstrateCS/Examples/BlockReplace/Program.cs @@ -1,5 +1,6 @@ using System; using Substrate; +using Substrate.Core; // This example replaces all instances of one block ID with another in a world. // Substrate will handle all of the lower-level headaches that can pop up, such @@ -24,11 +25,11 @@ namespace BlockReplace int after = Convert.ToInt32(args[2]); // Open our world - BetaWorld world = BetaWorld.Open(dest); + NbtWorld world = NbtWorld.Open(dest); // The chunk manager is more efficient than the block manager for // this purpose, since we'll inspect every block - BetaChunkManager cm = world.GetChunkManager(); + IChunkManager cm = world.GetChunkManager(); foreach (ChunkRef chunk in cm) { // You could hardcode your dimensions, but maybe some day they @@ -56,6 +57,8 @@ namespace BlockReplace // Save the chunk cm.Save(); + + Console.WriteLine("Processed Chunk {0},{1}", chunk.X, chunk.Z); } } } diff --git a/SubstrateCS/Examples/Convert/Program.cs b/SubstrateCS/Examples/Convert/Program.cs index 4709894..60dccf5 100644 --- a/SubstrateCS/Examples/Convert/Program.cs +++ b/SubstrateCS/Examples/Convert/Program.cs @@ -2,6 +2,7 @@ using Substrate; using Substrate.Core; using Substrate.Nbt; +using System.IO; // This example will convert worlds between alpha and beta format. // This will convert chunks to and from region format, and copy level.dat @@ -14,7 +15,7 @@ namespace Convert static void Main (string[] args) { if (args.Length != 3) { - Console.WriteLine("Usage: Convert "); + Console.WriteLine("Usage: Convert "); return; } @@ -22,16 +23,17 @@ namespace Convert 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 srcWorld = NbtWorld.Open(src); NbtWorld dstWorld; - if (srctype == "a") { - srcWorld = AlphaWorld.Open(src); - dstWorld = BetaWorld.Create(dst); - } - else { - srcWorld = BetaWorld.Open(src); - dstWorld = AlphaWorld.Create(dst); + 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 @@ -41,16 +43,12 @@ namespace Convert // 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()); - // If we're creating an alpha world, get rid of the version field - if (srctype == "b") { - dstWorld.Level.Version = 0; - } - // Save level.dat dstWorld.Level.Save(); } diff --git a/SubstrateCS/Examples/CustomBlocks/Program.cs b/SubstrateCS/Examples/CustomBlocks/Program.cs index 640eb9a..9279342 100644 --- a/SubstrateCS/Examples/CustomBlocks/Program.cs +++ b/SubstrateCS/Examples/CustomBlocks/Program.cs @@ -26,11 +26,11 @@ namespace CustomBlocks string dest = args[0]; // Open our world - BetaWorld world = BetaWorld.Open(dest); + NbtWorld world = NbtWorld.Open(dest); // The chunk manager is more efficient than the block manager for // this purpose, since we'll inspect every block - BetaChunkManager cm = world.GetChunkManager(); + IChunkManager cm = world.GetChunkManager(); foreach (ChunkRef chunk in cm) { // You could hardcode your dimensions, but maybe some day they diff --git a/SubstrateCS/Examples/FlatMap/FlatMap.csproj b/SubstrateCS/Examples/FlatMap/FlatMap.csproj index 8a89a10..eed7d35 100644 --- a/SubstrateCS/Examples/FlatMap/FlatMap.csproj +++ b/SubstrateCS/Examples/FlatMap/FlatMap.csproj @@ -51,7 +51,8 @@ 4 - + + False ..\..\bin\Release\NET2\Substrate.dll diff --git a/SubstrateCS/Examples/FlatMap/Program.cs b/SubstrateCS/Examples/FlatMap/Program.cs index f6f0f45..379d1fe 100644 --- a/SubstrateCS/Examples/FlatMap/Program.cs +++ b/SubstrateCS/Examples/FlatMap/Program.cs @@ -1,5 +1,8 @@ using System; using Substrate; +using Substrate.Nbt; +using Substrate.Core; +using System.IO; // FlatMap is an example of generating worlds from scratch with Substrate. // It will produce a completely flat, solid map with grass, dirt, stone, @@ -12,19 +15,48 @@ namespace FlatMap { static void Main (string[] args) { - string dest = "F:\\Minecraft\\test"; + if (args.Length < 2) { + Console.WriteLine("Usage: flatmap "); + Console.WriteLine("Available Types: alpha, beta, anvil"); + return; + } + + string dest = args[1]; int xmin = -20; int xmax = 20; int zmin = -20; int zmaz = 20; + 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); + }; + + if (!Directory.Exists(dest)) + Directory.CreateDirectory(dest); + // This will instantly create any necessary directory structure - BetaWorld world = BetaWorld.Create(dest); - BetaChunkManager cm = world.GetChunkManager(); + NbtWorld world; + switch (args[0]) { + case "alpha": world = AlphaWorld.Create(dest); break; + case "beta": world = BetaWorld.Create(dest); break; + case "anvil": world = AnvilWorld.Create(dest); break; + default: throw new Exception("Invalid world type specified."); + } + + IChunkManager cm = world.GetChunkManager(); // We can set different world parameters world.Level.LevelName = "Flatlands"; - world.Level.Spawn = new SpawnPoint(20, 20, 70); + world.Level.Spawn = new SpawnPoint(20, 70, 20); // world.Level.SetDefaultPlayer(); // We'll let MC create the player for us, but you could use the above @@ -51,6 +83,7 @@ namespace FlatMap FlatChunk(chunk, 64); // Reset and rebuild the lighting for the entire chunk at once + chunk.Blocks.RebuildHeightMap(); chunk.Blocks.RebuildBlockLight(); chunk.Blocks.RebuildSkyLight(); diff --git a/SubstrateCS/Examples/GiveItem/Program.cs b/SubstrateCS/Examples/GiveItem/Program.cs index 1f58170..22b5ea8 100644 --- a/SubstrateCS/Examples/GiveItem/Program.cs +++ b/SubstrateCS/Examples/GiveItem/Program.cs @@ -1,5 +1,6 @@ using System; using Substrate; +using Substrate.Core; // This example will insert x amount of an item into a player's // inventory in an SMP server (where there is a player directory) @@ -21,8 +22,8 @@ namespace GiveItem int count = Convert.ToInt32(args[3]); // Open the world and grab its player manager - BetaWorld world = BetaWorld.Open(dest); - PlayerManager pm = world.GetPlayerManager(); + NbtWorld world = NbtWorld.Open(dest); + IPlayerManager pm = world.GetPlayerManager(); // Check that the named player exists if (!pm.PlayerExists(player)) { diff --git a/SubstrateCS/Examples/GoodyChest/Program.cs b/SubstrateCS/Examples/GoodyChest/Program.cs index 9141620..027e20b 100644 --- a/SubstrateCS/Examples/GoodyChest/Program.cs +++ b/SubstrateCS/Examples/GoodyChest/Program.cs @@ -1,6 +1,7 @@ using System; using Substrate; using Substrate.TileEntities; +using Substrate.Core; // GoodyChest is an example that creates chests filled with random // items throughout the world, according to a probability of @@ -30,8 +31,8 @@ namespace GoodyChest rand = new Random(); // Open our world - BetaWorld world = BetaWorld.Open(dest); - BetaChunkManager cm = world.GetChunkManager(); + NbtWorld world = NbtWorld.Open(dest); + IChunkManager cm = world.GetChunkManager(); int added = 0; diff --git a/SubstrateCS/Examples/Maze/Program.cs b/SubstrateCS/Examples/Maze/Program.cs index fda1338..8726a5a 100644 --- a/SubstrateCS/Examples/Maze/Program.cs +++ b/SubstrateCS/Examples/Maze/Program.cs @@ -8,7 +8,13 @@ namespace Maze { static void Main (string[] args) { - BetaWorld world = BetaWorld.Open("F:\\Minecraft\\test"); + if (args.Length < 1) { + Console.WriteLine("You must specify a target directory"); + return; + } + string dest = args[0]; + + AnvilWorld world = AnvilWorld.Open("F:\\Minecraft\\test"); BlockManager bm = world.GetBlockManager(); bm.AutoLight = false; @@ -48,7 +54,7 @@ namespace Maze Console.WriteLine("Relight Chunks"); - BetaChunkManager cm = world.GetChunkManager(); + RegionChunkManager cm = world.GetChunkManager(); cm.RelightDirtyChunks(); world.Save(); diff --git a/SubstrateCS/Examples/MoveSpawn/Program.cs b/SubstrateCS/Examples/MoveSpawn/Program.cs index fc4e263..1ea4378 100644 --- a/SubstrateCS/Examples/MoveSpawn/Program.cs +++ b/SubstrateCS/Examples/MoveSpawn/Program.cs @@ -21,7 +21,7 @@ namespace MoveSpawn int z = Convert.ToInt32(args[3]); // Open our world - BetaWorld world = BetaWorld.Open(dest); + NbtWorld world = NbtWorld.Open(dest); // Set the level's spawn // Note: Players do not have separate spawns by default diff --git a/SubstrateCS/Examples/PurgeEntities/Program.cs b/SubstrateCS/Examples/PurgeEntities/Program.cs index cd740c3..3f6dab4 100644 --- a/SubstrateCS/Examples/PurgeEntities/Program.cs +++ b/SubstrateCS/Examples/PurgeEntities/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Substrate; +using Substrate.Core; // This example is a tool to delete all entities of a given type (e.g., "pig") // on a map. It optionally can be restricted to boxed region in block coords. @@ -35,8 +36,8 @@ namespace PurgeEntities } // Load world - BetaWorld world = BetaWorld.Open(dest); - BetaChunkManager cm = world.GetChunkManager(); + NbtWorld world = NbtWorld.Open(dest); + IChunkManager cm = world.GetChunkManager(); // Remove entities foreach (ChunkRef chunk in cm) { diff --git a/SubstrateCS/Examples/Relight/Program.cs b/SubstrateCS/Examples/Relight/Program.cs index 2a3429d..c7b7c83 100644 --- a/SubstrateCS/Examples/Relight/Program.cs +++ b/SubstrateCS/Examples/Relight/Program.cs @@ -1,6 +1,7 @@ using System; using Substrate; using Substrate.Core; +using Substrate.Nbt; // This example will reset and rebuild the lighting (heightmap, block light, // skylight) for all chunks in a map. @@ -24,6 +25,16 @@ namespace Relight } 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); diff --git a/SubstrateCS/Examples/Relight/Relight.csproj b/SubstrateCS/Examples/Relight/Relight.csproj index 554b961..dcba45a 100644 --- a/SubstrateCS/Examples/Relight/Relight.csproj +++ b/SubstrateCS/Examples/Relight/Relight.csproj @@ -51,7 +51,8 @@ 4 - + + False ..\..\bin\Release\NET2\Substrate.dll