diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java index 8f14a4be2..809eaf725 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/ProtocolSnapshotTo1_12_2.java @@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; +import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.MappingData; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.WorldPackets; @@ -285,8 +286,25 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol { registerOutgoing(State.PLAY, 0x46, 0x48); registerOutgoing(State.PLAY, 0x47, 0x49); registerOutgoing(State.PLAY, 0x48, 0x4A); - // New packet 0x4A - Stop sound (TODO: Migrate from Plugin Messages) - registerOutgoing(State.PLAY, 0x49, 0x4C); + + // Sound Effect packet + registerOutgoing(State.PLAY, 0x49, 0x4C, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Sound ID + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int soundId = wrapper.get(Type.VAR_INT, 0); + + // Handle new 'Pumpkin Carve' sound + if (soundId >= 86) + wrapper.set(Type.VAR_INT, 0, soundId + 1); + } + }); + } + }); registerOutgoing(State.PLAY, 0x4A, 0x4D); registerOutgoing(State.PLAY, 0x4B, 0x4E); registerOutgoing(State.PLAY, 0x4C, 0x4F); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/MappingData.java similarity index 97% rename from common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MappingData.java rename to common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/MappingData.java index bd095591e..3987ae3c3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/MappingData.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2; +package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data; import com.google.gson.JsonElement; import com.google.gson.JsonObject; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/SoundSource.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/SoundSource.java new file mode 100644 index 000000000..f2833d303 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/SoundSource.java @@ -0,0 +1,30 @@ +package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data; + +import com.google.common.base.Optional; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum SoundSource { + MASTER("master", 0), + MUSIC("music", 1), + RECORD("record", 2), + WEATHER("weather", 3), + BLOCK("block", 4), + HOSTILE("hostile", 5), + NEUTRAL("neutral", 6), + PLAYER("player", 7), + AMBIENT("ambient", 8), + VOICE("voice", 9); + + private final String name; + private final int id; + + public static Optional findBySource(String source) { + for (SoundSource item : SoundSource.values()) + if (item.getName().equalsIgnoreCase(source)) + return Optional.of(item); + return Optional.absent(); + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java index 7a98f5e1f..da311be98 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java @@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; +import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.protocol.Protocol; @@ -9,7 +10,8 @@ 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; -import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.MappingData; +import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.MappingData; +import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.SoundSource; public class InventoryPackets { private static String NBT_TAG_NAME; @@ -67,8 +69,37 @@ public class InventoryPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - // TODO: StopSound? - if (wrapper.get(Type.STRING, 0).equalsIgnoreCase("MC|TrList")) { + String channel = wrapper.get(Type.STRING, 0); + // Handle stopsound change + if (channel.equalsIgnoreCase("MC|StopSound")) { + String originalSource = wrapper.read(Type.STRING); + String originalSound = wrapper.read(Type.STRING); + + // Reset the packet + wrapper.clearPacket(); + wrapper.setId(0x4B); + + byte flags = 0; + wrapper.write(Type.BYTE, flags); // Placeholder + if (!originalSource.isEmpty()) { + flags |= 1; + Optional finalSource = SoundSource.findBySource(originalSource); + if (!finalSource.isPresent()) { + System.out.println("Could not handle unknown sound source " + originalSource + " falling back to default: master"); + finalSource = Optional.of(SoundSource.MASTER); + } + + System.out.println(finalSource.get()); + wrapper.write(Type.VAR_INT, finalSource.get().getId()); + } + if (!originalSound.isEmpty()) { + flags |= 2; + wrapper.write(Type.STRING, originalSound); + } + + wrapper.set(Type.BYTE, 0, flags); // Update flags + } + if (channel.equalsIgnoreCase("MC|TrList")) { wrapper.passthrough(Type.INT); // Passthrough Window ID int size = wrapper.passthrough(Type.UNSIGNED_BYTE); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/WorldPackets.java index 75772eeb9..9ec2d9399 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/WorldPackets.java @@ -15,7 +15,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.MappingData; +import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.MappingData; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.providers.BlockEntityProvider; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.storage.BlockStorage;