/// <summary> /// Updates the chunk's global world coordinates. /// </summary> /// <param name="x">Global X-coordinate.</param> /// <param name="z">Global Z-coordinate.</param> public virtual void SetLocation(int x, int z) { int diffx = (x - _cx) * XDIM; int diffz = (z - _cz) * ZDIM; // Update chunk position _cx = x; _cz = z; _tree.Root["Level"].ToTagCompound()["xPos"].ToTagInt().Data = x; _tree.Root["Level"].ToTagCompound()["zPos"].ToTagInt().Data = z; // Update tile entity coordinates List <TileEntity> tileEntites = new List <TileEntity>(); foreach (TagNodeCompound tag in _tileEntities) { TileEntity te = TileEntityFactory.Create(tag); if (te == null) { te = TileEntity.FromTreeSafe(tag); } if (te != null) { te.MoveBy(diffx, 0, diffz); tileEntites.Add(te); } } _tileEntities.Clear(); foreach (TileEntity te in tileEntites) { _tileEntities.Add(te.BuildTree()); } // Update entity coordinates List <TypedEntity> entities = new List <TypedEntity>(); foreach (TypedEntity entity in _entityManager) { entity.MoveBy(diffx, 0, diffz); entities.Add(entity); } _entities.Clear(); foreach (TypedEntity entity in entities) { _entityManager.Add(entity); } }
private void UpdateTileEntity(int old, int value) { BlockInfoEx info1 = BlockInfo.BlockTable[old] as BlockInfoEx; BlockInfoEx info2 = BlockInfo.BlockTable[value] as BlockInfoEx; if (info1 != info2) { if (info1 != null) { _tileEntity = null; } if (info2 != null) { _tileEntity = TileEntityFactory.Create(info2.TileEntityName); } } }
/// <summary> /// Creates a default Tile Entity record appropriate for the block. /// </summary> public void CreateTileEntity() { BlockInfoEx info = BlockInfo.BlockTable[_id] as BlockInfoEx; if (info == null) { throw new InvalidOperationException("The given block is of a type that does not support TileEntities."); } TileEntity te = TileEntityFactory.Create(info.TileEntityName); if (te == null) { throw new UnknownTileEntityException("The TileEntity type '" + info.TileEntityName + "' has not been registered with the TileEntityFactory."); } _tileEntity = te; }