forked from mirrors/NBTExplorer
Updating example code to reflect changes in Substrate API.
This commit is contained in:
parent
f19d86a27e
commit
ca56f70379
9 changed files with 17 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Maze
|
|||
|
||||
Console.WriteLine("Relight Chunks");
|
||||
|
||||
ChunkManager cm = world.GetChunkManager();
|
||||
BetaChunkManager cm = world.GetChunkManager();
|
||||
cm.RelightDirtyChunks();
|
||||
|
||||
world.Save();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue