mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
fix(sound): 修正一些写法不重复发声音
This commit is contained in:
@@ -188,16 +188,14 @@ public final class CraftEngineBlocks {
|
||||
* @param player player who breaks the block
|
||||
* @param dropLoot whether to drop block loots
|
||||
* @param isMoving is moving
|
||||
* @param playSound whether to play break sounds
|
||||
* @param sendParticles whether to send break particles
|
||||
* @param sendLevelEvent whether to send break particles and sounds
|
||||
* @return success or not
|
||||
*/
|
||||
public static boolean remove(@NotNull Block block,
|
||||
@Nullable Player player,
|
||||
boolean isMoving,
|
||||
boolean dropLoot,
|
||||
boolean playSound,
|
||||
boolean sendParticles) {
|
||||
boolean sendLevelEvent) {
|
||||
ImmutableBlockState state = getCustomBlockState(block);
|
||||
if (state == null || state.isEmpty()) return false;
|
||||
World world = new BukkitWorld(block.getWorld());
|
||||
@@ -215,16 +213,34 @@ public final class CraftEngineBlocks {
|
||||
world.dropItemNaturally(position, item);
|
||||
}
|
||||
}
|
||||
if (playSound) {
|
||||
world.playBlockSound(position, state.settings().sounds().breakSound());
|
||||
}
|
||||
if (sendParticles) {
|
||||
if (sendLevelEvent) {
|
||||
FastNMS.INSTANCE.method$LevelAccessor$levelEvent(world.serverWorld(), WorldEvents.BLOCK_BREAK_EFFECT, LocationUtils.toBlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), state.customBlockState().registryId());
|
||||
}
|
||||
FastNMS.INSTANCE.method$Level$removeBlock(world.serverWorld(), LocationUtils.toBlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), isMoving);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a block from the world if it's custom
|
||||
*
|
||||
* @param block block to remove
|
||||
* @param player player who breaks the block
|
||||
* @param dropLoot whether to drop block loots
|
||||
* @param isMoving is moving
|
||||
* @param playSound whether to play break sounds
|
||||
* @param sendParticles whether to send break particles
|
||||
* @return success or not
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean remove(@NotNull Block block,
|
||||
@Nullable Player player,
|
||||
boolean isMoving,
|
||||
boolean dropLoot,
|
||||
boolean playSound,
|
||||
boolean sendParticles) {
|
||||
return remove(block, player, dropLoot, isMoving, playSound || sendParticles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a block is custom
|
||||
*
|
||||
|
||||
@@ -70,11 +70,11 @@ public abstract class AbstractCanSurviveBlockBehavior extends BukkitBlockBehavio
|
||||
return state;
|
||||
}
|
||||
if (!canSurvive(thisBlock, new Object[] {state, level, blockPos}, () -> true)) {
|
||||
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
// BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
ImmutableBlockState customState = optionalCustomState.get();
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(pos));
|
||||
world.playBlockSound(position, customState.settings().sounds().breakSound());
|
||||
// net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
// WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(pos));
|
||||
// world.playBlockSound(position, customState.settings().sounds().breakSound()); // 下面触发事件也会有声音
|
||||
FastNMS.INSTANCE.method$LevelAccessor$levelEvent(level, WorldEvents.BLOCK_BREAK_EFFECT, blockPos, customState.customBlockState().registryId());
|
||||
return MBlocks.AIR$defaultState;
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ public class DoubleHighBlockBehavior extends BukkitBlockBehavior {
|
||||
if (anotherHalfCustomState != null && !anotherHalfCustomState.isEmpty()) return blockState;
|
||||
|
||||
// 破坏
|
||||
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(pos));
|
||||
world.playBlockSound(position, customState.settings().sounds().breakSound());
|
||||
// BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
// net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
// WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(pos));
|
||||
// world.playBlockSound(position, customState.settings().sounds().breakSound()); // 下面触发事件也会有声音
|
||||
FastNMS.INSTANCE.method$LevelAccessor$levelEvent(level, WorldEvents.BLOCK_BREAK_EFFECT, blockPos, customState.customBlockState().registryId());
|
||||
return MBlocks.AIR$defaultState;
|
||||
}
|
||||
|
||||
@@ -66,10 +66,10 @@ public class PressurePlateBlockBehavior extends BukkitBlockBehavior {
|
||||
return MBlocks.AIR$defaultState;
|
||||
}
|
||||
ImmutableBlockState customState = optionalCustomState.get();
|
||||
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(pos));
|
||||
world.playBlockSound(position, customState.settings().sounds().breakSound());
|
||||
// BlockPos pos = LocationUtils.fromBlockPos(blockPos);
|
||||
// net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
// WorldPosition position = new WorldPosition(world, Vec3d.atCenterOf(pos));
|
||||
// world.playBlockSound(position, customState.settings().sounds().breakSound()); // 下面触发事件也会有声音
|
||||
FastNMS.INSTANCE.method$LevelAccessor$levelEvent(level, WorldEvents.BLOCK_BREAK_EFFECT, blockPos, customState.customBlockState().registryId());
|
||||
return MBlocks.AIR$defaultState;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user