From 2c9cd7ed02b79c61f43d4bb968a2e218343e40f2 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 16 Jun 2021 11:05:10 -0400 Subject: [PATCH] Don't hardcode record IDs and fix records for 1.17 --- .../network/translators/effect/EffectRegistry.java | 11 +++-------- .../network/translators/item/ItemRegistry.java | 7 ++++++- connector/src/main/resources/mappings | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java index f767b5827..91b21fb2a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/effect/EffectRegistry.java @@ -127,20 +127,15 @@ public class EffectRegistry { javaEffect = SoundEffect.valueOf(entry.getKey()); String name = node.get("name").asText(); float volume = node.has("volume") ? node.get("volume").floatValue() : 1.0f; - boolean pitchSub = node.has("pitch_sub") ? node.get("pitch_sub").booleanValue() : false; + boolean pitchSub = node.has("pitch_sub") && node.get("pitch_sub").booleanValue(); float pitchMul = node.has("pitch_mul") ? node.get("pitch_mul").floatValue() : 1.0f; float pitchAdd = node.has("pitch_add") ? node.get("pitch_add").floatValue() : 0.0f; - boolean relative = node.has("relative") ? node.get("relative").booleanValue() : true; + boolean relative = node.has("relative") && node.get("relative").booleanValue(); effect = new PlaySoundEffect(name, volume, pitchSub, pitchMul, pitchAdd, relative); break; } case "record": { - JsonNode records = entry.getValue().get("records"); - Iterator> recordsIterator = records.fields(); - while (recordsIterator.hasNext()) { - Map.Entry recordEntry = recordsIterator.next(); - RECORDS.put(Integer.parseInt(recordEntry.getKey()), SoundEvent.valueOf(recordEntry.getValue().asText())); - } + // Special case handled in ItemRegistry break; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java index f428d37e9..0e5fc5819 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java @@ -33,6 +33,7 @@ import com.nukkitx.nbt.NbtMap; import com.nukkitx.nbt.NbtMapBuilder; import com.nukkitx.nbt.NbtType; import com.nukkitx.nbt.NbtUtils; +import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.data.inventory.ComponentItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.packet.StartGamePacket; @@ -44,10 +45,10 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.network.translators.effect.EffectRegistry; import org.geysermc.connector.network.translators.world.block.BlockTranslator; import org.geysermc.connector.network.translators.world.block.BlockTranslator1_17_0; import org.geysermc.connector.utils.FileUtils; -import org.geysermc.connector.utils.LanguageUtils; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -466,6 +467,10 @@ public class ItemRegistry { .damage(itemEntry.getBedrockData()) .count(1) .blockRuntimeId(itemEntry.getBedrockBlockId()).build()); + } else if (entry.getKey().startsWith("minecraft:music_disc_")) { + // The Java record level event uses the item ID as the "key" to play the record + EffectRegistry.RECORDS.put(itemIndex, SoundEvent.valueOf("RECORD_" + + entry.getKey().replace("minecraft:music_disc_", "").toUpperCase(Locale.ENGLISH))); } itemNames.add(entry.getKey()); diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index 6687e1480..e7c1e3211 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 6687e1480c65614e49f313afee81a9eaa39803b7 +Subproject commit e7c1e32117b8d5011ebe0ba86559285b6d8dfecf