From a4558c8d1eb6888095da221818ab87ac2c24f7d6 Mon Sep 17 00:00:00 2001 From: Walker Fowlkes Date: Sat, 13 Jul 2024 11:13:33 -0700 Subject: [PATCH 1/4] 6 lines to get this working... --- .../api/casting/eval/CastingEnvironment.java | 10 ++++++---- .../petrak/hexcasting/api/casting/eval/vm/CastingVM.kt | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java index d1f447cf85..92749a356e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java @@ -10,6 +10,7 @@ import at.petrak.hexcasting.api.pigment.FrozenPigment; import at.petrak.hexcasting.api.utils.HexUtils; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -27,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Predicate; @@ -42,21 +44,21 @@ public abstract class CastingEnvironment { /** * Stores all listeners that should be notified whenever a CastingEnvironment is initialised. */ - private static final List> createEventListeners = new ArrayList<>(); + private static final List> createEventListeners = new ArrayList<>(); /** * Add a listener that will be called whenever a new CastingEnvironment is created. */ - public static void addCreateEventListener(Consumer listener) { + public static void addCreateEventListener(BiConsumer listener) { createEventListeners.add(listener); } private boolean createEventTriggered = false; - public final void triggerCreateEvent() { + public final void triggerCreateEvent(CompoundTag userData) { if (!createEventTriggered) { for (var listener : createEventListeners) - listener.accept(this); + listener.accept(this, userData); createEventTriggered = true; } } diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt index 8cbd8d51e6..c8f034f08c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/vm/CastingVM.kt @@ -24,7 +24,7 @@ import net.minecraft.server.level.ServerLevel */ class CastingVM(var image: CastingImage, val env: CastingEnvironment) { init { - env.triggerCreateEvent() + env.triggerCreateEvent(image.userData) } /** From 8caad005d81e345c77f1dee7da9ce8aa000b5720 Mon Sep 17 00:00:00 2001 From: Walker Fowlkes Date: Sat, 13 Jul 2024 11:17:33 -0700 Subject: [PATCH 2/4] remove dead import --- .../petrak/hexcasting/api/casting/eval/CastingEnvironment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java index 92749a356e..d90af2b4ce 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java @@ -29,7 +29,6 @@ import java.util.List; import java.util.Map; import java.util.function.BiConsumer; -import java.util.function.Consumer; import java.util.function.Predicate; import static at.petrak.hexcasting.api.HexAPI.modLoc; From 621279d79ae0e06fc35c995fc9ed74645524b340 Mon Sep 17 00:00:00 2001 From: Walker Fowlkes Date: Thu, 22 Aug 2024 17:16:48 -0700 Subject: [PATCH 3/4] add a override for the old method as to not break other addons --- .../hexcasting/api/casting/eval/CastingEnvironment.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java index 45dc825255..7bd7585c20 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Predicate; import static at.petrak.hexcasting.api.HexAPI.modLoc; @@ -53,6 +54,13 @@ public static void addCreateEventListener(BiConsumer listener) { + createEventListeners.add((env, data) -> {listener.accept(env);}); + } + private boolean createEventTriggered = false; public final void triggerCreateEvent(CompoundTag userData) { From eacf4031e247c0bb9119d6b480ff8465628bab41 Mon Sep 17 00:00:00 2001 From: Walker Fowlkes Date: Thu, 22 Aug 2024 17:50:08 -0700 Subject: [PATCH 4/4] Deprecate the old method --- .../petrak/hexcasting/api/casting/eval/CastingEnvironment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java index 7bd7585c20..874428fe7c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java @@ -56,7 +56,9 @@ public static void addCreateEventListener(BiConsumer listener) { createEventListeners.add((env, data) -> {listener.accept(env);}); }