mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 03:19:14 +00:00
修复声音
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user