From bf6a65915443676161b79f3951797b1f9343ed20 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Mon, 22 Jul 2024 00:29:00 +1000 Subject: [PATCH] Suggestions --- .../skript/expressions/ExprDomestication.java | 19 ++++++++----- .../syntaxes/expressions/ExprDomestication.sk | 27 ++++++++++++++++--- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprDomestication.java b/src/main/java/ch/njol/skript/expressions/ExprDomestication.java index 2da91e0d843..f2f5dbeae1f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprDomestication.java +++ b/src/main/java/ch/njol/skript/expressions/ExprDomestication.java @@ -59,6 +59,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye case SET: case ADD: case REMOVE: + case RESET: return CollectionUtils.array(Number.class); default: return null; @@ -66,10 +67,11 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - assert mode != ChangeMode.REMOVE_ALL && mode != ChangeMode.DELETE && mode != ChangeMode.RESET; + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + assert mode != ChangeMode.REMOVE_ALL && mode != ChangeMode.DELETE; int change = delta == null ? 0 : ((Number) delta[0]).intValue(); + for (LivingEntity entity : getExpr().getArray(event)) { if (entity instanceof AbstractHorse) { AbstractHorse horse = (AbstractHorse) entity; @@ -84,6 +86,9 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { case REMOVE: level -= change; break; + case RESET: + level = 1; + break; default: assert false; return; @@ -91,6 +96,8 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { level = max ? Math.max(level, 1) : Math2.fit(1, level, horse.getMaxDomestication()); if (max) { horse.setMaxDomestication(level); + if (horse.getDomestication() > level) + horse.setDomestication(level); } else { horse.setDomestication(level); } @@ -99,13 +106,13 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { } @Override - protected String getPropertyName() { - return (max ? "max " : "") + "domestication level"; + public Class getReturnType() { + return Number.class; } @Override - public Class getReturnType() { - return Number.class; + protected String getPropertyName() { + return (max ? "max " : "") + "domestication level"; } } diff --git a/src/test/skript/tests/syntaxes/expressions/ExprDomestication.sk b/src/test/skript/tests/syntaxes/expressions/ExprDomestication.sk index 366e1ce80d2..ffbaa3c046c 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprDomestication.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprDomestication.sk @@ -19,10 +19,17 @@ test "domestication": assert max domestication level of {_e} is 100 with "removing from the max domestication of a horse should do exactly that" assert domestication level of {_e} is 50 with "removing from the domestication of a horse should do exactly that" - set {_max} to max domestication level of {_e} - set domestication level of {_e} to {_max} + 1 + subtract 60 from max domestication level of {_e} + assert domestication level of {_e} is 40 with "removing from the max domestication level of a horse should also clamp the domestication level if need be" + + reset max domestication level of {_e} + reset domestication level of {_e} + assert max domestication level of {_e} is 1 with "resetting the max domestication of a horse should do exactly that" + assert domestication level of {_e} is 1 with "resetting the domestication of a horse should do exactly that" + + set domestication level of {_e} to (max domestication level of {_e}) + 1 add 100 to domestication level of {_e} - assert domestication level of {_e} is not greater than {_max} with "the domestication level of a horse should never exceed it's max domestication level" + assert domestication level of {_e} is (max domestication level of {_e}) with "the domestication level of a horse should never exceed it's max domestication level" set domestication level of {_e} to 0 subtract 100 from domestication level of {_e} @@ -30,7 +37,19 @@ test "domestication": set max domestication level of {_e} to 0 subtract 100 from max domestication level of {_e} - assert max domestication level of {_e} is 1 with "the domestication level of a horse should never be less than 1" + assert max domestication level of {_e} is 1 with "the max domestication level of a horse should never be less than 1" + + add infinity value to max domestication level of {_e} + set max domestication level of {_e} to infinity value + add NaN value to max domestication level of {_e} + set max domestication level of {_e} to NaN value + assert max domestication level of {_e} is 1 with "infinity and NaN values affected the max domestication level of a horse, but shouldn't have" + + add infinity value to domestication level of {_e} + set domestication level of {_e} to infinity value + add NaN value to domestication level of {_e} + set domestication level of {_e} to NaN value + assert domestication level of {_e} is 1 with "infinity and NaN values affected the domestication level of a horse, but shouldn't have" assert max domestication level of {_z} is not set with "the max domestication of a non-horse should be null" assert domestication level of {_z} is not set with "the domestication of a non-horse should be null"