From f5b3799db92e962a2fa5c414e73bba1c2c08f7dc Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 20 Jun 2024 17:32:19 +0200 Subject: [PATCH] Use default dimension data for defaulted registry entry --- .../viaversion/api/minecraft/RegistryEntry.java | 6 ++++++ .../viaversion/data/entity/DimensionDataImpl.java | 8 ++++++++ .../viaversion/viaversion/rewriter/EntityRewriter.java | 6 +++++- 3 files changed, 19 insertions(+), 1 deletion(-) 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); }