mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-27 19:09:08 +00:00
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user