From ca56f7037989a9307c308dd0acddc601b04474cd Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 24 Jul 2011 20:03:47 +0000 Subject: [PATCH] Updating example code to reflect changes in Substrate API. --- Substrate/SubstrateCS/Examples/BlockReplace/Program.cs | 2 +- Substrate/SubstrateCS/Examples/Convert/Program.cs | 7 ++++--- Substrate/SubstrateCS/Examples/FlatMap/Program.cs | 6 ++---- Substrate/SubstrateCS/Examples/GoodyChest/Program.cs | 10 +++++----- Substrate/SubstrateCS/Examples/Maze/Program.cs | 2 +- Substrate/SubstrateCS/Examples/MoveSpawn/Program.cs | 4 +--- .../SubstrateCS/Examples/PurgeEntities/Program.cs | 2 +- Substrate/SubstrateCS/Examples/Relight/Program.cs | 10 +--------- Substrate/SubstrateCS/Source/AlphaBlockCollection.cs | 2 +- 9 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Substrate/SubstrateCS/Examples/BlockReplace/Program.cs b/Substrate/SubstrateCS/Examples/BlockReplace/Program.cs index 9ec75e4..8956c0b 100644 --- a/Substrate/SubstrateCS/Examples/BlockReplace/Program.cs +++ b/Substrate/SubstrateCS/Examples/BlockReplace/Program.cs @@ -28,7 +28,7 @@ namespace BlockReplace // The chunk manager is more efficient than the block manager for // this purpose, since we'll inspect every block - ChunkManager cm = world.GetChunkManager(); + BetaChunkManager cm = world.GetChunkManager(); foreach (ChunkRef chunk in cm) { // You could hardcode your dimensions, but maybe some day they diff --git a/Substrate/SubstrateCS/Examples/Convert/Program.cs b/Substrate/SubstrateCS/Examples/Convert/Program.cs index 880a0bf..4709894 100644 --- a/Substrate/SubstrateCS/Examples/Convert/Program.cs +++ b/Substrate/SubstrateCS/Examples/Convert/Program.cs @@ -1,6 +1,7 @@ using System; using Substrate; -using Substrate.NBT; +using Substrate.Core; +using Substrate.Nbt; // This example will convert worlds between alpha and beta format. // This will convert chunks to and from region format, and copy level.dat @@ -22,8 +23,8 @@ namespace Convert string srctype = args[2]; // Open source and destrination worlds depending on conversion type - INBTWorld srcWorld; - INBTWorld dstWorld; + NbtWorld srcWorld; + NbtWorld dstWorld; if (srctype == "a") { srcWorld = AlphaWorld.Open(src); dstWorld = BetaWorld.Create(dst); diff --git a/Substrate/SubstrateCS/Examples/FlatMap/Program.cs b/Substrate/SubstrateCS/Examples/FlatMap/Program.cs index 572b60b..f6f0f45 100644 --- a/Substrate/SubstrateCS/Examples/FlatMap/Program.cs +++ b/Substrate/SubstrateCS/Examples/FlatMap/Program.cs @@ -20,13 +20,11 @@ namespace FlatMap // This will instantly create any necessary directory structure BetaWorld world = BetaWorld.Create(dest); - ChunkManager cm = world.GetChunkManager(); + BetaChunkManager cm = world.GetChunkManager(); // We can set different world parameters world.Level.LevelName = "Flatlands"; - world.Level.SpawnX = 20; - world.Level.SpawnZ = 20; - world.Level.SpawnY = 70; + world.Level.Spawn = new SpawnPoint(20, 20, 70); // world.Level.SetDefaultPlayer(); // We'll let MC create the player for us, but you could use the above diff --git a/Substrate/SubstrateCS/Examples/GoodyChest/Program.cs b/Substrate/SubstrateCS/Examples/GoodyChest/Program.cs index 8f6010c..9141620 100644 --- a/Substrate/SubstrateCS/Examples/GoodyChest/Program.cs +++ b/Substrate/SubstrateCS/Examples/GoodyChest/Program.cs @@ -31,7 +31,7 @@ namespace GoodyChest // Open our world BetaWorld world = BetaWorld.Open(dest); - ChunkManager cm = world.GetChunkManager(); + BetaChunkManager cm = world.GetChunkManager(); int added = 0; @@ -51,7 +51,7 @@ namespace GoodyChest } // Get a block object, then assign it to the chunk - Block block = BuildChest(); + AlphaBlock block = BuildChest(); chunk.Blocks.SetBlock(x, y + 1, z, block); // Save the chunk @@ -67,10 +67,10 @@ namespace GoodyChest // This function will create a new Block object of type 'Chest', fills it // with random items, and returns it - static Block BuildChest () + static AlphaBlock BuildChest () { // A default, appropriate TileEntity entry is created - Block block = new Block(BlockType.CHEST); + AlphaBlock block = new AlphaBlock(BlockType.CHEST); TileEntityChest ent = block.GetTileEntity() as TileEntityChest; // Unless Substrate has a bug, the TileEntity was definitely a TileEntityChest @@ -84,7 +84,7 @@ namespace GoodyChest for (int i = 0; i < ent.Items.Capacity; i++) { if (rand.NextDouble() < 0.3) { // Ask the ItemTable for a random Item type registered with Substrate - ItemInfo itype = ItemInfo.ItemTable.Random(); + ItemInfo itype = ItemInfo.GetRandomItem(); // Create the item object, give it an appropriate, random count (items in stack) Item item = new Item(itype.ID); diff --git a/Substrate/SubstrateCS/Examples/Maze/Program.cs b/Substrate/SubstrateCS/Examples/Maze/Program.cs index 4d7c40c..fda1338 100644 --- a/Substrate/SubstrateCS/Examples/Maze/Program.cs +++ b/Substrate/SubstrateCS/Examples/Maze/Program.cs @@ -48,7 +48,7 @@ namespace Maze Console.WriteLine("Relight Chunks"); - ChunkManager cm = world.GetChunkManager(); + BetaChunkManager cm = world.GetChunkManager(); cm.RelightDirtyChunks(); world.Save(); diff --git a/Substrate/SubstrateCS/Examples/MoveSpawn/Program.cs b/Substrate/SubstrateCS/Examples/MoveSpawn/Program.cs index 5f5ea5e..fc4e263 100644 --- a/Substrate/SubstrateCS/Examples/MoveSpawn/Program.cs +++ b/Substrate/SubstrateCS/Examples/MoveSpawn/Program.cs @@ -27,9 +27,7 @@ namespace MoveSpawn // 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.SpawnX = x; - world.Level.SpawnY = y; - world.Level.SpawnZ = z; + world.Level.Spawn = new SpawnPoint(x, y, z); // Save the changes world.Save(); diff --git a/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs b/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs index f53e0b6..cd740c3 100644 --- a/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs +++ b/Substrate/SubstrateCS/Examples/PurgeEntities/Program.cs @@ -36,7 +36,7 @@ namespace PurgeEntities // Load world BetaWorld world = BetaWorld.Open(dest); - ChunkManager cm = world.GetChunkManager(); + BetaChunkManager cm = world.GetChunkManager(); // Remove entities foreach (ChunkRef chunk in cm) { diff --git a/Substrate/SubstrateCS/Examples/Relight/Program.cs b/Substrate/SubstrateCS/Examples/Relight/Program.cs index 27a1e2b..2a3429d 100644 --- a/Substrate/SubstrateCS/Examples/Relight/Program.cs +++ b/Substrate/SubstrateCS/Examples/Relight/Program.cs @@ -24,15 +24,7 @@ namespace Relight } string dest = args[0]; - // Load the world, supporting either alpha or beta format - /*INBTWorld world; - if (args.Length >= 2 && args[1] == "alpha") { - world = AlphaWorld.Open(dest); - } - else { - world = BetaWorld.Open(dest); - }*/ - + // 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 diff --git a/Substrate/SubstrateCS/Source/AlphaBlockCollection.cs b/Substrate/SubstrateCS/Source/AlphaBlockCollection.cs index 31b44d3..0176487 100644 --- a/Substrate/SubstrateCS/Source/AlphaBlockCollection.cs +++ b/Substrate/SubstrateCS/Source/AlphaBlockCollection.cs @@ -291,7 +291,7 @@ namespace Substrate BlockInfoEx einfo2 = info2 as BlockInfoEx; if (einfo1 != einfo2) { - if (einfo1 != null) { + if (einfo1 != null || !info1.Registered) { ClearTileEntity(x, y, z); }