当前位置: 首页>>代码示例>>C#>>正文


C# NbtCompound.ToString方法代码示例

本文整理汇总了C#中NbtCompound.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# NbtCompound.ToString方法的具体用法?C# NbtCompound.ToString怎么用?C# NbtCompound.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NbtCompound的用法示例。


在下文中一共展示了NbtCompound.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Entity

 public Entity(NbtCompound c)
 {
     orig = c;
     id = (orig["id"] as NbtString).Value;
     SetBaseStuff(c);
     #if DEBUG
     Console.WriteLine("*** BUG: Unknown entity (ID: {0})",id);
     Console.WriteLine(orig);
     #endif
     File.WriteAllText("UnknownEntity." + id + ".txt", orig.ToString().Replace("\n","\r\n"));
 }
开发者ID:herpit,项目名称:MineEdit,代码行数:11,代码来源:Entity.cs

示例2: GenTemplate

        // This tosses together a cheapass entity class for faster updates.
        //  Primarily because I'm a lazy fuck.
        private static void GenTemplate(NbtCompound c, string tpl)
        {
            string ID = c.Get<NbtString>("id").Value;
            string Name = ID.Substring(0, 1).ToUpper() + ID.Substring(1);

            string newthing = File.ReadAllText("TileEntities/"+tpl);

            // Construct variables
            string vardec = "";
            string dectmpl = "\n\t\t[Category(\"{0}\"), Description(\"(WIP)\")]\n\t\tpublic {1} {2} {{get;set;}}\n";

            string varassn = "";
            string assntpl = "\n\t\t\t{0} = c.Get<{1}>(\"{2}\").Value;";

            string nbtassn = "";
            string nbttpl = "\n\t\t\tc.Add(new {0}(\"{1}\", {2}));";

            // Figure out if there are any new fields that we should be concerned about...
            foreach (NbtTag t in c)
            {
                if (CommonTileEntityVars.Contains(t.Name))
                    continue;
                string vname = t.Name.Substring(0, 1).ToUpper() + t.Name.Substring(1);
                string tagname = t.Name;
                string type = GetNativeType(t);
                string nbtTag = t.GetType().Name;

                vardec += string.Format(dectmpl, Name, type, vname);
                varassn += string.Format(assntpl, vname, nbtTag, tagname);
                nbtassn += string.Format(nbttpl, nbtTag, tagname, vname);
            }

            // {DATA_DUMP} - Crap out a dump of the entity.
            // {ENTITY_NAME} - Entity name, but capitalized (CamelCase)
            // {NEW_VARS} - New var declarations.
            // {VAR_ASSIGNMENT} - Set the vars from the Compound.
            // {TO_NBT} - Set the appropriate stuff in the Compound.
            // {ENTITY_ID} - Raw entity ID

            newthing = newthing.Replace("{DATA_DUMP}", c.ToString());
            newthing = newthing.Replace("{TILEENTITY_NAME}", Name);
            newthing = newthing.Replace("{TILEENTITY_ID}", ID);
            newthing = newthing.Replace("{VAR_DECL}", vardec);
            newthing = newthing.Replace("{VAR_ASSIGNMENT}", varassn);
            newthing = newthing.Replace("{TO_NBT}", nbtassn);

            File.WriteAllText("TileEntities/" + Name + ".cs", newthing);

            // TODO: Compile?
        }
开发者ID:N3X15,项目名称:MineEdit,代码行数:52,代码来源:TileEntity.cs

示例3: GetEntity

        public static Entity GetEntity(NbtCompound c)
        {
            if (!c.Has("id"))
            {
                Console.WriteLine(c.ToString());
            }

            if (c.Has("x") && c.Has("y") && c.Has("z"))
                throw new Exception("TileEntity is in Entities compound!?");

            string entID = c.Get<NbtString>("id").Value;
            if (entID == "NULL") return null;
            if (EntityTypes.ContainsKey(entID))
            {
                try
                {
                    return (Entity)EntityTypes[entID].GetConstructor(new Type[] { typeof(NbtCompound) }).Invoke(new Object[] { c });
                }
                catch (TargetInvocationException e)
                {
                    Console.WriteLine("Failed to load " + entID + ": \n" + e.InnerException.ToString());
                    throw e.InnerException;
                }
            }

            // Try to figure out what the hell this is.

            if (!Directory.Exists("Entities"))
                Directory.CreateDirectory("Entities");

            // Do we have a LivingEntity or just an Entity?
            // Quick and simple test: health.
            if (c.Has("Health") && entID!="Item")
            {
                GenTemplate(c, "livingentity.template");
                // Goodie, just whip up a new LivingEntity and we're relatively home free.
                return new LivingEntity(c);
            }
            else
            {
                GenTemplate(c, "entity.template");
                return new Entity(c);
            }
        }
开发者ID:N3X15,项目名称:MineEdit,代码行数:44,代码来源:Entity.cs

示例4: GetEntity

 /// <summary>
 /// Load a TileEntity from an NbtCompound.
 /// </summary>
 /// <param name="CX">Chunk X Coordinate.</param>
 /// <param name="CY">Chunk Y Coordinate.</param>
 /// <param name="CS">Chunk horizontal scale (16 in /game/)</param>
 /// <param name="c"></param>
 /// <returns>TileEntity.</returns>
 public static TileEntity GetEntity(int CX, int CY, int CS, NbtCompound c)
 {
     TileEntity e;
     switch ((c["id"] as NbtString).Value)
     {
         case "Chest":
             e = new Chest(CX,CY,CS,c);
             break;
         case "MobSpawner":
             e = new MobSpawner(CX, CY, CS, c);
             break;
         case "Furnace":
             e = new Furnace(CX, CY, CS, c);
             break;
         case "Sign":
             e = new Sign(CX, CY, CS, c);
             break;
         case "NULL":
             // Ignore it :|
             return new TileEntity(CX, CY, CS, c);
         default:
     #if DEBUG
             Console.WriteLine("*** Unknown TileEntity: {0}", (c["id"] as NbtString).Value);
             Console.WriteLine(c);
     #endif
             File.WriteAllText(string.Format("UnknownTileEntity.{0}.txt", (c["id"] as NbtString).Value),c.ToString().Replace("\n","\r\n"));
             return new TileEntity(CX, CY, CS, c);
     }
     #if DEBUG
     Console.WriteLine("Loaded {1} @ {0}", e,e.Pos);
     #endif
     return e;
 }
开发者ID:herpit,项目名称:MineEdit,代码行数:41,代码来源:TileEntity.cs


注:本文中的NbtCompound.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。