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)); } }
public LivingEntity(NbtCompound c) { SetBaseStuff(c); if (!c.Has("HurtTime")) { Console.WriteLine(c); return; } lolID = (c["id"] as NbtString).Value; Health = (c["Health"] as NbtShort).Value; HurtTime = (c["HurtTime"] as NbtShort).Value; AttackTime = (c["AttackTime"] as NbtShort).Value; DeathTime = (c["DeathTime"] as NbtShort).Value; }
public LivingEntity(NbtCompound c) { SetBaseStuff(c); if (!c.Has("HurtTime")) { Console.WriteLine(c); return; } Air = (c["Air"] as NbtShort).Value; Fire = (c["Fire"] as NbtShort).Value; lolID = (c["id"] as NbtString).Value; Health = (c["Health"] as NbtShort).Value; HurtTime = (c["HurtTime"] as NbtShort).Value; AttackTime = (c["AttackTime"] as NbtShort).Value; DeathTime = (c["DeathTime"] as NbtShort).Value; }
public Minecart(NbtCompound c) { SetBaseStuff(c); Type = (MinecartType)c.Get <NbtInt>("Type").Value; if (c.Has("PushX")) { PushX = c.Get <NbtDouble>("PushX").Value; PushZ = c.Get <NbtDouble>("PushZ").Value; Fuel = c.Get <NbtShort>("Fuel").Value; } else { PushX = 0; PushZ = 0; Fuel = 0; } }
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); } }
public Minecart(NbtCompound c) { SetBaseStuff(c); Type = (MinecartType)c.Get<NbtInt>("Type").Value; if (c.Has("PushX")) { PushX = c.Get<NbtDouble>("PushX").Value; PushZ = c.Get<NbtDouble>("PushZ").Value; Fuel = c.Get<NbtShort>("Fuel").Value; } else { PushX = 0; PushZ = 0; Fuel = 0; } }