3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Replace unknown sounds with direct value in registry data

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-06 23:47:27 +02:00
Ursprung 35a00d0b95
Commit 68c2af2795
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
4 geänderte Dateien mit 36 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -28,6 +28,7 @@ public class MappingData extends MappingDataBase {
private KeyMappings items;
private KeyMappings blocks;
private KeyMappings sounds;
public MappingData() {
super("1.20.3", "1.20.5");
@ -37,9 +38,10 @@ public class MappingData extends MappingDataBase {
protected void loadExtras(final CompoundTag data) {
super.loadExtras(data);
final CompoundTag extraMappings = MappingDataLoader.INSTANCE.loadNBT("items-blocks-1.20.3.nbt");
final CompoundTag extraMappings = MappingDataLoader.INSTANCE.loadNBT("extra-identifiers-1.20.3.nbt");
items = new KeyMappings(extraMappings.getListTag("items", StringTag.class));
blocks = new KeyMappings(extraMappings.getListTag("blocks", StringTag.class));
sounds = new KeyMappings(extraMappings.getListTag("sounds", StringTag.class));
}
public int itemId(final String name) {
@ -57,4 +59,12 @@ public class MappingData extends MappingDataBase {
public @Nullable String blockName(final int id) {
return blocks.idToKey(id);
}
public int soundId(final String name) {
return sounds.keyToId(name);
}
public @Nullable String soundName(final int id) {
return sounds.idToKey(id);
}
}

Datei anzeigen

@ -42,6 +42,7 @@ import com.viaversion.viaversion.rewriter.EntityRewriter;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class EntityPacketRewriter1_20_5 extends EntityRewriter<ClientboundPacket1_20_3, Protocol1_20_5To1_20_3> {
@ -76,6 +77,16 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
}
}
// Fixup sound ids that are now hard checked against the registry
final ListTag<CompoundTag> biomes = registryData.getCompoundTag("minecraft:worldgen/biome").getListTag("value", CompoundTag.class);
for (final CompoundTag biome : biomes) {
final CompoundTag effects = biome.getCompoundTag("element").getCompoundTag("effects");
checkSoundTag(effects.getCompoundTag("mood_sound"), "sound");
checkSoundTag(effects.getCompoundTag("additions_sound"), "sound");
checkSoundTag(effects.getCompoundTag("music"), "sound");
checkSoundTag(effects, "ambient_sound");
}
for (final Map.Entry<String, Tag> entry : registryData.entrySet()) {
final CompoundTag entryTag = (CompoundTag) entry.getValue();
final String type = entryTag.getString("type");
@ -211,6 +222,20 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
});
}
private void checkSoundTag(@Nullable final CompoundTag tag, final String key) {
if (tag == null) {
return;
}
final String sound = tag.getString(key);
if (sound != null && protocol.getMappingData().soundId(sound) == -1) {
// Write as direct value
final CompoundTag directSoundValue = new CompoundTag();
directSoundValue.putString("sound_id", sound);
tag.put(key, directSoundValue);
}
}
private void replaceNullValues(final RegistryEntry[] entries) {
// Find the first non-null entry and fill the array with dummy values where needed (which is easier than remapping them to different ids in a new, smaller array)
RegistryEntry first = null;