diff --git a/src/main/java/net/gensokyoreimagined/nitori/access/IMixinChunkMap_TrackedEntityAccess.java b/src/main/java/net/gensokyoreimagined/nitori/access/IMixinChunkMap_TrackedEntityAccess.java
index ef1447f..fb36476 100644
--- a/src/main/java/net/gensokyoreimagined/nitori/access/IMixinChunkMap_TrackedEntityAccess.java
+++ b/src/main/java/net/gensokyoreimagined/nitori/access/IMixinChunkMap_TrackedEntityAccess.java
@@ -14,14 +14,15 @@
// along with this program. If not, see .
package net.gensokyoreimagined.nitori.access;
-import com.destroystokyo.paper.util.misc.PooledLinkedHashSets;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
+import java.util.List;
+
public interface IMixinChunkMap_TrackedEntityAccess {
@SuppressWarnings("EmptyMethod")
Entity getEntity();
@SuppressWarnings("EmptyMethod")
- void callUpdatePlayers(PooledLinkedHashSets.PooledObjectLinkedOpenHashSet newTrackerCandidates);
+ void callUpdatePlayers(List players);
}
diff --git a/src/main/java/net/gensokyoreimagined/nitori/common/block/BlockStateFlags.java b/src/main/java/net/gensokyoreimagined/nitori/common/block/BlockStateFlags.java
index 93a9b4a..85cc09f 100644
--- a/src/main/java/net/gensokyoreimagined/nitori/common/block/BlockStateFlags.java
+++ b/src/main/java/net/gensokyoreimagined/nitori/common/block/BlockStateFlags.java
@@ -67,7 +67,7 @@ public boolean test(BlockState operand) {
OVERSIZED_SHAPE = new TrackedBlockStatePredicate(countingFlags.size()) {
@Override
public boolean test(BlockState operand) {
- return operand.shapeExceedsCube();
+ return operand.hasLargeCollisionShape();
}
};
countingFlags.add(OVERSIZED_SHAPE);
diff --git a/src/main/java/net/gensokyoreimagined/nitori/common/math/random/RandomGeneratorRandom.java b/src/main/java/net/gensokyoreimagined/nitori/common/math/random/RandomGeneratorRandom.java
index 3123612..229bb67 100644
--- a/src/main/java/net/gensokyoreimagined/nitori/common/math/random/RandomGeneratorRandom.java
+++ b/src/main/java/net/gensokyoreimagined/nitori/common/math/random/RandomGeneratorRandom.java
@@ -94,6 +94,11 @@ public RandomSource fromHashOf(String seed) {
return new RandomGeneratorRandom((long) seed.hashCode() ^ this.seed);
}
+ @Override
+ public RandomSource fromSeed(long seed) {
+ return new RandomGeneratorRandom(seed ^ this.seed);
+ }
+
/*
@Override
public Random split(long seed) {
diff --git a/src/main/java/net/gensokyoreimagined/nitori/mixin/ChunkMapMixin.java b/src/main/java/net/gensokyoreimagined/nitori/mixin/ChunkMapMixin.java
index aab125a..993701e 100644
--- a/src/main/java/net/gensokyoreimagined/nitori/mixin/ChunkMapMixin.java
+++ b/src/main/java/net/gensokyoreimagined/nitori/mixin/ChunkMapMixin.java
@@ -14,7 +14,7 @@
// along with this program. If not, see .
package net.gensokyoreimagined.nitori.mixin;
-import com.destroystokyo.paper.util.misc.PooledLinkedHashSets;
+import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
@@ -42,6 +42,7 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.annotation.Nullable;
@@ -86,13 +87,13 @@ private void reassignEntityTrackers(CallbackInfo ci) {
}
}
- @Inject(method = "processTrackQueue", at = @At("HEAD"), cancellable = true)
+ @Inject(method = "newTrackerTick", at = @At("HEAD"), cancellable = true)
private void atProcessTrackQueueHead(CallbackInfo callbackInfo) {
// Implementation of 0107-Multithreaded-Tracker.patch
//TODO: Restore config condition
//if (NitoriConfig.enableAsyncEntityTracker) {
if (this.gensouHacks$multithreadedTracker == null) {
- this.gensouHacks$multithreadedTracker = new MultithreadedTracker(this.level.chunkSource.entityTickingChunks, this.gensouHacks$trackerMainThreadTasks);
+ this.gensouHacks$multithreadedTracker = new MultithreadedTracker(((ChunkSystemServerLevel) this.level).moonrise$getEntityTickingChunks(), this.gensouHacks$trackerMainThreadTasks);
}
this.gensouHacks$tracking = true;
@@ -132,9 +133,9 @@ private void reassignSeenBy(CallbackInfo ci) {
@Override
@Final
@Invoker
- public abstract void callUpdatePlayers(PooledLinkedHashSets.PooledObjectLinkedOpenHashSet newTrackerCandidates); // Mirai -> public
+ public abstract void callUpdatePlayers(List players); // Mirai -> public
- @Redirect(method = "updatePlayers(Lcom/destroystokyo/paper/util/misc/PooledLinkedHashSets$PooledObjectLinkedOpenHashSet;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap$TrackedEntity;updatePlayer(Lnet/minecraft/server/level/ServerPlayer;)V"))
+ @Redirect(method = "updatePlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap$TrackedEntity;updatePlayer(Lnet/minecraft/server/level/ServerPlayer;)V"))
private void handleCitizensPluginTracking(ChunkMap.TrackedEntity self, ServerPlayer serverPlayer) {
// Nitori - Citizens tracker must run on the main thread to avoid cyclic wait
if (PluginCompatibilityRegistry.CITIZENS.shouldRedirectToMainThread(self, serverPlayer)) {
diff --git a/src/main/java/net/gensokyoreimagined/nitori/mixin/MixinChunkEntitySlices.java b/src/main/java/net/gensokyoreimagined/nitori/mixin/MixinChunkEntitySlices.java
index 8560844..2d8c418 100644
--- a/src/main/java/net/gensokyoreimagined/nitori/mixin/MixinChunkEntitySlices.java
+++ b/src/main/java/net/gensokyoreimagined/nitori/mixin/MixinChunkEntitySlices.java
@@ -14,8 +14,8 @@
// along with this program. If not, see .
package net.gensokyoreimagined.nitori.mixin;
-import com.destroystokyo.paper.util.maplist.EntityList;
-import io.papermc.paper.world.ChunkEntitySlices;
+import ca.spottedleaf.moonrise.common.list.EntityList;
+import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices;
import net.gensokyoreimagined.nitori.access.IMixinChunkEntitySlicesAccess;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
diff --git a/src/main/java/net/gensokyoreimagined/nitori/mixin/MixinIteratorSafeOrderedReferenceSet.java b/src/main/java/net/gensokyoreimagined/nitori/mixin/MixinIteratorSafeOrderedReferenceSet.java
index 12049aa..f74f4a5 100644
--- a/src/main/java/net/gensokyoreimagined/nitori/mixin/MixinIteratorSafeOrderedReferenceSet.java
+++ b/src/main/java/net/gensokyoreimagined/nitori/mixin/MixinIteratorSafeOrderedReferenceSet.java
@@ -14,7 +14,7 @@
// along with this program. If not, see .
package net.gensokyoreimagined.nitori.mixin;
-import io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet;
+import ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet;
import net.gensokyoreimagined.nitori.access.IMixinIteratorSafeOrderedReferenceSetAccess;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
diff --git a/src/main/java/net/gensokyoreimagined/nitori/tracker/MultithreadedTracker.java b/src/main/java/net/gensokyoreimagined/nitori/tracker/MultithreadedTracker.java
index ed47c4c..0d688b8 100644
--- a/src/main/java/net/gensokyoreimagined/nitori/tracker/MultithreadedTracker.java
+++ b/src/main/java/net/gensokyoreimagined/nitori/tracker/MultithreadedTracker.java
@@ -18,6 +18,8 @@
* Ported from Petal, derived from Airplane
*/
+import ca.spottedleaf.moonrise.common.list.ReferenceList;
+import ca.spottedleaf.moonrise.common.misc.NearbyPlayers;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet; //io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet;
import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices; //io.papermc.paper.world.ChunkEntitySlices;
@@ -26,9 +28,13 @@
import net.gensokyoreimagined.nitori.access.IMixinIteratorSafeOrderedReferenceSetAccess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkMap;
+import net.minecraft.server.level.ServerChunkCache;
+import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.chunk.LevelChunk;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -47,64 +53,44 @@ private enum TrackerStage {
.setPriority(Thread.NORM_PRIORITY - 2)
.build());
- private final IteratorSafeOrderedReferenceSet entityTickingChunks;
+ private final ReferenceList entityTickingChunks;
private final AtomicInteger taskIndex = new AtomicInteger();
private final ConcurrentLinkedQueue mainThreadTasks;
private final AtomicInteger finishedTasks = new AtomicInteger();
- public MultithreadedTracker(IteratorSafeOrderedReferenceSet entityTickingChunks, ConcurrentLinkedQueue mainThreadTasks) {
+ public MultithreadedTracker(ReferenceList entityTickingChunks, ConcurrentLinkedQueue mainThreadTasks) {
this.entityTickingChunks = entityTickingChunks;
this.mainThreadTasks = mainThreadTasks;
}
public void tick() {
- int iterator = this.entityTickingChunks.createRawIterator();
+ this.taskIndex.set(0);
+ this.finishedTasks.set(0);
- if (iterator == -1) {
- return;
+ for (int i = 0; i < parallelism; i++) {
+ trackerExecutor.execute(this::runUpdatePlayers);
}
// start with updating players
- try {
- this.taskIndex.set(iterator);
- this.finishedTasks.set(0);
-
- for (int i = 0; i < parallelism; i++) {
- trackerExecutor.execute(this::runUpdatePlayers);
- }
-
- while (this.taskIndex.get() < ((IMixinIteratorSafeOrderedReferenceSetAccess) (Object) this.entityTickingChunks).getListSize()) {
- this.runMainThreadTasks();
- this.handleChunkUpdates(5); // assist
- }
-
- while (this.finishedTasks.get() != parallelism) {
- this.runMainThreadTasks();
- }
-
- this.runMainThreadTasks(); // finish any remaining tasks
- } finally {
- this.entityTickingChunks.finishRawIterator();
+ while (this.taskIndex.get() < this.entityTickingChunks.size()) {
+ this.runMainThreadTasks();
+ this.handleChunkUpdates(5); // assist
}
// then send changes
- iterator = this.entityTickingChunks.createRawIterator();
-
- if (iterator == -1) {
- return;
+ while (this.finishedTasks.get() != parallelism) {
+ this.runMainThreadTasks();
}
- try {
- do {
- LevelChunk chunk = this.entityTickingChunks.rawGet(iterator);
+ this.runMainThreadTasks(); // finish any remaining tasks
- if (chunk != null) {
- this.updateChunkEntities(chunk, TrackerStage.SEND_CHANGES);
- }
- } while (++iterator < ((IMixinIteratorSafeOrderedReferenceSetAccess) (Object) this.entityTickingChunks).getListSize());
- } finally {
- this.entityTickingChunks.finishRawIterator();
+ for (ServerChunkCache.ChunkAndHolder chunkAndHolder : this.entityTickingChunks) {
+ LevelChunk chunk = chunkAndHolder.chunk();
+
+ if (chunk != null) {
+ this.updateChunkEntities(chunk, TrackerStage.SEND_CHANGES);
+ }
}
}
@@ -129,9 +115,9 @@ private void runUpdatePlayers() {
private boolean handleChunkUpdates(int tasks) {
int index;
- while ((index = this.taskIndex.getAndAdd(tasks)) < ((IMixinIteratorSafeOrderedReferenceSetAccess) (Object) this.entityTickingChunks).getListSize()) {
- for (int i = index; i < index + tasks && i < ((IMixinIteratorSafeOrderedReferenceSetAccess) (Object) this.entityTickingChunks).getListSize(); i++) {
- LevelChunk chunk = this.entityTickingChunks.rawGet(i);
+ while ((index = this.taskIndex.getAndAdd(tasks)) < this.entityTickingChunks.size()) {
+ for (int i = index; i < index + tasks && i < this.entityTickingChunks.size(); i++) {
+ LevelChunk chunk = this.entityTickingChunks.getChecked(i).chunk();
if (chunk != null) {
try {
this.updateChunkEntities(chunk, TrackerStage.UPDATE_PLAYERS);
@@ -149,7 +135,7 @@ private boolean handleChunkUpdates(int tasks) {
}
private void updateChunkEntities(LevelChunk chunk, TrackerStage trackerStage) {
- final ChunkEntitySlices entitySlices = chunk.level.getEntityLookup().getChunk(chunk.locX, chunk.locZ);
+ final ChunkEntitySlices entitySlices = chunk.level.moonrise$getEntityLookup().getChunk(chunk.locX, chunk.locZ);
if (entitySlices == null) {
return;
}
@@ -165,7 +151,10 @@ private void updateChunkEntities(LevelChunk chunk, TrackerStage trackerStage) {
if (trackerStage == TrackerStage.SEND_CHANGES) {
entityTracker.serverEntity.sendChanges();
} else if (trackerStage == TrackerStage.UPDATE_PLAYERS) {
- ((IMixinChunkMap_TrackedEntityAccess) (Object) entityTracker).callUpdatePlayers(((IMixinChunkMap_TrackedEntityAccess) (Object) entityTracker).getEntity().getPlayersInTrackRange());
+ ReferenceList nearbyPlayers = chunkMap.level.moonrise$getNearbyPlayers().getChunk(entity.chunkPosition()).getPlayers(NearbyPlayers.NearbyMapType.VIEW_DISTANCE);
+ List nearbyPlayersList = new ArrayList(nearbyPlayers.size()); // intentionally typed as List for requirement clarity
+ nearbyPlayers.forEach(nearbyPlayersList::add);
+ ((IMixinChunkMap_TrackedEntityAccess) (Object) entityTracker).callUpdatePlayers(nearbyPlayersList);
}
}
}