2011-04-06 04:43:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2011-04-06 21:20:35 +00:00
|
|
|
|
namespace Substrate
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
2011-04-07 08:04:53 +00:00
|
|
|
|
using NBT;
|
|
|
|
|
|
2011-04-06 04:43:54 +00:00
|
|
|
|
public class World
|
|
|
|
|
{
|
|
|
|
|
protected RegionManager _regionMan;
|
2011-04-07 08:04:53 +00:00
|
|
|
|
protected IChunkManager _chunkMan;
|
|
|
|
|
protected IBlockManager _blockMan;
|
2011-04-07 07:03:54 +00:00
|
|
|
|
protected PlayerManager _playerMan;
|
2011-04-06 04:43:54 +00:00
|
|
|
|
|
|
|
|
|
protected string _worldPath;
|
|
|
|
|
|
2011-04-07 08:04:53 +00:00
|
|
|
|
protected Level _level;
|
|
|
|
|
|
|
|
|
|
public string WorldPath
|
|
|
|
|
{
|
|
|
|
|
get { return _worldPath; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 04:43:54 +00:00
|
|
|
|
public World (string world)
|
|
|
|
|
{
|
|
|
|
|
_worldPath = world;
|
|
|
|
|
|
2011-04-07 08:04:53 +00:00
|
|
|
|
if (!File.Exists(Path.Combine(_worldPath, "level.dat"))) {
|
|
|
|
|
throw new Exception("Could not locate level.dat");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!LoadLevel()) {
|
|
|
|
|
throw new Exception("Failed to load level.dat");
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-07 07:03:54 +00:00
|
|
|
|
if (Directory.Exists(Path.Combine(world, "region"))) {
|
|
|
|
|
_regionMan = new RegionManager(Path.Combine(world, "region"));
|
|
|
|
|
_chunkMan = new ChunkManager(_regionMan);
|
|
|
|
|
}
|
|
|
|
|
else if (Directory.Exists(Path.Combine(world, "0"))) {
|
2011-04-07 08:04:53 +00:00
|
|
|
|
_chunkMan = new ChunkFileManager(world);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw new Exception("Could not locate any world data");
|
2011-04-07 07:03:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 04:43:54 +00:00
|
|
|
|
_blockMan = new BlockManager(_chunkMan);
|
2011-04-07 07:03:54 +00:00
|
|
|
|
|
|
|
|
|
if (Directory.Exists(Path.Combine(world, "players"))) {
|
|
|
|
|
_playerMan = new PlayerManager(Path.Combine(world, "players"));
|
|
|
|
|
}
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-07 08:04:53 +00:00
|
|
|
|
protected bool LoadLevel ()
|
|
|
|
|
{
|
|
|
|
|
NBTFile nf = new NBTFile(Path.Combine(_worldPath, "level.dat"));
|
|
|
|
|
Stream nbtstr = nf.GetDataInputStream();
|
|
|
|
|
if (nbtstr == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 06:48:27 +00:00
|
|
|
|
NBT_Tree tree = new NBT_Tree(nbtstr);
|
|
|
|
|
|
|
|
|
|
_level = new Level(this);
|
|
|
|
|
_level = _level.LoadTreeSafe(tree.Root);
|
2011-04-07 08:04:53 +00:00
|
|
|
|
|
|
|
|
|
return _level != null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 04:43:54 +00:00
|
|
|
|
public RegionManager GetRegionManager ()
|
|
|
|
|
{
|
|
|
|
|
return _regionMan;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-07 08:04:53 +00:00
|
|
|
|
public IChunkManager GetChunkManager ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return _chunkMan;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-07 08:04:53 +00:00
|
|
|
|
public IBlockManager GetBlockManager ()
|
2011-04-06 04:43:54 +00:00
|
|
|
|
{
|
|
|
|
|
return _blockMan;
|
|
|
|
|
}
|
2011-04-07 07:03:54 +00:00
|
|
|
|
|
|
|
|
|
public PlayerManager GetPlayerManager ()
|
|
|
|
|
{
|
|
|
|
|
return _playerMan;
|
|
|
|
|
}
|
2011-04-06 04:43:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|