From e04499437ed445594503567c38b021242b0b1706 Mon Sep 17 00:00:00 2001 From: melontini <104443436+melontini@users.noreply.github.com> Date: Fri, 26 Apr 2024 23:31:26 +0700 Subject: [PATCH] No. Why? Should've added this earlier. --- CHANGELOG.md | 5 +---- gradle.properties | 2 +- .../commander/impl/expression/EvalUtils.java | 7 +++---- .../impl/util/functions/HasContextFunction.java | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/main/java/me/melontini/commander/impl/util/functions/HasContextFunction.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e49c4e..af2d1a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,3 @@ ### What's New: -* Added entity parameter to `cmd:explode`. The entity will be marked as the "creator" of the explosion and other entities will redirect their anger to the entity if affected by the explosion. -* Added fire parameter to `cmd:explode`. Creates fire, if true. -* Fixed `double` casts converting numbers to scientific notation. -* `long` and `int` casts no longer actually convert to their types, instead they truncate the trailing zeros. \ No newline at end of file +* Added `hasContext` function to expressions. Allows checking if loot context has the required parameter: `if(hasContext("tool"), "Hi", "Bye")` \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index cdc4464..cd6c665 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.20.1 yarn_mappings=1.20.1+build.10 loader_version=0.15.7 # Mod Properties -mod_version=0.3.0 +mod_version=0.3.1 maven_group=me.melontini archives_base_name=commander # Dependencies diff --git a/src/main/java/me/melontini/commander/impl/expression/EvalUtils.java b/src/main/java/me/melontini/commander/impl/expression/EvalUtils.java index 321c1d4..08afd93 100644 --- a/src/main/java/me/melontini/commander/impl/expression/EvalUtils.java +++ b/src/main/java/me/melontini/commander/impl/expression/EvalUtils.java @@ -18,10 +18,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import me.melontini.commander.api.expression.Arithmetica; import me.melontini.commander.impl.event.data.types.ExtractionTypes; -import me.melontini.commander.impl.util.functions.ClampFunction; -import me.melontini.commander.impl.util.functions.LerpFunction; -import me.melontini.commander.impl.util.functions.RangedRandomFunction; -import me.melontini.commander.impl.util.functions.StructContainsKeyFunction; +import me.melontini.commander.impl.util.functions.*; import net.minecraft.loot.context.LootContext; import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; @@ -68,6 +65,8 @@ public class EvalUtils { .put("clamp", new ClampFunction()) //maps .put("structContainsKey", new StructContainsKeyFunction()) + //meta + .put("hasContext", new HasContextFunction()) // trigonometric .put("acos", new AcosFunction()) .put("acosh", new AcosHFunction()) diff --git a/src/main/java/me/melontini/commander/impl/util/functions/HasContextFunction.java b/src/main/java/me/melontini/commander/impl/util/functions/HasContextFunction.java new file mode 100644 index 0000000..e80601b --- /dev/null +++ b/src/main/java/me/melontini/commander/impl/util/functions/HasContextFunction.java @@ -0,0 +1,16 @@ +package me.melontini.commander.impl.util.functions; + +import com.ezylang.evalex.EvaluationException; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.functions.AbstractFunction; +import com.ezylang.evalex.functions.FunctionParameter; +import com.ezylang.evalex.parser.Token; + +@FunctionParameter(name = "key") +public class HasContextFunction extends AbstractFunction { + @Override + public EvaluationValue evaluate(Expression expression, Token functionToken, EvaluationValue... par) throws EvaluationException { + return expression.convertValue(expression.getDataAccessor().getData(par[0].getStringValue()) != null); + } +}