Terrain support for 1.19

This commit is contained in:
BruceChen 2022-08-28 22:27:21 +08:00
parent 9e4184a98d
commit bc5298bf5f
3 changed files with 72 additions and 34 deletions

View file

@ -22,6 +22,13 @@ namespace MinecraftClient.Mapping
/// </summary>
public readonly bool piglinSafe = false;
/// <summary>
/// Possibly the light level(s) at which monsters can spawn.
/// </summary>
public readonly int monsterSpawnMinLightLevel = 0;
public readonly int monsterSpawnMaxLightLevel = 7;
public readonly int monsterSpawnBlockLightLimit = 0;
/// <summary>
/// When false, compasses spin randomly. When true, nether portals can spawn zombified piglins.
/// </summary>
@ -132,6 +139,25 @@ namespace MinecraftClient.Mapping
if (nbt.ContainsKey("piglin_safe"))
this.piglinSafe = 1 == (byte)nbt["piglin_safe"];
if (nbt.ContainsKey("monster_spawn_light_level"))
{
try
{
var monsterSpawnLightLevelObj = nbt["monster_spawn_light_level"];
if (monsterSpawnLightLevelObj.GetType() == typeof(int))
this.monsterSpawnMinLightLevel = this.monsterSpawnMaxLightLevel = (int)monsterSpawnLightLevelObj;
else
{
var inclusive = (Dictionary<string, object>)(((Dictionary<string, object>)monsterSpawnLightLevelObj)["value"]);
this.monsterSpawnMinLightLevel = (int)inclusive["min_inclusive"];
this.monsterSpawnMaxLightLevel = (int)inclusive["max_inclusive"];
}
}
catch (KeyNotFoundException) { }
}
if (nbt.ContainsKey("monster_spawn_block_light_limit"))
this.monsterSpawnBlockLightLimit = (int)nbt["monster_spawn_block_light_limit"];
if (nbt.ContainsKey("natural"))
this.natural = 1 == (byte)nbt["natural"];
if (nbt.ContainsKey("ambient_light"))

View file

@ -19,7 +19,9 @@ namespace MinecraftClient.Mapping
/// <summary>
/// The dimension info of the world
/// </summary>
private static Dimension dimension = new Dimension();
private static Dimension curDimension = new Dimension();
private static Dictionary<string, Dimension>? dimensionList = null;
/// <summary>
/// Lock for thread safety
@ -89,15 +91,35 @@ namespace MinecraftClient.Mapping
}
}
/// <summary>
/// Set dimension type
/// Storage of all dimensional data - 1.19.1 and above
/// </summary>
/// <param name="registryCodec">Registry Codec nbt data</param>
public static void StoreDimensionList(Dictionary<string, object> registryCodec)
{
dimensionList = new();
var dimensionListNbt = (object[])(((Dictionary<string, object>)registryCodec["minecraft:dimension_type"])["value"]);
foreach (Dictionary<string, object> dimensionNbt in dimensionListNbt)
{
string dimensionName = (string)dimensionNbt["name"];
Dictionary<string, object> element = (Dictionary<string, object>)dimensionNbt["element"];
dimensionList.Add(dimensionName, new Dimension(dimensionName, element));
}
}
/// <summary>
/// Set current dimension - 1.16 and above
/// </summary>
/// <param name="name"> The name of the dimension type</param>
/// <param name="nbt">The dimension type (NBT Tag Compound)</param>
public static void SetDimension(string name, Dictionary<string, object> nbt)
public static void SetDimension(string name)
{
// will change in 1.19 and above
dimension = new Dimension(name, nbt);
if (dimensionList!.TryGetValue(name, out Dimension? dimension))
curDimension = dimension;
else
Console.WriteLine("Can't find dimension \"" + name + "\"");
}
/// <summary>
@ -106,7 +128,7 @@ namespace MinecraftClient.Mapping
/// <returns>Current dimension</returns>
public static Dimension GetDimension()
{
return dimension;
return curDimension;
}
/// <summary>