diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java index 7350e97b4..e72055d3c 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java @@ -21,6 +21,7 @@ import net.momirealms.craftengine.core.plugin.context.ContextHolder; import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext; import net.momirealms.craftengine.core.plugin.context.event.EventTrigger; import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.sound.SoundSource; import net.momirealms.craftengine.core.util.Cancellable; import net.momirealms.craftengine.core.util.ItemUtils; import net.momirealms.craftengine.core.util.VersionHelper; @@ -166,7 +167,7 @@ public final class BlockEventListener implements Listener { } // play sound - world.playBlockSound(position, state.settings().sounds().breakSound()); + serverPlayer.playSound(position, state.settings().sounds().breakSound(), SoundSource.BLOCK); } } else { // override vanilla block loots @@ -191,7 +192,6 @@ public final class BlockEventListener implements Listener { } }); } - // sound system if (Config.enableSoundSystem()) { Object ownerBlock = BlockStateUtils.getBlockOwner(blockState); @@ -199,7 +199,7 @@ public final class BlockEventListener implements Listener { try { Object soundType = CoreReflections.field$BlockBehaviour$soundType.get(ownerBlock); Object breakSound = CoreReflections.field$SoundType$breakSound.get(soundType); - block.getWorld().playSound(block.getLocation().add(0.5, 0.5, 0.5), FastNMS.INSTANCE.field$SoundEvent$location(breakSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f); + player.playSound(block.getLocation().add(0.5, 0.5, 0.5), FastNMS.INSTANCE.field$SoundEvent$location(breakSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f); } catch (ReflectiveOperationException e) { this.plugin.logger().warn("Failed to get sound type", e); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/FlintAndSteelItemBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/FlintAndSteelItemBehavior.java index 2be578ff4..df3e667e0 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/FlintAndSteelItemBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/FlintAndSteelItemBehavior.java @@ -90,7 +90,7 @@ public class FlintAndSteelItemBehavior extends ItemBehavior { } // 且没有shift if (!player.isSecondaryUseActive()) { - player.playSound(FLINT_SOUND, firePos, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); + player.playSound(firePos, FLINT_SOUND, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); } } else { // 玩家觉得自定义方块不可燃,且点击了侧面,那么就要判断火源下方的方块是否可燃,如果不可燃,则补发声音 @@ -113,16 +113,16 @@ public class FlintAndSteelItemBehavior extends ItemBehavior { if (player.isSecondaryUseActive()) { // 如果底部不能燃烧,则燃烧点位为侧面,需要补发 if (!belowCanBurn) { - player.playSound(FLINT_SOUND, firePos, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); + player.playSound(firePos, FLINT_SOUND, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); player.swingHand(context.getHand()); } } else { - player.playSound(FLINT_SOUND, firePos, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); + player.playSound(firePos, FLINT_SOUND, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); } } else { // 如果底部方块不可燃烧才补发 if (!belowCanBurn) { - player.playSound(FLINT_SOUND, firePos, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); + player.playSound(firePos, FLINT_SOUND, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); player.swingHand(context.getHand()); } } @@ -153,7 +153,7 @@ public class FlintAndSteelItemBehavior extends ItemBehavior { } } } - player.playSound(FLINT_SOUND, firePos, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); + player.playSound(firePos, FLINT_SOUND, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f)); player.swingHand(context.getHand()); } return InteractionResult.PASS; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java index 48c15f39c..3403b6124 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java @@ -2293,28 +2293,50 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes int state = buf.readInt(); boolean global = buf.readBoolean(); int newState = user.clientModEnabled() ? modBlockStateMapper[state] : blockStateMapper[state]; - Object blockState = BlockStateUtils.idToBlockState(newState); - Object block = BlockStateUtils.getBlockOwner(blockState); - if (BukkitBlockManager.instance().isBlockSoundRemoved(block) && !FastNMS.INSTANCE.method$BlockStateBase$isAir(blockState)) { + if (BlockStateUtils.isVanillaBlock(state)) { + Object blockState = BlockStateUtils.idToBlockState(state); + Object block = BlockStateUtils.getBlockOwner(blockState); + if (BukkitBlockManager.instance().isBlockSoundRemoved(block)) { + Object soundType = FastNMS.INSTANCE.method$BlockBehaviour$BlockStateBase$getSoundType(blockState); + Object breakSound = FastNMS.INSTANCE.field$SoundType$breakSound(soundType); + Key soundId = Key.of(FastNMS.INSTANCE.field$SoundEvent$location(breakSound).toString()); + Key mappedSoundId = BukkitBlockManager.instance().replaceSoundIfExist(soundId); + if (mappedSoundId != null) { + Object mappedBreakSound = FastNMS.INSTANCE.constructor$SoundEvent(KeyUtils.toResourceLocation(mappedSoundId), Optional.empty()); + Object mappedBreakSoundHolder = FastNMS.INSTANCE.method$Holder$direct(mappedBreakSound); + Object packet = FastNMS.INSTANCE.constructor$ClientboundSoundPacket( + mappedBreakSoundHolder, + CoreReflections.instance$SoundSource$BLOCKS, + blockPos.x() + 0.5, + blockPos.y() + 0.5, + blockPos.z() + 0.5, + 1f, + 0.8F, + RandomUtils.generateRandomLong() + ); + user.sendPacket(packet, true); + } + } + } else { + Object blockState = BlockStateUtils.idToBlockState(state); Object soundType = FastNMS.INSTANCE.method$BlockBehaviour$BlockStateBase$getSoundType(blockState); Object breakSound = FastNMS.INSTANCE.field$SoundType$breakSound(soundType); Key soundId = Key.of(FastNMS.INSTANCE.field$SoundEvent$location(breakSound).toString()); Key mappedSoundId = BukkitBlockManager.instance().replaceSoundIfExist(soundId); - if (mappedSoundId != null) { - Object mappedBreakSound = FastNMS.INSTANCE.constructor$SoundEvent(KeyUtils.toResourceLocation(mappedSoundId), Optional.empty()); - Object mappedBreakSoundHolder = FastNMS.INSTANCE.method$Holder$direct(mappedBreakSound); - Object packet = FastNMS.INSTANCE.constructor$ClientboundSoundPacket( - mappedBreakSoundHolder, - CoreReflections.instance$SoundSource$BLOCKS, - blockPos.x() + 0.5, - blockPos.y() + 0.5, - blockPos.z() + 0.5, - (FastNMS.INSTANCE.field$SoundType$volume(soundType) + 1.0F) / 2.0F, - FastNMS.INSTANCE.field$SoundType$pitch(soundType) * 0.8F, - RandomUtils.generateRandomLong() - ); - user.sendPacket(packet, true); - } + Object finalSoundId = KeyUtils.toResourceLocation(mappedSoundId == null ? soundId : mappedSoundId); + Object mappedBreakSound = FastNMS.INSTANCE.constructor$SoundEvent(finalSoundId, Optional.empty()); + Object mappedBreakSoundHolder = FastNMS.INSTANCE.method$Holder$direct(mappedBreakSound); + Object packet = FastNMS.INSTANCE.constructor$ClientboundSoundPacket( + mappedBreakSoundHolder, + CoreReflections.instance$SoundSource$BLOCKS, + blockPos.x() + 0.5, + blockPos.y() + 0.5, + blockPos.z() + 0.5, + 1f, + 0.8F, + RandomUtils.generateRandomLong() + ); + user.sendPacket(packet, true); } if (newState == state) { return; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java index 11557ee15..2c4f7468f 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java @@ -370,8 +370,8 @@ public class BukkitServerPlayer extends Player { } @Override - public void playSound(Key sound, BlockPos blockPos, SoundSource source, float volume, float pitch) { - platformPlayer().playSound(new Location(null, blockPos.x() + 0.5, blockPos.y() + 0.5, blockPos.z() + 0.5), sound.toString(), SoundUtils.toBukkit(source), volume, pitch); + public void playSound(Position pos, Key sound, SoundSource source, float volume, float pitch) { + platformPlayer().playSound(new Location(null, pos.x(), pos.y(), pos.z()), sound.toString(), SoundUtils.toBukkit(source), volume, pitch); } @Override diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java b/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java index 9a33c2dbc..6df8b25c7 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java @@ -6,9 +6,12 @@ import net.momirealms.craftengine.core.entity.AbstractEntity; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.plugin.context.CooldownData; import net.momirealms.craftengine.core.plugin.network.NetWorkUser; +import net.momirealms.craftengine.core.sound.SoundData; import net.momirealms.craftengine.core.sound.SoundSource; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.world.BlockPos; +import net.momirealms.craftengine.core.world.Position; +import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.WorldPosition; import org.jetbrains.annotations.NotNull; @@ -100,7 +103,19 @@ public abstract class Player extends AbstractEntity implements NetWorkUser { public abstract void playSound(Key sound, SoundSource source, float volume, float pitch); - public abstract void playSound(Key sound, BlockPos pos, SoundSource source, float volume, float pitch); + public abstract void playSound(Position pos, Key sound, SoundSource source, float volume, float pitch); + + public void playSound(BlockPos pos, Key sound, SoundSource source, float volume, float pitch) { + this.playSound(Vec3d.atCenterOf(pos), sound, source, volume, pitch); + } + + public void playSound(BlockPos pos, SoundData data, SoundSource source) { + this.playSound(pos, data.id(), source, data.volume().get(), data.pitch().get()); + } + + public void playSound(Position pos, SoundData data, SoundSource source) { + this.playSound(pos, data.id(), source, data.volume().get(), data.pitch().get()); + } public abstract void giveItem(Item item); diff --git a/gradle.properties b/gradle.properties index f078e28e6..e56947eb0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=0.0.63.6 +project_version=0.0.63.7 config_version=46 lang_version=31 project_group=net.momirealms