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 f03011ad9..874428fe7 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 @@ -11,6 +11,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; @@ -28,6 +29,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; @@ -43,21 +45,30 @@ 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); } + /** + * Add a listener that will be called whenever a new CastingEnvironment is created (legacy). + * @deprecated replaced by {@link #addCreateEventListener(BiConsumer)} + */ + @Deprecated(since = "0.11.0-pre-660") + public static void addCreateEventListener(Consumer listener) { + createEventListeners.add((env, data) -> {listener.accept(env);}); + } + 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 8c605d9fb..caa000676 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) } /**