mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-28 21:15:51 +01:00
Use default dimension data for defaulted registry entry
This commit is contained in:
parent
00fedc7656
commit
f5b3799db9
@ -25,6 +25,12 @@ package com.viaversion.viaversion.api.minecraft;
|
|||||||
import com.viaversion.nbt.tag.Tag;
|
import com.viaversion.nbt.tag.Tag;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
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 record RegistryEntry(String key, @Nullable Tag tag) {
|
||||||
|
|
||||||
public RegistryEntry withKey(final String key) {
|
public RegistryEntry withKey(final String key) {
|
||||||
|
@ -48,6 +48,14 @@ public final class DimensionDataImpl implements DimensionData {
|
|||||||
this.minY = minY.asInt();
|
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
|
@Override
|
||||||
public int id() {
|
public int id() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -527,7 +527,11 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(entries.length);
|
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(entries.length);
|
||||||
for (int i = 0; i < entries.length; i++) {
|
for (int i = 0; i < entries.length; i++) {
|
||||||
final RegistryEntry entry = entries[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);
|
tracker(connection).setDimensions(dimensionDataMap);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user