From 2f0268d182fa3345ec79451ac7a7f2b3cd013bfb Mon Sep 17 00:00:00 2001 From: "max." Date: Sat, 8 Jun 2024 12:41:57 +0200 Subject: [PATCH 1/3] Fix BlockStatePredicate#of for lists with 1 element --- .../latvian/mods/kubejs/block/state/BlockStatePredicate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/block/state/BlockStatePredicate.java b/common/src/main/java/dev/latvian/mods/kubejs/block/state/BlockStatePredicate.java index 5e5143c69..da60ada99 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/block/state/BlockStatePredicate.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/block/state/BlockStatePredicate.java @@ -122,7 +122,7 @@ static BlockStatePredicate of(Object o) { return new AndMatch(predicates); } - return ofSingle(o); + return ofSingle(list.get(0)); } static RuleTest ruleTestOf(Object o) { From 738b58cc0b19d802dcb48d22605428110d95d9ef Mon Sep 17 00:00:00 2001 From: "max." Date: Sat, 8 Jun 2024 12:51:47 +0200 Subject: [PATCH 2/3] Fix error in duration calculation for days / weeks, closes #842 --- .../src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java b/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java index 09857eebc..e173a3b94 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java @@ -904,7 +904,7 @@ public static TemporalAmount getTemporalAmount(Object o) { ticks = 0L; } - ticks += amount; + ticks += (long) amount; } case "ns" -> nanos += (long) amount; @@ -912,8 +912,8 @@ public static TemporalAmount getTemporalAmount(Object o) { case "s" -> millis = (long) (amount * 1000D); case "m" -> millis = (long) (amount * 60000D); case "h" -> millis = (long) (amount * 60000D) * 60L; - case "d" -> millis = (long) (amount * 24D * 86400L) * 1000L; - case "w" -> millis = (long) (amount * 24D * 86400L) * 7000L; + case "d" -> millis = (long) (amount * 86400L) * 1000L; + case "w" -> millis = (long) (amount * 86400L) * 7000L; case "M" -> millis = (long) (amount * 31556952D / 12D) * 1000L; case "y" -> millis = (long) (amount * 31556952D) * 1000L; default -> throw new IllegalArgumentException("Invalid temporal unit: " + matcher.group(2)); From 620dc01fc91789e153438e62a06a2653cc9edb42 Mon Sep 17 00:00:00 2001 From: "max." Date: Sat, 8 Jun 2024 13:02:34 +0200 Subject: [PATCH 3/3] Fix more issues with duration wrapper (whitespace in between units is now optional, amounts are now correctly summed together) Fixes #814 --- .../dev/latvian/mods/kubejs/util/UtilsJS.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java b/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java index e173a3b94..9f2e4e9ea 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java @@ -105,7 +105,7 @@ public class UtilsJS { public static MinecraftServer staticServer = null; public static final ResourceLocation UNKNOWN_ID = new ResourceLocation("unknown", "unknown"); public static final Predicate ALWAYS_TRUE = o -> true; - public static final Pattern TEMPORAL_AMOUNT_PATTERN = Pattern.compile("(\\d+)\\s*(y|M|d|w|h|m|s|ms|ns|t)\\b"); + public static final Pattern TEMPORAL_AMOUNT_PATTERN = Pattern.compile("(\\d+)\\s*(y|M|d|w|h|m|s|ms|ns|t)\\b?"); private static Collection ALL_STATE_CACHE = null; private static final Map ENTITY_SELECTOR_CACHE = new HashMap<>(); @@ -909,13 +909,13 @@ public static TemporalAmount getTemporalAmount(Object o) { case "ns" -> nanos += (long) amount; case "ms" -> millis += (long) amount; - case "s" -> millis = (long) (amount * 1000D); - case "m" -> millis = (long) (amount * 60000D); - case "h" -> millis = (long) (amount * 60000D) * 60L; - case "d" -> millis = (long) (amount * 86400L) * 1000L; - case "w" -> millis = (long) (amount * 86400L) * 7000L; - case "M" -> millis = (long) (amount * 31556952D / 12D) * 1000L; - case "y" -> millis = (long) (amount * 31556952D) * 1000L; + case "s" -> millis += (long) (amount * 1000D); + case "m" -> millis += (long) (amount * 60000D); + case "h" -> millis += (long) (amount * 60000D) * 60L; + case "d" -> millis += (long) (amount * 86400L) * 1000L; + case "w" -> millis += (long) (amount * 86400L) * 7000L; + case "M" -> millis += (long) (amount * 31556952D / 12D) * 1000L; + case "y" -> millis += (long) (amount * 31556952D) * 1000L; default -> throw new IllegalArgumentException("Invalid temporal unit: " + matcher.group(2)); } }