Fix sound mapping lookup in 1.8->1.9 (#3801)

This commit is contained in:
EnZaXD 2024-04-23 10:46:40 +02:00 committed by GitHub
parent 7ac7ea485f
commit dcf741a2ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 14 deletions

View File

@ -46,6 +46,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.SoundEffect;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
@ -98,7 +99,7 @@ public class WorldPackets {
// Everything else gets written through // Everything else gets written through
handler(wrapper -> { handler(wrapper -> {
String name = wrapper.get(Type.STRING, 0); String name = Key.stripMinecraftNamespace(wrapper.get(Type.STRING, 0));
SoundEffect effect = SoundEffect.getByName(name); SoundEffect effect = SoundEffect.getByName(name);
int catid = 0; int catid = 0;
@ -109,7 +110,7 @@ public class WorldPackets {
} }
wrapper.set(Type.STRING, 0, newname); wrapper.set(Type.STRING, 0, newname);
wrapper.write(Type.VAR_INT, catid); // Write Category ID wrapper.write(Type.VAR_INT, catid); // Write Category ID
if (effect != null && effect.isBreaksound()) { if (effect != null && effect.isBreakSound()) {
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
int x = wrapper.passthrough(Type.INT); //Position X int x = wrapper.passthrough(Type.INT); //Position X
int y = wrapper.passthrough(Type.INT); //Position Y int y = wrapper.passthrough(Type.INT); //Position Y

View File

@ -273,7 +273,7 @@ public enum SoundEffect {
private final String name; private final String name;
private final String newName; private final String newName;
private final SoundCategory category; private final SoundCategory category;
private final boolean breaksound; private final boolean breakSound;
private static final Map<String, SoundEffect> effects; private static final Map<String, SoundEffect> effects;
@ -284,22 +284,21 @@ public enum SoundEffect {
} }
} }
SoundEffect(String name, String newname, SoundCategory cat) { SoundEffect(String name, String newName, SoundCategory category) {
this.category = cat; this.category = category;
this.newName = newname; this.newName = newName;
this.name = name; this.name = name;
this.breaksound = name.startsWith("dig."); this.breakSound = name.startsWith("dig.");
} }
SoundEffect(String name, String newname, SoundCategory cat, boolean shouldIgnore) { SoundEffect(String name, String newName, SoundCategory category, boolean shouldIgnore) {
this.category = cat; this.category = category;
this.newName = newname; this.newName = newName;
this.name = name; this.name = name;
this.breaksound = name.startsWith("dig.") || shouldIgnore; this.breakSound = name.startsWith("dig.") || shouldIgnore;
} }
public static SoundEffect getByName(String name) { public static SoundEffect getByName(String name) {
name = name.toLowerCase(Locale.ROOT);
return effects.get(name); return effects.get(name);
} }
@ -315,7 +314,7 @@ public enum SoundEffect {
return category; return category;
} }
public boolean isBreaksound() { public boolean isBreakSound() {
return breaksound; return breakSound;
} }
} }