/// <summary> /// Initializes a new instance of the <see cref="Slot"/> class. /// </summary> /// <remarks></remarks> public Slot() { this.Id = 0; this.Count = 1; this.Metadata = 0; this.Nbt = new NbtFile(); }
/// <summary> /// Initializes a new instance of the <see cref="Slot"/> class. /// </summary> /// <param name="id">The ID.</param> /// <param name="count">The count.</param> /// <remarks></remarks> public Slot(ushort id, byte count) { Id = id; this.Count = count; Metadata = 0; Nbt = new NbtFile(); }
public UpdateTileEntityPacket(Vector3 position, TileEntityAction action, NbtCompound data) { Data = new NbtFile(); Data.RootTag = data; Position = position; Action = action; }
/// <summary> /// Initializes a new instance of the <see cref="Slot"/> class. /// </summary> /// <remarks></remarks> public Slot() { Id = 0; Count = 1; Metadata = 0; Nbt = new NbtFile(); }
public override int TryReadPacket(byte[] buffer, int length) { int offset = 1; int x, z; short y; short dataLength; byte[] data; if (!DataUtility.TryReadInt32(buffer, ref offset, length, out x)) return -1; if (!DataUtility.TryReadInt16(buffer, ref offset, length, out y)) return -1; if (!DataUtility.TryReadInt32(buffer, ref offset, length, out z)) return -1; if (!DataUtility.TryReadByte(buffer, ref offset, length, out Action)) return -1; if (!DataUtility.TryReadInt16(buffer, ref offset, length, out dataLength)) return -1; if (dataLength != 0) { if (!DataUtility.TryReadArray(buffer, ref offset, length, out data, dataLength)) return -1; Data = new NbtFile(); Data.LoadFile(new MemoryStream(data), true); } Position = new Vector3(x, y, z); return offset; }
/// <summary> /// Initializes a new instance of the <see cref="Slot"/> class. /// </summary> /// <param name="ID">The ID.</param> /// <param name="Count">The count.</param> /// <remarks></remarks> public Slot(short ID, byte Count) { this.Id = ID; this.Count = Count; this.Metadata = 0; this.Nbt = new NbtFile(); }
public static string Get(string world_file, bool realspawn) { try { byte[] XOR_KEY = { 108, 111, 108, 32, 101, 97, 115, 116, 101, 114, 32, 101, 103, 103 }; NbtFile nbt = new NbtFile(world_file, true); nbt.LoadFile(); byte[] randSeed = BitConverter.GetBytes(nbt.RootTag.Tags[0].Query<NbtLong>("/Data/RandomSeed").Value); byte[] time = BitConverter.GetBytes(nbt.RootTag.Tags[0].Query<NbtLong>("/Data/Time").Value); byte[] playerX, playerY, playerZ, rotationX, rotationY; if (!realspawn) { playerX = BitConverter.GetBytes((int)Math.Floor(nbt.RootTag.Tags[0].Query<NbtDouble>("/Data/Player/Pos/0").Value)); playerY = BitConverter.GetBytes((int)Math.Floor(nbt.RootTag.Tags[0].Query<NbtDouble>("/Data/Player/Pos/1").Value)); playerZ = BitConverter.GetBytes((int)Math.Floor(nbt.RootTag.Tags[0].Query<NbtDouble>("/Data/Player/Pos/2").Value)); rotationX = BitConverter.GetBytes(nbt.RootTag.Tags[0].Query<NbtFloat>("/Data/Player/Rotation/0").Value); rotationY = BitConverter.GetBytes(nbt.RootTag.Tags[0].Query<NbtFloat>("/Data/Player/Rotation/1").Value); } else { playerX = BitConverter.GetBytes(nbt.RootTag.Tags[0].Query<NbtInt>("/Data/SpawnX").Value); playerY = BitConverter.GetBytes(nbt.RootTag.Tags[0].Query<NbtInt>("/Data/SpawnY").Value + 2); playerZ = BitConverter.GetBytes(nbt.RootTag.Tags[0].Query<NbtInt>("/Data/SpawnZ").Value); rotationX = BitConverter.GetBytes(0f); rotationY = BitConverter.GetBytes(0f); } uint size = (sizeof(long) * 2) + (sizeof(int) * 3) + (sizeof(float) * 2); byte[] data = new byte[size]; int end = 0; Array.Copy(randSeed, 0, data, end, randSeed.Length); end += randSeed.Length; Array.Copy(time, 0, data, end, time.Length); end += time.Length; Array.Copy(playerX, 0, data, end, playerX.Length); end += playerX.Length; Array.Copy(playerY, 0, data, end, playerY.Length); end += playerY.Length; Array.Copy(playerZ, 0, data, end, playerZ.Length); end += playerZ.Length; Array.Copy(rotationX, 0, data, end, rotationX.Length); end += rotationX.Length; Array.Copy(rotationY, 0, data, end, rotationY.Length); for (int i = 0; i < data.Length; i++) { int mod = i % XOR_KEY.Length; data[i] = (byte)((int)data[i] ^ (int)XOR_KEY[mod]); } return "[" + Convert.ToBase64String(data) + "]"; } catch (Exception ex) { return "ERROR: " + ex.Message; } }
private void Form1_Load(object sender, EventArgs e) { NbtFile test = new NbtFile("C:\\Users\\Paul Bruner\\Desktop\\Ol Drive\\alu-new-sixteen-bits.schematic",true); test.LoadFile(); redBmp = new redstoneBmp(); }
private void UpdatePosition() { NbtFile PlayerDat = new NbtFile(this.Server.ServerDirectory + "\\world\\players\\" + this.Username + ".dat"); PlayerDat.LoadFile(); this._position.x = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/0").Value; this._position.y = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/1").Value; this._position.z = PlayerDat.Query<LibNbt.Tags.NbtDouble>("//Pos/2").Value; PlayerDat.Dispose(); }
private void AssertNbtBigFile(NbtFile file) { // NbtList enities; //NbtList tileenities; // See TestFiles/bigtest.nbt.txt to see the expected format NbtCompound root = file.RootTag; if (root.Name == "Schematic") { redBmp = new redstoneBmp(); // I don't know why but I keep getting cofused with the height, width, length stuff // maybe its because I deal with to many 2d objects. rYmax = root.Query<NbtShort>("/Schematic/Width").Value; rZmax = root.Query<NbtShort>("/Schematic/Height").Value; rXmax = root.Query<NbtShort>("/Schematic/Length").Value; rMaterials = root.Query<NbtString>("/Schematic/Materials").Value; rBlocks = root.Query<NbtByteArray>("/Schematic/Blocks").Value; rData = root.Query<NbtByteArray>("/Schematic/Data").Value; rGrid = new gBlockTypeStruct[rBlocks.Length]; // Ok, lets get this link list a starting for (int i = 0; i < rBlocks.Length; i++) { // Put the normal code here to fill the data for the blocks, and data // skipping for now as its more important to get the link list working } // Just so I can get a good visual on it going to precaculate the numbers int xStride = rXmax; int zStride = xStride * rYmax; // Precaculate the last line in a floor and the last floor int zLast = rData.Length - zStride; int yLast = zStride - xStride; // Lets try something diffrent and do all bounds checking for (int i = 0; i < rBlocks.Length; i++) { int z = i/zStride; int y = (i - z * zStride)/xStride; int x = i - (y * xStride) - (z * zStride); rGrid[i] = redBmp.getSet(rBlocks[i]); rGrid[i].X = x; rGrid[i].Y = y; rGrid[i].Z = z; } } }
public static void test(Player player, Command cmd) { if (!File.Exists("C:/users/jb509/desktop/1.schematic")) { player.Message("Nop"); return; } NbtFile file = new NbtFile("C:/users/jb509/desktop/1.schematic"); file.RootTag = new NbtCompound("Schematic"); file.LoadFile(); bool notClassic = false; short width = file.RootTag.Query<NbtShort>("/Schematic/Width").Value; short height = file.RootTag.Query<NbtShort>("/Schematic/Height").Value; short length = file.RootTag.Query<NbtShort>("/Schematic/Length").Value; Byte[] blocks = file.RootTag.Query<NbtByteArray>("/Schematic/Blocks").Value; Vector3I pos = player.Position.ToBlockCoords(); int i = 0; player.Message("&SDrawing Schematic ({0}x{1}x{2})", length, width, height); for (int x = pos.X; x < width + pos.X; x++) { for (int y = pos.Y; y < length + pos.Y; y++) { for (int z = pos.Z; z < height + pos.Z; z++) { if (Enum.Parse(typeof(Block), ((Block)blocks[i]).ToString(), true) != null) { if (!notClassic && blocks[i] > 49) { notClassic = true; player.Message("&WSchematic used is not designed for Minecraft Classic;" + " Converting all unsupported blocks with air"); } if (blocks[i] < 50) { player.WorldMap.QueueUpdate(new BlockUpdate(null, (short)x, (short)y, (short)z, (Block)blocks[i])); } } i++; } } } file.Dispose(); }
public void Save(ChunkData chunk) { var nbt = new NbtFile { RootTag = new NbtCompound("", new NbtTag[] { new NbtCompound("Level", new NbtTag[] { new NbtByteArray("Blocks", chunk.Blocks), new NbtByteArray("BlockLight", chunk.BlockLight.Data), new NbtByteArray("SkyLight", chunk.SkyLight.Data), new NbtByteArray("Data", chunk.MetaData.Data), new NbtByteArray("HeightMap", chunk.Heightmap), new NbtInt("xPos", chunk.X), new NbtInt("yPos", chunk.Y), }) }) }; var path = GetChunkPath(chunk.X, chunk.Y); Directory.CreateDirectory(Path.GetDirectoryName(path)); nbt.SaveFile(path, true); }
public static bool Set(string input, string file, bool starterKit, bool sunRize) { try { byte[] XOR_KEY = { 108, 111, 108, 32, 101, 97, 115, 116, 101, 114, 32, 101, 103, 103 }; input = input.Trim(); if (!input.StartsWith("[") || !input.EndsWith("]")) return false; input = input.Replace("[", "").Replace("]", ""); byte[] data = Convert.FromBase64String(input); for (int i = 0; i < data.Length; i++) { int mod = i % XOR_KEY.Length; data[i] = (byte)((int)data[i] ^ (int)XOR_KEY[mod]); } int end = 0; long randomSeed = BitConverter.ToInt64(data, 0); end += sizeof(long); long time = BitConverter.ToInt64(data, end); end += sizeof(long); int playerX = BitConverter.ToInt32(data, end); end += sizeof(int); int playerY = BitConverter.ToInt32(data, end); // height end += sizeof(int); int playerZ = BitConverter.ToInt32(data, end); end += sizeof(int); float rotationX = BitConverter.ToSingle(data, end); end += sizeof(float); float rotationY = BitConverter.ToSingle(data, end); NbtFile nbt = new NbtFile(); NbtCompound compound = new NbtCompound(); NbtCompound data_compound = new NbtCompound("Data"); data_compound.Tags.Add(new NbtLong("RandomSeed", randomSeed)); data_compound.Tags.Add(new NbtLong("Time", sunRize ? 1 : time)); data_compound.Tags.Add(new NbtInt("SpawnX", playerX)); data_compound.Tags.Add(new NbtInt("SpawnY", playerY)); data_compound.Tags.Add(new NbtInt("SpawnZ", playerZ)); data_compound.Tags.Add(new NbtLong("LastPlayed", 1289561130810)); data_compound.Tags.Add(new NbtLong("SizeOnDisk", 1000)); NbtCompound player_compound = new NbtCompound("Player"); player_compound.Tags.Add(new NbtByte("OnGround", 1)); player_compound.Tags.Add(new NbtShort("Air", 300)); player_compound.Tags.Add(new NbtShort("AttackTime", 0)); player_compound.Tags.Add(new NbtShort("DeathTime", 0)); player_compound.Tags.Add(new NbtShort("Fire", -20)); player_compound.Tags.Add(new NbtShort("Health", 20)); player_compound.Tags.Add(new NbtShort("HurtTime", 0)); player_compound.Tags.Add(new NbtInt("Dimension", 0)); player_compound.Tags.Add(new NbtInt("Score", 0)); player_compound.Tags.Add(new NbtFloat("FallDistance", 0)); NbtList player_pos = new NbtList("Pos"); player_pos.Tags.Add(new NbtDouble("", (double)playerX + 0.5)); player_pos.Tags.Add(new NbtDouble("", (double)playerY + 0.65)); player_pos.Tags.Add(new NbtDouble("", (double)playerZ + 0.5)); player_compound.Tags.Add(player_pos); NbtList player_rot = new NbtList("Rotation"); player_rot.Tags.Add(new NbtFloat("", rotationX)); player_rot.Tags.Add(new NbtFloat("", rotationY)); player_compound.Tags.Add(player_rot); NbtList inv_compound = new NbtList("Inventory"); if (starterKit) { inv_compound.Tags.Add(GetItemCompound(263, 3, 34, 0)); inv_compound.Tags.Add(GetItemCompound(17, 10, 35, 0)); inv_compound.Tags.Add(GetItemCompound(274, 1, 0, 0)); inv_compound.Tags.Add(GetItemCompound(273, 1, 1, 0)); inv_compound.Tags.Add(GetItemCompound(319, 1, 6, 0)); inv_compound.Tags.Add(GetItemCompound(319, 1, 7, 0)); inv_compound.Tags.Add(GetItemCompound(50, 10, 8, 0)); } player_compound.Tags.Add(inv_compound); NbtList player_mot = new NbtList("Motion"); player_mot.Tags.Add(new NbtDouble("", 0.0)); player_mot.Tags.Add(new NbtDouble("", 0.0)); player_mot.Tags.Add(new NbtDouble("", 0.0)); player_compound.Tags.Add(player_mot); data_compound.Tags.Add(player_compound); nbt.RootTag = compound; nbt.RootTag.Tags.Add(data_compound); Stream stream = File.OpenWrite(file); nbt.SaveFile(stream, true); stream.Close(); stream.Dispose(); return true; } catch(Exception ex) { return false; } }
public static Chunk FromNbt(Vector3 position, NbtFile nbt) { Chunk chunk = new Chunk(position); // Load data var root = nbt.RootTag.Get<NbtCompound>("Level"); chunk.Biomes = root.Get<NbtByteArray>("Biomes").Value; chunk.HeightMap = root.Get<NbtIntArray>("HeightMap").Value; var sections = root.Get<NbtList>("Sections"); foreach (var sectionTag in sections) // TODO: This might not work properly { // Load data var compound = (NbtCompound)sectionTag; byte y = compound.Get<NbtByte>("Y").Value; var section = new Section(y); section.Blocks = compound.Get<NbtByteArray>("Blocks").Value; section.BlockLight.Data = compound.Get<NbtByteArray>("BlockLight").Value; section.SkyLight.Data = compound.Get<NbtByteArray>("SkyLight").Value; section.Metadata.Data = compound.Get<NbtByteArray>("Data").Value; // Process section section.ProcessSection(); chunk.Sections[y] = section; } var tileEntities = root.Get<NbtList>("TileEntities"); if (tileEntities != null) { foreach (var tag in tileEntities) { Vector3 tilePosition; var entity = TileEntity.FromNbt(tag as NbtCompound, out tilePosition); if (entity != null) chunk.TileEntities.Add(tilePosition, entity); } } return chunk; }
public NbtFile ToNbt() // TODO: Entities { NbtFile file = new NbtFile(); NbtCompound level = new NbtCompound("Level"); // Entities // TODO level.Add(new NbtList("Entities", NbtTagType.Compound)); // Biomes level.Add(new NbtByteArray("Biomes", Biomes)); // Last Update // TODO: What is this level.Add(new NbtLong("LastUpdate", 15)); // Position level.Add(new NbtInt("xPos", (int)AbsolutePosition.X)); level.Add(new NbtInt("zPos", (int)AbsolutePosition.Z)); // Tile Entities var tileEntityList = new NbtList("TileEntities", NbtTagType.Compound); foreach (var tileEntity in TileEntities) { // Get properties tileEntityList.Add(tileEntity.Value.ToNbt(tileEntity.Key)); } level.Add(tileEntityList); // Terrain Populated // TODO: When is this 0? Will vanilla use this? level.Add(new NbtByte("TerrainPopualted", 0)); // Sections and height level.Add(new NbtIntArray("HeightMap", HeightMap)); NbtList sectionList = new NbtList("Sections", NbtTagType.Compound); foreach (var section in Sections) { if (!section.IsAir) { NbtCompound sectionTag = new NbtCompound(); sectionTag.Add(new NbtByte("Y", section.Y)); sectionTag.Add(new NbtByteArray("Blocks", section.Blocks)); sectionTag.Add(new NbtByteArray("Data", section.Metadata.Data)); sectionTag.Add(new NbtByteArray("SkyLight", section.SkyLight.Data)); sectionTag.Add(new NbtByteArray("BlockLight", section.BlockLight.Data)); sectionList.Add(sectionTag); } } level.Add(sectionList); var rootCompound = new NbtCompound(""); rootCompound.Add(level); file.RootTag = rootCompound; return file; }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog.Filter = "Schematic Files .schematic | *.schematic"; openFileDialog.Title = "Select a Schematic"; openFileDialog.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal); if (openFileDialog.ShowDialog() == DialogResult.OK) { NbtFile test = new NbtFile(openFileDialog.FileName, true); test.LoadFile(); AssertNbtBigFile(test); paintIt = true; this.Width = rXmax * 20; this.Height = rYmax * 20; this.Refresh(); Console.WriteLine("CLICK!"); } }
public Slot(short id, sbyte count, short metadata, NbtFile nbt) : this(id, count, metadata) { Nbt = nbt; }
public override void Load(string Folder) { string f = Path.Combine(Folder, "DefaultMapGenerator.dat"); if (!File.Exists(f)) return; NbtFile nf = new NbtFile(f); nf.LoadFile(f); GenerateCaves = nf.Query<NbtByte>("/DefaultMapGenerator/GenerateCaves").Value == 0x01 ? true : false; GenerateDungeons = nf.Query<NbtByte>("/DefaultMapGenerator/GenerateDungeons").Value == 0x01 ? true : false; GenerateOres = nf.Query<NbtByte>("/DefaultMapGenerator/GenerateOres").Value == 0x01 ? true : false; GenerateWater = nf.Query<NbtByte>("/DefaultMapGenerator/GenerateWater").Value == 0x01 ? true : false; HellMode = nf.Query<NbtByte>("/DefaultMapGenerator/HellMode").Value == 0x01 ? true : false; GenerateTrees = nf.Query<NbtByte>("/DefaultMapGenerator/GenerateTrees").Value == 0x01 ? true : false; Frequency = nf.Query<NbtDouble>("/DefaultMapGenerator/Frequency").Value; NoiseQuality = (NoiseQuality) nf.Query<NbtByte>("/DefaultMapGenerator/NoiseQuality").Value; OctaveCount = nf.Query<NbtInt>("/DefaultMapGenerator/OctaveCount").Value; Lacunarity = nf.Query<NbtDouble>("/DefaultMapGenerator/Lacunarity").Value; Persistance = nf.Query<NbtDouble>("/DefaultMapGenerator/Persistance").Value; ContinentNoiseFrequency = nf.Query<NbtDouble>("/DefaultMapGenerator/ContinentNoiseFrequency").Value; CaveThreshold = nf.Query<NbtDouble>("/DefaultMapGenerator/CaveThreshold").Value; }
private void LoadFromFile(string directory) { NbtFile file = new NbtFile(); using (var stream = File.Open(Path.Combine(LevelDirectory, "level.dat"), FileMode.Open)) file.LoadFromStream(stream, NbtCompression.None, null); var data = file.RootTag.Get<NbtCompound>("Data"); var serializer = new NbtSerializer(typeof(SavedLevel)); SavedLevel level = (SavedLevel)serializer.Deserialize(data); Name = level.LevelName; Time = level.Time; GameMode = (GameMode)level.GameMode; MapFeatures = level.MapFeatures; Seed = level.Seed; // Find world generator string generatorName = level.GeneratorName; WorldGenerator = GetGenerator(generatorName); WorldGenerator.Seed = Seed; GeneratorOptions = level.GeneratorOptions; WorldGenerator.Initialize(this); SpawnPoint = level.SpawnPoint; World = new World(this, WorldGenerator, Path.Combine(directory, "region")); }
public static void Init() { if (File.Exists(".luf")) { foreach (string f in File.ReadAllLines(".luf")) { if(File.Exists(f)) LastUsedFiles.Push(f); } } if (File.Exists(".settings")) { try { NbtFile f = new NbtFile(".settings"); f.LoadFile(); ShowGridLines = f.RootTag.Get<NbtByte>("GridLines").Value == 0x01 ? true : false; ShowChunks = f.RootTag.Get<NbtByte>("ShowChunks").Value == 0x01 ? true : false; ShowMapIcons = f.RootTag.Get<NbtByte>("ShowMapIcons").Value == 0x01 ? true : false; ShowWaterDepth = f.RootTag.Get<NbtByte>("ShowWaterDepth").Value == 0x01 ? true : false; f.Dispose(); } catch (Exception) { Save(); } } }
public void TEST002_SaveMap() { if (Directory.Exists("002")) Directory.Delete("002", true); Directory.CreateDirectory("002"); // Saves map here. InfdevHandler mh = new InfdevHandler(); mh.Save("002/level.dat"); mh.SetDimension(0); Chunk cnkA = mh.NewChunk(0, 0); cnkA.Blocks[0, 0, 0] = 0x01; cnkA.Blocks[0, 0, 1] = 0x02; cnkA.Blocks[0, 0, 2] = 0x03; cnkA.Blocks[0, 0, 3] = 0x04; cnkA.Save(); FileInfo fA = new FileInfo(cnkA.Filename); Assert.Greater(fA.Length, 0, "System writing zero-length chunks."); Chunk cnkB = mh.GetChunk(0, 0); Assert.AreEqual(cnkB.Blocks[0, 0, 0], 0x01); Assert.AreEqual(cnkB.Blocks[0, 0, 1], 0x02); Assert.AreEqual(cnkB.Blocks[0, 0, 2], 0x03); Assert.AreEqual(cnkB.Blocks[0, 0, 3], 0x04); Console.WriteLine("Opening {0}...", cnkB.Filename); NbtFile chunkFile = new NbtFile(cnkB.Filename); chunkFile.LoadFile(); NbtCompound level = chunkFile.RootTag.Get<NbtCompound>("Level"); // Listed from a Minecraft-generated chunk. string[] reqdEntries = new string[]{ "xPos", "zPos", "LastUpdate", "Blocks", "Data", "SkyLight", "BlockLight", "HeightMap", "TerrainPopulated", "Entities", "TileEntities" }; foreach (string entry in reqdEntries) { if (level.Get(entry)==null) { Console.WriteLine(chunkFile.RootTag.ToString()); Assert.Fail(string.Format("\"{0}\" is not included", entry)); } else { Console.WriteLine(" * Has {0}...", entry); } } Directory.Delete("002", true); }
public PlayerEntity LoadPlayer(string name) { PlayerEntity entity = new PlayerEntity(Difficulty); if (LevelDirectory == null || !File.Exists(Path.Combine(LevelDirectory, "players", name + ".dat"))) { // Return default player entity entity.Position = SpawnPoint; entity.SpawnPoint = SpawnPoint; entity.Position += new Vector3(0, PlayerEntity.Height, 0); entity.GameMode = GameMode; return entity; } NbtFile file = new NbtFile(); using (Stream stream = File.Open(Path.Combine(LevelDirectory, "players", name + ".dat"), FileMode.Open)) file.LoadFromStream(stream, NbtCompression.GZip, null); var data = file.RootTag; entity.OnGround = data.Get<NbtByte>("OnGround").Value == 1; entity.Air = data.Get<NbtShort>("Air").Value; entity.Health = data.Get<NbtShort>("Health").Value; Dimension dimension = (Dimension)data.Get<NbtInt>("Dimension").Value; // TODO entity.Food = (short)data.Get<NbtInt>("foodLevel").Value; entity.XpLevel = data.Get<NbtInt>("XpLevel").Value; entity.XpTotal = data.Get<NbtInt>("XpTotal").Value; // TODO: Set velocity based on fall distance entity.FoodExhaustion = data.Get<NbtFloat>("foodExhaustionLevel").Value; entity.FoodSaturation = data.Get<NbtFloat>("foodSaturationLevel").Value; entity.XpProgress = data.Get<NbtFloat>("XpP").Value; var equipment = data.Get<NbtList>("Equipment"); var inventory = data.Get<NbtList>("Inventory"); var motion = data.Get<NbtList>("Motion"); var pos = data.Get<NbtList>("Pos"); var rotation = data.Get<NbtList>("Rotation"); var abilities = data.Get<NbtCompound>("abilities"); // Appears to be unused, is overriden by the inventory contents // foreach (var item in equipment.Tags) foreach (var item in inventory) { var slot = Slot.FromNbt((NbtCompound)item); slot.Index = DataSlotToNetworkSlot(slot.Index); entity.Inventory[slot.Index] = slot; } entity.Velocity = new Vector3( ((NbtDouble)motion[0]).Value, ((NbtDouble)motion[1]).Value, ((NbtDouble)motion[2]).Value); entity.Position = new Vector3( ((NbtDouble)pos[0]).Value, ((NbtDouble)pos[1]).Value, ((NbtDouble)pos[2]).Value); if (data.Get<NbtInt>("SpawnX") != null) { entity.SpawnPoint = new Vector3( data.Get<NbtInt>("SpawnX").Value, data.Get<NbtInt>("SpawnY").Value, data.Get<NbtInt>("SpawnZ").Value); } entity.Yaw = ((NbtFloat)rotation[0]).Value; entity.Pitch = ((NbtFloat)rotation[1]).Value; // TODO: Abilities return entity; }
/// <summary> /// Retrieves the requested chunk from the region, or /// generates it if a world generator is provided. /// </summary> /// <param name="position">The position of the requested local chunk coordinates.</param> public Chunk GetChunk(Vector3 position) { // TODO: This could use some refactoring lock (Chunks) { if (!Chunks.ContainsKey(position)) { if (regionFile != null) { // Search the stream for that region lock (regionFile) { var chunkData = GetChunkFromTable(position); if (chunkData == null) { if (WorldGenerator == null) throw new ArgumentException("The requested chunk is not loaded.", "position"); Chunks.Add(position, WorldGenerator.GenerateChunk(position, this)); return Chunks[position]; } regionFile.Seek(chunkData.Item1, SeekOrigin.Begin); int length = new MinecraftStream(regionFile).ReadInt32(); // TODO: Avoid making new objects here, and in the WriteInt32 int compressionMode = regionFile.ReadByte(); switch (compressionMode) { case 1: // gzip break; case 2: // zlib var nbt = new NbtFile(); nbt.LoadFromStream(regionFile, NbtCompression.ZLib, null); var chunk = Chunk.FromNbt(position, nbt); chunk.ParentRegion = this; Chunks.Add(position, chunk); break; default: throw new InvalidDataException("Invalid compression scheme provided by region file."); } } } else if (WorldGenerator == null) throw new ArgumentException("The requested chunk is not loaded.", "position"); else Chunks.Add(position, WorldGenerator.GenerateChunk(position, this)); } return Chunks[position]; } }
public void SavePlayer(PlayerEntity entity) { // TODO: Generalize to all mobs NbtFile file = new NbtFile(); var data = new NbtCompound(); data.Add(new NbtByte("OnGround", (byte)(entity.OnGround ? 1 : 0))); data.Add(new NbtShort("Air", entity.Air)); data.Add(new NbtShort("Health", entity.Health)); data.Add(new NbtInt("Dimension", 0)); // TODO data.Add(new NbtInt("foodLevel", entity.Food)); data.Add(new NbtInt("XpLevel", entity.XpLevel)); data.Add(new NbtInt("XpTotal", entity.XpTotal)); data.Add(new NbtFloat("foodExhaustionLevel", entity.FoodExhaustion)); data.Add(new NbtFloat("foodSaturationLevel", entity.FoodSaturation)); data.Add(new NbtFloat("XpP", entity.XpProgress)); data.Add(new NbtList("Equipment")); var inventory = new NbtList("Inventory"); for (int index = 0; index < entity.Inventory.Length; index++) { var slot = entity.Inventory[index]; if (slot.Empty) continue; slot.Index = NetworkSlotToDataSlot(index); inventory.Add(slot.ToNbt()); } data.Add(inventory); var motion = new NbtList("Motion"); motion.Add(new NbtDouble(entity.Velocity.X)); motion.Add(new NbtDouble(entity.Velocity.Y)); motion.Add(new NbtDouble(entity.Velocity.Z)); data.Add(motion); var pos = new NbtList("Pos"); pos.Add(new NbtDouble(entity.Position.X)); pos.Add(new NbtDouble(entity.Position.Y)); pos.Add(new NbtDouble(entity.Position.Z)); data.Add(pos); var rotation = new NbtList("Rotation"); rotation.Add(new NbtFloat(entity.Yaw)); rotation.Add(new NbtFloat(entity.Pitch)); data.Add(rotation); data.Add(new NbtCompound("abilities")); file.RootTag = data; if (!Directory.Exists(Path.Combine(LevelDirectory, "players"))) Directory.CreateDirectory(Path.Combine(LevelDirectory, "players")); using (Stream stream = File.Open(Path.Combine(LevelDirectory, "players", entity.Username + ".dat"), FileMode.OpenOrCreate)) file.SaveToStream(stream, NbtCompression.GZip); }
public static void Save() { File.WriteAllLines(".luf", LastUsedFiles.ToArray()); NbtFile f = new NbtFile(); f.RootTag.Add("GridLines",new NbtByte("GridLines", (byte) (ShowGridLines ? 0x01 : 0x00))); f.RootTag.Add("ShowChunks",new NbtByte("ShowChunks", (byte) (ShowChunks ? 0x01 : 0x00))); f.RootTag.Add("ShowMapIcons",new NbtByte("ShowMapIcons", (byte) (ShowMapIcons ? 0x01 : 0x00))); f.RootTag.Add("ShowWaterDepth",new NbtByte("ShowWaterDepth", (byte) (ShowWaterDepth ? 0x01 : 0x00))); f.SaveFile(".settings"); f.Dispose(); }
public UpdateTileEntityPacket(int x, short y, int z, byte action, NbtFile nbt) { X = x; Y = y; Z = z; Action = action; Nbt = nbt; }
/// <summary> /// Retrieves the requested chunk from the region, or /// generates it if a world generator is provided. /// </summary> /// <param name="position">The position of the requested local chunk coordinates.</param> public Chunk GetChunk(Vector3 position) { // TODO: This could use some refactoring lock (Chunks) { if (!Chunks.ContainsKey(position)) { if (regionFile != null) { // Search the stream for that region lock (regionFile) { var chunkData = GetChunkFromTable(position); if (chunkData == null) { if (WorldGenerator == null) throw new ArgumentException("The requested chunk is not loaded.", "position"); Chunks.Add(position, WorldGenerator.GenerateChunk(position, this)); return Chunks[position]; } regionFile.Seek(chunkData.Item1, SeekOrigin.Begin); int length = DataUtility.ReadInt32(regionFile); int compressionMode = regionFile.ReadByte(); switch (compressionMode) { case 1: // gzip break; case 2: // zlib byte[] compressed = new byte[length]; regionFile.Read(compressed, 0, compressed.Length); byte[] uncompressed = ZlibStream.UncompressBuffer(compressed); MemoryStream memoryStream = new MemoryStream(uncompressed); NbtFile nbt = new NbtFile(); nbt.LoadFile(memoryStream, false); var chunk = Chunk.FromNbt(position, nbt); chunk.ParentRegion = this; Chunks.Add(position, chunk); break; default: throw new InvalidDataException("Invalid compression scheme provided by region file."); } } } else if (WorldGenerator == null) throw new ArgumentException("The requested chunk is not loaded.", "position"); else Chunks.Add(position, WorldGenerator.GenerateChunk(position, this)); } return Chunks[position]; } }
public void ReadPacket(MinecraftStream stream) { X = stream.ReadInt32(); Y = stream.ReadInt16(); Z = stream.ReadInt32(); Action = stream.ReadUInt8(); var length = stream.ReadInt16(); var data = stream.ReadUInt8Array(length); Nbt = new NbtFile(); Nbt.LoadFromBuffer(data, 0, length, NbtCompression.GZip, null); }
public override void Save(string Folder) { string f = Path.Combine(Folder, "DefaultMapGenerator.dat"); NbtFile nf = new NbtFile(f); nf.RootTag = new NbtCompound("__ROOT__"); NbtCompound c = new NbtCompound("DefaultMapGenerator"); c.Tags.Add(new NbtByte("GenerateCaves", (byte) (GenerateCaves ? 1 : 0))); c.Tags.Add(new NbtByte("GenerateDungeons", (byte) (GenerateDungeons ? 1 : 0))); c.Tags.Add(new NbtByte("GenerateOres", (byte) (GenerateOres ? 1 : 0))); c.Tags.Add(new NbtByte("GenerateWater", (byte) (GenerateWater ? 1 : 0))); c.Tags.Add(new NbtByte("HellMode", (byte) (HellMode ? 1 : 0))); c.Tags.Add(new NbtByte("GenerateTrees", (byte) (GenerateTrees ? 1 : 0))); c.Tags.Add(new NbtDouble("Frequency", Frequency)); c.Tags.Add(new NbtByte("NoiseQuality", (byte) NoiseQuality)); c.Tags.Add(new NbtInt("OctaveCount", OctaveCount)); c.Tags.Add(new NbtDouble("Lacunarity", Lacunarity)); c.Tags.Add(new NbtDouble("Persistance", Persistance)); c.Tags.Add(new NbtDouble("ContinentNoiseFrequency", ContinentNoiseFrequency)); c.Tags.Add(new NbtDouble("CaveThreshold", CaveThreshold)); nf.RootTag.Tags.Add(c); nf.SaveFile(f); }
public static Blocks Load(string filename) { NbtFile f = new NbtFile(); f.LoadFile(filename); NbtCompound root = f.RootTag; NbtTag nBlocks = root["Blocks"]; NbtTag nData = root["Data"]; NbtTag nWidth = root["Width"]; NbtTag nLength = root["Length"]; NbtTag nHeight = root["Height"]; byte[] blocks = ((NbtByteArray)nBlocks).Value; byte[] extra = ((NbtByteArray)nData).Value; int X = (int)((NbtShort)nWidth).Value; int Y = (int)((NbtShort)nLength).Value; int Z = (int)((NbtShort)nHeight).Value; Blocks b = new Blocks(X, Y, Z); //bool sch = filename.EndsWith(".schematic"); for (int i = 0; i < blocks.Length; i++) switch (blocks[i]) { case 0: case 6: case 37: case 38: case 39: case 40: case 51: case 59: case 63: case 65: case 66: case 68: case 78: case 83: b[i] = Block.AIR; break; case 55: b[i] = Block.WIRE; break; case 75: // Off b[i] = new Block(BlockType.TORCH, PlaceTorch(extra[i]), 0, 0, 0); break; case 76: // Off b[i] = new Block(BlockType.TORCH, PlaceTorch(extra[i]), 16, 0, 0); // System.Console.WriteLine("Loc: {2} Torch Dir: {0} Byte: {1}", b[i].Place.ToString(), extra[i] & 0x7,i); break; case 69: b[i] = new Block(BlockType.LEVER, PlaceTorch(extra[i]),(extra[i] & 0x8) == 1 ? 16 : 0, 0, 0); // System.Console.WriteLine("Lever Dir: {0} Byte: {1}", b[i].Place.ToString(), extra[i] & 0x7); break; case 70: case 72: b[i] = Block.PREASUREPAD; break; case 77: b[i] = Block.BUTTON; b[i].Place = PlaceButton(extra[i]); break; case 64: // doors not working yet case 71: break; case 93: // skip repeaters for now break; default: b[i] = Block.BLOCK; break; } return b; }