Add TileEntities to Chunk objects
This commit is contained in:
parent
e1a01916ea
commit
ffa904260f
@ -7,6 +7,7 @@
|
|||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<RootNamespace>TrueCraft.Core</RootNamespace>
|
<RootNamespace>TrueCraft.Core</RootNamespace>
|
||||||
<AssemblyName>TrueCraft.Core</AssemblyName>
|
<AssemblyName>TrueCraft.Core</AssemblyName>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@ -17,7 +18,6 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
@ -26,7 +26,6 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
|
||||||
using fNbt;
|
using fNbt;
|
||||||
using fNbt.Serialization;
|
using fNbt.Serialization;
|
||||||
using TrueCraft.API.World;
|
using TrueCraft.API.World;
|
||||||
@ -35,6 +32,7 @@ namespace TrueCraft.Core.World
|
|||||||
public int X { get; set; }
|
public int X { get; set; }
|
||||||
[TagName("zPos")]
|
[TagName("zPos")]
|
||||||
public int Z { get; set; }
|
public int Z { get; set; }
|
||||||
|
public Dictionary<Coordinates3D, NbtCompound> TileEntities { get; set; }
|
||||||
|
|
||||||
public Coordinates2D Coordinates
|
public Coordinates2D Coordinates
|
||||||
{
|
{
|
||||||
@ -62,6 +60,7 @@ namespace TrueCraft.Core.World
|
|||||||
Biomes = new byte[Width * Depth];
|
Biomes = new byte[Width * Depth];
|
||||||
HeightMap = new int[Width * Depth];
|
HeightMap = new int[Width * Depth];
|
||||||
LastAccessed = DateTime.Now;
|
LastAccessed = DateTime.Now;
|
||||||
|
TileEntities = new Dictionary<Coordinates3D, NbtCompound>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chunk(Coordinates2D coordinates) : this()
|
public Chunk(Coordinates2D coordinates) : this()
|
||||||
@ -173,6 +172,27 @@ namespace TrueCraft.Core.World
|
|||||||
int index = coordinates.Y + (coordinates.Z * Height) + (coordinates.X * Height * Width);
|
int index = coordinates.Y + (coordinates.Z * Height) + (coordinates.X * Height * Width);
|
||||||
BlockLight[index] = value;
|
BlockLight[index] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tile entity for the given coordinates. May return null.
|
||||||
|
/// </summary>
|
||||||
|
public NbtCompound GetTileEntity(Coordinates3D coordinates)
|
||||||
|
{
|
||||||
|
LastAccessed = DateTime.Now;
|
||||||
|
if (TileEntities.ContainsKey(coordinates))
|
||||||
|
return TileEntities[coordinates];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the tile entity at the given coordinates to the given value.
|
||||||
|
/// </summary>
|
||||||
|
public void SetTileEntity(Coordinates3D coordinates, NbtCompound value)
|
||||||
|
{
|
||||||
|
LastAccessed = DateTime.Now;
|
||||||
|
TileEntities[coordinates] = value;
|
||||||
|
IsModified = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the height of the specified column.
|
/// Gets the height of the specified column.
|
||||||
@ -216,7 +236,22 @@ namespace TrueCraft.Core.World
|
|||||||
chunk.Add(new NbtByteArray("Data", Metadata.Data));
|
chunk.Add(new NbtByteArray("Data", Metadata.Data));
|
||||||
chunk.Add(new NbtByteArray("SkyLight", SkyLight.Data));
|
chunk.Add(new NbtByteArray("SkyLight", SkyLight.Data));
|
||||||
chunk.Add(new NbtByteArray("BlockLight", BlockLight.Data));
|
chunk.Add(new NbtByteArray("BlockLight", BlockLight.Data));
|
||||||
// TODO: Tile entities, entities
|
|
||||||
|
var tiles = new NbtList("TileEntities", NbtTagType.Compound);
|
||||||
|
foreach (var kvp in TileEntities)
|
||||||
|
{
|
||||||
|
var c = new NbtCompound();
|
||||||
|
c.Add(new NbtList("coordinates", new[] {
|
||||||
|
new NbtInt(kvp.Key.X),
|
||||||
|
new NbtInt(kvp.Key.Y),
|
||||||
|
new NbtInt(kvp.Key.Z)
|
||||||
|
}));
|
||||||
|
c.Add(new NbtList("value", new[] { kvp.Value }));
|
||||||
|
tiles.Add(c);
|
||||||
|
}
|
||||||
|
chunk.Add(tiles);
|
||||||
|
|
||||||
|
// TODO: Entities
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,6 +273,16 @@ namespace TrueCraft.Core.World
|
|||||||
BlockLight.Data = tag["BlockLight"].ByteArrayValue;
|
BlockLight.Data = tag["BlockLight"].ByteArrayValue;
|
||||||
SkyLight = new NibbleArray();
|
SkyLight = new NibbleArray();
|
||||||
SkyLight.Data = tag["SkyLight"].ByteArrayValue;
|
SkyLight.Data = tag["SkyLight"].ByteArrayValue;
|
||||||
|
|
||||||
|
if (tag.Contains("TileEntities"))
|
||||||
|
{
|
||||||
|
foreach (var entity in tag["TileEntities"] as NbtList)
|
||||||
|
{
|
||||||
|
TileEntities[new Coordinates3D(entity["coordinates"][0].IntValue,
|
||||||
|
entity["coordinates"][1].IntValue,
|
||||||
|
entity["coordinates"][2].IntValue)] = entity["value"][0] as NbtCompound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Tile entities, entities
|
// TODO: Tile entities, entities
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user