Updating example code to reflect changes in Substrate API.

This commit is contained in:
Justin Aquadro 2011-07-24 20:03:47 +00:00
parent f19d86a27e
commit ca56f70379
9 changed files with 17 additions and 28 deletions

View file

@ -28,7 +28,7 @@ namespace BlockReplace
// The chunk manager is more efficient than the block manager for // The chunk manager is more efficient than the block manager for
// this purpose, since we'll inspect every block // this purpose, since we'll inspect every block
ChunkManager cm = world.GetChunkManager(); BetaChunkManager cm = world.GetChunkManager();
foreach (ChunkRef chunk in cm) { foreach (ChunkRef chunk in cm) {
// You could hardcode your dimensions, but maybe some day they // You could hardcode your dimensions, but maybe some day they

View file

@ -1,6 +1,7 @@
using System; using System;
using Substrate; using Substrate;
using Substrate.NBT; using Substrate.Core;
using Substrate.Nbt;
// This example will convert worlds between alpha and beta format. // This example will convert worlds between alpha and beta format.
// This will convert chunks to and from region format, and copy level.dat // This will convert chunks to and from region format, and copy level.dat
@ -22,8 +23,8 @@ namespace Convert
string srctype = args[2]; string srctype = args[2];
// Open source and destrination worlds depending on conversion type // Open source and destrination worlds depending on conversion type
INBTWorld srcWorld; NbtWorld srcWorld;
INBTWorld dstWorld; NbtWorld dstWorld;
if (srctype == "a") { if (srctype == "a") {
srcWorld = AlphaWorld.Open(src); srcWorld = AlphaWorld.Open(src);
dstWorld = BetaWorld.Create(dst); dstWorld = BetaWorld.Create(dst);

View file

@ -20,13 +20,11 @@ namespace FlatMap
// This will instantly create any necessary directory structure // This will instantly create any necessary directory structure
BetaWorld world = BetaWorld.Create(dest); BetaWorld world = BetaWorld.Create(dest);
ChunkManager cm = world.GetChunkManager(); BetaChunkManager cm = world.GetChunkManager();
// We can set different world parameters // We can set different world parameters
world.Level.LevelName = "Flatlands"; world.Level.LevelName = "Flatlands";
world.Level.SpawnX = 20; world.Level.Spawn = new SpawnPoint(20, 20, 70);
world.Level.SpawnZ = 20;
world.Level.SpawnY = 70;
// world.Level.SetDefaultPlayer(); // world.Level.SetDefaultPlayer();
// We'll let MC create the player for us, but you could use the above // We'll let MC create the player for us, but you could use the above

View file

@ -31,7 +31,7 @@ namespace GoodyChest
// Open our world // Open our world
BetaWorld world = BetaWorld.Open(dest); BetaWorld world = BetaWorld.Open(dest);
ChunkManager cm = world.GetChunkManager(); BetaChunkManager cm = world.GetChunkManager();
int added = 0; int added = 0;
@ -51,7 +51,7 @@ namespace GoodyChest
} }
// Get a block object, then assign it to the chunk // Get a block object, then assign it to the chunk
Block block = BuildChest(); AlphaBlock block = BuildChest();
chunk.Blocks.SetBlock(x, y + 1, z, block); chunk.Blocks.SetBlock(x, y + 1, z, block);
// Save the chunk // Save the chunk
@ -67,10 +67,10 @@ namespace GoodyChest
// This function will create a new Block object of type 'Chest', fills it // This function will create a new Block object of type 'Chest', fills it
// with random items, and returns it // with random items, and returns it
static Block BuildChest () static AlphaBlock BuildChest ()
{ {
// A default, appropriate TileEntity entry is created // 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; TileEntityChest ent = block.GetTileEntity() as TileEntityChest;
// Unless Substrate has a bug, the TileEntity was definitely a 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++) { for (int i = 0; i < ent.Items.Capacity; i++) {
if (rand.NextDouble() < 0.3) { if (rand.NextDouble() < 0.3) {
// Ask the ItemTable for a random Item type registered with Substrate // 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) // Create the item object, give it an appropriate, random count (items in stack)
Item item = new Item(itype.ID); Item item = new Item(itype.ID);

View file

@ -48,7 +48,7 @@ namespace Maze
Console.WriteLine("Relight Chunks"); Console.WriteLine("Relight Chunks");
ChunkManager cm = world.GetChunkManager(); BetaChunkManager cm = world.GetChunkManager();
cm.RelightDirtyChunks(); cm.RelightDirtyChunks();
world.Save(); world.Save();

View file

@ -27,9 +27,7 @@ namespace MoveSpawn
// Note: Players do not have separate spawns by default // Note: Players do not have separate spawns by default
// If you wanted to change a player's spawn, you must set all // 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. // 3 coordinates for it to stick. It will not take the level's defaults.
world.Level.SpawnX = x; world.Level.Spawn = new SpawnPoint(x, y, z);
world.Level.SpawnY = y;
world.Level.SpawnZ = z;
// Save the changes // Save the changes
world.Save(); world.Save();

View file

@ -36,7 +36,7 @@ namespace PurgeEntities
// Load world // Load world
BetaWorld world = BetaWorld.Open(dest); BetaWorld world = BetaWorld.Open(dest);
ChunkManager cm = world.GetChunkManager(); BetaChunkManager cm = world.GetChunkManager();
// Remove entities // Remove entities
foreach (ChunkRef chunk in cm) { foreach (ChunkRef chunk in cm) {

View file

@ -24,15 +24,7 @@ namespace Relight
} }
string dest = args[0]; string dest = args[0];
// Load the world, supporting either alpha or beta format // Opening an NbtWorld will try to autodetect if a world is Alpha-style or Beta-style
/*INBTWorld world;
if (args.Length >= 2 && args[1] == "alpha") {
world = AlphaWorld.Open(dest);
}
else {
world = BetaWorld.Open(dest);
}*/
NbtWorld world = NbtWorld.Open(dest); NbtWorld world = NbtWorld.Open(dest);
// Grab a generic chunk manager reference // Grab a generic chunk manager reference

View file

@ -291,7 +291,7 @@ namespace Substrate
BlockInfoEx einfo2 = info2 as BlockInfoEx; BlockInfoEx einfo2 = info2 as BlockInfoEx;
if (einfo1 != einfo2) { if (einfo1 != einfo2) {
if (einfo1 != null) { if (einfo1 != null || !info1.Registered) {
ClearTileEntity(x, y, z); ClearTileEntity(x, y, z);
} }