/// <summary> /// Creates a new chunk at the specified location. /// </summary> public Chunk(Vector3 relativePosition) { Sections = new Section[16]; for (int i = 0; i < Sections.Length; i++) Sections[i] = new Section((byte)i); RelativePosition = relativePosition; Biomes = new byte[Width * Depth]; HeightMap = new int[Width * Depth]; }
/// <summary> /// Creates a new Chunk within the specified <see cref="Craft.Net.Data.Region"/> /// at the specified location. /// </summary> public Chunk(Vector3 relativePosition, Region parentRegion) { Sections = new Section[16]; for (int i = 0; i < Sections.Length; i++) Sections[i] = new Section((byte)i); RelativePosition = relativePosition; Biomes = new byte[Width * Depth]; HeightMap = new int[Width * Depth]; ParentRegion = parentRegion; IsModified = 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 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.Tags) { // 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; } return chunk; }
internal ReadOnlySection(Section section) { Section = section; }