Skip to content

Commit

Permalink
fabric: Call ServerChunkEvents.CHUNK_LOAD/CHUNK_UNLOAD, add and cal…
Browse files Browse the repository at this point in the history
…l `FabricHooks.ON_EXPLOSION` event

fixes #16
related to #45
  • Loading branch information
jpenilla committed Oct 15, 2024
1 parent 1dc3cb5 commit e8bad61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
include "me.shedaniel.cloth:cloth-config-fabric:${rootProject.cloth_version}"
modImplementation "com.terraformersmc:modmenu:11.0.1"

modImplementation fabricApiLibs.command.api.v2
modImplementation fabricApiLibs.fabric.api
include fabricApiLibs.command.api.v2
include fabricApiLibs.base
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import ca.spottedleaf.moonrise.common.PlatformHooks;
import ca.spottedleaf.moonrise.common.util.ConfigHolder;
import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.GenerationChunkHolder;
Expand All @@ -25,6 +28,19 @@

public final class FabricHooks implements PlatformHooks {

public interface OnExplosionDetonate {
void onExplosion(final Level world, final Explosion explosion, final List<Entity> possiblyAffecting, final double diameter);
}

public static final Event<OnExplosionDetonate> ON_EXPLOSION = EventFactory.createArrayBacked(
OnExplosionDetonate.class,
listeners -> (final Level world, final Explosion explosion, final List<Entity> possiblyAffecting, final double diameter) -> {
for (int i = 0; i < listeners.length; i++) {
listeners[i].onExplosion(world, explosion, possiblyAffecting, diameter);
}
}
);

@Override
public String getBrand() {
return "Moonrise";
Expand All @@ -44,7 +60,7 @@ public Predicate<BlockState> maybeHasLightEmission() {

@Override
public void onExplosion(final Level world, final Explosion explosion, final List<Entity> possiblyAffecting, final double diameter) {

ON_EXPLOSION.invoker().onExplosion(world, explosion, possiblyAffecting, diameter);
}

@Override
Expand All @@ -69,7 +85,7 @@ public void setCurrentlyLoading(final GenerationChunkHolder holder, final LevelC

@Override
public void chunkFullStatusComplete(final LevelChunk newChunk, final ProtoChunk original) {

ServerChunkEvents.CHUNK_LOAD.invoker().onChunkLoad((ServerLevel) newChunk.getLevel(), newChunk);
}

@Override
Expand All @@ -84,7 +100,7 @@ public void onChunkHolderTicketChange(final ServerLevel world, final NewChunkHol

@Override
public void chunkUnloadFromWorld(final LevelChunk chunk) {

ServerChunkEvents.CHUNK_UNLOAD.invoker().onChunkUnload((ServerLevel) chunk.getLevel(), chunk);
}

@Override
Expand Down

0 comments on commit e8bad61

Please sign in to comment.