mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-19 14:59:27 +00:00
Fix button sounds (#5367)
* fix buttons * delete unused mapper * remove ignore arm swing * Update mappings
This commit is contained in:
@@ -630,7 +630,7 @@ public final class Blocks {
|
||||
public static final Block REDSTONE_WALL_TORCH = register(new Block("redstone_wall_torch", builder().pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(LIT)));
|
||||
public static final Block STONE_BUTTON = register(new Block("stone_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block STONE_BUTTON = register(new ButtonBlock("stone_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
@@ -997,43 +997,43 @@ public final class Blocks {
|
||||
.intState(AGE_7)));
|
||||
public static final Block POTATOES = register(new Block("potatoes", builder().pushReaction(PistonBehavior.DESTROY)
|
||||
.intState(AGE_7)));
|
||||
public static final Block OAK_BUTTON = register(new Block("oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block OAK_BUTTON = register(new ButtonBlock("oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block SPRUCE_BUTTON = register(new Block("spruce_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block SPRUCE_BUTTON = register(new ButtonBlock("spruce_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block BIRCH_BUTTON = register(new Block("birch_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block BIRCH_BUTTON = register(new ButtonBlock("birch_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block JUNGLE_BUTTON = register(new Block("jungle_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block JUNGLE_BUTTON = register(new ButtonBlock("jungle_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block ACACIA_BUTTON = register(new Block("acacia_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block ACACIA_BUTTON = register(new ButtonBlock("acacia_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block CHERRY_BUTTON = register(new Block("cherry_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block CHERRY_BUTTON = register(new ButtonBlock("cherry_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block DARK_OAK_BUTTON = register(new Block("dark_oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block DARK_OAK_BUTTON = register(new ButtonBlock("dark_oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block PALE_OAK_BUTTON = register(new Block("pale_oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block PALE_OAK_BUTTON = register(new ButtonBlock("pale_oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block MANGROVE_BUTTON = register(new Block("mangrove_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block MANGROVE_BUTTON = register(new ButtonBlock("mangrove_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block BAMBOO_BUTTON = register(new Block("bamboo_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block BAMBOO_BUTTON = register(new ButtonBlock("bamboo_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
@@ -2232,11 +2232,11 @@ public final class Blocks {
|
||||
.enumState(HALF)
|
||||
.enumState(STAIRS_SHAPE)
|
||||
.booleanState(WATERLOGGED)));
|
||||
public static final Block CRIMSON_BUTTON = register(new Block("crimson_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block CRIMSON_BUTTON = register(new ButtonBlock("crimson_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block WARPED_BUTTON = register(new Block("warped_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block WARPED_BUTTON = register(new ButtonBlock("warped_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
@@ -2336,7 +2336,7 @@ public final class Blocks {
|
||||
.booleanState(WATERLOGGED)));
|
||||
public static final Block POLISHED_BLACKSTONE_PRESSURE_PLATE = register(new Block("polished_blackstone_pressure_plate", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.booleanState(POWERED)));
|
||||
public static final Block POLISHED_BLACKSTONE_BUTTON = register(new Block("polished_blackstone_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
public static final Block POLISHED_BLACKSTONE_BUTTON = register(new ButtonBlock("polished_blackstone_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
|
||||
.enumState(ATTACH_FACE)
|
||||
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
|
||||
.booleanState(POWERED)));
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2025 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.level.block.type;
|
||||
|
||||
public class ButtonBlock extends Block {
|
||||
public ButtonBlock(String javaIdentifier, Builder builder) {
|
||||
super(javaIdentifier, builder);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
package org.geysermc.geyser.registry.loader;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.registry.type.SoundMapping;
|
||||
|
||||
@@ -39,7 +40,6 @@ import java.util.Map;
|
||||
* Loads sounds from the given input.
|
||||
*/
|
||||
public class SoundRegistryLoader implements RegistryLoader<String, Map<String, SoundMapping>> {
|
||||
|
||||
@Override
|
||||
public Map<String, SoundMapping> load(String input) {
|
||||
JsonNode soundsTree;
|
||||
@@ -51,7 +51,7 @@ public class SoundRegistryLoader implements RegistryLoader<String, Map<String, S
|
||||
|
||||
Map<String, SoundMapping> soundMappings = new HashMap<>();
|
||||
Iterator<Map.Entry<String, JsonNode>> soundsIterator = soundsTree.fields();
|
||||
while(soundsIterator.hasNext()) {
|
||||
while (soundsIterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> next = soundsIterator.next();
|
||||
JsonNode brMap = next.getValue();
|
||||
String javaSound = next.getKey();
|
||||
@@ -61,7 +61,8 @@ public class SoundRegistryLoader implements RegistryLoader<String, Map<String, S
|
||||
brMap.has("playsound_mapping") && brMap.get("playsound_mapping").isTextual() ? brMap.get("playsound_mapping").asText() : null,
|
||||
brMap.has("extra_data") && brMap.get("extra_data").isInt() ? brMap.get("extra_data").asInt() : -1,
|
||||
brMap.has("identifier") && brMap.get("identifier").isTextual() ? brMap.get("identifier").asText() : null,
|
||||
brMap.has("level_event") && brMap.get("level_event").isBoolean() && brMap.get("level_event").asBoolean()
|
||||
brMap.has("level_event") && brMap.get("level_event").isBoolean() && brMap.get("level_event").asBoolean(),
|
||||
brMap.has("pitch_adjust") && brMap.get("pitch_adjust").isNumber() ? brMap.get("pitch_adjust").floatValue() : 1.0f
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,23 +25,15 @@
|
||||
|
||||
package org.geysermc.geyser.registry.type;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class SoundMapping {
|
||||
String java;
|
||||
String bedrock;
|
||||
String playsound;
|
||||
int extraData;
|
||||
String identifier;
|
||||
boolean levelEvent;
|
||||
|
||||
public SoundMapping(String java, String bedrock, String playsound, int extraData, String identifier, boolean levelEvent) {
|
||||
public record SoundMapping(String java, String bedrock, String playsound, int extraData, String identifier,
|
||||
boolean levelEvent, float pitchAdjust) {
|
||||
public SoundMapping(String java, String bedrock, String playsound, int extraData, String identifier, boolean levelEvent, float pitchAdjust) {
|
||||
this.java = java;
|
||||
this.bedrock = bedrock == null || bedrock.isEmpty() ? null : bedrock;
|
||||
this.playsound = playsound == null || playsound.isEmpty() ? null : playsound;
|
||||
this.extraData = extraData;
|
||||
this.identifier = identifier == null || identifier.isEmpty() ? ":" : identifier;
|
||||
this.levelEvent = levelEvent;
|
||||
this.pitchAdjust = pitchAdjust;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ import org.geysermc.geyser.level.block.Blocks;
|
||||
import org.geysermc.geyser.level.block.property.Properties;
|
||||
import org.geysermc.geyser.level.block.type.Block;
|
||||
import org.geysermc.geyser.level.block.type.BlockState;
|
||||
import org.geysermc.geyser.level.block.type.ButtonBlock;
|
||||
import org.geysermc.geyser.level.block.type.CauldronBlock;
|
||||
import org.geysermc.geyser.level.block.type.SkullBlock;
|
||||
import org.geysermc.geyser.registry.BlockRegistries;
|
||||
@@ -279,8 +280,14 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
Block place checks end - client is good to go
|
||||
*/
|
||||
|
||||
BlockState blockState = session.getGeyser().getWorldManager().blockAt(session, packet.getBlockPosition());
|
||||
|
||||
// Buttons on Java Edition cannot be interacted with when they are powered
|
||||
if (blockState.block() instanceof ButtonBlock && blockState.getValue(Properties.POWERED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.getItemInHand() != null && session.getItemMappings().getMapping(packet.getItemInHand()).getJavaItem() instanceof SpawnEggItem) {
|
||||
BlockState blockState = session.getGeyser().getWorldManager().blockAt(session, packet.getBlockPosition());
|
||||
if (blockState.is(Blocks.WATER) && blockState.getValue(Properties.LEVEL) == 0) {
|
||||
// Otherwise causes multiple mobs to spawn - just send a use item packet
|
||||
useItem(session, packet, blockState.javaId());
|
||||
@@ -304,7 +311,6 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||
Item item = session.getPlayerInventory().getItemInHand().asItem();
|
||||
if (packet.getItemInHand() != null) {
|
||||
ItemDefinition definition = packet.getItemInHand().getDefinition();
|
||||
BlockState blockState = session.getGeyser().getWorldManager().blockAt(session, packet.getBlockPosition());
|
||||
// Otherwise boats will not be able to be placed in survival and buckets, lily pads, frogspawn, and glass bottles won't work on mobile
|
||||
if (item instanceof BoatItem || item == Items.LILY_PAD || item == Items.FROGSPAWN) {
|
||||
useItem(session, packet, blockState.javaId());
|
||||
|
||||
@@ -70,7 +70,6 @@ final class BedrockBlockActions {
|
||||
PlayerActionType action = blockActionData.getAction();
|
||||
Vector3i vector = blockActionData.getBlockPosition();
|
||||
int blockFace = blockActionData.getFace();
|
||||
|
||||
switch (action) {
|
||||
case DROP_ITEM -> {
|
||||
ServerboundPlayerActionPacket dropItemPacket = new ServerboundPlayerActionPacket(PlayerAction.DROP_ITEM,
|
||||
|
||||
@@ -90,7 +90,7 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
|
||||
SoundMapping mapping = Registries.SOUNDS.get(jukeboxSong.soundEvent().replace("minecraft:", ""));
|
||||
SoundEvent soundEvent = null;
|
||||
if (mapping != null) {
|
||||
String bedrock = mapping.getBedrock();
|
||||
String bedrock = mapping.bedrock();
|
||||
if (bedrock != null && !bedrock.isEmpty()) {
|
||||
soundEvent = SoundUtils.toSoundEvent(bedrock);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.translator.sound.block;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3f;
|
||||
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
|
||||
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.level.block.property.Properties;
|
||||
import org.geysermc.geyser.level.block.type.BlockState;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
|
||||
import org.geysermc.geyser.translator.sound.SoundTranslator;
|
||||
|
||||
@SoundTranslator(blocks = "button")
|
||||
public class ButtonSoundInteractionTranslator implements BlockSoundInteractionTranslator {
|
||||
@Override
|
||||
public void translate(GeyserSession session, Vector3f position, BlockState state) {
|
||||
SoundEvent event = state.getValue(Properties.POWERED, false) ? SoundEvent.BUTTON_CLICK_ON : SoundEvent.BUTTON_CLICK_OFF;
|
||||
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
|
||||
levelSoundEventPacket.setPosition(position.add(0.5, 0.5, 0.5));
|
||||
levelSoundEventPacket.setBabySound(false);
|
||||
levelSoundEventPacket.setRelativeVolumeDisabled(false);
|
||||
levelSoundEventPacket.setIdentifier(":");
|
||||
levelSoundEventPacket.setSound(event);
|
||||
levelSoundEventPacket.setExtraData(session.getBlockMappings().getBedrockBlock(state).getRuntimeId());
|
||||
|
||||
session.sendUpstreamPacket(levelSoundEventPacket);
|
||||
}
|
||||
}
|
||||
@@ -69,12 +69,12 @@ public final class SoundUtils {
|
||||
public static String translatePlaySound(String javaIdentifier) {
|
||||
String soundIdentifier = removeMinecraftNamespace(javaIdentifier);
|
||||
SoundMapping soundMapping = Registries.SOUNDS.get(soundIdentifier);
|
||||
if (soundMapping == null || soundMapping.getPlaysound() == null) {
|
||||
if (soundMapping == null || soundMapping.playsound() == null) {
|
||||
// no mapping
|
||||
GeyserImpl.getInstance().getLogger().debug("[PlaySound] Defaulting to sound server gave us for " + javaIdentifier);
|
||||
return soundIdentifier;
|
||||
}
|
||||
return soundMapping.getPlaysound();
|
||||
return soundMapping.playsound();
|
||||
}
|
||||
|
||||
private static String removeMinecraftNamespace(String identifier) {
|
||||
@@ -112,50 +112,50 @@ public final class SoundUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (soundMapping.getPlaysound() != null) {
|
||||
if (soundMapping.playsound() != null) {
|
||||
// We always prefer the PlaySound mapping because we can control volume and pitch
|
||||
playSound(session, soundMapping.getPlaysound(), position, volume, pitch);
|
||||
playSound(session, soundMapping.playsound(), position, volume, pitch * soundMapping.pitchAdjust());
|
||||
return;
|
||||
}
|
||||
|
||||
if (soundMapping.isLevelEvent()) {
|
||||
if (soundMapping.levelEvent()) {
|
||||
LevelEventPacket levelEventPacket = new LevelEventPacket();
|
||||
levelEventPacket.setPosition(position);
|
||||
levelEventPacket.setData(0);
|
||||
levelEventPacket.setType(LevelEvent.valueOf(soundMapping.getBedrock()));
|
||||
levelEventPacket.setType(LevelEvent.valueOf(soundMapping.bedrock()));
|
||||
session.sendUpstreamPacket(levelEventPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
LevelSoundEventPacket soundPacket = new LevelSoundEventPacket();
|
||||
SoundEvent sound = SoundUtils.toSoundEvent(soundMapping.getBedrock());
|
||||
SoundEvent sound = SoundUtils.toSoundEvent(soundMapping.bedrock());
|
||||
if (sound == null) {
|
||||
sound = SoundUtils.toSoundEvent(soundIdentifier);
|
||||
}
|
||||
if (sound == null) {
|
||||
session.getGeyser().getLogger().debug("[Builtin] Sound for original '" + soundIdentifier + "' to mappings '" + soundMapping.getBedrock()
|
||||
session.getGeyser().getLogger().debug("[Builtin] Sound for original '" + soundIdentifier + "' to mappings '" + soundMapping.bedrock()
|
||||
+ "' was not a playable level sound, or has yet to be mapped to an enum in SoundEvent.");
|
||||
return;
|
||||
}
|
||||
|
||||
soundPacket.setSound(sound);
|
||||
soundPacket.setPosition(position);
|
||||
soundPacket.setIdentifier(soundMapping.getIdentifier());
|
||||
soundPacket.setIdentifier(soundMapping.identifier());
|
||||
if (sound == SoundEvent.NOTE) {
|
||||
// Minecraft Wiki: 2^(x/12) = Java pitch where x is -12 to 12
|
||||
// Java sends the note value as above starting with -12 and ending at 12
|
||||
// Bedrock has a number for each type of note, then proceeds up the scale by adding to that number
|
||||
soundPacket.setExtraData(soundMapping.getExtraData() + (int) (Math.round((Math.log10(pitch) / Math.log10(2)) * 12)) + 12);
|
||||
} else if (sound == SoundEvent.PLACE && soundMapping.getExtraData() == -1) {
|
||||
if (!soundMapping.getIdentifier().equals(":")) {
|
||||
int javaId = BlockRegistries.JAVA_IDENTIFIER_TO_ID.get().getOrDefault(soundMapping.getIdentifier(), Block.JAVA_AIR_ID);
|
||||
soundPacket.setExtraData(soundMapping.extraData() + (int) (Math.round((Math.log10(pitch) / Math.log10(2)) * 12)) + 12);
|
||||
} else if (sound == SoundEvent.PLACE && soundMapping.extraData() == -1) {
|
||||
if (!soundMapping.identifier().equals(":")) {
|
||||
int javaId = BlockRegistries.JAVA_IDENTIFIER_TO_ID.get().getOrDefault(soundMapping.identifier(), Block.JAVA_AIR_ID);
|
||||
soundPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(javaId));
|
||||
} else {
|
||||
session.getGeyser().getLogger().debug("PLACE sound mapping identifier was invalid! Please report: " + soundMapping);
|
||||
}
|
||||
soundPacket.setIdentifier(":");
|
||||
} else {
|
||||
soundPacket.setExtraData(soundMapping.getExtraData());
|
||||
soundPacket.setExtraData(soundMapping.extraData());
|
||||
}
|
||||
|
||||
soundPacket.setBabySound(false); // might need to adjust this in the future
|
||||
|
||||
Submodule core/src/main/resources/mappings updated: 2281e339fc...362665358e
Reference in New Issue
Block a user