mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
修改
This commit is contained in:
@@ -7,6 +7,8 @@ import net.momirealms.craftengine.core.item.Item;
|
|||||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||||
|
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
|
||||||
|
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
|
||||||
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
|
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
|
||||||
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
|
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
|
||||||
import net.momirealms.craftengine.core.sound.SoundData;
|
import net.momirealms.craftengine.core.sound.SoundData;
|
||||||
@@ -25,22 +27,22 @@ public class PlayTotemAnimationFunction<CTX extends Context> extends AbstractCon
|
|||||||
private final Key item;
|
private final Key item;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Key sound;
|
private final Key sound;
|
||||||
private final float volume;
|
private final NumberProvider volume;
|
||||||
private final float pitch;
|
private final NumberProvider pitch;
|
||||||
private final float minVolume;
|
private final NumberProvider minVolume;
|
||||||
private final float minPitch;
|
private final NumberProvider minPitch;
|
||||||
private final boolean noSound;
|
private final boolean silent;
|
||||||
|
|
||||||
public PlayTotemAnimationFunction(
|
public PlayTotemAnimationFunction(
|
||||||
List<Condition<CTX>> predicates,
|
List<Condition<CTX>> predicates,
|
||||||
PlayerSelector<CTX> selector,
|
PlayerSelector<CTX> selector,
|
||||||
Key item,
|
Key item,
|
||||||
@Nullable Key sound,
|
@Nullable Key sound,
|
||||||
float volume,
|
NumberProvider volume,
|
||||||
float pitch,
|
NumberProvider pitch,
|
||||||
float minVolume,
|
NumberProvider minVolume,
|
||||||
float minPitch,
|
NumberProvider minPitch,
|
||||||
boolean noSound
|
boolean silent
|
||||||
) {
|
) {
|
||||||
super(predicates);
|
super(predicates);
|
||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
@@ -50,7 +52,7 @@ public class PlayTotemAnimationFunction<CTX extends Context> extends AbstractCon
|
|||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
this.minVolume = minVolume;
|
this.minVolume = minVolume;
|
||||||
this.minPitch = minPitch;
|
this.minPitch = minPitch;
|
||||||
this.noSound = noSound;
|
this.silent = silent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,8 +65,8 @@ public class PlayTotemAnimationFunction<CTX extends Context> extends AbstractCon
|
|||||||
if (this.sound != null) {
|
if (this.sound != null) {
|
||||||
soundData = SoundData.of(
|
soundData = SoundData.of(
|
||||||
this.sound,
|
this.sound,
|
||||||
SoundData.SoundValue.ranged(this.minVolume, this.volume),
|
SoundData.SoundValue.ranged(Math.max(this.minVolume.getFloat(ctx), 0f), Math.max(this.volume.getFloat(ctx), 0f)),
|
||||||
SoundData.SoundValue.ranged(this.minPitch, this.pitch)
|
SoundData.SoundValue.ranged(MiscUtils.clamp(this.minPitch.getFloat(ctx), 0f, 2f), MiscUtils.clamp(this.pitch.getFloat(ctx), 0f, 2f))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (Player player : this.selector.get(ctx)) {
|
for (Player player : this.selector.get(ctx)) {
|
||||||
@@ -72,7 +74,7 @@ public class PlayTotemAnimationFunction<CTX extends Context> extends AbstractCon
|
|||||||
if (VersionHelper.isOrAbove1_21_2()) {
|
if (VersionHelper.isOrAbove1_21_2()) {
|
||||||
buildItem.setJavaComponent(DataComponentKeys.DEATH_PROTECTION, Map.of());
|
buildItem.setJavaComponent(DataComponentKeys.DEATH_PROTECTION, Map.of());
|
||||||
}
|
}
|
||||||
player.sendTotemAnimation(buildItem, soundData, this.noSound);
|
player.sendTotemAnimation(buildItem, soundData, this.silent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,12 +94,12 @@ public class PlayTotemAnimationFunction<CTX extends Context> extends AbstractCon
|
|||||||
PlayerSelector<CTX> selector = PlayerSelectors.fromObject(arguments.getOrDefault("target", "self"), conditionFactory());
|
PlayerSelector<CTX> selector = PlayerSelectors.fromObject(arguments.getOrDefault("target", "self"), conditionFactory());
|
||||||
Key item = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("item"), "warning.config.function.play_totem_animation.missing_item"));
|
Key item = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("item"), "warning.config.function.play_totem_animation.missing_item"));
|
||||||
@Nullable Key sound = Optional.ofNullable(arguments.get("sound")).map(String::valueOf).map(Key::of).orElse(null);
|
@Nullable Key sound = Optional.ofNullable(arguments.get("sound")).map(String::valueOf).map(Key::of).orElse(null);
|
||||||
float volume = Math.max(ResourceConfigUtils.getAsFloat(arguments.getOrDefault("volume", 1f), "volume"), 0f);
|
NumberProvider volume = NumberProviders.fromObject(arguments.getOrDefault("volume", 1f));
|
||||||
float pitch = MiscUtils.clamp(ResourceConfigUtils.getAsFloat(arguments.getOrDefault("pitch", 1f), "pitch"), 0f, 2f);
|
NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", 1f));
|
||||||
float minVolume = Math.max(ResourceConfigUtils.getAsFloat(arguments.getOrDefault("min-volume", 1f), "min-volume"), 0f);
|
NumberProvider minVolume = NumberProviders.fromObject(arguments.getOrDefault("min-volume", 1f));
|
||||||
float minPitch = MiscUtils.clamp(ResourceConfigUtils.getAsFloat(arguments.getOrDefault("min-pitch", 1f), "min-pitch"), 0f, 2f);
|
NumberProvider minPitch = NumberProviders.fromObject(arguments.getOrDefault("min-pitch", 1f));
|
||||||
boolean noSound = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("no-sound", false), "no-sound");
|
boolean silent = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("silent", false), "silent");
|
||||||
return new PlayTotemAnimationFunction<>(getPredicates(arguments), selector, item, sound, volume, pitch, minVolume, minPitch, noSound);
|
return new PlayTotemAnimationFunction<>(getPredicates(arguments), selector, item, sound, volume, pitch, minVolume, minPitch, silent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user