NBTExplorer/NBToolkit/NBToolkit/Map/Block.cs

123 lines
2.9 KiB
C#
Raw Normal View History

2011-04-02 00:42:15 +00:00
using System;
using System.Collections.Generic;
using System.Text;
namespace NBToolkit.Map
2011-04-02 00:42:15 +00:00
{
using NBT;
using Utility;
2011-04-02 00:42:15 +00:00
public class Block : IBlock, ICopyable<Block>
2011-04-02 00:42:15 +00:00
{
private int _id;
private int _data;
private int _skylight;
private int _blocklight;
2011-04-02 00:42:15 +00:00
private TileEntity _tileEntity;
2011-04-02 00:42:15 +00:00
public BlockInfo Info
{
get { return BlockInfo.BlockTable[_id]; }
}
public int ID
{
get { return _id; }
set
{
if (BlockInfo.SchemaTable[_id] != BlockInfo.SchemaTable[value]) {
_tileEntity = null;
}
_id = value;
}
2011-04-02 00:42:15 +00:00
}
public int Data
{
get { return _data; }
set
{
if (BlockManager.EnforceDataLimits && BlockInfo.BlockTable[_id] != null) {
if (!BlockInfo.BlockTable[_id].TestData(value)) {
return;
}
}
_data = value;
}
2011-04-02 00:42:15 +00:00
}
public int SkyLight
{
get { return _skylight; }
set { _skylight = value; }
}
public int BlockLight
{
get { return _blocklight; }
set { _blocklight = value; }
}
public Block (int id)
{
_id = id;
}
public Block (int id, int data)
{
_id = id;
_data = data;
}
public Block (IChunk chunk, int lx, int ly, int lz)
2011-04-02 00:42:15 +00:00
{
_id = chunk.GetBlockID(lx, ly, lz);
_data = chunk.GetBlockData(lx, ly, lz);
_skylight = chunk.GetBlockSkyLight(lx, ly, lz);
_blocklight = chunk.GetBlockLight(lx, ly, lz);
_tileEntity = chunk.GetTileEntity(lx, ly, lz).Copy();
2011-04-02 00:42:15 +00:00
}
public TileEntity GetTileEntity ()
2011-04-02 00:42:15 +00:00
{
return _tileEntity;
2011-04-02 00:42:15 +00:00
}
public bool SetTileEntity (TileEntity te)
2011-04-02 00:42:15 +00:00
{
NBTCompoundNode schema = BlockInfo.SchemaTable[_id];
if (schema == null) {
return false;
}
if (te.Verify(schema) == false) {
return false;
}
_tileEntity = te;
return true;
}
public bool ClearTileEntity ()
{
_tileEntity = null;
return true;
2011-04-02 00:42:15 +00:00
}
#region ICopyable<Block> Members
public Block Copy ()
2011-04-02 00:42:15 +00:00
{
Block block = new Block(_id, _data);
block._blocklight = _blocklight;
block._skylight = _skylight;
block._tileEntity = _tileEntity.Copy();
return block;
2011-04-02 00:42:15 +00:00
}
#endregion
2011-04-02 00:42:15 +00:00
}
}