public static int Place(int x, int y)
        {
            TETrainingDummy tETrainingDummy = new TETrainingDummy()
            {
                Position = new Point16(x, y),
                ID       = TileEntity.AssignNewID(),
                type     = 0
            };

            TileEntity.ByID[tETrainingDummy.ID]             = tETrainingDummy;
            TileEntity.ByPosition[tETrainingDummy.Position] = tETrainingDummy;
            return(tETrainingDummy.ID);
        }
Esempio n. 2
0
        public static int Place(int x, int y)
        {
            TEItemFrame tEItemFrame = new TEItemFrame()
            {
                Position = new Point16(x, y),
                ID       = TileEntity.AssignNewID(),
                type     = 1
            };

            TileEntity.ByID[tEItemFrame.ID]             = tEItemFrame;
            TileEntity.ByPosition[tEItemFrame.Position] = tEItemFrame;
            return(tEItemFrame.ID);
        }
Esempio n. 3
0
 internal static void LoadTileEntities(IList <TagCompound> list)
 {
     foreach (TagCompound tag in list)
     {
         Mod           mod        = ModLoader.GetMod(tag.GetString("mod"));
         ModTileEntity tileEntity = mod?.GetTileEntity(tag.GetString("name"));
         ModTileEntity newEntity;
         if (tileEntity != null)
         {
             newEntity          = ModTileEntity.ConstructFromBase(tileEntity);
             newEntity.type     = (byte)tileEntity.Type;
             newEntity.Position = new Point16(tag.GetShort("X"), tag.GetShort("Y"));
             if (tag.ContainsKey("data"))
             {
                 try
                 {
                     newEntity.Load(tag.GetCompound("data"));
                     if (newEntity is MysteryTileEntity)
                     {
                         ((MysteryTileEntity)newEntity).TryRestore(ref newEntity);
                     }
                 }
                 catch (Exception e)
                 {
                     throw new CustomModDataException(mod,
                                                      "Error in reading " + tileEntity.Name + " tile entity data for " + mod.Name, e);
                 }
             }
         }
         else
         {
             tileEntity         = ModLoader.GetMod("ModLoader").GetTileEntity("MysteryTileEntity");
             newEntity          = ModTileEntity.ConstructFromBase(tileEntity);
             newEntity.type     = (byte)tileEntity.Type;
             newEntity.Position = new Point16(tag.GetShort("X"), tag.GetShort("Y"));
             ((MysteryTileEntity)newEntity).SetData(tag);
         }
         if (tileEntity.ValidTile(newEntity.Position.X, newEntity.Position.Y))
         {
             newEntity.ID = TileEntity.AssignNewID();
             TileEntity.ByID[newEntity.ID] = newEntity;
             TileEntity other;
             if (TileEntity.ByPosition.TryGetValue(newEntity.Position, out other))
             {
                 TileEntity.ByID.Remove(other.ID);
             }
             TileEntity.ByPosition[newEntity.Position] = newEntity;
         }
     }
 }
Esempio n. 4
0
        internal static void LoadTileEntities(IList <TagCompound> list)
        {
            foreach (TagCompound tag in list)
            {
                string modName = tag.GetString("mod");
                string name    = tag.GetString("name");
                var    point   = new Point16(tag.GetShort("X"), tag.GetShort("Y"));

                ModTileEntity baseModTileEntity = null;
                TileEntity    tileEntity        = null;

                //If the TE is modded
                if (modName != "Terraria")
                {
                    //Find its type, defaulting to pending.
                    if (!ModContent.TryFind(modName, name, out baseModTileEntity))
                    {
                        baseModTileEntity = ModContent.GetInstance <UnloadedTileEntity>();
                    }

                    tileEntity          = ModTileEntity.ConstructFromBase(baseModTileEntity);
                    tileEntity.type     = (byte)baseModTileEntity.Type;
                    tileEntity.Position = point;

                    (tileEntity as UnloadedTileEntity)?.SetData(tag);
                }
                //Otherwise, if the TE is vanilla, try to find its existing instance for the current coordinate.
                else if (!TileEntity.ByPosition.TryGetValue(point, out tileEntity))
                {
                    //Do not create an PendingTileEntity on failure to do so.
                    continue;
                }

                //Load TE data.
                if (tag.ContainsKey("data"))
                {
                    try {
                        tileEntity.Load(tag.GetCompound("data"));

                        if (tileEntity is ModTileEntity modTileEntity)
                        {
                            (tileEntity as UnloadedTileEntity)?.TryRestore(ref modTileEntity);

                            tileEntity = modTileEntity;
                        }
                    }
                    catch (Exception e) {
                        throw new CustomModDataException((tileEntity as ModTileEntity)?.Mod, $"Error in reading {name} tile entity data for {modName}", e);
                    }
                }

                //Check mods' TEs for being valid. If they are, register them to TE collections.
                if (baseModTileEntity != null && baseModTileEntity.ValidTile(tileEntity.Position.X, tileEntity.Position.Y))
                {
                    tileEntity.ID = TileEntity.AssignNewID();
                    TileEntity.ByID[tileEntity.ID] = tileEntity;

                    if (TileEntity.ByPosition.TryGetValue(tileEntity.Position, out TileEntity other))
                    {
                        TileEntity.ByID.Remove(other.ID);
                    }

                    TileEntity.ByPosition[tileEntity.Position] = tileEntity;
                }
            }
        }