Example updates

This commit is contained in:
Justin Aquadro 2012-04-28 20:35:57 -04:00
parent 2b6dec51bf
commit b7c53caa5e
13 changed files with 91 additions and 34 deletions

View file

@ -36,7 +36,8 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Substrate"> <Reference Include="Substrate, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\Release\NET2\Substrate.dll</HintPath> <HintPath>..\..\bin\Release\NET2\Substrate.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />

View file

@ -1,5 +1,6 @@
using System; using System;
using Substrate; using Substrate;
using Substrate.Core;
// This example replaces all instances of one block ID with another in a world. // 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 // 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]); int after = Convert.ToInt32(args[2]);
// Open our world // Open our world
BetaWorld world = BetaWorld.Open(dest); NbtWorld world = NbtWorld.Open(dest);
// 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
BetaChunkManager cm = world.GetChunkManager(); IChunkManager 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
@ -56,6 +57,8 @@ namespace BlockReplace
// Save the chunk // Save the chunk
cm.Save(); cm.Save();
Console.WriteLine("Processed Chunk {0},{1}", chunk.X, chunk.Z);
} }
} }
} }

View file

@ -2,6 +2,7 @@
using Substrate; using Substrate;
using Substrate.Core; using Substrate.Core;
using Substrate.Nbt; using Substrate.Nbt;
using System.IO;
// 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
@ -14,7 +15,7 @@ namespace Convert
static void Main (string[] args) static void Main (string[] args)
{ {
if (args.Length != 3) { if (args.Length != 3) {
Console.WriteLine("Usage: Convert <world> <dest> <a|b>"); Console.WriteLine("Usage: Convert <world> <dest> <alpha|beta|anvil>");
return; return;
} }
@ -22,16 +23,17 @@ namespace Convert
string dst = args[1]; string dst = args[1];
string srctype = args[2]; string srctype = args[2];
if (!Directory.Exists(dst))
Directory.CreateDirectory(dst);
// Open source and destrination worlds depending on conversion type // Open source and destrination worlds depending on conversion type
NbtWorld srcWorld; NbtWorld srcWorld = NbtWorld.Open(src);
NbtWorld dstWorld; NbtWorld dstWorld;
if (srctype == "a") { switch (srctype) {
srcWorld = AlphaWorld.Open(src); case "alpha": dstWorld = AlphaWorld.Create(dst); break;
dstWorld = BetaWorld.Create(dst); case "beta": dstWorld = BetaWorld.Create(dst); break;
} case "anvil": dstWorld = AnvilWorld.Create(dst); break;
else { default: throw new Exception("Invalid conversion type");
srcWorld = BetaWorld.Open(src);
dstWorld = AlphaWorld.Create(dst);
} }
// Grab chunk managers to copy chunks // Grab chunk managers to copy chunks
@ -41,16 +43,12 @@ namespace Convert
// Copy each chunk from source to dest // Copy each chunk from source to dest
foreach (ChunkRef chunk in cmsrc) { foreach (ChunkRef chunk in cmsrc) {
cmdst.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef()); 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 // Copy level data from source to dest
dstWorld.Level.LoadTreeSafe(srcWorld.Level.BuildTree()); 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 // Save level.dat
dstWorld.Level.Save(); dstWorld.Level.Save();
} }

View file

@ -26,11 +26,11 @@ namespace CustomBlocks
string dest = args[0]; string dest = args[0];
// Open our world // Open our world
BetaWorld world = BetaWorld.Open(dest); NbtWorld world = NbtWorld.Open(dest);
// 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
BetaChunkManager cm = world.GetChunkManager(); IChunkManager 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

@ -51,7 +51,8 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Substrate"> <Reference Include="Substrate, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\Release\NET2\Substrate.dll</HintPath> <HintPath>..\..\bin\Release\NET2\Substrate.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />

View file

@ -1,5 +1,8 @@
using System; using System;
using Substrate; using Substrate;
using Substrate.Nbt;
using Substrate.Core;
using System.IO;
// FlatMap is an example of generating worlds from scratch with Substrate. // FlatMap is an example of generating worlds from scratch with Substrate.
// It will produce a completely flat, solid map with grass, dirt, stone, // It will produce a completely flat, solid map with grass, dirt, stone,
@ -12,19 +15,48 @@ namespace FlatMap
{ {
static void Main (string[] args) static void Main (string[] args)
{ {
string dest = "F:\\Minecraft\\test"; if (args.Length < 2) {
Console.WriteLine("Usage: flatmap <type> <target_dir>");
Console.WriteLine("Available Types: alpha, beta, anvil");
return;
}
string dest = args[1];
int xmin = -20; int xmin = -20;
int xmax = 20; int xmax = 20;
int zmin = -20; int zmin = -20;
int zmaz = 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 // This will instantly create any necessary directory structure
BetaWorld world = BetaWorld.Create(dest); NbtWorld world;
BetaChunkManager cm = world.GetChunkManager(); 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 // We can set different world parameters
world.Level.LevelName = "Flatlands"; world.Level.LevelName = "Flatlands";
world.Level.Spawn = new SpawnPoint(20, 20, 70); world.Level.Spawn = new SpawnPoint(20, 70, 20);
// 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
@ -51,6 +83,7 @@ namespace FlatMap
FlatChunk(chunk, 64); FlatChunk(chunk, 64);
// Reset and rebuild the lighting for the entire chunk at once // Reset and rebuild the lighting for the entire chunk at once
chunk.Blocks.RebuildHeightMap();
chunk.Blocks.RebuildBlockLight(); chunk.Blocks.RebuildBlockLight();
chunk.Blocks.RebuildSkyLight(); chunk.Blocks.RebuildSkyLight();

View file

@ -1,5 +1,6 @@
using System; using System;
using Substrate; using Substrate;
using Substrate.Core;
// This example will insert x amount of an item into a player's // This example will insert x amount of an item into a player's
// inventory in an SMP server (where there is a player directory) // inventory in an SMP server (where there is a player directory)
@ -21,8 +22,8 @@ namespace GiveItem
int count = Convert.ToInt32(args[3]); int count = Convert.ToInt32(args[3]);
// Open the world and grab its player manager // Open the world and grab its player manager
BetaWorld world = BetaWorld.Open(dest); NbtWorld world = NbtWorld.Open(dest);
PlayerManager pm = world.GetPlayerManager(); IPlayerManager pm = world.GetPlayerManager();
// Check that the named player exists // Check that the named player exists
if (!pm.PlayerExists(player)) { if (!pm.PlayerExists(player)) {

View file

@ -1,6 +1,7 @@
using System; using System;
using Substrate; using Substrate;
using Substrate.TileEntities; using Substrate.TileEntities;
using Substrate.Core;
// GoodyChest is an example that creates chests filled with random // GoodyChest is an example that creates chests filled with random
// items throughout the world, according to a probability of // items throughout the world, according to a probability of
@ -30,8 +31,8 @@ namespace GoodyChest
rand = new Random(); rand = new Random();
// Open our world // Open our world
BetaWorld world = BetaWorld.Open(dest); NbtWorld world = NbtWorld.Open(dest);
BetaChunkManager cm = world.GetChunkManager(); IChunkManager cm = world.GetChunkManager();
int added = 0; int added = 0;

View file

@ -8,7 +8,13 @@ namespace Maze
{ {
static void Main (string[] args) 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(); BlockManager bm = world.GetBlockManager();
bm.AutoLight = false; bm.AutoLight = false;
@ -48,7 +54,7 @@ namespace Maze
Console.WriteLine("Relight Chunks"); Console.WriteLine("Relight Chunks");
BetaChunkManager cm = world.GetChunkManager(); RegionChunkManager cm = world.GetChunkManager();
cm.RelightDirtyChunks(); cm.RelightDirtyChunks();
world.Save(); world.Save();

View file

@ -21,7 +21,7 @@ namespace MoveSpawn
int z = Convert.ToInt32(args[3]); int z = Convert.ToInt32(args[3]);
// Open our world // Open our world
BetaWorld world = BetaWorld.Open(dest); NbtWorld world = NbtWorld.Open(dest);
// Set the level's spawn // Set the level's spawn
// Note: Players do not have separate spawns by default // Note: Players do not have separate spawns by default

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Substrate; using Substrate;
using Substrate.Core;
// This example is a tool to delete all entities of a given type (e.g., "pig") // 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. // on a map. It optionally can be restricted to boxed region in block coords.
@ -35,8 +36,8 @@ namespace PurgeEntities
} }
// Load world // Load world
BetaWorld world = BetaWorld.Open(dest); NbtWorld world = NbtWorld.Open(dest);
BetaChunkManager cm = world.GetChunkManager(); IChunkManager cm = world.GetChunkManager();
// Remove entities // Remove entities
foreach (ChunkRef chunk in cm) { foreach (ChunkRef chunk in cm) {

View file

@ -1,6 +1,7 @@
using System; using System;
using Substrate; using Substrate;
using Substrate.Core; using Substrate.Core;
using Substrate.Nbt;
// This example will reset and rebuild the lighting (heightmap, block light, // This example will reset and rebuild the lighting (heightmap, block light,
// skylight) for all chunks in a map. // skylight) for all chunks in a map.
@ -24,6 +25,16 @@ namespace Relight
} }
string dest = args[0]; 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 // Opening an NbtWorld will try to autodetect if a world is Alpha-style or Beta-style
NbtWorld world = NbtWorld.Open(dest); NbtWorld world = NbtWorld.Open(dest);

View file

@ -51,7 +51,8 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Substrate"> <Reference Include="Substrate, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\Release\NET2\Substrate.dll</HintPath> <HintPath>..\..\bin\Release\NET2\Substrate.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />