Dont crash if key is null

This commit is contained in:
mcrcortex
2025-08-27 17:30:32 +10:00
parent 552a6e33a6
commit 63a969e5df
2 changed files with 10 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.ref.WeakReference;
@@ -21,7 +22,10 @@ public class WorldIdentifier {
private final transient long hashCode;
@Nullable transient WeakReference<WorldEngine> cachedEngineObject;
public WorldIdentifier(RegistryKey<World> key, long biomeSeed, @Nullable RegistryKey<DimensionType> dimension) {
public WorldIdentifier(@NotNull RegistryKey<World> key, long biomeSeed, @Nullable RegistryKey<DimensionType> dimension) {
if (key == null) {
throw new IllegalStateException("Key cannot be null");
}
dimension = dimension==null?NULL_DIM_KEY:dimension;
this.key = key;
this.biomeSeed = biomeSeed;

View File

@@ -29,7 +29,11 @@ public class MixinWorld implements IWorldGetIdentifier {
long seed,
int maxChainedNeighborUpdates,
CallbackInfo ci) {
this.identifier = new WorldIdentifier(key, seed, dimensionEntry.getKey().orElse(null));
if (key != null) {
this.identifier = new WorldIdentifier(key, seed, dimensionEntry == null?null:dimensionEntry.getKey().orElse(null));
} else {
this.identifier = null;
}
}
@Override