本文整理汇总了C#中NbtCompound类的典型用法代码示例。如果您正苦于以下问题:C# NbtCompound类的具体用法?C# NbtCompound怎么用?C# NbtCompound使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NbtCompound类属于命名空间,在下文中一共展示了NbtCompound类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetCompound
public override void SetCompound(NbtCompound compound)
{
Line1 = GetTextValue(compound, "Text1");
Line2 = GetTextValue(compound, "Text2");
Line3 = GetTextValue(compound, "Text3");
Line4 = GetTextValue(compound, "Text4");
}
示例2: UpdateTileEntityPacket
public UpdateTileEntityPacket(Vector3 position, TileEntityAction action, NbtCompound data)
{
Data = new NbtFile();
Data.RootTag = data;
Position = position;
Action = action;
}
示例3: ErrorTest
public void ErrorTest()
{
var root = new NbtCompound("root");
byte[] testData = new NbtFile(root).SaveToBuffer(NbtCompression.None);
// creating NbtReader without a stream, or with a non-readable stream
Assert.Throws<ArgumentNullException>(() => new NbtReader(null));
Assert.Throws<ArgumentException>(() => new NbtReader(new NonReadableStream()));
// corrupt the data
testData[0] = 123;
var reader = new NbtReader(new MemoryStream(testData));
// attempt to use ReadValue when not at value
Assert.Throws<InvalidOperationException>(() => reader.ReadValue());
reader.CacheTagValues = true;
Assert.Throws<InvalidOperationException>(() => reader.ReadValue());
// attempt to read a corrupt stream
Assert.Throws<NbtFormatException>(() => reader.ReadToFollowing());
// make sure we've properly entered the error state
Assert.IsTrue(reader.IsInErrorState);
Assert.IsFalse(reader.HasName);
Assert.Throws<InvalidReaderStateException>(() => reader.ReadToFollowing());
Assert.Throws<InvalidReaderStateException>(() => reader.ReadListAsArray<int>());
Assert.Throws<InvalidReaderStateException>(() => reader.ReadToNextSibling());
Assert.Throws<InvalidReaderStateException>(() => reader.ReadToDescendant("derp"));
Assert.Throws<InvalidReaderStateException>(() => reader.ReadAsTag());
Assert.Throws<InvalidReaderStateException>(() => reader.Skip());
}
示例4: ToNBT
public override NbtCompound ToNBT()
{
NbtCompound c = new NbtCompound();
Base2NBT(ref c);
c.Tags.Add(Inventory.ToNBT());
return c;
}
示例5: LoadEntity
public static McEntity LoadEntity(NbtCompound entity)
{
if (entity["id"] != null && entity["id"] is NbtString)
{
switch (((NbtString) entity["id"]).Value.ToLower())
{
case "mob":
McEntityMob mob = new McEntityMob();
mob.LoadEntity(entity);
return mob;
case "item":
McEntityItem item = new McEntityItem();
item.LoadEntity(entity);
return item;
case "localplayer":
McEntityLocalPlayer player = new McEntityLocalPlayer();
player.LoadEntity(entity);
return player;
default:
Console.WriteLine("Unknown Entity: {0}", ((NbtString) entity["id"]).Value);
break;
}
}
return null;
}
示例6: FurnaceBlockEntity
public FurnaceBlockEntity()
: base("Furnace")
{
UpdatesOnTick = true;
Compound = new NbtCompound(string.Empty)
{
new NbtString("id", Id),
new NbtList("Items", new NbtCompound()),
new NbtInt("x", Coordinates.X),
new NbtInt("y", Coordinates.Y),
new NbtInt("z", Coordinates.Z)
};
NbtList items = (NbtList) Compound["Items"];
for (byte i = 0; i < 3; i++)
{
items.Add(new NbtCompound()
{
new NbtByte("Count", 0),
new NbtByte("Slot", i),
new NbtShort("id", 0),
new NbtByte("Damage", 0),
});
}
}
示例7: SkippingLists
public void SkippingLists()
{
{
var file = new NbtFile(TestFiles.MakeListTest());
byte[] savedFile = file.SaveToBuffer(NbtCompression.None);
file.LoadFromBuffer(savedFile, 0, savedFile.Length, NbtCompression.None,
tag => tag.TagType != NbtTagType.List);
Assert.AreEqual(0, file.RootTag.Count);
}
{
// Check list-compound interaction
NbtCompound comp = new NbtCompound("root") {
new NbtCompound("compOfLists") {
new NbtList("listOfComps") {
new NbtCompound {
new NbtList("emptyList", NbtTagType.Compound)
}
}
}
};
var file = new NbtFile(comp);
byte[] savedFile = file.SaveToBuffer(NbtCompression.None);
file.LoadFromBuffer(savedFile, 0, savedFile.Length, NbtCompression.None,
tag => tag.TagType != NbtTagType.List);
Assert.AreEqual(1, file.RootTag.Count);
}
}
示例8: SetCompound
public override void SetCompound(NbtCompound compound)
{
Text1 = GetTextValue(compound, "Text1");
Text2 = GetTextValue(compound, "Text2");
Text3 = GetTextValue(compound, "Text3");
Text4 = GetTextValue(compound, "Text4");
}
示例9: ToNBT
public override NbtCompound ToNBT()
{
NbtCompound c = new NbtCompound();
Base2NBT(ref c,GetID());
c.Tags.Add(new NbtByte("Tile", Tile));
return c;
}
示例10: AddingAndRemoving
public void AddingAndRemoving()
{
NbtCompound test = new NbtCompound();
NbtInt foo = new NbtInt( "Foo" );
test.Add( foo );
// adding duplicate object
Assert.Throws<ArgumentException>( () => test.Add( foo ) );
// adding duplicate name
Assert.Throws<ArgumentException>( () => test.Add( new NbtByte( "Foo" ) ) );
// adding unnamed tag
Assert.Throws<ArgumentException>( () => test.Add( new NbtInt() ) );
// adding null
Assert.Throws<ArgumentNullException>( () => test.Add( null ) );
// contains existing name
Assert.IsTrue( test.Contains( "Foo" ) );
// contains existing object
Assert.IsTrue( test.Contains( foo ) );
// contains non-existent name
Assert.IsFalse( test.Contains( "Bar" ) );
// contains existing name / different object
Assert.IsFalse( test.Contains( new NbtInt( "Foo" ) ) );
// removing non-existent name
Assert.IsFalse( test.Remove( "Bar" ) );
// removing existing name
Assert.IsTrue( test.Remove( "Foo" ) );
// removing non-existent name
Assert.IsFalse( test.Remove( "Foo" ) );
// re-adding object
test.Add( foo );
// removing existing object
Assert.IsTrue( test.Remove( foo ) );
// clearing an empty NbtCompound
Assert.AreEqual( test.Count, 0 );
test.Clear();
// re-adding after clearing
test.Add( foo );
Assert.AreEqual( test.Count, 1 );
// clearing a non-empty NbtCompound
test.Clear();
Assert.AreEqual( test.Count, 0 );
}
示例11: ToNBT
public NbtCompound ToNBT()
{
NbtCompound c = new NbtCompound();
Base2NBT(ref c,GetID());
c.Tags.Add(new NbtByte("Tile", Tile));
c.Tags.Add(new NbtByte("OnGround", OnGround));
return c;
}
示例12: LivingEntity
public LivingEntity(NbtCompound c)
{
SetBaseStuff(c);
Health = (c["Health"] as NbtShort).Value;
HurtTime = (c["HurtTime"] as NbtShort).Value;
AttackTime = (c["AttackTime"] as NbtShort).Value;
DeathTime = (c["DeathTime"] as NbtShort).Value;
}
示例13: ToNBT
public override NbtCompound ToNBT()
{
NbtCompound c = new NbtCompound();
Base2NBT(ref c);
c.Tags.Add(new NbtString("EntityId", EntityId));
c.Tags.Add(new NbtShort("Delay", Delay));
return c;
}
示例14: Read
public NbtCompound Read(NbtCompound metadata) {
Tags = new NbtTag[metadata.Tags.Count()];
metadata.CopyTo(Tags, 0);
foreach (NbtTag b in Tags)
metadata.Remove(b);
return metadata;
}
示例15: TileEntity
/// <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;
}