Skip to content

Commit

Permalink
Move ChunkSystem hook class to common util package
Browse files Browse the repository at this point in the history
This class is supposed to be interfaced by a lot of other patches,
so it makes sense to move it here.
  • Loading branch information
Spottedleaf committed Jul 17, 2024
1 parent bbf85f3 commit 59c3043
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ca.spottedleaf.moonrise.common.list.ReferenceList;
import ca.spottedleaf.moonrise.common.util.CoordinateUtils;
import ca.spottedleaf.moonrise.common.util.MoonriseConstants;
import ca.spottedleaf.moonrise.patches.chunk_system.ChunkSystem;
import ca.spottedleaf.moonrise.common.util.ChunkSystem;
import ca.spottedleaf.moonrise.patches.chunk_tick_iteration.ChunkTickConstants;
import it.unimi.dsi.fastutil.longs.Long2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ca.spottedleaf.moonrise.patches.chunk_system;
package ca.spottedleaf.moonrise.common.util;

import ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor;
import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
Expand Down Expand Up @@ -36,7 +36,6 @@ public static void scheduleChunkLoad(final ServerLevel level, final int chunkX,
((ChunkSystemServerLevel)level).moonrise$getChunkTaskScheduler().scheduleChunkLoad(chunkX, chunkZ, gen, toStatus, addTicket, priority, onComplete);
}

// Paper - rewrite chunk system
public static void scheduleChunkLoad(final ServerLevel level, final int chunkX, final int chunkZ, final ChunkStatus toStatus,
final boolean addTicket, final PrioritisedExecutor.Priority priority, final Consumer<ChunkAccess> onComplete) {
((ChunkSystemServerLevel)level).moonrise$getChunkTaskScheduler().scheduleChunkLoad(chunkX, chunkZ, toStatus, addTicket, priority, onComplete);
Expand Down Expand Up @@ -68,8 +67,8 @@ public static boolean hasAnyChunkHolders(final ServerLevel level) {
return getUpdatingChunkHolderCount(level) != 0;
}

public static void onEntityPreAdd(final ServerLevel level, final Entity entity) {

public static boolean screenEntity(final ServerLevel level, final Entity entity) {
return true;
}

public static void onChunkHolderCreate(final ServerLevel level, final ChunkHolder holder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ca.spottedleaf.moonrise.mixin.chunk_system;

import ca.spottedleaf.moonrise.common.util.MoonriseConstants;
import ca.spottedleaf.moonrise.patches.chunk_system.ChunkSystem;
import ca.spottedleaf.moonrise.common.util.ChunkSystem;
import ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread;
import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
import ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkSystemChunkHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ protected abstract void entitySectionChangeCallback(

protected abstract void entityEndTicking(final Entity entity);

protected abstract boolean screenEntity(final Entity entity);

private static Entity maskNonAccessible(final Entity entity) {
if (entity == null) {
return null;
Expand Down Expand Up @@ -412,6 +414,10 @@ protected boolean addEntity(final Entity entity, final boolean fromDisk) {
return false;
}

if (!this.screenEntity(entity)) {
return false;
}

Entity currentlyMapped = this.entityById.putIfAbsent((long)entity.getId(), entity);
if (currentlyMapped != null) {
LOGGER.warn("Entity id already exists: " + entity.getId() + ", mapped to " + currentlyMapped + ", can't add " + entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ protected void entityEndTicking(final Entity entity) {

}

@Override
protected boolean screenEntity(final Entity entity) {
return true;
}

public void markTicking(final long pos) {
if (this.tickingChunks.add(pos)) {
final int chunkX = CoordinateUtils.getChunkX(pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ protected void entityEndTicking(final Entity entity) {

}

@Override
protected boolean screenEntity(final Entity entity) {
return true;
}

protected static final class DefaultLevelCallback implements LevelCallback<Entity> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.spottedleaf.moonrise.common.list.ReferenceList;
import ca.spottedleaf.moonrise.common.util.TickThread;
import ca.spottedleaf.moonrise.common.util.ChunkSystem;
import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices;
import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.EntityLookup;
Expand Down Expand Up @@ -104,4 +105,9 @@ protected void entityStartTicking(final Entity entity) {
protected void entityEndTicking(final Entity entity) {

}

@Override
protected boolean screenEntity(final Entity entity) {
return ChunkSystem.screenEntity(this.serverWorld, entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ca.spottedleaf.moonrise.common.util.MoonriseCommon;
import ca.spottedleaf.moonrise.common.util.TickThread;
import ca.spottedleaf.moonrise.common.util.WorldUtil;
import ca.spottedleaf.moonrise.patches.chunk_system.ChunkSystem;
import ca.spottedleaf.moonrise.common.util.ChunkSystem;
import ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread;
import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ca.spottedleaf.moonrise.common.util.CoordinateUtils;
import ca.spottedleaf.moonrise.common.util.TickThread;
import ca.spottedleaf.moonrise.common.util.WorldUtil;
import ca.spottedleaf.moonrise.patches.chunk_system.ChunkSystem;
import ca.spottedleaf.moonrise.common.util.ChunkSystem;
import ca.spottedleaf.moonrise.patches.chunk_system.ChunkSystemFeatures;
import ca.spottedleaf.moonrise.patches.chunk_system.async_save.AsyncChunkSaveData;
import ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread;
Expand Down Expand Up @@ -43,7 +43,6 @@
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
import net.minecraft.world.level.chunk.storage.EntityStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.invoke.VarHandle;
Expand Down

0 comments on commit 59c3043

Please sign in to comment.