diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkStorageMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkStorageMixin.java index 84d6e477..402f80dd 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkStorageMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkStorageMixin.java @@ -1,8 +1,13 @@ package ca.spottedleaf.moonrise.mixin.chunk_system; +import ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO; import ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemChunkStorage; +import com.mojang.datafixers.DataFixer; import com.mojang.logging.LogUtils; +import java.nio.file.Path; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.StreamTagVisitor; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.storage.ChunkScanAccess; import net.minecraft.world.level.chunk.storage.ChunkStorage; @@ -10,6 +15,7 @@ import net.minecraft.world.level.chunk.storage.RegionFileStorage; import net.minecraft.world.level.chunk.storage.RegionStorageInfo; import net.minecraft.world.level.levelgen.structure.LegacyStructureDataHandler; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -35,6 +41,14 @@ abstract class ChunkStorageMixin implements ChunkSystemChunkStorage, AutoCloseab @Unique private RegionFileStorage storage; + @Unique + private ServerLevel level; + + @Override + public void moonrise$setLevel(final ServerLevel level) { + this.level = level; + } + /** * @reason Destroy old IO worker field after retrieving region storage from it * @author Spottedleaf @@ -45,9 +59,53 @@ abstract class ChunkStorageMixin implements ChunkSystemChunkStorage, AutoCloseab value = "RETURN" ) ) - private void initHook(final CallbackInfo ci) { + private void initHook(final RegionStorageInfo arg, final Path path, final DataFixer dataFixer, final boolean bl, final CallbackInfo ci) { this.storage = this.worker.storage; - this.worker = null; + // Dummy impl for mods that try to loadAsync directly + this.worker = new IOWorker(arg, path, bl) { + @Override + public boolean isOldChunkAround(final ChunkPos chunkPos, final int i) { + throw new UnsupportedOperationException(); + } + + @Override + public CompletableFuture store(final ChunkPos chunkPos, final @Nullable CompoundTag compoundTag) { + throw new UnsupportedOperationException(); + } + + @Override + public CompletableFuture> loadAsync(final ChunkPos chunkPos) { + final CompletableFuture> future = new CompletableFuture<>(); + MoonriseRegionFileIO.loadDataAsync(ChunkStorageMixin.this.level, chunkPos.x, chunkPos.z, MoonriseRegionFileIO.RegionFileType.CHUNK_DATA, (tag, throwable) -> { + if (throwable != null) { + future.completeExceptionally(throwable); + } else { + future.complete(Optional.ofNullable(tag)); + } + }, false); + return future; + } + + @Override + public CompletableFuture synchronize(final boolean bl) { + throw new UnsupportedOperationException(); + } + + @Override + public CompletableFuture scanChunk(final ChunkPos chunkPos, final StreamTagVisitor streamTagVisitor) { + throw new UnsupportedOperationException(); + } + + @Override + public void close() throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public RegionStorageInfo storageInfo() { + throw new UnsupportedOperationException(); + } + }; } @Override diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/datacontroller/ChunkDataController.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/datacontroller/ChunkDataController.java index a36ab89f..31d75cb3 100644 --- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/datacontroller/ChunkDataController.java +++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/datacontroller/ChunkDataController.java @@ -20,6 +20,7 @@ public final class ChunkDataController extends MoonriseRegionFileIO.RegionDataCo public ChunkDataController(final ServerLevel world, final ChunkTaskScheduler taskScheduler) { super(MoonriseRegionFileIO.RegionFileType.CHUNK_DATA, taskScheduler.ioExecutor, taskScheduler.compressionExecutor); this.world = world; + ((ChunkSystemChunkStorage)this.world.getChunkSource().chunkMap).moonrise$setLevel(world); } @Override diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkStorage.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkStorage.java index 129a35ff..5345312b 100644 --- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkStorage.java +++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkStorage.java @@ -1,9 +1,12 @@ package ca.spottedleaf.moonrise.patches.chunk_system.storage; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.storage.RegionFileStorage; public interface ChunkSystemChunkStorage { public RegionFileStorage moonrise$getRegionStorage(); + public void moonrise$setLevel(final ServerLevel level); + }