diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/RegistryEntry.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/RegistryEntry.java index 61d0ea877..36ab302b0 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/RegistryEntry.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/RegistryEntry.java @@ -25,6 +25,12 @@ package com.viaversion.viaversion.api.minecraft; import com.viaversion.nbt.tag.Tag; import org.checkerframework.checker.nullness.qual.Nullable; +/** + * Represents an entry in a registry. + * + * @param key key of the registry entry + * @param tag data of the registry entry, or null if the client should use its default + */ public record RegistryEntry(String key, @Nullable Tag tag) { public RegistryEntry withKey(final String key) { diff --git a/common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java b/common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java index e5e3cf639..669191a74 100644 --- a/common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java @@ -48,6 +48,14 @@ public final class DimensionDataImpl implements DimensionData { this.minY = minY.asInt(); } + public static DimensionData withDefaultsFor(final String key, final int id) { + return switch (key) { + case "overworld", "overworld_caves" -> new DimensionDataImpl(id, -64, 384); + case "the_nether", "the_end" -> new DimensionDataImpl(id, 0, 256); + default -> throw new IllegalArgumentException("Missing registry data for unknown dimension: " + key); + }; + } + @Override public int id() { return id; diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index 0ce1a9f07..c970dc321 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -527,7 +527,11 @@ public abstract class EntityRewriter dimensionDataMap = new HashMap<>(entries.length); for (int i = 0; i < entries.length; i++) { final RegistryEntry entry = entries[i]; - dimensionDataMap.put(Key.stripMinecraftNamespace(entry.key()), new DimensionDataImpl(i, (CompoundTag) entry.tag())); + final String key = Key.stripMinecraftNamespace(entry.key()); + final DimensionData dimensionData = entry.tag() != null + ? new DimensionDataImpl(i, (CompoundTag) entry.tag()) + : DimensionDataImpl.withDefaultsFor(key, i); + dimensionDataMap.put(key, dimensionData); } tracker(connection).setDimensions(dimensionDataMap); }