Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 00:00:33 +01:00
Map named sound packets, some cleanup
Dieser Commit ist enthalten in:
Ursprung
2b269a6563
Commit
8087b42c40
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 SoundData added(int id, int replacement, float newPitch) {
|
public void registerMap() {
|
||||||
SoundData data = new SoundData(replacement, true, newPitch, true);
|
map(Type.VAR_INT); // Sound Id
|
||||||
soundRewrites.put(id, data);
|
handler(wrapper -> {
|
||||||
return data;
|
int soundId = wrapper.get(Type.VAR_INT, 0);
|
||||||
}
|
int mappedId = soundMappings.getNewId(soundId);
|
||||||
|
if (mappedId != -1 && soundId != mappedId) {
|
||||||
public SoundData removed(int id) {
|
wrapper.set(Type.VAR_INT, 0, mappedId);
|
||||||
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) {
|
public void registerNamedSound(int oldId, int newId) {
|
||||||
SoundData data = soundRewrites.get(soundId);
|
protocol.registerOutgoing(State.PLAY, oldId, newId, new PacketRemapper() {
|
||||||
return data != null && data.isChangePitch();
|
@Override
|
||||||
}
|
public void registerMap() {
|
||||||
|
map(Type.STRING); // Sound identifier
|
||||||
public float handlePitch(int soundId) {
|
handler(wrapper -> {
|
||||||
SoundData data = soundRewrites.get(soundId);
|
String soundId = wrapper.get(Type.STRING, 0);
|
||||||
return data != null ? data.getNewPitch() : 1F;
|
String mappedId = soundMappings.getNewId(soundId);
|
||||||
}
|
if (mappedId == null) return;
|
||||||
|
if (!mappedId.isEmpty()) {
|
||||||
public static final class SoundData {
|
wrapper.set(Type.STRING, 0, mappedId);
|
||||||
private final int replacementSound;
|
} else {
|
||||||
private final boolean changePitch;
|
wrapper.cancel();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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());
|
||||||
|
@ -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,22 +19,18 @@ 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
|
String newSound = wrapper.get(Type.STRING, 0);
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
String oldSound = NamedSoundMapping.getOldId(newSound);
|
||||||
String newSound = wrapper.get(Type.STRING, 0);
|
if (oldSound != null || (oldSound = BackwardsMappings.soundMappings.getNewId(newSound)) != null) {
|
||||||
String oldSound = NamedSoundMapping.getOldId(newSound);
|
wrapper.set(Type.STRING, 0, oldSound);
|
||||||
if (oldSound != null) {
|
} else if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||||
wrapper.set(Type.STRING, 0, oldSound);
|
ViaBackwards.getPlatform().getLogger().warning("Unknown named sound in 1.13->1.12 protocol: " + newSound);
|
||||||
} else if (!Via.getConfig().isSuppressConversionWarnings()) {
|
|
||||||
ViaBackwards.getPlatform().getLogger().warning("Unknown named sound in 1.13->1.12 protocol: " + newSound);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -46,22 +40,19 @@ 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
|
wrapper.write(Type.STRING, "MC|StopSound");
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
byte flags = wrapper.read(Type.BYTE);
|
||||||
wrapper.write(Type.STRING, "MC|StopSound");
|
String source;
|
||||||
byte flags = wrapper.read(Type.BYTE);
|
if ((flags & 0x01) != 0) {
|
||||||
String source;
|
source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)];
|
||||||
if ((flags & 0x01) != 0) {
|
} else {
|
||||||
source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)];
|
source = "";
|
||||||
} else {
|
|
||||||
source = "";
|
|
||||||
}
|
|
||||||
String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : "";
|
|
||||||
|
|
||||||
wrapper.write(Type.STRING, source);
|
|
||||||
wrapper.write(Type.STRING, sound);
|
|
||||||
}
|
}
|
||||||
|
String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : "";
|
||||||
|
|
||||||
|
wrapper.write(Type.STRING, source);
|
||||||
|
wrapper.write(Type.STRING, sound);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -71,16 +62,13 @@ 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
|
int newSound = wrapper.get(Type.VAR_INT, 0);
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
int oldSound = BackwardsMappings.soundMappings.getNewId(newSound);
|
||||||
int newSound = wrapper.get(Type.VAR_INT, 0);
|
if (oldSound == -1) {
|
||||||
int oldSound = BackwardsMappings.soundMappings.getNewId(newSound);
|
wrapper.cancel();
|
||||||
if (oldSound == -1) {
|
} else {
|
||||||
wrapper.cancel();
|
wrapper.set(Type.VAR_INT, 0, oldSound);
|
||||||
} else {
|
|
||||||
wrapper.set(Type.VAR_INT, 0, oldSound);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,64 +20,46 @@ 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
|
wrapper.cancel();
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
wrapper.cancel();
|
|
||||||
|
|
||||||
int soundId = wrapper.read(Type.VAR_INT);
|
int soundId = wrapper.read(Type.VAR_INT);
|
||||||
int newId = BackwardsMappings.soundMappings.getNewId(soundId);
|
int newId = BackwardsMappings.soundMappings.getNewId(soundId);
|
||||||
if (newId == -1) return;
|
if (newId == -1) return;
|
||||||
|
|
||||||
int category = wrapper.read(Type.VAR_INT);
|
int category = wrapper.read(Type.VAR_INT);
|
||||||
int entityId = wrapper.read(Type.VAR_INT);
|
int entityId = wrapper.read(Type.VAR_INT);
|
||||||
|
|
||||||
EntityTracker.StoredEntity storedEntity = wrapper.user().get(EntityTracker.class).get(protocol).getEntity(entityId);
|
EntityTracker.StoredEntity storedEntity = wrapper.user().get(EntityTracker.class).get(protocol).getEntity(entityId);
|
||||||
EntityPositionStorage1_14 entityStorage;
|
EntityPositionStorage1_14 entityStorage;
|
||||||
if (storedEntity == null || (entityStorage = storedEntity.get(EntityPositionStorage1_14.class)) == null) {
|
if (storedEntity == null || (entityStorage = storedEntity.get(EntityPositionStorage1_14.class)) == null) {
|
||||||
ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId);
|
ViaBackwards.getPlatform().getLogger().warning("Untracked entity with id " + entityId);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
float volume = wrapper.read(Type.FLOAT);
|
|
||||||
float pitch = wrapper.read(Type.FLOAT);
|
|
||||||
int x = (int) (entityStorage.getX() * 8D);
|
|
||||||
int y = (int) (entityStorage.getY() * 8D);
|
|
||||||
int z = (int) (entityStorage.getZ() * 8D);
|
|
||||||
|
|
||||||
PacketWrapper soundPacket = wrapper.create(0x4D);
|
|
||||||
soundPacket.write(Type.VAR_INT, newId);
|
|
||||||
soundPacket.write(Type.VAR_INT, category);
|
|
||||||
soundPacket.write(Type.INT, x);
|
|
||||||
soundPacket.write(Type.INT, y);
|
|
||||||
soundPacket.write(Type.INT, z);
|
|
||||||
soundPacket.write(Type.FLOAT, volume);
|
|
||||||
soundPacket.write(Type.FLOAT, pitch);
|
|
||||||
soundPacket.send(Protocol1_13_2To1_14.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float volume = wrapper.read(Type.FLOAT);
|
||||||
|
float pitch = wrapper.read(Type.FLOAT);
|
||||||
|
int x = (int) (entityStorage.getX() * 8D);
|
||||||
|
int y = (int) (entityStorage.getY() * 8D);
|
||||||
|
int z = (int) (entityStorage.getZ() * 8D);
|
||||||
|
|
||||||
|
PacketWrapper soundPacket = wrapper.create(0x4D);
|
||||||
|
soundPacket.write(Type.VAR_INT, newId);
|
||||||
|
soundPacket.write(Type.VAR_INT, category);
|
||||||
|
soundPacket.write(Type.INT, x);
|
||||||
|
soundPacket.write(Type.INT, y);
|
||||||
|
soundPacket.write(Type.INT, z);
|
||||||
|
soundPacket.write(Type.FLOAT, volume);
|
||||||
|
soundPacket.write(Type.FLOAT, pitch);
|
||||||
|
soundPacket.send(Protocol1_13_2To1_14.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -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);
|
||||||
|
@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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() {
|
||||||
|
@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren