Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Use default dimension data for defaulted registry entry
Dieser Commit ist enthalten in:
Ursprung
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);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren