9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-23 00:49:20 +00:00

Merge pull request #390 from Xiao-MoMi/dev

同步dev
This commit is contained in:
XiaoMoMi
2025-09-27 03:28:13 +08:00
committed by GitHub
6 changed files with 67 additions and 30 deletions

View File

@@ -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.PlayerOptionalContext;
import net.momirealms.craftengine.core.plugin.context.event.EventTrigger; import net.momirealms.craftengine.core.plugin.context.event.EventTrigger;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters; 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.Cancellable;
import net.momirealms.craftengine.core.util.ItemUtils; import net.momirealms.craftengine.core.util.ItemUtils;
import net.momirealms.craftengine.core.util.VersionHelper; import net.momirealms.craftengine.core.util.VersionHelper;
@@ -166,7 +167,7 @@ public final class BlockEventListener implements Listener {
} }
// play sound // play sound
world.playBlockSound(position, state.settings().sounds().breakSound()); serverPlayer.playSound(position, state.settings().sounds().breakSound(), SoundSource.BLOCK);
} }
} else { } else {
// override vanilla block loots // override vanilla block loots
@@ -191,7 +192,6 @@ public final class BlockEventListener implements Listener {
} }
}); });
} }
// sound system // sound system
if (Config.enableSoundSystem()) { if (Config.enableSoundSystem()) {
Object ownerBlock = BlockStateUtils.getBlockOwner(blockState); Object ownerBlock = BlockStateUtils.getBlockOwner(blockState);
@@ -199,7 +199,7 @@ public final class BlockEventListener implements Listener {
try { try {
Object soundType = CoreReflections.field$BlockBehaviour$soundType.get(ownerBlock); Object soundType = CoreReflections.field$BlockBehaviour$soundType.get(ownerBlock);
Object breakSound = CoreReflections.field$SoundType$breakSound.get(soundType); 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) { } catch (ReflectiveOperationException e) {
this.plugin.logger().warn("Failed to get sound type", e); this.plugin.logger().warn("Failed to get sound type", e);
} }

View File

@@ -90,7 +90,7 @@ public class FlintAndSteelItemBehavior extends ItemBehavior {
} }
// 且没有shift // 且没有shift
if (!player.isSecondaryUseActive()) { 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 { } else {
// 玩家觉得自定义方块不可燃,且点击了侧面,那么就要判断火源下方的方块是否可燃,如果不可燃,则补发声音 // 玩家觉得自定义方块不可燃,且点击了侧面,那么就要判断火源下方的方块是否可燃,如果不可燃,则补发声音
@@ -113,16 +113,16 @@ public class FlintAndSteelItemBehavior extends ItemBehavior {
if (player.isSecondaryUseActive()) { if (player.isSecondaryUseActive()) {
// 如果底部不能燃烧,则燃烧点位为侧面,需要补发 // 如果底部不能燃烧,则燃烧点位为侧面,需要补发
if (!belowCanBurn) { 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()); player.swingHand(context.getHand());
} }
} else { } 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 { } else {
// 如果底部方块不可燃烧才补发 // 如果底部方块不可燃烧才补发
if (!belowCanBurn) { 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()); 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()); player.swingHand(context.getHand());
} }
return InteractionResult.PASS; return InteractionResult.PASS;

View File

@@ -2293,28 +2293,50 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
int state = buf.readInt(); int state = buf.readInt();
boolean global = buf.readBoolean(); boolean global = buf.readBoolean();
int newState = user.clientModEnabled() ? modBlockStateMapper[state] : blockStateMapper[state]; int newState = user.clientModEnabled() ? modBlockStateMapper[state] : blockStateMapper[state];
Object blockState = BlockStateUtils.idToBlockState(newState); if (BlockStateUtils.isVanillaBlock(state)) {
Object block = BlockStateUtils.getBlockOwner(blockState); Object blockState = BlockStateUtils.idToBlockState(state);
if (BukkitBlockManager.instance().isBlockSoundRemoved(block) && !FastNMS.INSTANCE.method$BlockStateBase$isAir(blockState)) { 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 soundType = FastNMS.INSTANCE.method$BlockBehaviour$BlockStateBase$getSoundType(blockState);
Object breakSound = FastNMS.INSTANCE.field$SoundType$breakSound(soundType); Object breakSound = FastNMS.INSTANCE.field$SoundType$breakSound(soundType);
Key soundId = Key.of(FastNMS.INSTANCE.field$SoundEvent$location(breakSound).toString()); Key soundId = Key.of(FastNMS.INSTANCE.field$SoundEvent$location(breakSound).toString());
Key mappedSoundId = BukkitBlockManager.instance().replaceSoundIfExist(soundId); Key mappedSoundId = BukkitBlockManager.instance().replaceSoundIfExist(soundId);
if (mappedSoundId != null) { Object finalSoundId = KeyUtils.toResourceLocation(mappedSoundId == null ? soundId : mappedSoundId);
Object mappedBreakSound = FastNMS.INSTANCE.constructor$SoundEvent(KeyUtils.toResourceLocation(mappedSoundId), Optional.empty()); Object mappedBreakSound = FastNMS.INSTANCE.constructor$SoundEvent(finalSoundId, Optional.empty());
Object mappedBreakSoundHolder = FastNMS.INSTANCE.method$Holder$direct(mappedBreakSound); Object mappedBreakSoundHolder = FastNMS.INSTANCE.method$Holder$direct(mappedBreakSound);
Object packet = FastNMS.INSTANCE.constructor$ClientboundSoundPacket( Object packet = FastNMS.INSTANCE.constructor$ClientboundSoundPacket(
mappedBreakSoundHolder, mappedBreakSoundHolder,
CoreReflections.instance$SoundSource$BLOCKS, CoreReflections.instance$SoundSource$BLOCKS,
blockPos.x() + 0.5, blockPos.x() + 0.5,
blockPos.y() + 0.5, blockPos.y() + 0.5,
blockPos.z() + 0.5, blockPos.z() + 0.5,
(FastNMS.INSTANCE.field$SoundType$volume(soundType) + 1.0F) / 2.0F, 1f,
FastNMS.INSTANCE.field$SoundType$pitch(soundType) * 0.8F, 0.8F,
RandomUtils.generateRandomLong() RandomUtils.generateRandomLong()
); );
user.sendPacket(packet, true); user.sendPacket(packet, true);
}
} }
if (newState == state) { if (newState == state) {
return; return;

View File

@@ -370,8 +370,8 @@ public class BukkitServerPlayer extends Player {
} }
@Override @Override
public void playSound(Key sound, BlockPos blockPos, SoundSource source, float volume, float pitch) { public void playSound(Position pos, Key sound, 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); platformPlayer().playSound(new Location(null, pos.x(), pos.y(), pos.z()), sound.toString(), SoundUtils.toBukkit(source), volume, pitch);
} }
@Override @Override

View File

@@ -6,9 +6,12 @@ import net.momirealms.craftengine.core.entity.AbstractEntity;
import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.plugin.context.CooldownData; import net.momirealms.craftengine.core.plugin.context.CooldownData;
import net.momirealms.craftengine.core.plugin.network.NetWorkUser; 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.sound.SoundSource;
import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.world.BlockPos; 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 net.momirealms.craftengine.core.world.WorldPosition;
import org.jetbrains.annotations.NotNull; 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, 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); public abstract void giveItem(Item<?> item);

View File

@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=0.0.63.6 project_version=0.0.63.7
config_version=46 config_version=46
lang_version=31 lang_version=31
project_group=net.momirealms project_group=net.momirealms