9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

修复摔落音效

This commit is contained in:
XiaoMoMi
2025-12-04 17:32:51 +08:00
parent d9cbe039b2
commit cac852eb81
5 changed files with 43 additions and 15 deletions

View File

@@ -41,8 +41,8 @@ dependencies {
compileOnly("io.github.toxicity188:bettermodel:1.14.0")
compileOnly("com.mojang:authlib:${rootProject.properties["authlib_version"]}")
// MMOItems
compileOnly("net.Indyuce:MMOItems-API:6.10-SNAPSHOT")
compileOnly("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT")
compileOnly("net.Indyuce:MMOItems-API:6.10.1-SNAPSHOT")
compileOnly("io.lumine:MythicLib-dist:1.7.1-SNAPSHOT")
// Nexo
compileOnly("com.nexomc:nexo:1.13.0")
// LuckPerms
@@ -62,7 +62,7 @@ dependencies {
// McMMO
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.2.038")
// MMOCore
compileOnly("net.Indyuce:MMOCore-API:1.12.1-SNAPSHOT")
compileOnly("net.Indyuce:MMOCore-API:1.13.1-SNAPSHOT")
// JobsReborn
compileOnly("com.github.Zrips:Jobs:v5.2.2.3")
// CustomFishing

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.event.EventTrigger;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import net.momirealms.craftengine.core.sound.SoundData;
import net.momirealms.craftengine.core.sound.SoundSource;
import net.momirealms.craftengine.core.util.Cancellable;
import net.momirealms.craftengine.core.util.ItemUtils;
@@ -38,6 +39,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.world.GenericGameEvent;
import org.bukkit.inventory.ItemStack;
@@ -233,12 +235,14 @@ public final class BlockEventListener implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void onStep(GenericGameEvent event) {
if (event.getEvent() != GameEvent.STEP) return;
GameEvent gameEvent = event.getEvent();
// 只处理落地和走路
if (gameEvent != GameEvent.STEP) return;
Entity entity = event.getEntity();
if (!(entity instanceof Player player)) return;
BlockPos pos = EntityUtils.getOnPos(player);
Block block = player.getWorld().getBlockAt(pos.x(), pos.y(), pos.z());
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(FastNMS.INSTANCE.field$CraftWorld$ServerLevel(block.getWorld()), LocationUtils.toBlockPos(block.getX(), block.getY(), block.getZ()));
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(FastNMS.INSTANCE.field$CraftWorld$ServerLevel(player.getWorld()), LocationUtils.toBlockPos(pos));
Optional<ImmutableBlockState> optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(blockState);
if (optionalCustomState.isPresent()) {
Location location = player.getLocation();
@@ -253,7 +257,8 @@ public final class BlockEventListener implements Listener {
if (cancellable.isCancelled() && !Config.processCancelledStep()) {
return;
}
player.playSound(location, state.settings().sounds().stepSound().id().toString(), SoundCategory.BLOCKS, state.settings().sounds().stepSound().volume().get(), state.settings().sounds().stepSound().pitch().get());
SoundData soundData = state.settings().sounds().stepSound();
player.playSound(location, soundData.id().toString(), SoundCategory.BLOCKS, soundData.volume().get(), soundData.pitch().get());
} else if (Config.enableSoundSystem()) {
if (event.isCancelled() && !Config.processCancelledStep()) {
return;
@@ -267,6 +272,32 @@ public final class BlockEventListener implements Listener {
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onFall(EntityDamageEvent event) {
if (event.getCause() != EntityDamageEvent.DamageCause.FALL)
return;
if (!(event.getEntity() instanceof Player player)) return;
BlockPos pos = EntityUtils.getOnPos(player);
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(FastNMS.INSTANCE.field$CraftWorld$ServerLevel(player.getWorld()), LocationUtils.toBlockPos(pos));
Optional<ImmutableBlockState> optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(blockState);
if (optionalCustomState.isPresent()) {
Location location = player.getLocation();
ImmutableBlockState state = optionalCustomState.get();
SoundData soundData = state.settings().sounds().fallSound();
player.playSound(location, soundData.id().toString(), SoundCategory.BLOCKS, soundData.volume().get(), soundData.pitch().get());
} else if (Config.enableSoundSystem()) {
if (event.isCancelled() && !Config.processCancelledStep()) {
return;
}
Object soundType = FastNMS.INSTANCE.method$BlockBehaviour$BlockStateBase$getSoundType(blockState);
Object soundEvent = FastNMS.INSTANCE.field$SoundType$fallSound(soundType);
Object soundId = FastNMS.INSTANCE.field$SoundEvent$location(soundEvent);
if (this.manager.isStepSoundMissing(soundId)) {
player.playSound(player.getLocation(), soundId.toString(), SoundCategory.BLOCKS, 0.15f, 1f);
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockPhysics(BlockPhysicsEvent event) {
// for vanilla blocks

View File

@@ -26,13 +26,9 @@ public final class EntityUtils {
}
public static BlockPos getOnPos(Player player) {
try {
Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player);
Object blockPos = CoreReflections.method$Entity$getOnPos.invoke(serverPlayer, 1.0E-5F);
return LocationUtils.fromBlockPos(blockPos);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player);
Object blockPos = FastNMS.INSTANCE.method$Entity$getOnPos(serverPlayer);
return LocationUtils.fromBlockPos(blockPos);
}
public static Entity spawnEntity(World world, Location loc, EntityType type, Consumer<Entity> function) {

View File

@@ -11,7 +11,8 @@ public enum EventTrigger {
BREAK("break", "dig"),
PLACE("place", "build"),
PICK_UP("pick_up", "pick"),
STEP("step"),;
STEP("step"),
FALL("fall"),;
public static final Map<String, EventTrigger> BY_NAME = new HashMap<>();
private final String[] names;

View File

@@ -48,7 +48,7 @@ byte_buddy_version=1.18.1
ahocorasick_version=0.6.3
snake_yaml_version=2.5
anti_grief_version=1.0.5
nms_helper_version=1.0.140
nms_helper_version=1.0.141
evalex_version=3.5.0
reactive_streams_version=1.0.4
amazon_awssdk_version=2.38.7