9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-28 03:19:14 +00:00

修复声音

This commit is contained in:
XiaoMoMi
2025-04-09 02:46:56 +08:00
parent b45fef8892
commit 6640eac5ec
7 changed files with 29 additions and 14 deletions

View File

@@ -63,18 +63,20 @@ public class BlockEventListener implements Listener {
if (Config.enableSoundSystem()) {
Block block = event.getBlock();
Object blockState = BlockStateUtils.blockDataToBlockState(block.getBlockData());
Object ownerBlock = BlockStateUtils.getBlockOwner(blockState);
if (this.manager.isBlockSoundRemoved(ownerBlock)) {
if (player.getInventory().getItemInMainHand().getType() != Material.DEBUG_STICK) {
try {
Object soundType = Reflections.field$BlockBehaviour$soundType.get(ownerBlock);
Object placeSound = Reflections.field$SoundType$placeSound.get(soundType);
player.playSound(block.getLocation(), Reflections.field$SoundEvent$location.get(placeSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f);
} catch (ReflectiveOperationException e) {
this.plugin.logger().warn("Failed to get sound type", e);
if (blockState != Reflections.instance$Blocks$AIR$defaultState) {
Object ownerBlock = BlockStateUtils.getBlockOwner(blockState);
if (this.manager.isBlockSoundRemoved(ownerBlock)) {
if (player.getInventory().getItemInMainHand().getType() != Material.DEBUG_STICK) {
try {
Object soundType = Reflections.field$BlockBehaviour$soundType.get(ownerBlock);
Object placeSound = Reflections.field$SoundType$placeSound.get(soundType);
player.playSound(block.getLocation(), Reflections.field$SoundEvent$location.get(placeSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f);
} catch (ReflectiveOperationException e) {
this.plugin.logger().warn("Failed to get sound type", e);
}
}
return;
}
return;
}
}
// resend sound if the clicked block is interactable on client side

View File

@@ -311,7 +311,10 @@ public class BukkitBlockManager extends AbstractBlockManager {
for (Object block : (Iterable<Object>) Reflections.instance$BuiltInRegistries$BLOCK) {
Object soundType = Reflections.field$BlockBehaviour$soundType.get(block);
if (affectedSounds.contains(soundType)) {
affectedBlocks.add(block);
Object state = getOnlyBlockState(block);
if (BlockStateUtils.isVanillaBlock(state)) {
affectedBlocks.add(block);
}
}
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.sound;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
@@ -17,6 +18,7 @@ public class BukkitSoundManager extends AbstractSoundManager {
public BukkitSoundManager(CraftEngine plugin) {
super(plugin);
VANILLA_SOUND_EVENTS.addAll(FastNMS.INSTANCE.getAllVanillaSounds().stream().map(it -> Key.of(it.getNamespace(), it.getKey())).toList());
}
@Override