diff --git a/SubstrateCS/Source/AlphaWorld.cs b/SubstrateCS/Source/AlphaWorld.cs index 9599b42..9a171f5 100644 --- a/SubstrateCS/Source/AlphaWorld.cs +++ b/SubstrateCS/Source/AlphaWorld.cs @@ -19,15 +19,15 @@ namespace Substrate private Level _level; - private Dictionary _chunkMgrs; - private Dictionary _blockMgrs; + private Dictionary _chunkMgrs; + private Dictionary _blockMgrs; private PlayerManager _playerMan; private AlphaWorld () { - _chunkMgrs = new Dictionary(); - _blockMgrs = new Dictionary(); + _chunkMgrs = new Dictionary(); + _blockMgrs = new Dictionary(); } /// @@ -99,7 +99,7 @@ namespace Substrate { _level.Save(); - foreach (KeyValuePair cm in _chunkMgrs) { + foreach (KeyValuePair cm in _chunkMgrs) { cm.Value.Save(); } } @@ -128,6 +128,11 @@ namespace Substrate /// protected override IBlockManager GetBlockManagerVirt (int dim) + { + return GetBlockManagerVirt(DimensionFromInt(dim)); + } + + protected override IBlockManager GetBlockManagerVirt (string dim) { BlockManager rm; if (_blockMgrs.TryGetValue(dim, out rm)) { @@ -140,6 +145,11 @@ namespace Substrate /// protected override IChunkManager GetChunkManagerVirt (int dim) + { + return GetChunkManagerVirt(DimensionFromInt(dim)); + } + + protected override IChunkManager GetChunkManagerVirt (string dim) { AlphaChunkManager rm; if (_chunkMgrs.TryGetValue(dim, out rm)) { @@ -163,11 +173,19 @@ namespace Substrate return _playerMan; } - private void OpenDimension (int dim) + private string DimensionFromInt (int dim) + { + if (dim == Dimension.DEFAULT) + return ""; + else + return "DIM" + dim; + } + + private void OpenDimension (string dim) { string path = Path; - if (dim != Dimension.DEFAULT) { - path = IO.Path.Combine(path, "DIM" + dim); + if (!String.IsNullOrEmpty(dim)) { + path = IO.Path.Combine(path, dim); } if (!Directory.Exists(path)) { diff --git a/SubstrateCS/Source/AnvilWorld.cs b/SubstrateCS/Source/AnvilWorld.cs index e59b024..b74ce93 100644 --- a/SubstrateCS/Source/AnvilWorld.cs +++ b/SubstrateCS/Source/AnvilWorld.cs @@ -22,11 +22,11 @@ namespace Substrate private Level _level; - private Dictionary _regionMgrs; - private Dictionary _chunkMgrs; - private Dictionary _blockMgrs; + private Dictionary _regionMgrs; + private Dictionary _chunkMgrs; + private Dictionary _blockMgrs; - private Dictionary _caches; + private Dictionary _caches; private PlayerManager _playerMan; private BetaDataManager _dataMan; @@ -35,11 +35,11 @@ namespace Substrate private AnvilWorld () { - _regionMgrs = new Dictionary(); - _chunkMgrs = new Dictionary(); - _blockMgrs = new Dictionary(); + _regionMgrs = new Dictionary(); + _chunkMgrs = new Dictionary(); + _blockMgrs = new Dictionary(); - _caches = new Dictionary(); + _caches = new Dictionary(); } /// @@ -75,6 +75,11 @@ namespace Substrate return GetBlockManagerVirt(dim) as BlockManager; } + public new BlockManager GetBlockManager (string dim) + { + return GetBlockManagerVirt(dim) as BlockManager; + } + /// /// Gets a for the default dimension. /// @@ -96,6 +101,11 @@ namespace Substrate return GetChunkManagerVirt(dim) as RegionChunkManager; } + public new RegionChunkManager GetChunkManager (string dim) + { + return GetChunkManagerVirt(dim) as RegionChunkManager; + } + /// /// Gets a for the default dimension. /// @@ -115,6 +125,11 @@ namespace Substrate /// Regions are a higher-level unit of organization for blocks unique to worlds created in Beta 1.3 and beyond. /// Consider using the if you are interested in working with blocks. public AnvilRegionManager GetRegionManager (int dim) + { + return GetRegionManager(DimensionFromInt(dim)); + } + + public AnvilRegionManager GetRegionManager (string dim) { AnvilRegionManager rm; if (_regionMgrs.TryGetValue(dim, out rm)) { @@ -149,7 +164,7 @@ namespace Substrate { _level.Save(); - foreach (KeyValuePair cm in _chunkMgrs) { + foreach (KeyValuePair cm in _chunkMgrs) { cm.Value.Save(); } } @@ -169,6 +184,11 @@ namespace Substrate /// The id of a dimension to look up. /// The for the given dimension, or null if the dimension was not found. public ChunkCache GetChunkCache (int dim) + { + return GetChunkCache(DimensionFromInt(dim)); + } + + public ChunkCache GetChunkCache (string dim) { if (_caches.ContainsKey(dim)) { return _caches[dim]; @@ -230,6 +250,11 @@ namespace Substrate /// protected override IBlockManager GetBlockManagerVirt (int dim) + { + return GetBlockManagerVirt(DimensionFromInt(dim)); + } + + protected override IBlockManager GetBlockManagerVirt(string dim) { BlockManager rm; if (_blockMgrs.TryGetValue(dim, out rm)) { @@ -242,6 +267,11 @@ namespace Substrate /// protected override IChunkManager GetChunkManagerVirt (int dim) + { + return GetChunkManagerVirt(DimensionFromInt(dim)); + } + + protected override IChunkManager GetChunkManagerVirt (string dim) { RegionChunkManager rm; if (_chunkMgrs.TryGetValue(dim, out rm)) { @@ -276,14 +306,22 @@ namespace Substrate return _dataMan; } - private void OpenDimension (int dim) + private string DimensionFromInt (int dim) + { + if (dim == Dimension.DEFAULT) + return ""; + else + return "DIM" + dim; + } + + private void OpenDimension (string dim) { string path = Path; - if (dim == Dimension.DEFAULT) { + if (String.IsNullOrEmpty(dim)) { path = IO.Path.Combine(path, _REGION_DIR); } else { - path = IO.Path.Combine(path, "DIM" + dim); + path = IO.Path.Combine(path, dim); path = IO.Path.Combine(path, _REGION_DIR); } diff --git a/SubstrateCS/Source/BetaWorld.cs b/SubstrateCS/Source/BetaWorld.cs index bde0bd1..14447d8 100644 --- a/SubstrateCS/Source/BetaWorld.cs +++ b/SubstrateCS/Source/BetaWorld.cs @@ -22,11 +22,11 @@ namespace Substrate private Level _level; - private Dictionary _regionMgrs; - private Dictionary _chunkMgrs; - private Dictionary _blockMgrs; + private Dictionary _regionMgrs; + private Dictionary _chunkMgrs; + private Dictionary _blockMgrs; - private Dictionary _caches; + private Dictionary _caches; private PlayerManager _playerMan; private BetaDataManager _dataMan; @@ -35,11 +35,11 @@ namespace Substrate private BetaWorld () { - _regionMgrs = new Dictionary(); - _chunkMgrs = new Dictionary(); - _blockMgrs = new Dictionary(); + _regionMgrs = new Dictionary(); + _chunkMgrs = new Dictionary(); + _blockMgrs = new Dictionary(); - _caches = new Dictionary(); + _caches = new Dictionary(); } /// @@ -75,6 +75,11 @@ namespace Substrate return GetBlockManagerVirt(dim) as BlockManager; } + public new BlockManager GetBlockManager (string dim) + { + return GetBlockManagerVirt(dim) as BlockManager; + } + /// /// Gets a for the default dimension. /// @@ -96,6 +101,11 @@ namespace Substrate return GetChunkManagerVirt(dim) as RegionChunkManager; } + public new RegionChunkManager GetChunkManager (string dim) + { + return GetChunkManagerVirt(dim) as RegionChunkManager; + } + /// /// Gets a for the default dimension. /// @@ -115,6 +125,11 @@ namespace Substrate /// Regions are a higher-level unit of organization for blocks unique to worlds created in Beta 1.3 and beyond. /// Consider using the if you are interested in working with blocks. public BetaRegionManager GetRegionManager (int dim) + { + return GetRegionManager(DimensionFromInt(dim)); + } + + public BetaRegionManager GetRegionManager (string dim) { BetaRegionManager rm; if (_regionMgrs.TryGetValue(dim, out rm)) { @@ -149,7 +164,7 @@ namespace Substrate { _level.Save(); - foreach (KeyValuePair cm in _chunkMgrs) { + foreach (KeyValuePair cm in _chunkMgrs) { cm.Value.Save(); } } @@ -169,6 +184,11 @@ namespace Substrate /// The id of a dimension to look up. /// The for the given dimension, or null if the dimension was not found. public ChunkCache GetChunkCache (int dim) + { + return GetChunkCache(DimensionFromInt(dim)); + } + + public ChunkCache GetChunkCache (string dim) { if (_caches.ContainsKey(dim)) { return _caches[dim]; @@ -230,6 +250,11 @@ namespace Substrate /// protected override IBlockManager GetBlockManagerVirt (int dim) + { + return GetBlockManagerVirt(DimensionFromInt(dim)); + } + + protected override IBlockManager GetBlockManagerVirt (string dim) { BlockManager rm; if (_blockMgrs.TryGetValue(dim, out rm)) { @@ -242,6 +267,11 @@ namespace Substrate /// protected override IChunkManager GetChunkManagerVirt (int dim) + { + return GetChunkManagerVirt(DimensionFromInt(dim)); + } + + protected override IChunkManager GetChunkManagerVirt (string dim) { RegionChunkManager rm; if (_chunkMgrs.TryGetValue(dim, out rm)) { @@ -276,14 +306,22 @@ namespace Substrate return _dataMan; } - private void OpenDimension (int dim) + private string DimensionFromInt (int dim) + { + if (dim == Dimension.DEFAULT) + return ""; + else + return "DIM" + dim; + } + + private void OpenDimension (string dim) { string path = Path; - if (dim == Dimension.DEFAULT) { + if (String.IsNullOrEmpty(dim)) { path = IO.Path.Combine(path, _REGION_DIR); } else { - path = IO.Path.Combine(path, "DIM" + dim); + path = IO.Path.Combine(path, dim); path = IO.Path.Combine(path, _REGION_DIR); } diff --git a/SubstrateCS/Source/NbtWorld.cs b/SubstrateCS/Source/NbtWorld.cs index f7c2d6e..bbb3100 100644 --- a/SubstrateCS/Source/NbtWorld.cs +++ b/SubstrateCS/Source/NbtWorld.cs @@ -73,6 +73,11 @@ namespace Substrate return GetBlockManagerVirt(dim); } + public IBlockManager GetBlockManager (string dim) + { + return GetBlockManagerVirt(dim); + } + /// /// Gets an for the default dimension. /// @@ -92,6 +97,11 @@ namespace Substrate return GetChunkManagerVirt(dim); } + public IChunkManager GetChunkManager (string dim) + { + return GetChunkManagerVirt(dim); + } + /// /// Gets an for maanging players on multiplayer worlds. /// @@ -162,6 +172,16 @@ namespace Substrate /// An for the given dimension in the world. protected abstract IChunkManager GetChunkManagerVirt (int dim); + protected virtual IBlockManager GetBlockManagerVirt (string dim) + { + throw new NotImplementedException(); + } + + protected virtual IChunkManager GetChunkManagerVirt (string dim) + { + throw new NotImplementedException(); + } + /// /// Virtual implementor of . ///