Use default dimension data for defaulted registry entry

This commit is contained in:
Nassim Jahnke 2024-06-20 17:32:19 +02:00
parent 00fedc7656
commit f5b3799db9
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
3 changed files with 19 additions and 1 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -527,7 +527,11 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
final Map<String, DimensionData> 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);
}