diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index 985333fdd..26a9afbb3 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -95,6 +95,8 @@ warning.config.condition.equals.missing_value1: "Issue found in file Issue found in file - The config '' is missing the required 'value2' argument for 'equals' condition." warning.config.condition.expression.missing_expression: "Issue found in file - The config '' is missing the required 'expression' argument for 'expression' condition." warning.config.condition.is_null.missing_argument: "Issue found in file - The config '' is missing the required 'argument' argument for 'is_null' condition." +warning.config.condition.hand.missing_hand: "Issue found in file - The config '' is missing the required 'hand' argument for 'hand' condition." +warning.config.condition.hand.invalid_hand: "Issue found in file - The config '' is using an invalid 'hand' argument '' for 'hand' condition. Allowed hand types: []" warning.config.structure.not_section: "Issue found in file - The config '' is expected to be a config section while it's actually a(n) ''." warning.config.image.duplicate: "Issue found in file - Duplicated image ''. Please check if there is the same configuration in other files." warning.config.image.missing_height: "Issue found in file - The image '' is missing the required 'height' argument." @@ -319,6 +321,9 @@ warning.config.function.open_window.missing_gui_type: "Issue found in fi warning.config.function.open_window.invalid_gui_type: "Issue found in file - The config '' is using an invalid gui type for 'open_window' function. Allowed types: []." warning.config.function.run.missing_functions: "Issue found in file - The config '' is missing the required 'functions' argument for 'run' function." warning.config.function.place_block.missing_block_state: "Issue found in file - The config '' is missing the required 'block-state' argument for 'place_block' function." +warning.config.function.set_food.missing_food: "Issue found in file - The config '' is missing the required 'food' argument for 'set_food' function." +warning.config.function.set_saturation.missing_saturation: "Issue found in file - The config '' is missing the required 'saturation' argument for 'set_saturation' function." +warning.config.function.play_sound.missing_sound: "Issue found in file - The config '' is missing the required 'sound' argument for 'play_sound' function." warning.config.selector.missing_type: "Issue found in file - The config '' is missing the required 'type' argument for selector." warning.config.selector.invalid_type: "Issue found in file - The config '' is using an invalid selector type ''." warning.config.selector.invalid_target: "Issue found in file - The config '' is using an invalid selector target ''." diff --git a/bukkit/loader/src/main/resources/translations/zh_cn.yml b/bukkit/loader/src/main/resources/translations/zh_cn.yml index ab9ca80ab..983dc9e9c 100644 --- a/bukkit/loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit/loader/src/main/resources/translations/zh_cn.yml @@ -96,6 +96,8 @@ warning.config.condition.equals.missing_value2: "在文件 中 warning.config.condition.expression.missing_expression: "在文件 中发现问题 - 配置项 '' 缺少 'expression' 条件必需的 'expression' 参数" warning.config.condition.is_null.missing_argument: "在文件 发现问题 - 配置项 '' 缺少 'is_null' 条件的必需的 'argument' 参数." warning.config.structure.not_section: "在文件 发现问题 - 配置项 '' 应为配置段落 但实际类型为 ''" +warning.config.condition.hand.missing_hand: "Issue found in file - The config '' is missing the required 'hand' argument for 'hand' condition." +warning.config.condition.hand.invalid_hand: "Issue found in file - The config '' is using an invalid 'hand' argument '' for 'hand' condition. Allowed hand types: []" warning.config.image.duplicate: "在文件 发现问题 - 重复的图片配置 '' 请检查其他文件中是否存在相同配置" warning.config.image.missing_height: "在文件 发现问题 - 图片 '' 缺少必需的 'height' 参数" warning.config.image.height_ascent_conflict: "在文件 发现问题 - 图片 '' 违反位图规则: 'height' 参数 '' 必须不小于 'ascent' 参数 ''" @@ -319,6 +321,9 @@ warning.config.function.open_window.missing_gui_type: "在文件 warning.config.function.open_window.invalid_gui_type: "在文件 中发现问题 - 配置项 '' 为 'open_window' 函数使用了无效的 GUI 类型 . 允许的类型: []。" warning.config.function.run.missing_functions: "在文件 中发现问题 - 配置项 '' 缺少 'run' 函数必需的 'functions' 参数" warning.config.function.place_block.missing_block_state: "在文件 中发现问题 - 配置项 '' 缺少 'place_block' 函数必需的 'block-state' 参数." +warning.config.function.set_food.missing_food: "Issue found in file - The config '' is missing the required 'food' argument for 'set_food' function." +warning.config.function.set_saturation.missing_saturation: "Issue found in file - The config '' is missing the required 'saturation' argument for 'set_saturation' function." +warning.config.function.play_sound.missing_sound: "Issue found in file - The config '' is missing the required 'sound' argument for 'play_sound' function." warning.config.selector.missing_type: "在文件 中发现问题 - 配置项 '' 缺少选择器必需的 'type' 参数" warning.config.selector.invalid_type: "在文件 中发现问题 - 配置项 '' 使用了无效的选择器类型 ''" warning.config.selector.invalid_target: "在文件 中发现问题 - 配置项 '' 使用了无效的选择器目标 ''" diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/BukkitEntity.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/BukkitEntity.java index ffe08c8fd..2193b86f9 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/BukkitEntity.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/BukkitEntity.java @@ -42,12 +42,12 @@ public class BukkitEntity extends AbstractEntity { } @Override - public float getXRot() { + public float xRot() { return literalObject().getYaw(); } @Override - public float getYRot() { + public float yRot() { return literalObject().getPitch(); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ComponentItemWrapper.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ComponentItemWrapper.java index b7c1eb500..c4bdbc860 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ComponentItemWrapper.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/ComponentItemWrapper.java @@ -98,6 +98,6 @@ public class ComponentItemWrapper implements ItemWrapper { @Override public void count(int amount) { - this.item.setAmount(amount); + this.item.setAmount(Math.max(amount, 0)); } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/LegacyItemWrapper.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/LegacyItemWrapper.java index 5e58510c9..154e121e5 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/LegacyItemWrapper.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/LegacyItemWrapper.java @@ -60,7 +60,7 @@ public class LegacyItemWrapper implements ItemWrapper { @Override public ItemStack load() { ItemStack itemStack = this.rtagItem.load(); - itemStack.setAmount(this.count); + itemStack.setAmount(Math.max(this.count, 0)); return itemStack; } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/FurnitureItemBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/FurnitureItemBehavior.java index 3c49d8c86..b604359e9 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/FurnitureItemBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/FurnitureItemBehavior.java @@ -105,7 +105,7 @@ public class FurnitureItemBehavior extends ItemBehavior { finalPlacePosition = new Vec3d(xz.left(), xz.right(), clickedPosition.z()); } } else { - furnitureYaw = placement.rotationRule().apply(180 + player.getXRot()); + furnitureYaw = placement.rotationRule().apply(180 + player.xRot()); Pair xz = placement.alignmentRule().apply(Pair.of(clickedPosition.x(), clickedPosition.z())); finalPlacePosition = new Vec3d(xz.left(), clickedPosition.y(), xz.right()); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java index 00d219bd8..3dce61b66 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java @@ -675,12 +675,12 @@ public class BukkitServerPlayer extends Player { } @Override - public float getYRot() { + public float yRot() { return platformPlayer().getPitch(); } @Override - public float getXRot() { + public float xRot() { return platformPlayer().getYaw(); } @@ -838,4 +838,24 @@ public class BukkitServerPlayer extends Player { public boolean isFlying() { return platformPlayer().isFlying(); } + + @Override + public int foodLevel() { + return platformPlayer().getFoodLevel(); + } + + @Override + public void setFoodLevel(int foodLevel) { + this.platformPlayer().setFoodLevel(Math.min(Math.max(0, foodLevel), 20)); + } + + @Override + public float saturation() { + return platformPlayer().getSaturation(); + } + + @Override + public void setSaturation(float saturation) { + this.platformPlayer().setSaturation(saturation); + } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/SoundUtils.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/SoundUtils.java index a733074e5..de80480fa 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/SoundUtils.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/SoundUtils.java @@ -1,7 +1,9 @@ package net.momirealms.craftengine.bukkit.util; import net.momirealms.craftengine.core.block.BlockSounds; +import net.momirealms.craftengine.core.sound.SoundSource; import net.momirealms.craftengine.core.util.Key; +import org.bukkit.SoundCategory; public class SoundUtils { @@ -21,4 +23,19 @@ public class SoundUtils { public static Object getOrRegisterSoundEvent(Key key) throws ReflectiveOperationException { return Reflections.method$SoundEvent$createVariableRangeEvent.invoke(null, KeyUtils.toResourceLocation(key)); } + + public static SoundCategory toBukkit(SoundSource source) { + return switch (source) { + case BLOCK -> SoundCategory.BLOCKS; + case MUSIC -> SoundCategory.MUSIC; + case VOICE -> SoundCategory.VOICE; + case MASTER -> SoundCategory.MASTER; + case PLAYER -> SoundCategory.PLAYERS; + case RECORD -> SoundCategory.RECORDS; + case AMBIENT -> SoundCategory.AMBIENT; + case HOSTILE -> SoundCategory.HOSTILE; + case NEUTRAL -> SoundCategory.NEUTRAL; + case WEATHER -> SoundCategory.WEATHER; + }; + } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorld.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorld.java index 4314a2fda..c1b6949a5 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorld.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/world/BukkitWorld.java @@ -3,8 +3,10 @@ package net.momirealms.craftengine.bukkit.world; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.util.EntityUtils; import net.momirealms.craftengine.bukkit.util.ItemUtils; +import net.momirealms.craftengine.bukkit.util.SoundUtils; import net.momirealms.craftengine.core.block.BlockStateWrapper; import net.momirealms.craftengine.core.item.Item; +import net.momirealms.craftengine.core.sound.SoundSource; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.VersionHelper; import net.momirealms.craftengine.core.world.BlockInWorld; @@ -87,6 +89,11 @@ public class BukkitWorld implements World { }); } + @Override + public void playSound(Position location, Key sound, float volume, float pitch, SoundSource source) { + platformWorld().playSound(new Location(null, location.x(), location.y(), location.z()), sound.toString(), SoundUtils.toBukkit(source), volume, pitch); + } + @Override public void playBlockSound(Position location, Key sound, float volume, float pitch) { platformWorld().playSound(new Location(null, location.x(), location.y(), location.z()), sound.toString(), SoundCategory.BLOCKS, volume, pitch); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/AbstractEntity.java b/core/src/main/java/net/momirealms/craftengine/core/entity/AbstractEntity.java index c9eb5a247..fa9643892 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/AbstractEntity.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/AbstractEntity.java @@ -6,6 +6,6 @@ public abstract class AbstractEntity implements Entity { @Override public WorldPosition position() { - return new WorldPosition(world(), x(), y(), z(), getXRot(), getYRot()); + return new WorldPosition(world(), x(), y(), z(), xRot(), yRot()); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/Entity.java b/core/src/main/java/net/momirealms/craftengine/core/entity/Entity.java index 15720fa5c..aac181c4b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/Entity.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/Entity.java @@ -20,12 +20,12 @@ public interface Entity { void tick(); - float getXRot(); + float xRot(); + + float yRot(); int entityID(); - float getYRot(); - World world(); Direction getDirection(); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java b/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java index 70e614cd2..c0132edf8 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/player/Player.java @@ -116,4 +116,12 @@ public abstract class Player extends AbstractEntity implements NetWorkUser { public boolean isAdventureMode() { return gameMode() == GameMode.ADVENTURE; } + + public abstract int foodLevel(); + + public abstract void setFoodLevel(int foodLevel); + + public abstract float saturation(); + + public abstract void setSaturation(float saturation); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/context/UseOnContext.java b/core/src/main/java/net/momirealms/craftengine/core/item/context/UseOnContext.java index 5e6280e02..e07191478 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/context/UseOnContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/context/UseOnContext.java @@ -73,6 +73,6 @@ public class UseOnContext { } public float getRotation() { - return this.player == null ? 0.0F : this.player.getYRot(); + return this.player == null ? 0.0F : this.player.yRot(); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/LootConditions.java b/core/src/main/java/net/momirealms/craftengine/core/loot/LootConditions.java index 9ea20df82..26798ceb1 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/LootConditions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/LootConditions.java @@ -34,6 +34,7 @@ public class LootConditions { register(CommonConditions.EQUALS, new EqualsCondition.FactoryImpl<>()); register(CommonConditions.EXPRESSION, new ExpressionCondition.FactoryImpl<>()); register(CommonConditions.IS_NULL, new IsNullCondition.FactoryImpl<>()); + register(CommonConditions.HAND, new HandCondition.FactoryImpl<>()); } public static void register(Key key, ConditionFactory factory) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java b/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java index 32d744ba0..662cefcea 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java @@ -78,15 +78,15 @@ public class LootTable { ); } - public ArrayList> getRandomItems(ContextHolder parameters, World world) { + public List> getRandomItems(ContextHolder parameters, World world) { return this.getRandomItems(parameters, world, null); } - public ArrayList> getRandomItems(ContextHolder parameters, World world, @Nullable Player player) { + public List> getRandomItems(ContextHolder parameters, World world, @Nullable Player player) { return this.getRandomItems(new LootContext(world, player, player == null ? 1f : (float) player.luck(), parameters)); } - private ArrayList> getRandomItems(LootContext context) { + private List> getRandomItems(LootContext context) { ArrayList> list = new ArrayList<>(); this.getRandomItems(context, list::add); return list; diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/CommonConditions.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/CommonConditions.java index ad64b2ec5..44a588cb9 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/CommonConditions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/CommonConditions.java @@ -21,4 +21,5 @@ public final class CommonConditions { public static final Key EQUALS = Key.from("craftengine:equals"); public static final Key EXPRESSION = Key.from("craftengine:expression"); public static final Key IS_NULL = Key.from("craftengine:is_null"); + public static final Key HAND = Key.from("craftengine:hand"); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/HandCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/HandCondition.java new file mode 100644 index 000000000..8cc171076 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/HandCondition.java @@ -0,0 +1,49 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.entity.player.InteractionHand; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.ResourceConfigUtils; + +import java.util.Locale; +import java.util.Map; +import java.util.Optional; + +public class HandCondition implements Condition { + private final InteractionHand hand; + + public HandCondition(InteractionHand hand) { + this.hand = hand; + } + + @Override + public Key type() { + return CommonConditions.HAND; + } + + @Override + public boolean test(CTX ctx) { + Optional optional = ctx.getOptionalParameter(DirectContextParameters.HAND); + if (optional.isPresent()) { + InteractionHand hand = optional.get(); + return hand.equals(this.hand); + } + return false; + } + + public static class FactoryImpl implements ConditionFactory { + + @Override + public Condition create(Map arguments) { + String hand = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("hand"), "warning.config.condition.hand.missing_hand"); + try { + return new HandCondition<>(InteractionHand.valueOf(hand.toUpperCase(Locale.ENGLISH))); + } catch (IllegalArgumentException e) { + throw new LocalizedResourceConfigException("warning.config.condition.hand.invalid_hand", hand); + } + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/IsNullCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/IsNullCondition.java index 7ea6d60cb..010221218 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/IsNullCondition.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/IsNullCondition.java @@ -24,7 +24,7 @@ public class IsNullCondition implements Condition { @Override public boolean test(CTX ctx) { Optional optional = ctx.getOptionalParameter(this.key); - return optional.isPresent(); + return optional.isEmpty(); } public static class FactoryImpl implements ConditionFactory { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventConditions.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventConditions.java index e7eea8bc8..3c93dd0e0 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventConditions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventConditions.java @@ -32,6 +32,7 @@ public class EventConditions { register(CommonConditions.EQUALS, new EqualsCondition.FactoryImpl<>()); register(CommonConditions.EXPRESSION, new ExpressionCondition.FactoryImpl<>()); register(CommonConditions.IS_NULL, new IsNullCondition.FactoryImpl<>()); + register(CommonConditions.HAND, new HandCondition.FactoryImpl<>()); } public static void register(Key key, ConditionFactory factory) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventFunctions.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventFunctions.java index c056c1c7e..ae0c66bd3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventFunctions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventFunctions.java @@ -26,6 +26,13 @@ public class EventFunctions { register(CommonFunctions.RUN, new RunFunction.FactoryImpl<>(EventFunctions::fromMap, EventConditions::fromMap)); register(CommonFunctions.PLACE_BLOCK, new PlaceBlockFunction.FactoryImpl<>(EventConditions::fromMap)); register(CommonFunctions.BREAK_BLOCK, new BreakBlockFunction.FactoryImpl<>(EventConditions::fromMap)); + register(CommonFunctions.UPDATE_INTERACTION_TICK, new UpdateInteractionFunction.FactoryImpl<>(EventConditions::fromMap)); + register(CommonFunctions.SET_COUNT, new SetCountFunction.FactoryImpl<>(EventConditions::fromMap)); + register(CommonFunctions.DROP_LOOT, new DropLootFunction.FactoryImpl<>(EventConditions::fromMap)); + register(CommonFunctions.SWING_HAND, new SwingHandFunction.FactoryImpl<>(EventConditions::fromMap)); + register(CommonFunctions.SET_FOOD, new SetFoodFunction.FactoryImpl<>(EventConditions::fromMap)); + register(CommonFunctions.SET_SATURATION, new SetSaturationFunction.FactoryImpl<>(EventConditions::fromMap)); + register(CommonFunctions.PLAY_SOUND, new PlaySoundFunction.FactoryImpl<>(EventConditions::fromMap)); } public static void register(Key key, FunctionFactory factory) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/BreakBlockFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/BreakBlockFunction.java index 97d5fc4b4..025cda880 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/BreakBlockFunction.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/BreakBlockFunction.java @@ -44,9 +44,9 @@ public class BreakBlockFunction extends AbstractConditional @Override public Function create(Map arguments) { - NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "")); - NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "")); - NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "")); + NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "")); + NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "")); + NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "")); return new BreakBlockFunction<>(x, y, z, getPredicates(arguments)); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/CommonFunctions.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/CommonFunctions.java index 4e7b764b4..82de72647 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/CommonFunctions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/CommonFunctions.java @@ -12,15 +12,15 @@ public final class CommonFunctions { public static final Key TITLE = Key.of("craftengine:title"); public static final Key OPEN_WINDOW = Key.of("craftengine:open_window"); public static final Key PARTICLE = Key.of("craftengine:particle"); - public static final Key SOUND = Key.of("craftengine:sound"); + public static final Key PLAY_SOUND = Key.of("craftengine:play_sound"); public static final Key POTION_EFFECT = Key.of("craftengine:potion_effect"); public static final Key BREAK_BLOCK = Key.of("craftengine:break_block"); public static final Key CANCEL_EVENT = Key.of("craftengine:cancel_event"); + public static final Key UPDATE_INTERACTION_TICK = Key.of("craftengine:update_interaction_tick"); + public static final Key SET_COUNT = Key.of("craftengine:set_count"); public static final Key PLACE_BLOCK = Key.of("craftengine:place_block"); - public static final Key FOOD = Key.of("craftengine:food"); - public static final Key SATURATION = Key.of("craftengine:saturation"); - public static final Key MONEY = Key.of("craftengine:money"); - public static final Key OXYGEN = Key.of("craftengine:oxygen"); - public static final Key MINE_RADIUS = Key.of("craftengine:mine_radius"); + public static final Key SET_FOOD = Key.of("craftengine:food"); + public static final Key SET_SATURATION = Key.of("craftengine:saturation"); public static final Key DROP_LOOT = Key.of("craftengine:drop_loot"); + public static final Key SWING_HAND = Key.of("craftengine:swing_hand"); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/DropLootFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/DropLootFunction.java new file mode 100644 index 000000000..216c1c511 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/DropLootFunction.java @@ -0,0 +1,68 @@ +package net.momirealms.craftengine.core.plugin.context.function; + +import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.item.Item; +import net.momirealms.craftengine.core.loot.LootTable; +import net.momirealms.craftengine.core.plugin.context.Condition; +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.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.MiscUtils; +import net.momirealms.craftengine.core.world.World; +import net.momirealms.craftengine.core.world.WorldPosition; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class DropLootFunction extends AbstractConditionalFunction { + private final NumberProvider x; + private final NumberProvider y; + private final NumberProvider z; + private final LootTable lootTable; + + public DropLootFunction(NumberProvider x, NumberProvider y, NumberProvider z, LootTable lootTable, List> predicates) { + super(predicates); + this.x = x; + this.y = y; + this.z = z; + this.lootTable = lootTable; + } + + @Override + public void runInternal(CTX ctx) { + Optional optionalWorldPosition = ctx.getOptionalParameter(DirectContextParameters.POSITION); + if (optionalWorldPosition.isPresent()) { + World world = optionalWorldPosition.get().world(); + WorldPosition position = new WorldPosition(world, x.getDouble(ctx), y.getDouble(ctx), z.getDouble(ctx)); + Player player = ctx.getOptionalParameter(DirectContextParameters.PLAYER).orElse(null); + List> items = lootTable.getRandomItems(ctx.contexts(), world, player); + for (Item item : items) { + world.dropItemNaturally(position, item); + } + } + } + + @Override + public Key type() { + return CommonFunctions.DROP_LOOT; + } + + public static class FactoryImpl extends AbstractFactory { + + public FactoryImpl(java.util.function.Function, Condition> factory) { + super(factory); + } + + @Override + public Function create(Map arguments) { + NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "")); + NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "")); + NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "")); + LootTable loots = LootTable.fromMap(MiscUtils.castToMap(arguments.get("loot"), true)); + return new DropLootFunction<>(x, y, z, loots, getPredicates(arguments)); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/PlaceBlockFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/PlaceBlockFunction.java index 2c0daf916..c5fbeae29 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/PlaceBlockFunction.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/PlaceBlockFunction.java @@ -77,9 +77,9 @@ public class PlaceBlockFunction extends AbstractConditional public Function create(Map arguments) { String state = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("block-state"), "warning.config.function.place_block.missing_block_state"); DelayedInitBlockState delayedInitBlockState = new DelayedInitBlockState(state); - NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "")); - NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "")); - NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "")); + NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "")); + NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "")); + NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "")); NumberProvider flags = Optional.ofNullable(arguments.get("update-flags")).map(NumberProviders::fromObject).orElse(NumberProviders.direct(UpdateOption.UPDATE_ALL.flags())); return new PlaceBlockFunction<>(delayedInitBlockState, x, y, z, flags, getPredicates(arguments)); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/PlaySoundFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/PlaySoundFunction.java new file mode 100644 index 000000000..ea5f4c547 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/PlaySoundFunction.java @@ -0,0 +1,73 @@ +package net.momirealms.craftengine.core.plugin.context.function; + +import net.momirealms.craftengine.core.plugin.context.Condition; +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.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.sound.SoundSource; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.ResourceConfigUtils; +import net.momirealms.craftengine.core.world.Vec3d; +import net.momirealms.craftengine.core.world.World; +import net.momirealms.craftengine.core.world.WorldPosition; + +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Optional; + +public class PlaySoundFunction extends AbstractConditionalFunction { + private final Key soundEvent; + private final NumberProvider x; + private final NumberProvider y; + private final NumberProvider z; + private final NumberProvider volume; + private final NumberProvider pitch; + private final SoundSource source; + + public PlaySoundFunction(Key soundEvent, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider volume, NumberProvider pitch, SoundSource source, List> predicates) { + super(predicates); + this.soundEvent = soundEvent; + this.x = x; + this.y = y; + this.z = z; + this.volume = volume; + this.pitch = pitch; + this.source = source; + } + + @Override + public void runInternal(CTX ctx) { + Optional optionalWorldPosition = ctx.getOptionalParameter(DirectContextParameters.POSITION); + if (optionalWorldPosition.isPresent()) { + World world = optionalWorldPosition.get().world(); + world.playSound(new Vec3d(this.x.getDouble(ctx), this.y.getDouble(ctx), this.z.getDouble(ctx)), + this.soundEvent, this.volume.getFloat(ctx), this.pitch.getFloat(ctx), this.source); + } + } + + @Override + public Key type() { + return CommonFunctions.PLAY_SOUND; + } + + public static class FactoryImpl extends AbstractFactory { + + public FactoryImpl(java.util.function.Function, Condition> factory) { + super(factory); + } + + @Override + public Function create(Map arguments) { + Key soundEvent = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("sound"), "warning.config.function.play_sound.missing_sound")); + NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "")); + NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "")); + NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "")); + NumberProvider volume = NumberProviders.fromObject(arguments.getOrDefault("volume", 1)); + NumberProvider pitch = NumberProviders.fromObject(arguments.getOrDefault("pitch", 1)); + SoundSource source = Optional.ofNullable(arguments.get("source")).map(String::valueOf).map(it -> SoundSource.valueOf(it.toUpperCase(Locale.ENGLISH))).orElse(SoundSource.MASTER); + return new PlaySoundFunction<>(soundEvent, x, y, z, volume, pitch, source, getPredicates(arguments)); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetCountFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetCountFunction.java new file mode 100644 index 000000000..6d9e6b496 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetCountFunction.java @@ -0,0 +1,57 @@ +package net.momirealms.craftengine.core.plugin.context.function; + +import net.momirealms.craftengine.core.item.Item; +import net.momirealms.craftengine.core.plugin.context.Condition; +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.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.ResourceConfigUtils; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class SetCountFunction extends AbstractConditionalFunction { + private final NumberProvider count; + private final boolean add; + + public SetCountFunction(NumberProvider count, boolean add, List> predicates) { + super(predicates); + this.count = count; + this.add = add; + } + + @Override + public void runInternal(CTX ctx) { + Optional> optionalItem = ctx.getOptionalParameter(DirectContextParameters.ITEM_IN_HAND); + if (optionalItem.isPresent()) { + Item item = optionalItem.get(); + if (this.add) { + item.count(Math.min(item.count() + (this.count.getInt(ctx)), item.maxStackSize())); + } else { + item.count(Math.min(this.count.getInt(ctx), item.maxStackSize())); + } + } + } + + @Override + public Key type() { + return CommonFunctions.SET_COUNT; + } + + public static class FactoryImpl extends AbstractFactory { + + public FactoryImpl(java.util.function.Function, Condition> factory) { + super(factory); + } + + @Override + public Function create(Map arguments) { + Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.function.set_count.missing_count"); + boolean add = (boolean) arguments.getOrDefault("add", false); + return new SetCountFunction<>(NumberProviders.fromObject(value), add, getPredicates(arguments)); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetFoodFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetFoodFunction.java new file mode 100644 index 000000000..fcd05f71a --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetFoodFunction.java @@ -0,0 +1,50 @@ +package net.momirealms.craftengine.core.plugin.context.function; + +import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.plugin.context.Condition; +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.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.ResourceConfigUtils; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class SetFoodFunction extends AbstractConditionalFunction { + private final NumberProvider count; + private final boolean add; + + public SetFoodFunction(NumberProvider count, boolean add, List> predicates) { + super(predicates); + this.count = count; + this.add = add; + } + + @Override + public void runInternal(CTX ctx) { + Optional optionalPlayer = ctx.getOptionalParameter(DirectContextParameters.PLAYER); + optionalPlayer.ifPresent(player -> player.setFoodLevel(this.add ? player.foodLevel() + this.count.getInt(ctx) : this.count.getInt(ctx))); + } + + @Override + public Key type() { + return CommonFunctions.SET_FOOD; + } + + public static class FactoryImpl extends AbstractFactory { + + public FactoryImpl(java.util.function.Function, Condition> factory) { + super(factory); + } + + @Override + public Function create(Map arguments) { + Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("food"), "warning.config.function.set_food.missing_food"); + boolean add = (boolean) arguments.getOrDefault("add", false); + return new SetFoodFunction<>(NumberProviders.fromObject(value), add, getPredicates(arguments)); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetSaturationFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetSaturationFunction.java new file mode 100644 index 000000000..86634543f --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SetSaturationFunction.java @@ -0,0 +1,50 @@ +package net.momirealms.craftengine.core.plugin.context.function; + +import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.plugin.context.Condition; +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.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.ResourceConfigUtils; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class SetSaturationFunction extends AbstractConditionalFunction { + private final NumberProvider count; + private final boolean add; + + public SetSaturationFunction(NumberProvider count, boolean add, List> predicates) { + super(predicates); + this.count = count; + this.add = add; + } + + @Override + public void runInternal(CTX ctx) { + Optional optionalPlayer = ctx.getOptionalParameter(DirectContextParameters.PLAYER); + optionalPlayer.ifPresent(player -> player.setSaturation(this.add ? player.saturation() + this.count.getFloat(ctx) : this.count.getFloat(ctx))); + } + + @Override + public Key type() { + return CommonFunctions.SET_SATURATION; + } + + public static class FactoryImpl extends AbstractFactory { + + public FactoryImpl(java.util.function.Function, Condition> factory) { + super(factory); + } + + @Override + public Function create(Map arguments) { + Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("saturation"), "warning.config.function.set_saturation.missing_saturation"); + boolean add = (boolean) arguments.getOrDefault("add", false); + return new SetSaturationFunction<>(NumberProviders.fromObject(value), add, getPredicates(arguments)); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SwingHandFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SwingHandFunction.java new file mode 100644 index 000000000..935fa210e --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/SwingHandFunction.java @@ -0,0 +1,52 @@ +package net.momirealms.craftengine.core.plugin.context.function; + +import net.momirealms.craftengine.core.entity.player.InteractionHand; +import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.util.Key; + +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Optional; + +public class SwingHandFunction extends AbstractConditionalFunction { + private final Optional hand; + + public SwingHandFunction(Optional hand, List> predicates) { + super(predicates); + this.hand = hand; + } + + @Override + public void runInternal(CTX ctx) { + Optional cancellable = ctx.getOptionalParameter(DirectContextParameters.PLAYER); + cancellable.ifPresent(value -> { + if (this.hand.isPresent()) { + value.swingHand(this.hand.get()); + } else { + value.swingHand(ctx.getOptionalParameter(DirectContextParameters.HAND).orElse(InteractionHand.MAIN_HAND)); + } + }); + } + + @Override + public Key type() { + return CommonFunctions.SWING_HAND; + } + + public static class FactoryImpl extends AbstractFactory { + + public FactoryImpl(java.util.function.Function, Condition> factory) { + super(factory); + } + + @Override + public Function create(Map arguments) { + Optional optionalHand = Optional.ofNullable(arguments.get("hand")).map(it -> InteractionHand.valueOf(it.toString().toUpperCase(Locale.ENGLISH))); + return new SwingHandFunction<>(optionalHand, getPredicates(arguments)); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/UpdateInteractionFunction.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/UpdateInteractionFunction.java new file mode 100644 index 000000000..6ef587ad5 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/function/UpdateInteractionFunction.java @@ -0,0 +1,41 @@ +package net.momirealms.craftengine.core.plugin.context.function; + +import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.util.Key; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class UpdateInteractionFunction extends AbstractConditionalFunction { + + public UpdateInteractionFunction(List> predicates) { + super(predicates); + } + + @Override + public void runInternal(CTX ctx) { + Optional cancellable = ctx.getOptionalParameter(DirectContextParameters.PLAYER); + cancellable.ifPresent(value -> value.updateLastSuccessfulInteractionTick(value.gameTicks())); + } + + @Override + public Key type() { + return CommonFunctions.UPDATE_INTERACTION_TICK; + } + + public static class FactoryImpl extends AbstractFactory { + + public FactoryImpl(java.util.function.Function, Condition> factory) { + super(factory); + } + + @Override + public Function create(Map arguments) { + return new UpdateInteractionFunction<>(getPredicates(arguments)); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/DirectContextParameters.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/DirectContextParameters.java index 798c8e53d..495739c3b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/DirectContextParameters.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/DirectContextParameters.java @@ -39,9 +39,13 @@ public final class DirectContextParameters { public static final ContextKey X = ContextKey.direct("x"); public static final ContextKey Y = ContextKey.direct("y"); public static final ContextKey Z = ContextKey.direct("z"); + public static final ContextKey YAW = ContextKey.direct("yaw"); + public static final ContextKey PITCH = ContextKey.direct("pitch"); public static final ContextKey BLOCK_X = ContextKey.direct("block_x"); public static final ContextKey BLOCK_Y = ContextKey.direct("block_y"); public static final ContextKey BLOCK_Z = ContextKey.direct("block_z"); + public static final ContextKey FOOD = ContextKey.direct("food"); + public static final ContextKey SATURATION = ContextKey.direct("saturation"); public static final ContextKey UUID = ContextKey.direct("uuid"); public static final ContextKey> MAIN_HAND_ITEM = ContextKey.direct("main_hand_item"); public static final ContextKey> OFF_HAND_ITEM = ContextKey.direct("off_hand_item"); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/EntityParameterProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/EntityParameterProvider.java index b36225670..465b49809 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/EntityParameterProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/EntityParameterProvider.java @@ -16,6 +16,8 @@ public class EntityParameterProvider implements ChainParameterProvider { CONTEXT_FUNCTIONS.put(DirectContextParameters.X, Entity::x); CONTEXT_FUNCTIONS.put(DirectContextParameters.Y, Entity::y); CONTEXT_FUNCTIONS.put(DirectContextParameters.Z, Entity::z); + CONTEXT_FUNCTIONS.put(DirectContextParameters.YAW, Entity::xRot); + CONTEXT_FUNCTIONS.put(DirectContextParameters.PITCH, Entity::yRot); CONTEXT_FUNCTIONS.put(DirectContextParameters.POSITION, Entity::position); CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_X, p -> MCUtils.fastFloor(p.x())); CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MCUtils.fastFloor(p.y())); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameterProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameterProvider.java index 4075c6ff8..042b08c05 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameterProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameterProvider.java @@ -1,6 +1,5 @@ package net.momirealms.craftengine.core.plugin.context.parameter; -import net.momirealms.craftengine.core.entity.AbstractEntity; import net.momirealms.craftengine.core.entity.Entity; import net.momirealms.craftengine.core.entity.player.InteractionHand; import net.momirealms.craftengine.core.entity.player.Player; @@ -16,13 +15,17 @@ import java.util.function.Function; public class PlayerParameterProvider implements ChainParameterProvider { private static final Map, Function> CONTEXT_FUNCTIONS = new HashMap<>(); static { - CONTEXT_FUNCTIONS.put(DirectContextParameters.X, AbstractEntity::x); - CONTEXT_FUNCTIONS.put(DirectContextParameters.Y, AbstractEntity::y); - CONTEXT_FUNCTIONS.put(DirectContextParameters.Z, AbstractEntity::z); - CONTEXT_FUNCTIONS.put(DirectContextParameters.POSITION, AbstractEntity::position); + CONTEXT_FUNCTIONS.put(DirectContextParameters.X, Entity::x); + CONTEXT_FUNCTIONS.put(DirectContextParameters.Y, Entity::y); + CONTEXT_FUNCTIONS.put(DirectContextParameters.Z, Entity::z); + CONTEXT_FUNCTIONS.put(DirectContextParameters.YAW, Entity::xRot); + CONTEXT_FUNCTIONS.put(DirectContextParameters.PITCH, Entity::yRot); + CONTEXT_FUNCTIONS.put(DirectContextParameters.POSITION, Entity::position); CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_X, p -> MCUtils.fastFloor(p.x())); CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MCUtils.fastFloor(p.y())); CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Z, p -> MCUtils.fastFloor(p.z())); + CONTEXT_FUNCTIONS.put(DirectContextParameters.FOOD, Player::foodLevel); + CONTEXT_FUNCTIONS.put(DirectContextParameters.SATURATION, Player::saturation); CONTEXT_FUNCTIONS.put(DirectContextParameters.NAME, Player::name); CONTEXT_FUNCTIONS.put(DirectContextParameters.UUID, Player::uuid); CONTEXT_FUNCTIONS.put(DirectContextParameters.WORLD, Entity::world); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PositionParameterProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PositionParameterProvider.java index 710917c19..b7e2b26b6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PositionParameterProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PositionParameterProvider.java @@ -18,6 +18,8 @@ public class PositionParameterProvider implements ChainParameterProvider MCUtils.fastFloor(p.x())); CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Y, p -> MCUtils.fastFloor(p.y())); CONTEXT_FUNCTIONS.put(DirectContextParameters.BLOCK_Z, p -> MCUtils.fastFloor(p.z())); diff --git a/core/src/main/java/net/momirealms/craftengine/core/sound/SoundSource.java b/core/src/main/java/net/momirealms/craftengine/core/sound/SoundSource.java new file mode 100644 index 000000000..e48a6c429 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/sound/SoundSource.java @@ -0,0 +1,27 @@ +package net.momirealms.craftengine.core.sound; + +import org.jetbrains.annotations.NotNull; + +public enum SoundSource { + MASTER("master"), + MUSIC("music"), + RECORD("record"), + WEATHER("weather"), + BLOCK("block"), + HOSTILE("hostile"), + NEUTRAL("neutral"), + PLAYER("player"), + AMBIENT("ambient"), + VOICE("voice"); + + private final String id; + + SoundSource(final String id) { + this.id = id; + } + + @NotNull + public String id() { + return this.id; + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/Direction.java b/core/src/main/java/net/momirealms/craftengine/core/util/Direction.java index 87cd8df73..a48bfdc14 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/Direction.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/Direction.java @@ -94,8 +94,8 @@ public enum Direction { } public static Direction[] orderedByNearest(AbstractEntity entity) { - float xRotation = entity.getXRot() * (float) (Math.PI / 180.0); - float yRotation = -entity.getYRot() * (float) (Math.PI / 180.0); + float xRotation = entity.xRot() * (float) (Math.PI / 180.0); + float yRotation = -entity.yRot() * (float) (Math.PI / 180.0); float sinX = (float) Math.sin(xRotation); float cosX = (float) Math.cos(xRotation); float sinY = (float) Math.sin(yRotation); diff --git a/core/src/main/java/net/momirealms/craftengine/core/world/World.java b/core/src/main/java/net/momirealms/craftengine/core/world/World.java index c48a66415..08efec880 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/world/World.java +++ b/core/src/main/java/net/momirealms/craftengine/core/world/World.java @@ -1,8 +1,10 @@ package net.momirealms.craftengine.core.world; +import net.kyori.adventure.sound.Sound; import net.momirealms.craftengine.core.block.BlockStateWrapper; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.sound.SoundData; +import net.momirealms.craftengine.core.sound.SoundSource; import net.momirealms.craftengine.core.util.Key; import java.nio.file.Path; @@ -34,6 +36,8 @@ public interface World { void dropExp(Position location, int amount); + void playSound(Position location, Key sound, float volume, float pitch, SoundSource source); + void playBlockSound(Position location, Key sound, float volume, float pitch); default void playBlockSound(Position location, SoundData data) {