Skip to content

Commit

Permalink
6 lines to get this working...
Browse files Browse the repository at this point in the history
  • Loading branch information
walksanatora committed Jul 13, 2024
1 parent e08e58a commit a4558c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -42,21 +44,21 @@ public abstract class CastingEnvironment {
/**
* Stores all listeners that should be notified whenever a CastingEnvironment is initialised.
*/
private static final List<Consumer<CastingEnvironment>> createEventListeners = new ArrayList<>();
private static final List<BiConsumer<CastingEnvironment, CompoundTag>> createEventListeners = new ArrayList<>();

/**
* Add a listener that will be called whenever a new CastingEnvironment is created.
*/
public static void addCreateEventListener(Consumer<CastingEnvironment> listener) {
public static void addCreateEventListener(BiConsumer<CastingEnvironment, CompoundTag> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down

0 comments on commit a4558c8

Please sign in to comment.