public virtual void readFromNbt(NbtCompound tag) { this.transform.position = NbtHelper.readVector3(tag.Get <NbtCompound>("position")); this.transform.eulerAngles = NbtHelper.readVector3(tag.Get <NbtCompound>("rotation")); this.rBody.velocity = NbtHelper.readVector3(tag.Get <NbtCompound>("velocity")); this.rBody.angularVelocity = NbtHelper.readVector3(tag.Get <NbtCompound>("angularVelocity")); }
public PieceCenter(NbtCompound tag) : base(tag) { this.topFloor = tag.Get <NbtInt>("topFloor").IntValue; this.bottomFloor = tag.Get <NbtInt>("bottomFloor").IntValue; this.useFartherEntrance = tag.Get <NbtByte>("useFarEntrance").ByteValue == 1; this.isTall = tag.Get <NbtByte>("isTall").ByteValue == 1; }
/// <summary> /// Reads a Vector3 compound from the passed tag. /// </summary> public static Vector3 readVector3(NbtCompound tag) { return(new Vector3( tag.Get <NbtFloat>("x").FloatValue, tag.Get <NbtFloat>("y").FloatValue, tag.Get <NbtFloat>("z").FloatValue)); }
public Furnace(int CX, int CY, int CS, LibNbt.Tags.NbtCompound c) : base(CX, CY, CS, c) { BurnTime = (c["BurnTime"] as NbtShort).Value; CookTime = (c["CookTime"] as NbtShort).Value; for (int i = 0; i < Slots.Length; i++) { try { if ((c["Items"] as NbtList).Tags[i] != null) { NbtCompound cc = (NbtCompound)(c["Items"] as NbtList).Tags[i]; Slots[i] = new InventoryItem(); Slots[i].ID = cc.Get <NbtShort>("id").Value; Slots[i].Damage = cc.Get <NbtShort>("Damage").Value; Slots[i].Slot = 0; Slots[i].Count = cc.Get <NbtByte>("Count").Value; } } catch (Exception) { } } }
public PieceMobSpawner(NbtCompound tag) : base(tag) { this.northGate = tag.Get <NbtByte>("nGateg").Value == 1; this.eastGate = tag.Get <NbtByte>("eGateg").Value == 1; this.southGate = tag.Get <NbtByte>("sGateg").Value == 1; this.westGate = tag.Get <NbtByte>("wGateg").Value == 1; }
public static Pos readDirectBlockPos(NbtCompound tag, string prefix) { return(new Pos( tag.Get <NbtInt>(prefix + "x").IntValue, tag.Get <NbtInt>(prefix + "y").IntValue, tag.Get <NbtInt>(prefix + "z").IntValue)); }
public static Vector3 readDirectVector3(NbtCompound tag, string prefix) { return(new Vector3( tag.Get <NbtFloat>(prefix + "x").FloatValue, tag.Get <NbtFloat>(prefix + "y").FloatValue, tag.Get <NbtFloat>(prefix + "z").FloatValue)); }
public void readFromNbt(NbtCompound tag) { this.seed = tag.Get <NbtInt>("seed").IntValue; this.spawnPos = NbtHelper.readDirectVector3(tag, "spawn"); this.worldType = tag.Get <NbtInt>("worldType").IntValue; this.lastLoaded = DateTime.FromBinary(tag.Get <NbtLong>("lastLoaded").LongValue); }
public void SerializingEmpty() { // check saving/loading lists of all possible value types var testFile = new NbtFile(new NbtCompound("root") { new NbtList("emptyList", NbtTagType.End), new NbtList("listyList", NbtTagType.List) { new NbtList(NbtTagType.End) } }); byte[] buffer = testFile.SaveToBuffer(NbtCompression.None); testFile.LoadFromBuffer(buffer, 0, buffer.Length, NbtCompression.None); NbtCompound testFileRootTag = (NbtCompound)testFile.RootTag; NbtList list1 = testFileRootTag.Get <NbtList>("emptyList"); Assert.AreEqual(list1.Count, 0); Assert.AreEqual(list1.ListType, NbtTagType.End); NbtList list2 = testFileRootTag.Get <NbtList>("listyList"); Assert.AreEqual(list2.Count, 1); Assert.AreEqual(list2.ListType, NbtTagType.List); Assert.AreEqual(list2.Get <NbtList>(0).Count, 0); Assert.AreEqual(list2.Get <NbtList>(0).ListType, NbtTagType.End); }
public ReplayEvent <T> LoadTag(NbtCompound tag, Dictionary <int, Type> types) { Tick = tag.Get <NbtInt>("tick")?.Value ?? -1; TypeId = tag.Get <NbtInt>("type")?.Value ?? -1; Action = LoadAction(tag, TypeId, types); return(this); }
public void CheckSynchronized() { var root = new NbtCompound("test"); var view = new NbtTreeView(); var model = new NbtTreeModel((object)root); view.Model = model; Assert.AreEqual(model.Root.Children.Count(), 1); Assert.AreEqual(view.Root.Children.Count, 1); AssertSynchronized(view, model); root.Add(new NbtByte("test1")); AssertSynchronized(view, model); root.Add(new NbtByte("test2")); AssertSynchronized(view, model); root.Add(new NbtCompound("test3")); AssertSynchronized(view, model); root.Get <NbtCompound>("test3").Add(new NbtShort("test4")); Assert.AreEqual(view.Root.DescendantsCount, 5); Assert.AreEqual(model.Root.DescendantsCount, 5); AssertSynchronized(view, model); root.Remove("test2"); AssertSynchronized(view, model); root.Get <NbtCompound>("test3").Clear(); Assert.AreEqual(view.Root.DescendantsCount, 3); Assert.AreEqual(model.Root.DescendantsCount, 3); AssertSynchronized(view, model); root.Clear(); AssertSynchronized(view, model); }
public void Read(NbtCompound compound) { X = compound.Get <NbtInt>("x").Value; Y = compound.Get <NbtInt>("y").Value; Z = compound.Get <NbtInt>("z").Value; ReadFrom(compound); }
/// <summary> /// Load a TileEntity's basic values (call via base() in all inheriting files) /// </summary> /// <param name="c"></param> public TileEntity(NbtCompound c) { orig = c; Pos = new Vector3i( c.Get <NbtInt>("x").Value, c.Get <NbtInt>("y").Value, c.Get <NbtInt>("z").Value); ID = c.Get <NbtString>("id").Value; }
internal void SetBaseStuff(NbtCompound c) { FallDistance = (c["FallDistance"] as NbtFloat).Value; Motion = new Vector3d(c["Motion"] as NbtList, false); Pos = new Vector3d(c["Pos"] as NbtList, false); OnGround = c.Get <NbtByte>("OnGround").Value; Rotation = Rotation.FromNbt(c.Get <NbtList>("Rotation")); //Console.WriteLine("Loaded entity {0} @ {1}", (c["id"] as NbtString).Value, Pos); }
/// <summary> /// Load a TileEntity's basic values (call via base() in all inheriting files) /// </summary> /// <param name="c"></param> public TileEntity(NbtCompound c) { orig = c; Pos = new Vector3i( c.Get<NbtInt>("x").Value, c.Get<NbtInt>("z").Value, c.Get<NbtInt>("y").Value); id = c.Get<NbtString>("id").Value; }
/// <summary> /// Reads a BlockPos compound from the passed tag. /// </summary> public static Pos readBlockPos(NbtCompound tag, string compoundName) { NbtCompound tag1 = tag.Get <NbtCompound>(compoundName); return(new Pos( tag1.Get <NbtInt>("x").IntValue, tag1.Get <NbtInt>("y").IntValue, tag1.Get <NbtInt>("z").IntValue)); }
/// <summary> /// Load a TileEntity's basic values (call via base() in all inheriting files) /// </summary> /// <param name="CX">Chunk X Coordinate</param> /// <param name="CY">Chunk Y Coordinate</param> /// <param name="CS">Chunk horizontal scale</param> /// <param name="c">TileEntity's NbtCompound.</param> public TileEntity(int CX, int CY, int CS, NbtCompound c) { Pos = new Vector3i( c.Get <NbtInt>("x").Value, c.Get <NbtInt>("y").Value, c.Get <NbtInt>("z").Value); ID = (c["id"] as NbtString).Value; orig = c; }
/// <summary> /// Load a TileEntity's basic values (call via base() in all inheriting files) /// </summary> /// <param name="CX">Chunk X Coordinate</param> /// <param name="CY">Chunk Y Coordinate</param> /// <param name="CS">Chunk horizontal scale</param> /// <param name="c">TileEntity's NbtCompound.</param> public TileEntity(int CX,int CY,int CS,NbtCompound c) { Pos = new Vector3i( c.Get<NbtInt>("x").Value, c.Get<NbtInt>("y").Value, c.Get<NbtInt>("z").Value); ID = (c["id"] as NbtString).Value; orig = c; }
public static Schematic newSchematic(NbtCompound tag) { Schematic s = new Schematic( tag.Get <NbtInt>("sizeX").IntValue, tag.Get <NbtInt>("sizeY").IntValue, tag.Get <NbtInt>("sizeZ").IntValue); s.readFromNbt(tag); return(s); }
public void readFromNbt(NbtCompound tag) { // sizeX, sizeY and sizeZ are set in constructor. this.schematicName = tag.Get <NbtString>("name").StringValue; byte[] blockBytes = tag.Get <NbtByteArray>("blocks").ByteArrayValue; for (int i = 0; i < Chunk.BLOCK_COUNT; i++) { this.blocks[i] = Block.getBlockFromId(blockBytes[i]); } this.metaData = tag.Get <NbtByteArray>("meta").ByteArrayValue; }
public static ItemStack FromNbt(NbtCompound compound) { var itemStack = EmptyStack; itemStack.ID = compound.Get <NbtShort>("id")?.Value ?? 0; itemStack.Damage = compound.Get <NbtShort>("Damage")?.Value ?? 0; itemStack.Count = compound.Get <NbtByte>("Count")?.Value ?? 0; itemStack.Index = compound.Get <NbtByte>("Slot")?.Value ?? 0; itemStack.Nbt = compound.Get <NbtCompound>("tag"); return(itemStack); }
public Area(NbtCompound cmpd) { name = cmpd.Get<NbtString>("name").Value; NbtList ground = cmpd.Get<NbtList>("ground"); foreach(NbtCompound alpha in ground) { int x = alpha.Get<NbtByte>("x").Value; int y = alpha.Get<NbtByte>("y").Value; platformMap.Add(new Point(x, y)); } Map.portalsToProcess[this] = cmpd.Get<NbtList>("portal").ToArray<NbtCompound>().ToList<NbtCompound>(); }
public override void readFromNbt(NbtCompound tag) { base.readFromNbt(tag); this.setTile( Block.getBlockFromId(tag.Get <NbtInt>("blockId").Value), tag.Get <NbtInt>("meta").Value); tag.TryGet <NbtCompound>("blockNbt", out this.blockNbt); this.startPos = NbtHelper.readDirectBlockPos(tag, "start"); }
// differs slightly from the Minecraft implementation // emits block states in the form [key=value] instead of {key:value} private NbtString PackBlockState(NbtCompound compound) { var builder = new StringBuilder(compound.Get <NbtString>("Name").Value); var properties = compound.Get <NbtCompound>("Properties"); if (properties != null) { string str = String.Join(',', properties.Select(x => x.Name + '=' + x.StringValue)); builder.Append('[').Append(str).Append(']'); } return(new NbtString(builder.ToString())); }
public virtual void readFromNbt(NbtCompound tag) { foreach (NbtCompound compound in tag.Get <NbtList>("items")) { this.items[compound.Get <NbtInt>("slotIndex").IntValue] = new ItemStack(compound); } }
public NbtCompound Read(NbtCompound Metadata) { var HCData = Metadata.Get <NbtCompound>("Hypercube"); if (HCData != null) { try { BuildRanks = HCData["BuildRanks"].StringValue; ShowRanks = HCData["ShowRanks"].StringValue; JoinRanks = HCData["JoinRanks"].StringValue; Physics = Convert.ToBoolean(HCData["Physics"].ByteValue); Building = Convert.ToBoolean(HCData["Building"].ByteValue); History = HCData["History"].IntArrayValue; if (HCData["MOTD"] != null) { MOTD = HCData["MOTD"].StringValue; } } catch { } Metadata.Remove(HCData); } return(Metadata); }
public void Add(NbtCompound item) { InventoryItem c = new InventoryItem(); c.Count = item.Get <NbtByte>("Count").Value; c.Damage = item.Get <NbtShort>("Damage").Value; c.ID = item.Get <NbtShort>("id").Value; c.Slot = item.Get <NbtByte>("Slot").Value; if (ContainsKey(c.Slot)) { Console.WriteLine("Tried to add to slot {0}, which already has something.", c.Slot); Remove(c.Slot); } base.Add(c.Slot, c); SlotChanged(c.Slot); }
public void SerializeComplexCompoundTest() { var faker = new Faker(); var element = new CustomComplexNbtElement { IntegerValue = faker.Random.Int(), FlatElement = new CustomFlatNbtElement { ByteValue = faker.Random.Byte(), ShortValue = faker.Random.Short(), IntegerValue = faker.Random.Int(), FloatValue = faker.Random.Float(), LongValue = faker.Random.Long(), DoubleValue = faker.Random.Double(), StringValue = faker.Lorem.Sentence(), } }; NbtCompound compound = NbtSerializer.SerializeCompound(element); Assert.NotNull(compound); AssertTag <NbtInt, int>(compound, "integer_value", element.IntegerValue, x => x.IntValue); NbtCompound innerCompound = compound.Get("flat_element_compound") as NbtCompound; Assert.NotNull(innerCompound); AssertTag <NbtByte, byte>(innerCompound, "byte_value", element.FlatElement.ByteValue, x => x.ByteValue); AssertTag <NbtShort, short>(innerCompound, "short_value", element.FlatElement.ShortValue, x => x.ShortValue); AssertTag <NbtInt, int>(innerCompound, "integer_value", element.FlatElement.IntegerValue, x => x.IntValue); AssertTag <NbtFloat, float>(innerCompound, "float_value", element.FlatElement.FloatValue, x => x.FloatValue); AssertTag <NbtLong, long>(innerCompound, "long_value", element.FlatElement.LongValue, x => x.LongValue); AssertTag <NbtDouble, double>(innerCompound, "double_value", element.FlatElement.DoubleValue, x => x.DoubleValue); AssertTag <NbtString, string>(innerCompound, "string_value", element.FlatElement.StringValue, x => x.StringValue); }
public Area(NbtCompound cmpd) { name = cmpd.Get<NbtString>("name").Value; NbtList ground = cmpd.Get<NbtList>("ground"); foreach(NbtCompound alpha in ground) { int x = alpha.Get<NbtByte>("x").Value; int y = alpha.Get<NbtByte>("y").Value; map.Add(new Point(x, y), new Platform(x, y, this)); } NbtList portal = cmpd.Get<NbtList>("portal"); foreach(NbtCompound alpha in portal) { int x = alpha.Get<NbtByte>("x").Value; int y = alpha.Get<NbtByte>("y").Value; map.Add(new Point(x, y), new Portal(x, y, this)); Portal.portalsToProcess.Add(new Portal(x, y, this), alpha); } }
private void AssertTag <TTag, TValue>(NbtCompound compound, string name, TValue expectedValue, Func <NbtTag, TValue> getValueFunction) { NbtTag tag = compound.Get(name); Assert.NotNull(tag); Assert.IsType <TTag>(tag); Assert.Equal(expectedValue, getValueFunction(tag)); }
public static TileEntity FromNbt(NbtCompound entityTag, out Vector3 position) { position = Vector3.Zero; var id = entityTag.Get<NbtString>("id").Value; Type type = (from e in dummyInstances where e.Id == id select e.GetType()).FirstOrDefault(); if (type == null) return null; var serializer = new NbtSerializer(type); var entity = (TileEntity)serializer.Deserialize(entityTag); position = new Vector3( entityTag.Get<NbtInt>("x").Value, entityTag.Get<NbtInt>("y").Value, entityTag.Get<NbtInt>("z").Value); return entity; }
public void loadData(NbtCompound tag) { foreach (NbtCompound compound in tag.Get <NbtList>("mineshafts")) { StructureMineshaft mineshaft = new StructureMineshaft(); mineshaft.readFromNbt(compound); this.mineshaftList.Add(mineshaft); } }
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 Furnace(NbtCompound c) : base(c) { BurnTime = (c["BurnTime"] as NbtShort).Value; CookTime = (c["CookTime"] as NbtShort).Value; for (byte i = 0; i < 3; i++) { if ((c["Items"] as NbtList).Tags[i] != null) { NbtCompound cc = (NbtCompound)(c["Items"] as NbtList).Tags[i]; Slots[i] = new InventoryItem(); Slots[i].ID = cc.Get <NbtShort>("id").Value; Slots[i].Damage = cc.Get <NbtShort>("Damage").Value; Slots[i].Count = cc.Get <NbtByte>("Count").Value; Slots[i].Slot = i; } } }
public virtual void SetNbt(NbtCompound nbt) { ItemCount = nbt["Count"].ByteValue; // Id = nbt["id"].StringValue var tag = nbt.Get <NbtCompound>("tag"); Damage = tag["Damage"].IntValue; Unbreakable = tag["Unbreakable"].ByteValue != 0; // CanDestroy = tag["CanDestroy"].ListValue; }
public NbtCompound Read(NbtCompound metadata) { var Data = metadata.Get<NbtCompound>("MCForge"); Logger.Log(Data["perbuild"].ToString()); if (Data != null) { perbuild = Data["perbuild"].ByteValue; pervisit = Data["pervisit"].ByteValue; metadata.Remove(Data); } return metadata; }
public NbtCompound Read(NbtCompound Metadata) { NbtCompound CPEData = Metadata.Get<NbtCompound>("CPE"); if (CPEData != null) { if (CPEData["ClickDistance"] != null) { ClickDistanceVersion = CPEData["ClickDistance"]["ExtensionVersion"].IntValue; ClickDistance = CPEData["ClickDistance"]["Distance"].ShortValue; } if (CPEData["CustomBlocks"] != null) { CustomBlocksVersion = CPEData["CustomBlocks"]["ExtensionVersion"].IntValue; CustomBlocksLevel = CPEData["CustomBlocks"]["SupportLevel"].ShortValue; CustomBlocksFallback = CPEData["CustomBlocks"]["Fallback"].ByteArrayValue; } if (CPEData["EnvColors"] != null) { EnvColorsVersion = CPEData["EnvColors"]["ExtensionVersion"].IntValue; SkyColor = new short[] { CPEData["EnvColors"]["Sky"]["R"].ShortValue, CPEData["EnvColors"]["Sky"]["G"].ShortValue, CPEData["EnvColors"]["Sky"]["B"].ShortValue }; CloudColor = new short[] { CPEData["EnvColors"]["Cloud"]["R"].ShortValue, CPEData["EnvColors"]["Cloud"]["G"].ShortValue, CPEData["EnvColors"]["Cloud"]["B"].ShortValue }; FogColor = new short[] { CPEData["EnvColors"]["Fog"]["R"].ShortValue, CPEData["EnvColors"]["Fog"]["G"].ShortValue, CPEData["EnvColors"]["Fog"]["B"].ShortValue }; AmbientColor = new short[] { CPEData["EnvColors"]["Ambient"]["R"].ShortValue, CPEData["EnvColors"]["Ambient"]["G"].ShortValue, CPEData["EnvColors"]["Ambient"]["B"].ShortValue }; SunlightColor = new short[] { CPEData["EnvColors"]["Sunlight"]["R"].ShortValue, CPEData["EnvColors"]["Sunlight"]["R"].ShortValue, CPEData["EnvColors"]["Sunlight"]["R"].ShortValue }; } if (CPEData["EnvMapAppearance"] != null) { EnvMapAppearanceVersion = CPEData["EnvMapAppearance"]["ExtensionVersion"].IntValue; TextureURL = CPEData["EnvMapAppearance"]["TextureURL"].StringValue; SideBlock = CPEData["EnvMapAppearance"]["SideBlock"].ByteValue; EdgeBlock = CPEData["EnvMapAppearance"]["EdgeBlock"].ByteValue; SideLevel = CPEData["EnvMapAppearance"]["SideLevel"].ShortValue; } Metadata.Remove(CPEData); } return Metadata; }
public static Slot FromNbt(NbtCompound compound) { var s = Slot.EmptySlot; s.Id = compound.Get<NbtShort>("id").Value; s.Metadata = compound.Get<NbtShort>("Damage").Value; s.Count = (sbyte)compound.Get<NbtByte>("Count").Value; s.Index = compound.Get<NbtByte>("Slot").Value; if (compound.Get<NbtCompound>("tag") != null) { s.Nbt = new NbtFile(); s.Nbt.RootTag = compound.Get<NbtCompound>("tag"); } return s; }
public NbtCompound Read(NbtCompound metadata) { var cpeData = metadata.Get<NbtCompound>("CPE"); if (cpeData == null) return metadata; if (cpeData["ClickDistance"] != null) { ClickDistanceVersion = cpeData["ClickDistance"]["ExtensionVersion"].IntValue; ClickDistance = cpeData["ClickDistance"]["Distance"].ShortValue; } if (cpeData["CustomBlocks"] != null) { CustomBlocksVersion = cpeData["CustomBlocks"]["ExtensionVersion"].IntValue; CustomBlocksLevel = cpeData["CustomBlocks"]["SupportLevel"].ShortValue; CustomBlocksFallback = cpeData["CustomBlocks"]["Fallback"].ByteArrayValue; } if (cpeData["EnvColors"] != null) { EnvColorsVersion = cpeData["EnvColors"]["ExtensionVersion"].IntValue; SkyColor = new[] { cpeData["EnvColors"]["Sky"]["R"].ShortValue, cpeData["EnvColors"]["Sky"]["G"].ShortValue, cpeData["EnvColors"]["Sky"]["B"].ShortValue }; CloudColor = new[] { cpeData["EnvColors"]["Cloud"]["R"].ShortValue, cpeData["EnvColors"]["Cloud"]["G"].ShortValue, cpeData["EnvColors"]["Cloud"]["B"].ShortValue }; FogColor = new[] { cpeData["EnvColors"]["Fog"]["R"].ShortValue, cpeData["EnvColors"]["Fog"]["G"].ShortValue, cpeData["EnvColors"]["Fog"]["B"].ShortValue }; AmbientColor = new[] { cpeData["EnvColors"]["Ambient"]["R"].ShortValue, cpeData["EnvColors"]["Ambient"]["G"].ShortValue, cpeData["EnvColors"]["Ambient"]["B"].ShortValue }; SunlightColor = new[] { cpeData["EnvColors"]["Sunlight"]["R"].ShortValue, cpeData["EnvColors"]["Sunlight"]["R"].ShortValue, cpeData["EnvColors"]["Sunlight"]["R"].ShortValue }; } if (cpeData["EnvMapAppearance"] != null) { EnvMapAppearanceVersion = cpeData["EnvMapAppearance"]["ExtensionVersion"].IntValue; TextureUrl = cpeData["EnvMapAppearance"]["TextureURL"].StringValue; SideBlock = cpeData["EnvMapAppearance"]["SideBlock"].ByteValue; EdgeBlock = cpeData["EnvMapAppearance"]["EdgeBlock"].ByteValue; SideLevel = cpeData["EnvMapAppearance"]["SideLevel"].ShortValue; } if (cpeData["EnvWeatherType"] != null) Weather = cpeData["EnvWeatherType"]["WeatherType"].ByteValue; metadata.Remove(cpeData); return metadata; }
public NbtCompound Read(NbtCompound metadata) { var hcData = metadata.Get<NbtCompound>("Hypercube"); if (hcData == null) return metadata; BuildPerms = hcData["BuildPerms"].StringValue; ShowPerms = hcData["ShowPerms"].StringValue; JoinPerms = hcData["JoinPerms"].StringValue; Physics = Convert.ToBoolean(hcData["Physics"].ByteValue); Building = Convert.ToBoolean(hcData["Building"].ByteValue); History = Convert.ToBoolean(hcData["History"].ByteValue); SaveInterval = hcData["SaveInterval"].IntValue; if (hcData["MOTD"] != null) Motd = hcData["MOTD"].StringValue; metadata.Remove(hcData); return metadata; }
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 Slot FromNbt(NbtCompound compound) { var s = new Slot(); s.Id = (ushort)compound.Get<NbtShort>("id").Value; s.Metadata = (ushort)compound.Get<NbtShort>("Damage").Value; s.Count = compound.Get<NbtByte>("Count").Value; s.Index = compound.Get<NbtByte>("Slot").Value; return s; }
public Zone( NbtCompound tag ) { NbtCompound boundsTag = tag.Get<NbtCompound>( "Bounds" ); if( boundsTag == null ) { throw new SerializationException( "Bounds missing from zone definition tag." ); } Bounds = new BoundingBox( boundsTag ); NbtCompound controllerTag = tag.Get<NbtCompound>( "Controller" ); if( controllerTag == null ) { throw new SerializationException( "Controller missing from zone definition tag." ); } Controller = new SecurityController( controllerTag ); var createdByTag = tag.Get<NbtString>( "CreatedBy" ); var createdDateTag = tag.Get<NbtLong>( "CreatedDate" ); if( createdByTag != null && createdDateTag != null ) { CreatedBy = createdByTag.Value; CreatedDate = DateTimeUtil.TryParseDateTime( createdDateTag.Value ); } var editedByTag = tag.Get<NbtString>( "EditedBy" ); var editedDateTag = tag.Get<NbtLong>( "EditedDate" ); if( editedByTag != null && editedDateTag != null ) { EditedBy = editedByTag.Value; EditedDate = DateTimeUtil.TryParseDateTime( editedDateTag.Value ); } }
public void GettersAndSetters() { // construct a document for us to test. var nestedChild = new NbtCompound("NestedChild"); var nestedInt = new NbtInt(1); var nestedChildList = new NbtList("NestedChildList") { nestedInt }; var child = new NbtCompound("Child") { nestedChild, nestedChildList }; var childList = new NbtList("ChildList") { new NbtInt(1) }; var parent = new NbtCompound("Parent") { child, childList }; // Accessing nested compound tags using indexers Assert.AreEqual(parent["Child"]["NestedChild"], nestedChild); Assert.AreEqual(parent["Child"]["NestedChildList"], nestedChildList); Assert.AreEqual(parent["Child"]["NestedChildList"][0], nestedInt); // Accessing nested compound tags using Get and Get<T> Assert.AreEqual(parent.Get<NbtCompound>("Child").Get<NbtCompound>("NestedChild"), nestedChild); Assert.AreEqual(parent.Get<NbtCompound>("Child").Get<NbtList>("NestedChildList"), nestedChildList); Assert.AreEqual(parent.Get<NbtCompound>("Child").Get<NbtList>("NestedChildList")[0], nestedInt); Assert.AreEqual((parent.Get("Child") as NbtCompound).Get("NestedChild"), nestedChild); Assert.AreEqual((parent.Get("Child") as NbtCompound).Get("NestedChildList"), nestedChildList); Assert.AreEqual((parent.Get("Child") as NbtCompound).Get("NestedChildList")[0], nestedInt); // Accessing with Get<T> and an invalid given type Assert.Throws<InvalidCastException>(() => parent.Get<NbtInt>("Child")); // Using TryGet and TryGet<T> NbtTag dummyTag; Assert.IsTrue(parent.TryGet("Child", out dummyTag)); NbtCompound dummyCompoundTag; Assert.IsTrue(parent.TryGet("Child", out dummyCompoundTag)); // Trying to use integer indexers on non-NbtList tags Assert.Throws<InvalidOperationException>(() => parent[0] = nestedInt); Assert.Throws<InvalidOperationException>(() => nestedInt[0] = nestedInt); // Trying to use string indexers on non-NbtCompound tags Assert.Throws<InvalidOperationException>(() => childList["test"] = nestedInt); Assert.Throws<InvalidOperationException>(() => nestedInt["test"] = nestedInt); // Trying to get a non-existent element by name Assert.IsNull(parent.Get<NbtTag>("NonExistentTag")); Assert.IsNull(parent["NonExistentTag"]); // Null indices on NbtCompound Assert.Throws<ArgumentNullException>(() => parent.Get<NbtTag>(null)); Assert.Throws<ArgumentNullException>(() => parent[null] = new NbtInt(1)); Assert.Throws<ArgumentNullException>(() => nestedInt = (NbtInt)parent[null]); // Out-of-range indices on NbtList Assert.Throws<ArgumentOutOfRangeException>(() => nestedInt = (NbtInt)childList[-1]); Assert.Throws<ArgumentOutOfRangeException>(() => childList[-1] = new NbtInt(1)); Assert.Throws<ArgumentOutOfRangeException>(() => nestedInt = childList.Get<NbtInt>(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => nestedInt = (NbtInt)childList[childList.Count]); Assert.Throws<ArgumentOutOfRangeException>(() => nestedInt = childList.Get<NbtInt>(childList.Count)); // Using setter correctly parent["NewChild"] = new NbtByte("NewChild"); // Using setter incorrectly object dummyObject; Assert.Throws<ArgumentNullException>(() => parent["Child"] = null); Assert.NotNull(parent["Child"]); Assert.Throws<ArgumentException>(() => parent["Child"] = new NbtByte("NotChild")); Assert.Throws<InvalidOperationException>(() => dummyObject = parent[0]); Assert.Throws<InvalidOperationException>(() => parent[0] = new NbtByte("NewerChild")); // Try adding tag to self var selfTest = new NbtCompound("SelfTest"); Assert.Throws<ArgumentException>(() => selfTest["SelfTest"] = selfTest); // Try adding a tag that already has a parent Assert.Throws<ArgumentException>(() => selfTest[child.Name] = child); }
public PigZombie(NbtCompound c) : base(c) { Anger = c.Get<NbtShort>("Anger").Value; }
public Slime(NbtCompound c) : base(c) { Size = c.Get<NbtInt>("Size").Value; }
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); } }
internal void SetBaseStuff(NbtCompound c) { FallDistance = (c["FallDistance"] as NbtFloat).Value; Motion = new Vector3d(c["Motion"] as NbtList,false); Pos = new Vector3d(c["Pos"] as NbtList,false); OnGround = c.Get<NbtByte>("OnGround").Value; Rotation = Rotation.FromNbt(c.Get<NbtList>("Rotation")); //Console.WriteLine("Loaded entity {0} @ {1}", (c["id"] as NbtString).Value, Pos); }
// This tosses together a cheapass entity class for faster updates. // Primarily because I'm a lazy f**k. 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? }
/// <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) { string entID = c.Get<NbtString>("id").Value; if (TileEntityTypes.ContainsKey(entID)) return (TileEntity)TileEntityTypes[entID].GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(NbtCompound) }).Invoke(new Object[] { CX,CY,CS,c }); // Try to figure out what the hell this is. if (!Directory.Exists("TileEntities")) Directory.CreateDirectory("TileEntities"); GenTemplate(c, "tileentity.template"); return new TileEntity(c); }
public void GettersAndSetters() { NbtCompound parent = new NbtCompound( "Parent" ); NbtCompound child = new NbtCompound( "Child" ); NbtCompound nestedChild = new NbtCompound( "NestedChild" ); NbtList childList = new NbtList( "ChildList" ); NbtList nestedChildList = new NbtList( "NestedChildList" ); NbtInt testInt = new NbtInt( 1 ); childList.Add( testInt ); nestedChildList.Add( testInt ); parent.Add( child ); parent.Add( childList ); child.Add( nestedChild ); child.Add( nestedChildList ); // Accessing nested compound tags using indexers Assert.AreEqual( parent["Child"]["NestedChild"], nestedChild ); Assert.AreEqual( parent["Child"]["NestedChildList"], nestedChildList ); Assert.AreEqual( parent["Child"]["NestedChildList"][0], testInt ); // Accessing nested compound tags using Get<T> Assert.AreEqual( parent.Get<NbtCompound>( "Child" ).Get<NbtCompound>( "NestedChild" ), nestedChild ); Assert.AreEqual( parent.Get<NbtCompound>( "Child" ).Get<NbtList>( "NestedChildList" ), nestedChildList ); Assert.AreEqual( parent.Get<NbtCompound>( "Child" ).Get<NbtList>( "NestedChildList" )[0], testInt ); // Accessing with Get<T> and an invalid given type Assert.Throws<InvalidCastException>( () => parent.Get<NbtInt>( "Child" ) ); // Trying to use integer indexers on non-NbtList tags Assert.Throws<InvalidOperationException>( () => parent[0] = testInt ); Assert.Throws<InvalidOperationException>( () => testInt[0] = testInt ); // Trying to use string indexers on non-NbtCompound tags Assert.Throws<InvalidOperationException>( () => childList["test"] = testInt ); Assert.Throws<InvalidOperationException>( () => testInt["test"] = testInt ); // Trying to get a non-existent element by name Assert.IsNull( parent.Get<NbtTag>( "NonExistentTag" ) ); Assert.IsNull( parent["NonExistentTag"] ); // Null indices on NbtCompound Assert.Throws<ArgumentNullException>( () => parent.Get<NbtTag>( null ) ); Assert.Throws<ArgumentNullException>( () => parent[null] = testInt ); Assert.Throws<ArgumentNullException>( () => testInt = (NbtInt)parent[null] ); // Out-of-range indices on NbtList Assert.Throws<ArgumentOutOfRangeException>( () => testInt = (NbtInt)childList[-1] ); Assert.Throws<ArgumentOutOfRangeException>( () => childList[-1] = testInt ); Assert.Throws<ArgumentOutOfRangeException>( () => testInt = childList.Get<NbtInt>( -1 ) ); Assert.Throws<ArgumentOutOfRangeException>( () => testInt = (NbtInt)childList[childList.Count] ); Assert.Throws<ArgumentOutOfRangeException>( () => testInt = childList.Get<NbtInt>( childList.Count ) ); }