2012-11-05 05:33:30 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using Substrate.Core;
|
2012-08-31 05:29:32 +00:00
|
|
|
|
using Substrate.Nbt;
|
|
|
|
|
|
|
|
|
|
namespace NBTExplorer.Model
|
|
|
|
|
{
|
|
|
|
|
public class RegionChunkDataNode : DataNode, IMetaTagContainer
|
|
|
|
|
{
|
|
|
|
|
private RegionFile _regionFile;
|
|
|
|
|
private NbtTree _tree;
|
|
|
|
|
private int _x;
|
|
|
|
|
private int _z;
|
|
|
|
|
|
|
|
|
|
private CompoundTagContainer _container;
|
|
|
|
|
|
|
|
|
|
public RegionChunkDataNode (RegionFile regionFile, int x, int z)
|
|
|
|
|
{
|
|
|
|
|
_regionFile = regionFile;
|
|
|
|
|
_x = x;
|
|
|
|
|
_z = z;
|
|
|
|
|
_container = new CompoundTagContainer(new TagNodeCompound());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override NodeCapabilities Capabilities
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return NodeCapabilities.CreateTag
|
|
|
|
|
| NodeCapabilities.PasteInto
|
|
|
|
|
| NodeCapabilities.Search;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool HasUnexpandedChildren
|
|
|
|
|
{
|
|
|
|
|
get { return !IsExpanded; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 06:11:04 +00:00
|
|
|
|
public override string NodePathName
|
|
|
|
|
{
|
|
|
|
|
get { return _x + "." + _z; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 05:29:32 +00:00
|
|
|
|
public override string NodeDisplay
|
|
|
|
|
{
|
|
|
|
|
get { return "Chunk [" + _x + ", " + _z + "]"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ExpandCore ()
|
|
|
|
|
{
|
|
|
|
|
if (_tree == null) {
|
|
|
|
|
_tree = new NbtTree();
|
|
|
|
|
_tree.ReadFrom(_regionFile.GetChunkDataInputStream(_x, _z));
|
|
|
|
|
|
|
|
|
|
if (_tree.Root != null)
|
|
|
|
|
_container = new CompoundTagContainer(_tree.Root);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (TagNode tag in _tree.Root.Values) {
|
|
|
|
|
TagDataNode node = TagDataNode.CreateFromTag(tag);
|
|
|
|
|
if (node != null)
|
|
|
|
|
Nodes.Add(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ReleaseCore ()
|
|
|
|
|
{
|
|
|
|
|
_tree = null;
|
|
|
|
|
Nodes.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-01 23:27:50 +00:00
|
|
|
|
protected override void SaveCore ()
|
|
|
|
|
{
|
|
|
|
|
using (Stream str = _regionFile.GetChunkDataOutputStream(_x, _z)) {
|
|
|
|
|
_tree.WriteTo(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-30 02:17:07 +00:00
|
|
|
|
public override bool IsContainerType
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 05:29:32 +00:00
|
|
|
|
public bool IsNamedContainer
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsOrderedContainer
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public INamedTagContainer NamedTagContainer
|
|
|
|
|
{
|
|
|
|
|
get { return _container; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IOrderedTagContainer OrderedTagContainer
|
|
|
|
|
{
|
|
|
|
|
get { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int TagCount
|
|
|
|
|
{
|
|
|
|
|
get { return _container.TagCount; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeleteTag (TagNode tag)
|
|
|
|
|
{
|
|
|
|
|
return _container.DeleteTag(tag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|