Skip to content

Commit 814cd69

Browse files
authored
SetDimension bug fix
Fixed bug in `SetDimension` method of `World` class, where it would c…
2 parents 27e6643 + d0c9695 commit 814cd69

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

MinecraftClient/Mapping/World.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class World
1919
/// <summary>
2020
/// The dimension info of the world
2121
/// </summary>
22-
private static Dimension curDimension = new();
22+
private static Dimension curDimension= new();
2323

2424
private static readonly Dictionary<string, Dimension> dimensionList = new();
2525

@@ -87,10 +87,32 @@ public static void StoreOneDimension(string dimensionName, Dictionary<string, ob
8787
/// </summary>
8888
/// <param name="name"> The name of the dimension type</param>
8989
/// <param name="nbt">The dimension type (NBT Tag Compound)</param>
90-
public static void SetDimension(string name)
91-
{
92-
curDimension = dimensionList[name]; // Should not fail
93-
}
90+
public static void SetDimension(string name)
91+
{
92+
// Try to get the dimension using the name as is
93+
if (dimensionList.TryGetValue(name, out Dimension dimension))
94+
{
95+
curDimension = dimension;
96+
return; // Dimension found
97+
}
98+
99+
// If not found, check if name lacks 'minecraft:' prefix and try again
100+
if (!name.StartsWith("minecraft:"))
101+
{
102+
string prefixedName = "minecraft:" + name;
103+
if (dimensionList.TryGetValue(prefixedName, out dimension))
104+
{
105+
curDimension = dimension;
106+
return; // Dimension found with prefixed name
107+
}
108+
}
109+
110+
// If still not found, dimension does not exist
111+
throw new KeyNotFoundException($"Dimension '{name}' not found in dimensions dictionary.");
112+
}
113+
114+
115+
94116

95117

96118
/// <summary>

MinecraftClient/Protocol/Handlers/Protocol18.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,8 @@ private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
660660
{
661661
case >= MC_1_16_2_Version and <= MC_1_18_2_Version:
662662
World.StoreOneDimension(dimensionName, dimensionType!);
663-
World.SetDimension(dimensionName);
663+
// World.SetDimension(dimensionName);
664+
World.SetDimension(dimensionName);
664665
break;
665666
default:
666667
World.SetDimension(dimensionTypeName!);

0 commit comments

Comments
 (0)