3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Sound rewriter cleanup - don't send -1 sound ids

Addresses #1783
Dieser Commit ist enthalten in:
KennyTV 2020-05-23 10:56:27 +02:00
Ursprung 062d846c37
Commit 6b9e67f96b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
7 geänderte Dateien mit 53 neuen und 135 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,36 @@
package us.myles.ViaVersion.api.rewriters;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public class SoundRewriter {
private final Protocol protocol;
// Can't hold the mappings instance here since it's loaded later
private final IdRewriteFunction idRewriter;
public SoundRewriter(Protocol protocol, IdRewriteFunction idRewriter) {
this.protocol = protocol;
this.idRewriter = idRewriter;
}
// The same for entity sound effect
public void registerSound(int oldId, int newId) {
protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(wrapper -> {
int soundId = wrapper.get(Type.VAR_INT, 0);
int mappedId = idRewriter.rewrite(soundId);
if (mappedId == -1) {
wrapper.cancel();
} else if (soundId != mappedId) {
wrapper.set(Type.VAR_INT, 0, mappedId);
}
});
}
});
}
}

Datei anzeigen

@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_9;
import us.myles.ViaVersion.packets.State;
@ -86,31 +87,7 @@ public class Protocol1_11To1_10 extends Protocol {
}
});
// Sound effect
registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Sound name
map(Type.VAR_INT); // 1 - Sound Category
map(Type.INT); // 2 - x
map(Type.INT); // 3 - y
map(Type.INT); // 4 - z
map(Type.FLOAT); // 5 - Volume
map(Type.FLOAT); // 6 - Pitch
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
id = getNewSoundId(id);
if (id == -1) // Removed
wrapper.cancel();
wrapper.set(Type.VAR_INT, 0, id);
}
});
}
});
new SoundRewriter(this, this::getNewSoundId).registerSound(0x46, 0x46);
// Collect item packet
registerOutgoing(State.PLAY, 0x48, 0x48, new PacketRemapper() {

Datei anzeigen

@ -4,7 +4,6 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
@ -14,6 +13,7 @@ import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_12;
import us.myles.ViaVersion.packets.State;
@ -183,31 +183,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
registerOutgoing(State.PLAY, 0x44, 0x46);
registerOutgoing(State.PLAY, 0x45, 0x47);
// Sound effect
registerOutgoing(State.PLAY, 0x46, 0x48, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Sound name
map(Type.VAR_INT); // 1 - Sound Category
map(Type.INT); // 2 - x
map(Type.INT); // 3 - y
map(Type.INT); // 4 - z
map(Type.FLOAT); // 5 - Volume
map(Type.FLOAT); // 6 - Pitch
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
id = getNewSoundId(id);
if (id == -1) // Removed
wrapper.cancel();
wrapper.set(Type.VAR_INT, 0, id);
}
});
}
});
new SoundRewriter(this, this::getNewSoundId).registerSound(0x46, 0x48);
registerOutgoing(State.PLAY, 0x47, 0x49);
registerOutgoing(State.PLAY, 0x48, 0x4a);

Datei anzeigen

@ -15,6 +15,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
@ -759,21 +760,8 @@ public class Protocol1_13To1_12_2 extends Protocol {
});
// New 0x4C - Stop Sound
// Sound Effect packet
registerOutgoing(State.PLAY, 0x49, 0x4D, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Sound ID
new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(0x49, 0x4D);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int soundId = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, getNewSoundID(soundId));
}
});
}
});
// Player list header and footer
registerOutgoing(State.PLAY, 0x4A, 0x4E, new PacketRemapper() {
@Override
@ -1175,10 +1163,6 @@ public class Protocol1_13To1_12_2 extends Protocol {
providers.register(PaintingProvider.class, new PaintingProvider());
}
private int getNewSoundID(final int oldID) {
return MappingData.soundMappings.getNewId(oldID);
}
// Based on method from https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/ChatColor.java
public ChatColor getLastColor(String input) {
int length = input.length();

Datei anzeigen

@ -6,6 +6,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
@ -80,19 +81,8 @@ public class Protocol1_14To1_13_2 extends Protocol {
registerOutgoing(State.PLAY, 0x4B, 0x4F);
registerOutgoing(State.PLAY, 0x4C, 0x52);
// Sound Effect
registerOutgoing(State.PLAY, 0x4D, 0x51, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(Type.VAR_INT, 0, getNewSoundId(wrapper.get(Type.VAR_INT, 0)));
}
});
}
});
new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(0x4D, 0x51);
registerOutgoing(State.PLAY, 0x4E, 0x53);
registerOutgoing(State.PLAY, 0x4F, 0x55);
registerOutgoing(State.PLAY, 0x50, 0x56);
@ -262,15 +252,6 @@ public class Protocol1_14To1_13_2 extends Protocol {
WorldPackets.caveAir = MappingData.blockStateMappings.getNewId(8592);
}
public static int getNewSoundId(int id) {
int newId = MappingData.soundMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.14 sound for 1.13.2 sound " + id);
return 0;
}
return newId;
}
public static int getNewBlockStateId(int id) {
int newId = MappingData.blockStateMappings.getNewId(id);
if (newId == -1) {

Datei anzeigen

@ -6,6 +6,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.rewriters.TagRewriter;
import us.myles.ViaVersion.api.rewriters.TagType;
import us.myles.ViaVersion.api.type.Type;
@ -36,33 +37,9 @@ public class Protocol1_15To1_14_4 extends Protocol {
WorldPackets.register(this);
InventoryPackets.register(this);
// Entity Sound Effect (added somewhere in 1.14)
registerOutgoing(State.PLAY, 0x50, 0x51, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(Type.VAR_INT, 0, MappingData.soundMappings.getNewId(wrapper.get(Type.VAR_INT, 0)));
}
});
}
});
// Sound Effect
registerOutgoing(State.PLAY, 0x51, 0x52, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.set(Type.VAR_INT, 0, MappingData.soundMappings.getNewId(wrapper.get(Type.VAR_INT, 0)));
}
});
}
});
SoundRewriter soundRewriter = new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id));
soundRewriter.registerSound(0x50, 0x51); // Entity Sound Effect (added somewhere in 1.14)
soundRewriter.registerSound(0x51, 0x52);
// Edit Book
registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {

Datei anzeigen

@ -4,6 +4,7 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.rewriters.TagRewriter;
import us.myles.ViaVersion.api.rewriters.TagType;
import us.myles.ViaVersion.api.type.Type;
@ -60,23 +61,9 @@ public class Protocol1_16To1_15_2 extends Protocol {
}
});
// Entity Sound Effect
registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(wrapper -> wrapper.set(Type.VAR_INT, 0, MappingData.soundMappings.getNewId(wrapper.get(Type.VAR_INT, 0))));
}
});
// Sound Effect
registerOutgoing(State.PLAY, 0x52, 0x52, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(wrapper -> wrapper.set(Type.VAR_INT, 0, MappingData.soundMappings.getNewId(wrapper.get(Type.VAR_INT, 0))));
}
});
SoundRewriter soundRewriter = new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id));
soundRewriter.registerSound(0x51, 0x51);
soundRewriter.registerSound(0x52, 0x52);
// Edit Book
registerIncoming(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {