mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-14 10:55:20 +01:00
Rewrite SoundRewriter and generate placeholders for 1.11
This commit is contained in:
parent
373f519464
commit
5ef109c037
@ -11,4 +11,5 @@ TODO:
|
||||
|
||||
- Entity names that changed?
|
||||
- llama inventory slots
|
||||
- Rewrite Shulker box name
|
||||
- Rewrite Shulker box name
|
||||
- Play Guardian effect for totems?
|
@ -23,4 +23,5 @@ public class ViaBackwards {
|
||||
|
||||
ViaBackwards.platform = platform;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class SoundIdRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||
private Map<Integer, Integer> soundRewriter = new ConcurrentHashMap<>();
|
||||
private Map<Integer, Float> pitchRewriter = new ConcurrentHashMap<>();
|
||||
|
||||
protected void rewriteSound(int newId, int oldId) {
|
||||
soundRewriter.put(newId, oldId);
|
||||
}
|
||||
|
||||
protected void rewriteSound(int newId, int oldId, float newPitch) {
|
||||
rewriteSound(newId, oldId);
|
||||
pitchRewriter.put(newId, newPitch);
|
||||
}
|
||||
|
||||
public int handleSounds(int soundId) {
|
||||
int newSoundId = soundId;
|
||||
if (soundRewriter.containsKey(soundId))
|
||||
newSoundId = soundId = soundRewriter.get(soundId);
|
||||
for (Integer i : soundRewriter.keySet()) {
|
||||
if (soundId > i)
|
||||
newSoundId--;
|
||||
}
|
||||
return newSoundId;
|
||||
}
|
||||
|
||||
public boolean hasPitch(int soundId) {
|
||||
return pitchRewriter.containsKey(soundId);
|
||||
}
|
||||
|
||||
public float handlePitch(int soundId) {
|
||||
if (pitchRewriter.containsKey(soundId))
|
||||
return pitchRewriter.get(soundId);
|
||||
return -1;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class SoundRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||
private Map<Integer, SoundData> soundRewrites = new HashMap<>();
|
||||
|
||||
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;
|
||||
if (soundRewrites.containsKey(soundId))
|
||||
return soundRewrites.get(soundId).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) {
|
||||
if (soundRewrites.containsKey(soundId))
|
||||
return soundRewrites.get(soundId).isChangePitch();
|
||||
return false;
|
||||
}
|
||||
|
||||
public float handlePitch(int soundId) {
|
||||
if (soundRewrites.containsKey(soundId))
|
||||
return soundRewrites.get(soundId).getNewPitch();
|
||||
return 1f;
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class SoundData {
|
||||
private int replacementSound;
|
||||
private boolean changePitch = false;
|
||||
private float newPitch = 1f;
|
||||
private boolean added;
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.BlockItemPackets;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.EntityPackets;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.PlayerPackets;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.SoundPackets;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
@ -28,6 +29,7 @@ public class Protocol1_10To1_11 extends BackwardsProtocol {
|
||||
(entityPackets = new EntityPackets()).register(this);
|
||||
new PlayerPackets().register(this);
|
||||
new BlockItemPackets().register(this);
|
||||
new SoundPackets().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.protocol.protocol1_10to1_11.packets;
|
||||
|
||||
import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
||||
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.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
|
||||
public class SoundPackets extends SoundRewriter<Protocol1_10To1_11> {
|
||||
@Override
|
||||
protected void registerPackets(Protocol1_10To1_11 protocol) {
|
||||
// Named sound effect
|
||||
protocol.registerOutgoing(State.PLAY, 0x19, 0x19, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING); // 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
|
||||
}
|
||||
});
|
||||
|
||||
// Sound effect
|
||||
protocol.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 oldId = wrapper.get(Type.VAR_INT, 0);
|
||||
int newId = handleSounds(oldId);
|
||||
if (newId == -1)
|
||||
wrapper.cancel();
|
||||
else {
|
||||
if (hasPitch(oldId))
|
||||
wrapper.set(Type.FLOAT, 0, handlePitch(oldId));
|
||||
wrapper.set(Type.VAR_INT, 0, newId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// TODO find good replacement sounds
|
||||
// Automatically generated from PAaaS
|
||||
added(85, -1); // block.shulker_box.close
|
||||
added(86, -1); // block.shulker_box.open
|
||||
|
||||
added(176, -1); // entity.elder_guardian.flop
|
||||
|
||||
removed(196); // entity.experience_orb.touch
|
||||
|
||||
added(197, -1); // entity.evocation_fangs.attack
|
||||
added(198, -1); // entity.evocation_illager.ambient
|
||||
added(199, -1); // entity.evocation_illager.cast_spell
|
||||
added(200, -1); // entity.evocation_illager.death
|
||||
added(201, -1); // entity.evocation_illager.hurt
|
||||
added(202, -1); // entity.evocation_illager.prepare_attack
|
||||
added(203, -1); // entity.evocation_illager.prepare_summon
|
||||
added(204, -1); // entity.evocation_illager.prepare_wololo
|
||||
|
||||
added(279, -1); // entity.llama.ambient
|
||||
added(280, -1); // entity.llama.angry
|
||||
added(281, -1); // entity.llama.chest
|
||||
added(282, -1); // entity.llama.death
|
||||
added(283, -1); // entity.llama.eat
|
||||
added(284, -1); // entity.llama.hurt
|
||||
added(285, -1); // entity.llama.spit
|
||||
added(286, -1); // entity.llama.step
|
||||
added(287, -1); // entity.llama.swag
|
||||
added(296, -1); // entity.mule.chest
|
||||
|
||||
added(390, -1); // entity.vex.ambient
|
||||
added(391, -1); // entity.vex.charge
|
||||
added(392, -1); // entity.vex.death
|
||||
added(393, -1); // entity.vex.hurt
|
||||
|
||||
added(400, -1); // entity.vindication_illager.ambient
|
||||
added(401, -1); // entity.vindication_illager.death
|
||||
added(402, -1); // entity.vindication_illager.hurt
|
||||
|
||||
added(450, -1); // item.armor.equip_elytra
|
||||
added(455, -1); // item.bottle.empty
|
||||
added(470, -1); // item.totem.use
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
|
||||
package nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets;
|
||||
|
||||
import nl.matsv.viabackwards.api.rewriters.SoundIdRewriter;
|
||||
import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
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.packets.State;
|
||||
|
||||
public class SoundPackets extends SoundIdRewriter<Protocol1_9_4To1_10> {
|
||||
public class SoundPackets extends SoundRewriter<Protocol1_9_4To1_10> {
|
||||
protected static ValueTransformer<Float, Short> toOldPitch = new ValueTransformer<Float, Short>(Type.UNSIGNED_BYTE) {
|
||||
public Short transform(PacketWrapper packetWrapper, Float inputValue) throws Exception {
|
||||
return (short) Math.round(inputValue * 63.5F);
|
||||
@ -74,32 +74,33 @@ public class SoundPackets extends SoundIdRewriter<Protocol1_9_4To1_10> {
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
rewriteSound(24, -1); // Enchantment table sound
|
||||
|
||||
added(24, -1); // Enchantment table sound
|
||||
|
||||
// Husk
|
||||
rewriteSound(249, 400); // Husk -> Zombie ambient
|
||||
rewriteSound(250, 404); // Husk -> Zombie death
|
||||
rewriteSound(251, 405); // Husk -> Zombie hurt
|
||||
rewriteSound(252, 407); // Husk -> Zombie step
|
||||
added(249, 381); // Husk -> Zombie ambient
|
||||
added(250, 385); // Husk -> Zombie death
|
||||
added(251, 386); // Husk -> Zombie hurt
|
||||
added(252, 388); // Husk -> Zombie step
|
||||
|
||||
// Polar bear
|
||||
rewriteSound(301, 400, .6F); // Polar bear ambient
|
||||
rewriteSound(302, 400, 1.9F); // Polar baby bear ambient
|
||||
rewriteSound(303, 404, .7F); // Polar bear death
|
||||
rewriteSound(304, 320, .6F); // Polar bear hurt
|
||||
rewriteSound(305, 241, .6F); // Polar bear step
|
||||
rewriteSound(306, 393, 1.2F); // Polar bear warning
|
||||
added(301, 381, .6F); // Polar bear ambient -> Zombie ambient
|
||||
added(302, 381, 1.9F); // Polar baby bear ambient -> Zombie ambient
|
||||
added(303, 385, .7F); // Polar bear death -> Zombie death
|
||||
added(304, 309, .6F); // Polar bear hurt -> Shulker hurt
|
||||
added(305, 240, .6F); // Polar bear step -> Horse step
|
||||
added(306, 374, 1.2F); // Polar bear warning -> Wolf growl
|
||||
|
||||
// Stray
|
||||
rewriteSound(365, 331); // Stray -> Skeleton ambient
|
||||
rewriteSound(366, 332); // Stray -> Skeleton death
|
||||
rewriteSound(367, 333); // Stray -> Skeleton hurt
|
||||
rewriteSound(368, 335); // Stray -> Skeleton step
|
||||
added(365, 320); // Stray -> Skeleton ambient
|
||||
added(366, 321); // Stray -> Skeleton death
|
||||
added(367, 322); // Stray -> Skeleton hurt
|
||||
added(368, 324); // Stray -> Skeleton step
|
||||
|
||||
// Wither skeleton
|
||||
rewriteSound(387, 331); // Wither skeleton -> Skeleton ambient
|
||||
rewriteSound(388, 332); // Wither skeleton -> Skeleton death
|
||||
rewriteSound(389, 333); // Wither skeleton -> Skeleton hurt
|
||||
rewriteSound(390, 335); // Wither skeleton -> Skeleton step
|
||||
added(387, 320); // Wither skeleton -> Skeleton ambient
|
||||
added(388, 321); // Wither skeleton -> Skeleton death
|
||||
added(389, 322); // Wither skeleton -> Skeleton hurt
|
||||
added(390, 324); // Wither skeleton -> Skeleton step
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user