mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-20 07:29:17 +00:00
修复摔落音效
This commit is contained in:
@@ -41,8 +41,8 @@ dependencies {
|
|||||||
compileOnly("io.github.toxicity188:bettermodel:1.14.0")
|
compileOnly("io.github.toxicity188:bettermodel:1.14.0")
|
||||||
compileOnly("com.mojang:authlib:${rootProject.properties["authlib_version"]}")
|
compileOnly("com.mojang:authlib:${rootProject.properties["authlib_version"]}")
|
||||||
// MMOItems
|
// MMOItems
|
||||||
compileOnly("net.Indyuce:MMOItems-API:6.10-SNAPSHOT")
|
compileOnly("net.Indyuce:MMOItems-API:6.10.1-SNAPSHOT")
|
||||||
compileOnly("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT")
|
compileOnly("io.lumine:MythicLib-dist:1.7.1-SNAPSHOT")
|
||||||
// Nexo
|
// Nexo
|
||||||
compileOnly("com.nexomc:nexo:1.13.0")
|
compileOnly("com.nexomc:nexo:1.13.0")
|
||||||
// LuckPerms
|
// LuckPerms
|
||||||
@@ -62,7 +62,7 @@ dependencies {
|
|||||||
// McMMO
|
// McMMO
|
||||||
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.2.038")
|
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.2.038")
|
||||||
// MMOCore
|
// MMOCore
|
||||||
compileOnly("net.Indyuce:MMOCore-API:1.12.1-SNAPSHOT")
|
compileOnly("net.Indyuce:MMOCore-API:1.13.1-SNAPSHOT")
|
||||||
// JobsReborn
|
// JobsReborn
|
||||||
compileOnly("com.github.Zrips:Jobs:v5.2.2.3")
|
compileOnly("com.github.Zrips:Jobs:v5.2.2.3")
|
||||||
// CustomFishing
|
// CustomFishing
|
||||||
|
|||||||
@@ -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.SoundData;
|
||||||
import net.momirealms.craftengine.core.sound.SoundSource;
|
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;
|
||||||
@@ -38,6 +39,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.world.GenericGameEvent;
|
import org.bukkit.event.world.GenericGameEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@@ -233,12 +235,14 @@ public final class BlockEventListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onStep(GenericGameEvent event) {
|
public void onStep(GenericGameEvent event) {
|
||||||
if (event.getEvent() != GameEvent.STEP) return;
|
GameEvent gameEvent = event.getEvent();
|
||||||
|
// 只处理落地和走路
|
||||||
|
if (gameEvent != GameEvent.STEP) return;
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (!(entity instanceof Player player)) return;
|
if (!(entity instanceof Player player)) return;
|
||||||
BlockPos pos = EntityUtils.getOnPos(player);
|
BlockPos pos = EntityUtils.getOnPos(player);
|
||||||
Block block = player.getWorld().getBlockAt(pos.x(), pos.y(), pos.z());
|
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);
|
Optional<ImmutableBlockState> optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(blockState);
|
||||||
if (optionalCustomState.isPresent()) {
|
if (optionalCustomState.isPresent()) {
|
||||||
Location location = player.getLocation();
|
Location location = player.getLocation();
|
||||||
@@ -253,7 +257,8 @@ public final class BlockEventListener implements Listener {
|
|||||||
if (cancellable.isCancelled() && !Config.processCancelledStep()) {
|
if (cancellable.isCancelled() && !Config.processCancelledStep()) {
|
||||||
return;
|
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()) {
|
} else if (Config.enableSoundSystem()) {
|
||||||
if (event.isCancelled() && !Config.processCancelledStep()) {
|
if (event.isCancelled() && !Config.processCancelledStep()) {
|
||||||
return;
|
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)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||||
// for vanilla blocks
|
// for vanilla blocks
|
||||||
|
|||||||
@@ -26,13 +26,9 @@ public final class EntityUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BlockPos getOnPos(Player player) {
|
public static BlockPos getOnPos(Player player) {
|
||||||
try {
|
|
||||||
Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player);
|
Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player);
|
||||||
Object blockPos = CoreReflections.method$Entity$getOnPos.invoke(serverPlayer, 1.0E-5F);
|
Object blockPos = FastNMS.INSTANCE.method$Entity$getOnPos(serverPlayer);
|
||||||
return LocationUtils.fromBlockPos(blockPos);
|
return LocationUtils.fromBlockPos(blockPos);
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entity spawnEntity(World world, Location loc, EntityType type, Consumer<Entity> function) {
|
public static Entity spawnEntity(World world, Location loc, EntityType type, Consumer<Entity> function) {
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ public enum EventTrigger {
|
|||||||
BREAK("break", "dig"),
|
BREAK("break", "dig"),
|
||||||
PLACE("place", "build"),
|
PLACE("place", "build"),
|
||||||
PICK_UP("pick_up", "pick"),
|
PICK_UP("pick_up", "pick"),
|
||||||
STEP("step"),;
|
STEP("step"),
|
||||||
|
FALL("fall"),;
|
||||||
|
|
||||||
public static final Map<String, EventTrigger> BY_NAME = new HashMap<>();
|
public static final Map<String, EventTrigger> BY_NAME = new HashMap<>();
|
||||||
private final String[] names;
|
private final String[] names;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ byte_buddy_version=1.18.1
|
|||||||
ahocorasick_version=0.6.3
|
ahocorasick_version=0.6.3
|
||||||
snake_yaml_version=2.5
|
snake_yaml_version=2.5
|
||||||
anti_grief_version=1.0.5
|
anti_grief_version=1.0.5
|
||||||
nms_helper_version=1.0.140
|
nms_helper_version=1.0.141
|
||||||
evalex_version=3.5.0
|
evalex_version=3.5.0
|
||||||
reactive_streams_version=1.0.4
|
reactive_streams_version=1.0.4
|
||||||
amazon_awssdk_version=2.38.7
|
amazon_awssdk_version=2.38.7
|
||||||
|
|||||||
Reference in New Issue
Block a user