mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fixed bug in SetDimension method of World class, where it would crash if joining a paper server. Added error handling.
This commit is contained in:
parent
27e66433cd
commit
d0c9695a79
2 changed files with 29 additions and 6 deletions
|
|
@ -19,7 +19,7 @@ namespace MinecraftClient.Mapping
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The dimension info of the world
|
/// The dimension info of the world
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static Dimension curDimension = new();
|
private static Dimension curDimension= new();
|
||||||
|
|
||||||
private static readonly Dictionary<string, Dimension> dimensionList = new();
|
private static readonly Dictionary<string, Dimension> dimensionList = new();
|
||||||
|
|
||||||
|
|
@ -89,9 +89,31 @@ namespace MinecraftClient.Mapping
|
||||||
/// <param name="nbt">The dimension type (NBT Tag Compound)</param>
|
/// <param name="nbt">The dimension type (NBT Tag Compound)</param>
|
||||||
public static void SetDimension(string name)
|
public static void SetDimension(string name)
|
||||||
{
|
{
|
||||||
curDimension = dimensionList[name]; // Should not fail
|
// Try to get the dimension using the name as is
|
||||||
|
if (dimensionList.TryGetValue(name, out Dimension dimension))
|
||||||
|
{
|
||||||
|
curDimension = dimension;
|
||||||
|
return; // Dimension found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 still not found, dimension does not exist
|
||||||
|
throw new KeyNotFoundException($"Dimension '{name}' not found in dimensions dictionary.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get current dimension
|
/// Get current dimension
|
||||||
|
|
|
||||||
|
|
@ -660,6 +660,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
{
|
{
|
||||||
case >= MC_1_16_2_Version and <= MC_1_18_2_Version:
|
case >= MC_1_16_2_Version and <= MC_1_18_2_Version:
|
||||||
World.StoreOneDimension(dimensionName, dimensionType!);
|
World.StoreOneDimension(dimensionName, dimensionType!);
|
||||||
|
// World.SetDimension(dimensionName);
|
||||||
World.SetDimension(dimensionName);
|
World.SetDimension(dimensionName);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue