2011-04-14 07:04:13 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Substrate;
|
2011-07-07 04:27:48 +00:00
|
|
|
|
using Substrate.Core;
|
2011-04-14 07:04:13 +00:00
|
|
|
|
|
2011-06-02 07:35:25 +00:00
|
|
|
|
// This example will reset and rebuild the lighting (heightmap, block light,
|
|
|
|
|
// skylight) for all chunks in a map.
|
|
|
|
|
|
|
|
|
|
// Note: If it looks silly to reset the lighting, loading and saving
|
|
|
|
|
// all the chunks, just to load and save them again later: it's not.
|
|
|
|
|
// If the world lighting is not correct, it must be completely reset
|
|
|
|
|
// before rebuilding the light in any chunks. That's just how the
|
|
|
|
|
// algorithms work, in order to limit the number of chunks that must
|
|
|
|
|
// be loaded at any given time.
|
|
|
|
|
|
2011-04-14 07:04:13 +00:00
|
|
|
|
namespace Relight
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main (string[] args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Length < 1) {
|
|
|
|
|
Console.WriteLine("You must specify a target directory");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string dest = args[0];
|
|
|
|
|
|
2011-07-24 20:03:47 +00:00
|
|
|
|
// Opening an NbtWorld will try to autodetect if a world is Alpha-style or Beta-style
|
2011-07-07 04:27:48 +00:00
|
|
|
|
NbtWorld world = NbtWorld.Open(dest);
|
2011-04-14 07:04:13 +00:00
|
|
|
|
|
|
|
|
|
// Grab a generic chunk manager reference
|
|
|
|
|
IChunkManager cm = world.GetChunkManager();
|
|
|
|
|
|
|
|
|
|
// First blank out all of the lighting in all of the chunks
|
|
|
|
|
foreach (ChunkRef chunk in cm) {
|
2011-05-13 03:09:57 +00:00
|
|
|
|
chunk.Blocks.RebuildHeightMap();
|
|
|
|
|
chunk.Blocks.ResetBlockLight();
|
2011-05-13 03:21:53 +00:00
|
|
|
|
chunk.Blocks.ResetSkyLight();
|
2011-06-08 01:51:59 +00:00
|
|
|
|
|
2011-04-14 07:04:13 +00:00
|
|
|
|
cm.Save();
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Reset Chunk {0},{1}", chunk.X, chunk.Z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// In a separate pass, reconstruct the light
|
|
|
|
|
foreach (ChunkRef chunk in cm) {
|
2011-05-13 03:09:57 +00:00
|
|
|
|
chunk.Blocks.RebuildBlockLight();
|
2011-05-13 03:21:53 +00:00
|
|
|
|
chunk.Blocks.RebuildSkyLight();
|
2011-04-14 07:04:13 +00:00
|
|
|
|
|
|
|
|
|
// Save the chunk to disk so it doesn't hang around in RAM
|
|
|
|
|
cm.Save();
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Lit Chunk {0},{1}", chunk.X, chunk.Z);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|