diff --git a/common/src/main/java/dev/ryanhcode/sable/platform/SableChunkEventPlatform.java b/common/src/main/java/dev/ryanhcode/sable/platform/SableChunkEventPlatform.java index 26ac1ae7..f39fee89 100644 --- a/common/src/main/java/dev/ryanhcode/sable/platform/SableChunkEventPlatform.java +++ b/common/src/main/java/dev/ryanhcode/sable/platform/SableChunkEventPlatform.java @@ -10,4 +10,6 @@ public interface SableChunkEventPlatform { void onChunkPacketReplaced(final LevelChunk chunk); void onOldChunkInvalid(final LevelChunk chunk); + + void onServerChunkLoad(final LevelChunk chunk); } diff --git a/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/LevelPlot.java b/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/LevelPlot.java index 4bcb4121..512619e1 100644 --- a/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/LevelPlot.java +++ b/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/LevelPlot.java @@ -5,6 +5,7 @@ import dev.ryanhcode.sable.api.sublevel.SubLevelContainer; import dev.ryanhcode.sable.companion.math.BoundingBox3i; import dev.ryanhcode.sable.companion.math.BoundingBox3ic; +import dev.ryanhcode.sable.platform.SableChunkEventPlatform; import dev.ryanhcode.sable.sublevel.ServerSubLevel; import dev.ryanhcode.sable.sublevel.SubLevel; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -140,7 +141,7 @@ public BlockPos getCenterBlock() { * * @param pos the global chunk position */ - protected void newChunk(final ChunkPos pos, final LevelChunk chunk, final boolean initializeLighting) { + protected void newChunk(final ChunkPos pos, final LevelChunk chunk, final boolean initializeLighting, final boolean fireEvent) { final ChunkPos local = this.toLocal(pos); if (this.getChunkHolder(local) != null) { @@ -149,6 +150,9 @@ protected void newChunk(final ChunkPos pos, final LevelChunk chunk, final boolea final PlotChunkHolder holder = PlotChunkHolder.create(chunk.getLevel(), pos, this.getLightEngine(), chunk); this.addChunkHolder(local, holder, initializeLighting); + if (fireEvent) { + SableChunkEventPlatform.INSTANCE.onServerChunkLoad(chunk); + } } /** @@ -176,7 +180,7 @@ public void newEmptyChunk(final ChunkPos pos) { } final LevelChunk chunk = new LevelChunk(level, pos, UpgradeData.EMPTY, new LevelChunkTicks<>(), new LevelChunkTicks<>(), 0L, sections, null, null); - this.newChunk(pos, chunk, true); + this.newChunk(pos, chunk, true, true); } diff --git a/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/ServerLevelPlot.java b/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/ServerLevelPlot.java index 1bc7964e..20911fe3 100644 --- a/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/ServerLevelPlot.java +++ b/common/src/main/java/dev/ryanhcode/sable/sublevel/plot/ServerLevelPlot.java @@ -10,6 +10,7 @@ import dev.ryanhcode.sable.companion.math.BoundingBox3i; import dev.ryanhcode.sable.index.SableTags; import dev.ryanhcode.sable.mixinterface.plot.serialization.LevelChunkTicksExtension; +import dev.ryanhcode.sable.platform.SableChunkEventPlatform; import dev.ryanhcode.sable.platform.SablePlotPlatform; import dev.ryanhcode.sable.sublevel.ServerSubLevel; import dev.ryanhcode.sable.sublevel.SubLevel; @@ -324,7 +325,7 @@ private void newNonLitChunk(final ChunkPos pos) { } final LevelChunk chunk = new LevelChunk(level, pos, UpgradeData.EMPTY, new LevelChunkTicks<>(), new LevelChunkTicks<>(), 0L, sections, null, null); - this.newChunk(pos, chunk, false); + this.newChunk(pos, chunk, false, false); } /** @@ -648,6 +649,16 @@ public void load(final CompoundTag tag) { subLevel.updateMergedMassData(1.0f); physicsSystem.getPipeline().onStatsChanged(subLevel); + for (final String key : chunks.getAllKeys()) { + final long chunkPos = Long.parseLong(key); + + final int x = ChunkPos.getX(chunkPos); + final int z = ChunkPos.getZ(chunkPos); + final ChunkPos local = new ChunkPos(x, z); + final LevelChunk chunk = this.getChunk(local); + + SableChunkEventPlatform.INSTANCE.onServerChunkLoad(chunk); + } } /** diff --git a/common/src/main/resources/natives/sable_rapier/sable_rapier_binaries.zip.l4z b/common/src/main/resources/natives/sable_rapier/sable_rapier_binaries.zip.l4z index 3d11cc17..0ac035dd 100644 Binary files a/common/src/main/resources/natives/sable_rapier/sable_rapier_binaries.zip.l4z and b/common/src/main/resources/natives/sable_rapier/sable_rapier_binaries.zip.l4z differ diff --git a/fabric/src/main/java/dev/ryanhcode/sable/fabric/platform/SableChunkEventPlatformImpl.java b/fabric/src/main/java/dev/ryanhcode/sable/fabric/platform/SableChunkEventPlatformImpl.java index 1747e55f..ab47e32c 100644 --- a/fabric/src/main/java/dev/ryanhcode/sable/fabric/platform/SableChunkEventPlatformImpl.java +++ b/fabric/src/main/java/dev/ryanhcode/sable/fabric/platform/SableChunkEventPlatformImpl.java @@ -2,8 +2,8 @@ import dev.ryanhcode.sable.platform.SableChunkEventPlatform; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.world.level.chunk.LevelChunk; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.server.level.ServerLevel;import net.minecraft.world.level.chunk.LevelChunk; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal @@ -18,4 +18,9 @@ public void onChunkPacketReplaced(final LevelChunk chunk) { public void onOldChunkInvalid(final LevelChunk chunk) { ClientChunkEvents.CHUNK_UNLOAD.invoker().onChunkUnload((ClientLevel) chunk.getLevel(), chunk); } + + @Override + public void onServerChunkLoad(final LevelChunk chunk) { + ServerChunkEvents.CHUNK_LOAD.invoker().onChunkLoad((ServerLevel) chunk.getLevel(), chunk); + } } diff --git a/neoforge/src/main/java/dev/ryanhcode/sable/neoforge/platform/SableChunkEventPlatformImpl.java b/neoforge/src/main/java/dev/ryanhcode/sable/neoforge/platform/SableChunkEventPlatformImpl.java index bb55f58e..3bc719c3 100644 --- a/neoforge/src/main/java/dev/ryanhcode/sable/neoforge/platform/SableChunkEventPlatformImpl.java +++ b/neoforge/src/main/java/dev/ryanhcode/sable/neoforge/platform/SableChunkEventPlatformImpl.java @@ -18,4 +18,9 @@ public void onChunkPacketReplaced(final LevelChunk chunk) { public void onOldChunkInvalid(final LevelChunk chunk) { // no-op } + + @Override + public void onServerChunkLoad(final LevelChunk chunk) { + NeoForge.EVENT_BUS.post(new ChunkEvent.Load(chunk, false)); + } }