-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle reentrance in ServerEntityManager#unloadChunks
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...main/java/com/ishland/c2me/rewrites/chunksystem/mixin/fixes/MixinServerEntityManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.ishland.c2me.rewrites.chunksystem.mixin.fixes; | ||
|
||
import it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet; | ||
import it.unimi.dsi.fastutil.longs.LongSet; | ||
import net.minecraft.server.world.ServerEntityManager; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ServerEntityManager.class) | ||
public abstract class MixinServerEntityManager { | ||
|
||
@Mutable | ||
@Shadow @Final private LongSet pendingUnloads; | ||
|
||
@Shadow protected abstract boolean unload(long chunkPos); | ||
|
||
@Inject(method = "<init>", at = @At("RETURN")) | ||
private void replacePendingUnloads(CallbackInfo ci) { | ||
this.pendingUnloads = new LongLinkedOpenHashSet(this.pendingUnloads); | ||
} | ||
|
||
/** | ||
* @author ishland | ||
* @reason use alternative method for unloading | ||
*/ | ||
@Overwrite | ||
private void unloadChunks() { | ||
LongSet pendingUnloads = this.pendingUnloads; | ||
if (!(pendingUnloads instanceof LongLinkedOpenHashSet)) { | ||
// set is replaced by someone else, replace it again | ||
pendingUnloads = this.pendingUnloads = new LongLinkedOpenHashSet(pendingUnloads); | ||
} | ||
|
||
// apparently vanilla also have a `this.trackingStatuses.get(pos) != EntityTrackingStatus.HIDDEN` check????? | ||
// removed here because chunks in pendingUnloads should always satisfy that constraint | ||
// if it does not, you have other serious problems | ||
LongLinkedOpenHashSet linkedOpenHashSet = (LongLinkedOpenHashSet) pendingUnloads; | ||
while (!linkedOpenHashSet.isEmpty()) { | ||
long pos = linkedOpenHashSet.removeFirstLong(); | ||
this.unload(pos); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters