Map the sound name in stop sound packets

This commit is contained in:
KennyTV 2020-04-28 11:23:56 +02:00
parent 8409f6fb2a
commit c2d81e6e9d
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
7 changed files with 46 additions and 3 deletions

View File

@ -60,4 +60,35 @@ public class SoundRewriter {
}
});
}
public void registerStopSound(int oldId, int newId) {
protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
byte flags = wrapper.passthrough(Type.BYTE);
if ((flags & 0x02) == 0) return; // No sound specified
if ((flags & 0x01) != 0) {
wrapper.passthrough(Type.STRING); // Source
}
String soundId = wrapper.read(Type.STRING);
String mappedId = stringIdRewriter.apply(soundId);
if (mappedId == null) {
// No mapping found
wrapper.write(Type.STRING, soundId);
return;
}
if (!mappedId.isEmpty()) {
wrapper.write(Type.STRING, mappedId);
} else {
// Cancel if set to empty
wrapper.cancel();
}
});
}
});
}
}

View File

@ -49,7 +49,16 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
} else {
source = "";
}
String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : "";
String sound;
if ((flags & 0x02) != 0) {
sound = BackwardsMappings.soundMappings.getNewId(wrapper.read(Type.STRING));
if (sound == null) {
sound = "";
}
} else {
sound = "";
}
wrapper.write(Type.STRING, source);
wrapper.write(Type.STRING, sound);

View File

@ -76,7 +76,6 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol {
registerOutgoing(State.PLAY, 0x4B, 0x47);
registerOutgoing(State.PLAY, 0x4C, 0x48);
registerOutgoing(State.PLAY, 0x4E, 0x4A);
registerOutgoing(State.PLAY, 0x52, 0x4C);
registerOutgoing(State.PLAY, 0x55, 0x4F);
// Update View Position

View File

@ -24,6 +24,7 @@ public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
id -> BackwardsMappings.soundMappings.getNewId(id), stringId -> BackwardsMappings.soundMappings.getNewId(stringId));
soundRewriter.registerSound(0x51, 0x4D);
soundRewriter.registerNamedSound(0x19, 0x1A);
soundRewriter.registerStopSound(0x52, 0x4C);
// Entity Sound Effect
protocol.registerOutgoing(State.PLAY, 0x50, -1, new PacketRemapper() {

View File

@ -46,6 +46,7 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol {
soundRewriter.registerSound(0x52, 0x51);
soundRewriter.registerSound(0x51, 0x50);
soundRewriter.registerNamedSound(0x1A, 0x19);
soundRewriter.registerStopSound(0x53, 0x52);
// Explosion - manually send an explosion sound
registerOutgoing(State.PLAY, 0x1D, 0x1C, new PacketRemapper() {
@ -205,7 +206,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol {
registerOutgoing(State.PLAY, 0x4D, 0x4C);
registerOutgoing(State.PLAY, 0x4E, 0x4D);
registerOutgoing(State.PLAY, 0x4F, 0x4E);
registerOutgoing(State.PLAY, 0x53, 0x52);
registerOutgoing(State.PLAY, 0x55, 0x54);
registerOutgoing(State.PLAY, 0x56, 0x55);
registerOutgoing(State.PLAY, 0x57, 0x56);

View File

@ -47,6 +47,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol {
soundRewriter.registerSound(0x51, 0x51);
soundRewriter.registerSound(0x52, 0x52);
soundRewriter.registerNamedSound(0x1A, 0x1A);
soundRewriter.registerStopSound(0x53, 0x53);
// Login success
registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() {

View File

@ -80,6 +80,8 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter {
hoverEvent.addProperty("value", contentsElement.toString());
} else {
//TODO escape/fix?
// the server sends the json as a string
hoverEvent.addProperty("value", contentsElement.toString());
}
}