Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface SableChunkEventPlatform {
void onChunkPacketReplaced(final LevelChunk chunk);

void onOldChunkInvalid(final LevelChunk chunk);

void onServerChunkLoad(final LevelChunk chunk);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}