public void SetTileEntity(int x, int y, int z, TileEntity te) { BlockInfoEx info = BlockInfo.BlockTable[_blocks[x, y, z]] as BlockInfoEx; if (info == null) { throw new InvalidOperationException("The given block is of a type that does not support TileEntities."); } if (te.GetType() != TileEntityFactory.Lookup(info.TileEntityName)) { throw new ArgumentException("The TileEntity type is not valid for this block.", "te"); } BlockKey key = (TranslateCoordinates != null) ? TranslateCoordinates(x, y, z) : new BlockKey(x, y, z); TagNodeCompound oldte; if (_tileEntityTable.TryGetValue(key, out oldte)) { _tileEntities.Remove(oldte); } te.X = key.x; te.Y = key.y; te.Z = key.z; TagNodeCompound tree = te.BuildTree() as TagNodeCompound; _tileEntities.Add(tree); _tileEntityTable[key] = tree; }
public static void Main(string[] args) { TileEntityFactory.Register(TileEntityBrewingStand.TypeId, typeof(TileEntityBrewingStand)); TileEntityFactory.Register(TileEntityChest.TypeId, typeof(TileEntityChest)); TileEntityFactory.Register(TileEntityTrap.TypeId, typeof(TileEntityTrap)); TileEntityFactory.Register(TileEntityMobSpawner.TypeId, typeof(TileEntityMobSpawner)); string path = args.Length == 0 ? "." : string.Join(" ", args); NbtWorld world = NbtWorld.Open(path); if (world == null) { Dialog.WorldInvalidDialog(); return; } Console.WriteLine("Working with world: {0}", world.Level.LevelName); fixPotions = Dialog.FixPotionsDialog(); fixSpawners = Dialog.FixSpawnersDialog(); DateTime startTime = DateTime.Now; LoopChunks(world, Dimension.DEFAULT); LoopChunks(world, Dimension.NETHER); LoopChunks(world, Dimension.THE_END); TimeSpan time = DateTime.Now.Subtract(startTime); Console.Write("Finished searching {0} in {1}. Fixed:", world.Level.LevelName, time.ToString(@"h\:mm\:ss")); Console.Write(" [{0} chest{1}]", fixedIssues["chest"], fixedIssues["chest"] == 1 ? "" : "s"); Console.Write(" [{0} potion{1}]", fixedIssues["potion"], fixedIssues["potion"] == 1 ? "" : "s"); Console.Write(" [{0} spawner{1}]", fixedIssues["spawner"], fixedIssues["spawner"] == 1 ? "" : "s"); Console.WriteLine(); Dialog.NewDialog(); }
public TileEntity GetTileEntity(int x, int y, int z) { BlockKey key = (TranslateCoordinates != null) ? TranslateCoordinates(x, y, z) : new BlockKey(x, y, z); TagNodeCompound te; if (!_tileEntityTable.TryGetValue(key, out te)) { return(null); } return(TileEntityFactory.CreateGeneric(te)); }
static RegisterTileEntities() { TileEntityFactory.Register(TileEntityEndPortal.TypeId, typeof(TileEntityEndPortal)); TileEntityFactory.Register(TileEntityBeacon.TypeId, typeof(TileEntityBeacon)); TileEntityFactory.Register(TileEntityBrewingStand.TypeId, typeof(TileEntityBrewingStand)); TileEntityFactory.Register(TileEntityChest.TypeId, typeof(TileEntityChest)); TileEntityFactory.Register(TileEntityControl.TypeId, typeof(TileEntityControl)); TileEntityFactory.Register(TileEntityEnchantmentTable.TypeId, typeof(TileEntityEnchantmentTable)); TileEntityFactory.Register(TileEntityFurnace.TypeId, typeof(TileEntityFurnace)); TileEntityFactory.Register(TileEntityMobSpawner.TypeId, typeof(TileEntityMobSpawner)); TileEntityFactory.Register(TileEntityMusic.TypeId, typeof(TileEntityMusic)); TileEntityFactory.Register(TileEntityPiston.TypeId, typeof(TileEntityPiston)); TileEntityFactory.Register(TileEntityRecordPlayer.TypeId, typeof(TileEntityRecordPlayer)); TileEntityFactory.Register(TileEntitySign.TypeId, typeof(TileEntitySign)); TileEntityFactory.Register(TileEntityTrap.TypeId, typeof(TileEntityTrap)); }
public void GetEntitysInChunk(int chunkX, int chunkZ) { foreach (var player in Level.GetOnlinePlayers) { if (player == this) { continue; } var x = (int)player.KnownPosition.X >> 4; var z = (int)player.KnownPosition.Z >> 4; if (chunkX == x && chunkZ == z) { new SpawnPlayer(Wrapper) { Player = player }.Write(); } } foreach (var entity in Level.Entities) { var x = (int)entity.KnownPosition.X >> 4; var z = (int)entity.KnownPosition.Z >> 4; if (chunkX == x && chunkZ == z) { new SpawnObject(Wrapper) { X = entity.KnownPosition.X, Y = entity.KnownPosition.Y, Z = entity.KnownPosition.Z, EntityId = entity.EntityId, Type = (ObjectType)entity.EntityTypeId, Yaw = entity.KnownPosition.Yaw, Pitch = entity.KnownPosition.Pitch }.Write(); } } ChunkColumn chunk = Level.Generator.GenerateChunkColumn(new Vector2(chunkX, chunkZ)); foreach (var raw in chunk.TileEntities) { var nbt = raw.Value; if (nbt == null) { continue; } string id = null; var idTag = nbt.Get("id"); if (idTag != null) { id = idTag.StringValue; } if (string.IsNullOrEmpty(id)) { continue; } var tileEntity = TileEntityFactory.GetBlockEntityById(id); tileEntity.Coordinates = raw.Key; tileEntity.SetCompound(nbt); if (tileEntity.Id == "Sign") { var sign = (SignTileEntity)tileEntity; new UpdateSign(Wrapper) { SignCoordinates = sign.Coordinates, Line1 = sign.Line1, Line2 = sign.Line2, Line3 = sign.Line3, Line4 = sign.Line4, }.Write(); } } }
public void Init() { _data = ScriptableObject.CreateInstance <TileData>(); _factory = new TileEntityFactory(_contexts.tile); }