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 extends Item>> 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