-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly capture saving future for vanilla chunk serializer
Fixes #371
- Loading branch information
Showing
1 changed file
with
13 additions
and
9 deletions.
There are no files selected for viewing
22 changes: 13 additions & 9 deletions
22
...nd/c2me/rewrites/chunksystem/mixin/serialization_sync/MixinThreadedAnvilChunkStorage.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 |
---|---|---|
@@ -1,30 +1,34 @@ | ||
package com.ishland.c2me.rewrites.chunksystem.mixin.serialization_sync; | ||
|
||
import com.ishland.c2me.rewrites.chunksystem.common.NewChunkHolderVanillaInterface; | ||
import com.ishland.c2me.base.mixin.access.IChunkHolder; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.server.world.ChunkHolder; | ||
import net.minecraft.server.world.ServerChunkLoadingManager; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.util.math.ChunkPos; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Supplier; | ||
|
||
@Mixin(ServerChunkLoadingManager.class) | ||
public abstract class MixinThreadedAnvilChunkStorage { | ||
|
||
@Shadow protected abstract @Nullable ChunkHolder getCurrentChunkHolder(long pos); | ||
|
||
// it is the responsibility of the caller to make sure the chunk is accessible or in a safe state | ||
@ModifyVariable(method = "save(Lnet/minecraft/world/chunk/Chunk;)Z", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/server/world/ServerChunkLoadingManager;setNbt(Lnet/minecraft/util/math/ChunkPos;Ljava/util/function/Supplier;)Ljava/util/concurrent/CompletableFuture;")) | ||
private CompletableFuture<Void> submitSavingFuture(CompletableFuture<Void> future, Chunk chunk) { | ||
ChunkHolder holder = this.getCurrentChunkHolder(chunk.getPos().toLong()); | ||
if (holder instanceof NewChunkHolderVanillaInterface vif) { | ||
vif.getBackingHolder().submitOp(future); | ||
@WrapOperation(method = "save(Lnet/minecraft/world/chunk/Chunk;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkLoadingManager;setNbt(Lnet/minecraft/util/math/ChunkPos;Ljava/util/function/Supplier;)Ljava/util/concurrent/CompletableFuture;")) | ||
private CompletableFuture<Void> submitSavingFuture(ServerChunkLoadingManager instance, ChunkPos chunkPos, Supplier<NbtCompound> supplier, Operation<CompletableFuture<Void>> original) { | ||
CompletableFuture<Void> ret = original.call(instance, chunkPos, supplier); | ||
ChunkHolder holder = this.getCurrentChunkHolder(chunkPos.toLong()); | ||
if (holder != null) { | ||
((IChunkHolder) holder).invokeCombineSavingFuture(ret); | ||
} | ||
return future; | ||
return ret; | ||
} | ||
|
||
} |