public void NBTJsonSerializerTests_DeserializeTest() { ListTag list = new ListTag("list", NBTTagType.INT); list.Add(new IntTag(12345)); list.Add(new IntTag(67890)); CompoundTag subTag = new CompoundTag(); subTag.PutBool("bool", true); subTag.PutByte("byte", 123); CompoundTag tag = new CompoundTag(); tag.PutBool("bool", true); tag.PutByte("byte", 123); tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200)); tag.PutShort("short", 12345); tag.PutInt("int", 12345678); tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200)); tag.PutLong("long", 123456789123456); tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200)); tag.PutFloat("float", 12.3456f); tag.PutDouble("double", 12.3456789); tag.PutList(list); tag.PutCompound("com", subTag); JObject json = NBTJsonSerializer.Serialize(tag); Console.WriteLine(NBTJsonSerializer.Serialize(NBTJsonSerializer.Deserialize(json)).ToString()); }
public Item SetLore(params string[] lores) { if (lores == null || lores.Length < 1) { this.ClearLore(); return(this); } CompoundTag tag = this.NamedTag; ListTag list = new ListTag("Lore", NBTTagType.STRING); for (int i = 0; i < lores.Length; ++i) { list.Add(new StringTag(lores[i])); } if (tag.Exist("display")) { tag.GetCompound("display").PutList(list); } else { tag.PutCompound("display", new CompoundTag("display").PutList(list)); } this.NamedTag = tag; return(this); }
public void NBTIOTests_WriteGZFileTest() { ListTag list = new ListTag("list", NBTTagType.COMPOUND); list.Add(new CompoundTag().PutInt("c1", 123)); list.Add(new CompoundTag().PutLong("c2", 123456)); CompoundTag subTag = new CompoundTag(); subTag.PutBool("bool", true); subTag.PutByte("byte", 123); CompoundTag tag = new CompoundTag(); tag.PutBool("bool", true); tag.PutByte("byte", 123); tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200)); tag.PutShort("short", 12345); tag.PutInt("int", 12345678); tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200)); tag.PutLong("long", 123456789123456); tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200)); tag.PutFloat("float", 12.3456f); tag.PutDouble("double", 12.3456789); tag.PutList(list); tag.PutCompound("com", subTag); NBTIO.WriteGZIPFile(Environment.CurrentDirectory + "\\test2.nbt", tag); }
public void Create(World world) { CompoundTag tag = new CompoundTag(""); tag.PutCompound("Data", this.CreateData(world)); NBTIO.WriteGZIPFile($"{Server.ExecutePath}\\worlds\\{world.Name}\\level.dat", tag); }
public void Save() { CompoundTag tag = new CompoundTag(); tag.PutCompound("Data", this.Data); tag = new CompoundTag().PutCompound("", tag); NBTIO.WriteGZIPFile(this.FolderPath, tag, NBTEndian.BIG_ENDIAN); }
public override CompoundTag SaveNBT() { CompoundTag nbt = base.SaveNBT(); nbt.PutShort("Age", this.Age); nbt.PutShort("PickupDelay", this.PickupDelay); nbt.PutString("Owner", this.Owner); nbt.PutCompound("Item", NBTIO.WriteItem(this.Item)); return(nbt); }
internal static CompoundTag CompoundTagDeserialize(JObject json) { CompoundTag tag = new CompoundTag(); foreach (KeyValuePair <string, JToken> kv in json) { JToken token = kv.Value; if (token is JValue) { JValue value = (JValue)token; object t = value.Value; if (t is byte) { tag.PutByte(kv.Key, (byte)t); } else if (t is double) { tag.PutDouble(kv.Key, (double)t); } else if (t is float) { tag.PutFloat(kv.Key, (float)t); } else if (t is int) { tag.PutInt(kv.Key, (int)t); } else if (t is long) { tag.PutLong(kv.Key, (long)t); } else if (t is short) { tag.PutShort(kv.Key, (short)t); } else if (t is string) { tag.PutString(kv.Key, (string)t); } } else if (token is JObject) { tag.PutCompound(kv.Key, NBTJsonSerializer.CompoundTagDeserialize((JObject)token)); } else { tag.PutList(NBTJsonSerializer.ListTagDeserialize((JArray)token, kv.Key)); } } return(tag); }
public static CompoundTag WriteItem(Item item, int slot = -1) { CompoundTag nbt = new CompoundTag() .PutShort("id", (short)item.ID) .PutShort("damage", (short)item.Damage) .PutByte("count", (byte)item.Count); if (slot != -1) { nbt.PutByte("slot", (byte)slot); } if (item.NamedTag.Count != 0) { nbt.PutCompound("tag", item.NamedTag); } string[] canPlaceOn = item.CanPlaceOn; if (canPlaceOn.Length > 0) { ListTag list = new ListTag("CanPlaceOn", NBTTagType.STRING); for (int i = 0; i < canPlaceOn.Length; ++i) { list.Add(new StringTag(canPlaceOn[i])); } nbt.PutList(list); } string[] canDestroy = item.CanDestroy; if (canDestroy.Length > 0) { ListTag list = new ListTag("CanDestroy", NBTTagType.STRING); for (int i = 0; i < canDestroy.Length; ++i) { list.Add(new StringTag(canDestroy[i])); } nbt.PutList(list); } return(nbt); }
public Item SetCustomName(string name) { if (name == null || name == "") { this.ClearCustomName(); return(this); } CompoundTag tag = this.NamedTag; if (tag.Exist("display")) { tag.GetCompound("display").PutString("Name", name); } else { tag.PutCompound("display", new CompoundTag("display").PutString("Name", name)); } this.NamedTag = tag; return(this); }
public CompoundTag NBTSerialize(Chunk chunk) { CompoundTag tag = new CompoundTag("Level"); tag.PutInt("xPos", chunk.X); //Chunk X tag.PutInt("zPos", chunk.Z); //Chunk Z tag.PutLong("LastUpdate", chunk.LastUpdate); //Last Save Tick tag.PutByte("LightPopulated", chunk.LightPopulated ? (byte)1 : (byte)0); // tag.PutByte("TerrainPopulated", chunk.TerrainPopulated ? (byte)1 : (byte)0); // tag.PutByte("V", 1); //Version tag.PutLong("InhabitedTime", chunk.InhabitedTime); tag.PutByteArray("Biomes", chunk.Biomes); int[] cast = new int[256]; chunk.HeightMap.CopyTo(cast, 0); tag.PutIntArray("HeightMap", cast); ListTag sections = new ListTag("Sections", NBTTagType.COMPOUND); SubChunk[] subChunks = chunk.SubChunks; for (int i = 0; i < subChunks.Length; ++i) { if (subChunks[i].IsEnpty) { continue; } CompoundTag data = new CompoundTag(); data.PutByte("Y", (byte)i); data.PutIntArray("Blocks", subChunks[i].BlockDatas); data.PutByteArray("Data", subChunks[i].MetaDatas.ArrayData); data.PutByteArray("SkyLight", subChunks[i].SkyLights.ArrayData); data.PutByteArray("BlockLight", subChunks[i].BlockLigths.ArrayData); sections.Add(data); } tag.PutList(sections); ListTag entitiesTag = new ListTag("Entities", NBTTagType.COMPOUND); Entity[] entities = chunk.GetEntities(); for (int i = 0; i < entities.Length; ++i) { if (entities[i].IsPlayer) { continue; } entitiesTag.Add(entities[i].SaveNBT()); } tag.PutList(entitiesTag); ListTag blockEntitiesTag = new ListTag("TileEntities", NBTTagType.COMPOUND); BlockEntity[] blockEntities = chunk.GetBlockEntities(); for (int i = 0; i < blockEntities.Length; ++i) { blockEntitiesTag.Add(blockEntities[i].SaveNBT()); } tag.PutList(blockEntitiesTag); CompoundTag outTag = new CompoundTag(""); outTag.PutCompound(tag.Name, tag); return(outTag); }
public CompoundTag CreateData(World world) { CompoundTag customBossEvents = new CompoundTag("CustomBossEvents"); CompoundTag dimensionData = new CompoundTag("DimensionData"); CompoundTag gameRules = new CompoundTag("GameRules"); CompoundTag version = new CompoundTag("Version"); version.PutInt("Id", -1); version.PutString("Name", ProtocolInfo.CLIENT_VERSION); version.PutByte("Snapshot", 0); CompoundTag data = new CompoundTag("Data"); data.PutCompound("CustomBossEvents", customBossEvents); data.PutCompound("DimensionData", dimensionData); data.PutInt("version", 19133); data.PutByte("initialized", 0); data.PutString("LevelName", world.Name); data.PutString("generatorName", world.GeneratorName); data.PutInt("generatorVersion", 0); data.PutString("generatorOptions", "{}"); data.PutLong("RandomSeed", world.Seed); data.PutByte("MapFeatures", 0); data.PutLong("LastPlayed", world.LastPlayed); data.PutLong("SizeOnDisk", 0); data.PutByte("allowCommands", 1); data.PutByte("hardcore", 0); data.PutInt("GameType", world.DefaultGameMode.GameModeToInt()); data.PutByte("Difficulty", (byte)world.Difficulty); data.PutByte("DifficultyLocked", 0); data.PutLong("Time", 0); data.PutLong("DayTime", 0); data.PutInt("SpawnX", (int)world.SpawnPoint.X); data.PutInt("SpawnY", (int)world.SpawnPoint.Y); data.PutInt("SpawnZ", (int)world.SpawnPoint.Z); data.PutDouble("BorderCenterX", 0d); data.PutDouble("BorderCenterZ", 0d); data.PutDouble("BorderSize", 60000000); data.PutDouble("BorderSafeZone", 5); data.PutDouble("BorderWarningBlocks", 5); data.PutDouble("BorderWarningTime", 15); data.PutDouble("BorderSizeLerpTarget", 60000000); data.PutDouble("BorderSizeLerpTime", 0); data.PutDouble("BorderDamagePerBlock", 0.2d); data.PutByte("raining", 0); data.PutInt("rainTime", 0); data.PutByte("thundering", 0); data.PutInt("thunderTime", 0); data.PutInt("clearWeatherTime", 0); data.PutCompound("GameRules", gameRules); data.PutCompound("Version", version); return(data); }