mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fix inventory handling across protocol versions
This commit is contained in:
parent
03e2e0d3fd
commit
5228670131
9 changed files with 364 additions and 89 deletions
|
|
@ -69,7 +69,16 @@ namespace MinecraftClient.Mapping
|
|||
/// <param name="registryCodec">Registry Codec nbt data</param>
|
||||
public static void StoreDimensionList(Dictionary<string, object> registryCodec)
|
||||
{
|
||||
var dimensionListNbt = (object[])(((Dictionary<string, object>)registryCodec["minecraft:dimension_type"])["value"]);
|
||||
const string namespacedDimensionTypeKey = "minecraft:dimension_type";
|
||||
const string legacyDimensionTypeKey = "dimension_type";
|
||||
|
||||
if (!registryCodec.TryGetValue(namespacedDimensionTypeKey, out var dimensionTypeRegistry)
|
||||
&& !registryCodec.TryGetValue(legacyDimensionTypeKey, out dimensionTypeRegistry))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dimensionListNbt = (object[])(((Dictionary<string, object>)dimensionTypeRegistry)["value"]);
|
||||
foreach (var (dimensionName, dimensionType) in from Dictionary<string, object> dimensionNbt in dimensionListNbt
|
||||
let dimensionName = (string)dimensionNbt["name"]
|
||||
let dimensionType = (Dictionary<string, object>)dimensionNbt["element"]
|
||||
|
|
@ -324,19 +333,48 @@ namespace MinecraftClient.Mapping
|
|||
}
|
||||
|
||||
// If not found, check if name lacks 'minecraft:' prefix and try again
|
||||
if (!name.StartsWith("minecraft:"))
|
||||
{
|
||||
string prefixedName = "minecraft:" + name;
|
||||
if (dimensionList.TryGetValue(prefixedName, out dimension))
|
||||
{
|
||||
curDimension = dimension;
|
||||
return; // Dimension found with prefixed name
|
||||
}
|
||||
}
|
||||
if (!name.StartsWith("minecraft:"))
|
||||
{
|
||||
string prefixedName = "minecraft:" + name;
|
||||
if (dimensionList.TryGetValue(prefixedName, out dimension))
|
||||
{
|
||||
curDimension = dimension;
|
||||
return; // Dimension found with prefixed name
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string unprefixedName = name["minecraft:".Length..];
|
||||
if (dimensionList.TryGetValue(unprefixedName, out dimension))
|
||||
{
|
||||
curDimension = dimension;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If still not found, dimension does not exist
|
||||
throw new KeyNotFoundException($"Dimension '{name}' not found in dimensions dictionary.");
|
||||
}
|
||||
if (TryStoreDefaultVanillaDimension(name)
|
||||
&& dimensionList.TryGetValue(name, out dimension))
|
||||
{
|
||||
curDimension = dimension;
|
||||
return;
|
||||
}
|
||||
|
||||
// If still not found, dimension does not exist
|
||||
throw new KeyNotFoundException($"Dimension '{name}' not found in dimensions dictionary.");
|
||||
}
|
||||
|
||||
private static bool TryStoreDefaultVanillaDimension(string name)
|
||||
{
|
||||
var normalizedName = name.StartsWith("minecraft:")
|
||||
? name
|
||||
: "minecraft:" + name;
|
||||
|
||||
if (normalizedName is not ("minecraft:overworld" or "minecraft:the_nether" or "minecraft:the_end"))
|
||||
return false;
|
||||
|
||||
StoreOneDimension(name, new Dictionary<string, object>());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue