3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 16:12:43 +01:00

Map named sound packets, some cleanup

Dieser Commit ist enthalten in:
KennyTV 2020-03-15 12:09:56 +01:00
Ursprung 2b269a6563
Commit 8087b42c40
15 geänderte Dateien mit 266 neuen und 247 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,41 @@
package nl.matsv.viabackwards.api.data;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.viaversion.libs.gson.JsonArray;
import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject;
import java.util.HashMap;
import java.util.Map;
/**
* Backwards mappings for sound ids and names.
*/
public class VBSoundMappings {
private final Map<String, String> namedSoundMappings = new HashMap<>();
private final Mappings idMappings;
public VBSoundMappings(JsonArray oldSounds, JsonArray newSounds, JsonObject diffMapping) {
idMappings = new VBMappings(oldSounds, newSounds, diffMapping);
for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) {
String key = entry.getKey();
if (key.indexOf(':') == -1) {
key = "minecraft:" + key;
}
String value = entry.getValue().getAsString();
if (value.indexOf(':') == -1) {
value = "minecraft:" + value;
}
namedSoundMappings.put(key, value);
}
}
public String getNewId(String oldId) {
return namedSoundMappings.get(oldId);
}
public int getNewId(int oldId) {
return idMappings.getNewId(oldId);
}
}

Datei anzeigen

@ -0,0 +1,97 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.api.BackwardsProtocol;
import java.util.HashMap;
import java.util.Map;
public abstract class LegacySoundRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
private final Map<Integer, SoundData> soundRewrites = new HashMap<>();
protected LegacySoundRewriter(T protocol) {
super(protocol);
}
public SoundData added(int id, int replacement) {
return added(id, replacement, -1);
}
public SoundData added(int id, int replacement, float newPitch) {
SoundData data = new SoundData(replacement, true, newPitch, true);
soundRewrites.put(id, data);
return data;
}
public SoundData removed(int id) {
SoundData data = new SoundData(-1, false, -1, false);
soundRewrites.put(id, data);
return data;
}
public int handleSounds(int soundId) {
int newSoundId = soundId;
SoundData data = soundRewrites.get(soundId);
if (data != null) return data.getReplacementSound();
for (Map.Entry<Integer, SoundData> entry : soundRewrites.entrySet()) {
if (soundId > entry.getKey()) {
if (entry.getValue().isAdded()) {
newSoundId--;
} else {
newSoundId++;
}
}
}
return newSoundId;
}
public boolean hasPitch(int soundId) {
SoundData data = soundRewrites.get(soundId);
return data != null && data.isChangePitch();
}
public float handlePitch(int soundId) {
SoundData data = soundRewrites.get(soundId);
return data != null ? data.getNewPitch() : 1F;
}
public static final class SoundData {
private final int replacementSound;
private final boolean changePitch;
private final float newPitch;
private final boolean added;
private SoundData(int replacementSound, boolean changePitch, float newPitch, boolean added) {
this.replacementSound = replacementSound;
this.changePitch = changePitch;
this.newPitch = newPitch;
this.added = added;
}
public int getReplacementSound() {
return replacementSound;
}
public boolean isChangePitch() {
return changePitch;
}
public float getNewPitch() {
return newPitch;
}
public boolean isAdded() {
return added;
}
}
}

Datei anzeigen

@ -1,97 +1,54 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.api.rewriters; package nl.matsv.viabackwards.api.rewriters;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import java.util.HashMap; public class SoundRewriter {
import java.util.Map;
public abstract class SoundRewriter<T extends BackwardsProtocol> extends Rewriter<T> { private final BackwardsProtocol protocol;
private final Map<Integer, SoundData> soundRewrites = new HashMap<>(); private final VBSoundMappings soundMappings;
protected SoundRewriter(T protocol) { public SoundRewriter(BackwardsProtocol protocol, VBSoundMappings soundMappings) {
super(protocol); this.protocol = protocol;
this.soundMappings = soundMappings;
} }
public SoundData added(int id, int replacement) { // The same for entity sound effect
return added(id, replacement, -1); 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 = soundMappings.getNewId(soundId);
if (mappedId != -1 && soundId != mappedId) {
wrapper.set(Type.VAR_INT, 0, mappedId);
}
});
}
});
} }
public SoundData added(int id, int replacement, float newPitch) { public void registerNamedSound(int oldId, int newId) {
SoundData data = new SoundData(replacement, true, newPitch, true); protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() {
soundRewrites.put(id, data); @Override
return data; public void registerMap() {
} map(Type.STRING); // Sound identifier
handler(wrapper -> {
public SoundData removed(int id) { String soundId = wrapper.get(Type.STRING, 0);
SoundData data = new SoundData(-1, false, -1, false); String mappedId = soundMappings.getNewId(soundId);
soundRewrites.put(id, data); if (mappedId == null) return;
return data; if (!mappedId.isEmpty()) {
} wrapper.set(Type.STRING, 0, mappedId);
public int handleSounds(int soundId) {
int newSoundId = soundId;
SoundData data = soundRewrites.get(soundId);
if (data != null) return data.getReplacementSound();
for (Map.Entry<Integer, SoundData> entry : soundRewrites.entrySet()) {
if (soundId > entry.getKey()) {
if (entry.getValue().isAdded()) {
newSoundId--;
} else { } else {
newSoundId++; wrapper.cancel();
} }
} });
} }
return newSoundId; });
}
public boolean hasPitch(int soundId) {
SoundData data = soundRewrites.get(soundId);
return data != null && data.isChangePitch();
}
public float handlePitch(int soundId) {
SoundData data = soundRewrites.get(soundId);
return data != null ? data.getNewPitch() : 1F;
}
public static final class SoundData {
private final int replacementSound;
private final boolean changePitch;
private final float newPitch;
private final boolean added;
private SoundData(int replacementSound, boolean changePitch, float newPitch, boolean added) {
this.replacementSound = replacementSound;
this.changePitch = changePitch;
this.newPitch = newPitch;
this.added = added;
}
public int getReplacementSound() {
return replacementSound;
}
public boolean isChangePitch() {
return changePitch;
}
public float getNewPitch() {
return newPitch;
}
public boolean isAdded() {
return added;
}
} }
} }

Datei anzeigen

@ -10,7 +10,7 @@
package nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets; package nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.api.rewriters.LegacySoundRewriter;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -18,7 +18,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class SoundPackets1_11 extends SoundRewriter<Protocol1_10To1_11> { public class SoundPackets1_11 extends LegacySoundRewriter<Protocol1_10To1_11> {
public SoundPackets1_11(Protocol1_10To1_11 protocol) { public SoundPackets1_11(Protocol1_10To1_11 protocol) {
super(protocol); super(protocol);

Datei anzeigen

@ -10,7 +10,7 @@
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets; package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.api.rewriters.LegacySoundRewriter;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -18,7 +18,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class SoundPackets1_12 extends SoundRewriter<Protocol1_11_1To1_12> { public class SoundPackets1_12 extends LegacySoundRewriter<Protocol1_11_1To1_12> {
public SoundPackets1_12(Protocol1_11_1To1_12 protocol) { public SoundPackets1_12(Protocol1_11_1To1_12 protocol) {
super(protocol); super(protocol);

Datei anzeigen

@ -14,6 +14,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.data.VBItemMappings; import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader; import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings; import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings; import us.myles.ViaVersion.api.data.Mappings;
@ -31,7 +32,7 @@ public class BackwardsMappings {
public static final Map<Integer, String> statisticMappings = new HashMap<>(); public static final Map<Integer, String> statisticMappings = new HashMap<>();
public static final Map<String, String> translateMappings = new HashMap<>(); public static final Map<String, String> translateMappings = new HashMap<>();
public static BlockMappingsShortArray blockMappings; public static BlockMappingsShortArray blockMappings;
public static Mappings soundMappings; public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings; public static VBItemMappings itemMappings;
public static void init() { public static void init() {
@ -42,7 +43,7 @@ public class BackwardsMappings {
ViaBackwards.getPlatform().getLogger().info("Loading 1.13 -> 1.12.2 mappings..."); ViaBackwards.getPlatform().getLogger().info("Loading 1.13 -> 1.12.2 mappings...");
blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks"), mapping1_12_2to1_13.getAsJsonObject("blockstates")); blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks"), mapping1_12_2to1_13.getAsJsonObject("blockstates"));
itemMappings = new VBItemMappings(mapping1_13.getAsJsonObject("items"), mapping1_12.getAsJsonObject("items"), mapping1_12_2to1_13.getAsJsonObject("items")); itemMappings = new VBItemMappings(mapping1_13.getAsJsonObject("items"), mapping1_12.getAsJsonObject("items"), mapping1_12_2to1_13.getAsJsonObject("items"));
soundMappings = new VBMappings(mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"), mapping1_12_2to1_13.getAsJsonObject("sounds")); soundMappings = new VBSoundMappings(mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds"), mapping1_12_2to1_13.getAsJsonObject("sounds"));
for (Map.Entry<String, Integer> entry : StatisticMappings.statistics.entrySet()) { for (Map.Entry<String, Integer> entry : StatisticMappings.statistics.entrySet()) {
statisticMappings.put(entry.getValue(), entry.getKey()); statisticMappings.put(entry.getValue(), entry.getKey());

Datei anzeigen

@ -5,9 +5,7 @@ import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMapping; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.NamedSoundMapping;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
@ -21,23 +19,19 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
// Named Sound Event // Named Sound Event
protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() { protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.STRING); map(Type.STRING);
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String newSound = wrapper.get(Type.STRING, 0); String newSound = wrapper.get(Type.STRING, 0);
String oldSound = NamedSoundMapping.getOldId(newSound); String oldSound = NamedSoundMapping.getOldId(newSound);
if (oldSound != null) { if (oldSound != null || (oldSound = BackwardsMappings.soundMappings.getNewId(newSound)) != null) {
wrapper.set(Type.STRING, 0, oldSound); wrapper.set(Type.STRING, 0, oldSound);
} else if (!Via.getConfig().isSuppressConversionWarnings()) { } else if (!Via.getConfig().isSuppressConversionWarnings()) {
ViaBackwards.getPlatform().getLogger().warning("Unknown named sound in 1.13->1.12 protocol: " + newSound); ViaBackwards.getPlatform().getLogger().warning("Unknown named sound in 1.13->1.12 protocol: " + newSound);
} }
}
}); });
} }
}); });
@ -46,9 +40,7 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() { protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "MC|StopSound"); wrapper.write(Type.STRING, "MC|StopSound");
byte flags = wrapper.read(Type.BYTE); byte flags = wrapper.read(Type.BYTE);
String source; String source;
@ -61,7 +53,6 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
wrapper.write(Type.STRING, source); wrapper.write(Type.STRING, source);
wrapper.write(Type.STRING, sound); wrapper.write(Type.STRING, sound);
}
}); });
} }
}); });
@ -71,9 +62,7 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); map(Type.VAR_INT);
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int newSound = wrapper.get(Type.VAR_INT, 0); int newSound = wrapper.get(Type.VAR_INT, 0);
int oldSound = BackwardsMappings.soundMappings.getNewId(newSound); int oldSound = BackwardsMappings.soundMappings.getNewId(newSound);
if (oldSound == -1) { if (oldSound == -1) {
@ -81,7 +70,6 @@ public class SoundPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
} else { } else {
wrapper.set(Type.VAR_INT, 0, oldSound); wrapper.set(Type.VAR_INT, 0, oldSound);
} }
}
}); });
} }
}); });

Datei anzeigen

@ -49,7 +49,6 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol {
registerOutgoing(State.PLAY, 0x15, 0x16); registerOutgoing(State.PLAY, 0x15, 0x16);
registerOutgoing(State.PLAY, 0x18, 0x19); registerOutgoing(State.PLAY, 0x18, 0x19);
registerOutgoing(State.PLAY, 0x19, 0x1A);
registerOutgoing(State.PLAY, 0x1B, 0x1C); registerOutgoing(State.PLAY, 0x1B, 0x1C);
registerOutgoing(State.PLAY, 0x54, 0x1D); registerOutgoing(State.PLAY, 0x54, 0x1D);
registerOutgoing(State.PLAY, 0x1E, 0x20); registerOutgoing(State.PLAY, 0x1E, 0x20);

Datei anzeigen

@ -4,6 +4,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.data.VBItemMappings; import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader; import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings; import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings; import us.myles.ViaVersion.api.data.Mappings;
import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonObject;
@ -11,7 +12,7 @@ import us.myles.viaversion.libs.gson.JsonObject;
public class BackwardsMappings { public class BackwardsMappings {
public static Mappings blockStateMappings; public static Mappings blockStateMappings;
public static Mappings blockMappings; public static Mappings blockMappings;
public static Mappings soundMappings; public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings; public static VBItemMappings itemMappings;
public static void init() { public static void init() {
@ -23,6 +24,6 @@ public class BackwardsMappings {
blockStateMappings = new VBMappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_13_2.getAsJsonObject("blockstates"), mapping1_13_2to1_14.getAsJsonObject("blockstates")); blockStateMappings = new VBMappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_13_2.getAsJsonObject("blockstates"), mapping1_13_2to1_14.getAsJsonObject("blockstates"));
blockMappings = new VBMappings(mapping1_14.getAsJsonObject("blocks"), mapping1_13_2.getAsJsonObject("blocks"), mapping1_13_2to1_14.getAsJsonObject("blocks"), false); blockMappings = new VBMappings(mapping1_14.getAsJsonObject("blocks"), mapping1_13_2.getAsJsonObject("blocks"), mapping1_13_2to1_14.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_14.getAsJsonObject("items"), mapping1_13_2.getAsJsonObject("items"), mapping1_13_2to1_14.getAsJsonObject("items")); itemMappings = new VBItemMappings(mapping1_14.getAsJsonObject("items"), mapping1_13_2.getAsJsonObject("items"), mapping1_13_2to1_14.getAsJsonObject("items"));
soundMappings = new VBMappings(mapping1_14.getAsJsonArray("sounds"), mapping1_13_2.getAsJsonArray("sounds"), mapping1_13_2to1_14.getAsJsonObject("sounds")); soundMappings = new VBSoundMappings(mapping1_14.getAsJsonArray("sounds"), mapping1_13_2.getAsJsonArray("sounds"), mapping1_13_2to1_14.getAsJsonObject("sounds"));
} }
} }

Datei anzeigen

@ -3,11 +3,11 @@ package nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.Rewriter; import nl.matsv.viabackwards.api.rewriters.Rewriter;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
@ -20,32 +20,15 @@ public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
// Sound Effect SoundRewriter soundRewriter = new SoundRewriter(protocol, BackwardsMappings.soundMappings);
protocol.registerOutgoing(State.PLAY, 0x51, 0x4D, new PacketRemapper() { soundRewriter.registerSound(0x51, 0x4D);
@Override soundRewriter.registerNamedSound(0x19, 0x1A);
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int newId = BackwardsMappings.soundMappings.getNewId(wrapper.get(Type.VAR_INT, 0));
if (newId == -1) {
wrapper.cancel();
} else {
wrapper.set(Type.VAR_INT, 0, newId);
}
}
});
}
});
// Entity Sound Effect // Entity Sound Effect
protocol.registerOutgoing(State.PLAY, 0x50, -1, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x50, -1, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel(); wrapper.cancel();
int soundId = wrapper.read(Type.VAR_INT); int soundId = wrapper.read(Type.VAR_INT);
@ -77,7 +60,6 @@ public class SoundPackets1_14 extends Rewriter<Protocol1_13_2To1_14> {
soundPacket.write(Type.FLOAT, volume); soundPacket.write(Type.FLOAT, volume);
soundPacket.write(Type.FLOAT, pitch); soundPacket.write(Type.FLOAT, pitch);
soundPacket.send(Protocol1_13_2To1_14.class); soundPacket.send(Protocol1_13_2To1_14.class);
}
}); });
} }
}); });

Datei anzeigen

@ -3,6 +3,7 @@ package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping; import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.EntityTypeMapping;
@ -38,6 +39,11 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol {
translatableRewriter.registerTitle(0x50, 0x4F); translatableRewriter.registerTitle(0x50, 0x4F);
translatableRewriter.registerPing(); translatableRewriter.registerPing();
SoundRewriter soundRewriter = new SoundRewriter(this, BackwardsMappings.soundMappings);
soundRewriter.registerSound(0x52, 0x51);
soundRewriter.registerSound(0x51, 0x50);
soundRewriter.registerNamedSound(0x1A, 0x19);
// Explosion - manually send an explosion sound // Explosion - manually send an explosion sound
registerOutgoing(State.PLAY, 0x1D, 0x1C, new PacketRemapper() { registerOutgoing(State.PLAY, 0x1D, 0x1C, new PacketRemapper() {
@Override @Override
@ -63,36 +69,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol {
} }
}); });
// Entity Sound Effect
registerOutgoing(State.PLAY, 0x51, 0x50, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(wrapper -> {
int id = wrapper.get(Type.VAR_INT, 0);
int newId = BackwardsMappings.soundMappings.getNewId(id);
if (newId != -1 && id != newId) {
wrapper.set(Type.VAR_INT, 0, newId);
}
});
}
});
// Sound Effect
registerOutgoing(State.PLAY, 0x52, 0x51, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(wrapper -> {
int id = wrapper.get(Type.VAR_INT, 0);
int newId = BackwardsMappings.soundMappings.getNewId(id);
if (newId != -1 && id != newId) {
wrapper.set(Type.VAR_INT, 0, newId);
}
});
}
});
// Advancements // Advancements
registerOutgoing(State.PLAY, 0x58, 0x57, new PacketRemapper() { registerOutgoing(State.PLAY, 0x58, 0x57, new PacketRemapper() {
@Override @Override
@ -188,7 +164,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol {
registerOutgoing(State.PLAY, 0x14, 0x13); registerOutgoing(State.PLAY, 0x14, 0x13);
registerOutgoing(State.PLAY, 0x16, 0x15); registerOutgoing(State.PLAY, 0x16, 0x15);
registerOutgoing(State.PLAY, 0x19, 0x18); registerOutgoing(State.PLAY, 0x19, 0x18);
registerOutgoing(State.PLAY, 0x1A, 0x19);
registerOutgoing(State.PLAY, 0x1C, 0x1B); registerOutgoing(State.PLAY, 0x1C, 0x1B);
registerOutgoing(State.PLAY, 0x1E, 0x1D); registerOutgoing(State.PLAY, 0x1E, 0x1D);
registerOutgoing(State.PLAY, 0x20, 0x1F); registerOutgoing(State.PLAY, 0x20, 0x1F);

Datei anzeigen

@ -4,6 +4,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.data.VBItemMappings; import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader; import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings; import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings; import us.myles.ViaVersion.api.data.Mappings;
import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonObject;
@ -11,7 +12,7 @@ import us.myles.viaversion.libs.gson.JsonObject;
public class BackwardsMappings { public class BackwardsMappings {
public static Mappings blockStateMappings; public static Mappings blockStateMappings;
public static Mappings blockMappings; public static Mappings blockMappings;
public static Mappings soundMappings; public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings; public static VBItemMappings itemMappings;
public static void init() { public static void init() {
@ -23,6 +24,6 @@ public class BackwardsMappings {
blockStateMappings = new VBMappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"), mapping1_14to1_15.getAsJsonObject("blockstates")); blockStateMappings = new VBMappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"), mapping1_14to1_15.getAsJsonObject("blockstates"));
blockMappings = new VBMappings(mapping1_15.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"), mapping1_14to1_15.getAsJsonObject("blocks"), false); blockMappings = new VBMappings(mapping1_15.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"), mapping1_14to1_15.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_15.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"), mapping1_14to1_15.getAsJsonObject("items")); itemMappings = new VBItemMappings(mapping1_15.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"), mapping1_14to1_15.getAsJsonObject("items"));
soundMappings = new VBMappings(mapping1_15.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"), mapping1_14to1_15.getAsJsonObject("sounds")); soundMappings = new VBSoundMappings(mapping1_15.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"), mapping1_14to1_15.getAsJsonObject("sounds"));
} }
} }

Datei anzeigen

@ -3,6 +3,7 @@ package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16;
import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.BackwardsProtocol;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16;
@ -34,35 +35,10 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol {
translatableRewriter.registerTitle(0x50, 0x50); translatableRewriter.registerTitle(0x50, 0x50);
translatableRewriter.registerPing(); translatableRewriter.registerPing();
// Entity Sound Effect SoundRewriter soundRewriter = new SoundRewriter(this, BackwardsMappings.soundMappings);
registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { soundRewriter.registerSound(0x51, 0x51);
@Override soundRewriter.registerSound(0x52, 0x52);
public void registerMap() { soundRewriter.registerNamedSound(0x1A, 0x1A);
map(Type.VAR_INT); // Sound Id
handler(wrapper -> {
int id = wrapper.get(Type.VAR_INT, 0);
int newId = BackwardsMappings.soundMappings.getNewId(id);
if (newId != -1 && id != newId) {
wrapper.set(Type.VAR_INT, 0, newId);
}
});
}
});
// Sound Effect
registerOutgoing(State.PLAY, 0x52, 0x52, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound Id
handler(wrapper -> {
int id = wrapper.get(Type.VAR_INT, 0);
int newId = BackwardsMappings.soundMappings.getNewId(id);
if (newId != -1 && id != newId) {
wrapper.set(Type.VAR_INT, 0, newId);
}
});
}
});
// Advancements // Advancements
registerOutgoing(State.PLAY, 0x58, 0x58, new PacketRemapper() { registerOutgoing(State.PLAY, 0x58, 0x58, new PacketRemapper() {

Datei anzeigen

@ -4,6 +4,7 @@ import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.data.VBItemMappings; import nl.matsv.viabackwards.api.data.VBItemMappings;
import nl.matsv.viabackwards.api.data.VBMappingDataLoader; import nl.matsv.viabackwards.api.data.VBMappingDataLoader;
import nl.matsv.viabackwards.api.data.VBMappings; import nl.matsv.viabackwards.api.data.VBMappings;
import nl.matsv.viabackwards.api.data.VBSoundMappings;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings; import us.myles.ViaVersion.api.data.Mappings;
import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonObject;
@ -11,7 +12,7 @@ import us.myles.viaversion.libs.gson.JsonObject;
public class BackwardsMappings { public class BackwardsMappings {
public static Mappings blockStateMappings; public static Mappings blockStateMappings;
public static Mappings blockMappings; public static Mappings blockMappings;
public static Mappings soundMappings; public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings; public static VBItemMappings itemMappings;
public static void init() { public static void init() {
@ -23,6 +24,6 @@ public class BackwardsMappings {
blockStateMappings = new VBMappings(mapping1_16.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), mapping1_15to1_16.getAsJsonObject("blockstates")); blockStateMappings = new VBMappings(mapping1_16.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), mapping1_15to1_16.getAsJsonObject("blockstates"));
blockMappings = new VBMappings(mapping1_16.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"), mapping1_15to1_16.getAsJsonObject("blocks"), false); blockMappings = new VBMappings(mapping1_16.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"), mapping1_15to1_16.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_16.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"), mapping1_15to1_16.getAsJsonObject("items")); itemMappings = new VBItemMappings(mapping1_16.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"), mapping1_15to1_16.getAsJsonObject("items"));
soundMappings = new VBMappings(mapping1_16.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), mapping1_15to1_16.getAsJsonObject("sounds")); soundMappings = new VBSoundMappings(mapping1_16.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), mapping1_15to1_16.getAsJsonObject("sounds"));
} }
} }

Datei anzeigen

@ -10,7 +10,7 @@
package nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets; package nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets;
import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.api.rewriters.LegacySoundRewriter;
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -19,7 +19,7 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
public class SoundPackets1_10 extends SoundRewriter<Protocol1_9_4To1_10> { public class SoundPackets1_10 extends LegacySoundRewriter<Protocol1_9_4To1_10> {
protected static ValueTransformer<Float, Short> toOldPitch = new ValueTransformer<Float, Short>(Type.UNSIGNED_BYTE) { protected static ValueTransformer<Float, Short> toOldPitch = new ValueTransformer<Float, Short>(Type.UNSIGNED_BYTE) {
public Short transform(PacketWrapper packetWrapper, Float inputValue) throws Exception { public Short transform(PacketWrapper packetWrapper, Float inputValue) throws Exception {
return (short) Math.round(inputValue * 63.5F); return (short) Math.round(inputValue * 63.5F);