Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add moonrise compatibility #368

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.popcraft.chunky.mixin;

import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.world.level.ChunkPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

import java.util.Optional;
Expand All @@ -20,7 +18,4 @@ public interface ChunkMapMixin {

@Invoker("readChunk")
public CompletableFuture<Optional<CompoundTag>> invokeReadChunk(ChunkPos pos);

@Accessor("pendingUnloads")
public Long2ObjectLinkedOpenHashMap<ChunkHolder> getPendingUnloads();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package org.popcraft.chunky.mixin;

import net.minecraft.server.level.ChunkResult;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

import java.util.concurrent.CompletableFuture;

@Mixin(ServerChunkCache.class)
public interface ServerChunkCacheMixin {
@Invoker("runDistanceManagerUpdates")
@SuppressWarnings({"UnusedReturnValue", "UnnecessaryInterfaceModifier"})
public boolean invokeRunDistanceManagerUpdates();
@SuppressWarnings("UnnecessaryModifier")
@Invoker("getChunkFutureMainThread")
public CompletableFuture<ChunkResult<ChunkAccess>> invokeGetChunkFutureMainThread(final int chunkX,
final int chunkZ,
final ChunkStatus toStatus,
final boolean create);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ public CompletableFuture<Boolean> isChunkGenerated(final int x, final int z) {
if (loadedChunkHolder != null && loadedChunkHolder.getLatestStatus() == ChunkStatus.FULL) {
return CompletableFuture.completedFuture(true);
}
final ChunkHolder unloadedChunkHolder = chunkMapMixin.getPendingUnloads().get(chunkPos.toLong());
if (unloadedChunkHolder != null && unloadedChunkHolder.getLatestStatus() == ChunkStatus.FULL) {
return CompletableFuture.completedFuture(true);
}
if (UPDATE_CHUNK_NBT) {
return chunkMapMixin.invokeReadChunk(chunkPos)
.thenApply(optionalNbt -> optionalNbt
Expand Down Expand Up @@ -106,11 +102,7 @@ public CompletableFuture<Void> getChunkAtAsync(final int x, final int z) {
if (TICKING_LOAD_DURATION > 0) {
serverChunkCache.addRegionTicket(CHUNKY_TICKING, chunkPos, 1, Unit.INSTANCE);
}
((ServerChunkCacheMixin) serverChunkCache).invokeRunDistanceManagerUpdates();
final ChunkMap chunkManager = serverChunkCache.chunkMap;
final ChunkMapMixin chunkMapMixin = (ChunkMapMixin) chunkManager;
final ChunkHolder chunkHolder = chunkMapMixin.invokeGetVisibleChunkIfPresent(chunkPos.toLong());
final CompletableFuture<Void> chunkFuture = chunkHolder == null ? CompletableFuture.completedFuture(null) : CompletableFuture.allOf(chunkHolder.scheduleChunkGenerationTask(ChunkStatus.FULL, chunkManager));
final CompletableFuture<Void> chunkFuture = CompletableFuture.allOf(((ServerChunkCacheMixin) world.getChunkSource()).invokeGetChunkFutureMainThread(x, z, ChunkStatus.FULL, true));
chunkFuture.whenCompleteAsync((ignored, throwable) -> serverChunkCache.removeRegionTicket(CHUNKY, chunkPos, 0, Unit.INSTANCE), world.getServer());
return chunkFuture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ public CompletableFuture<Boolean> isChunkGenerated(final int x, final int z) {
if (loadedChunkHolder != null && loadedChunkHolder.getLatestStatus() == ChunkStatus.FULL) {
return CompletableFuture.completedFuture(true);
}
final ChunkHolder unloadedChunkHolder = chunkStorage.pendingUnloads.get(chunkPos.toLong());
if (unloadedChunkHolder != null && unloadedChunkHolder.getLatestStatus() == ChunkStatus.FULL) {
return CompletableFuture.completedFuture(true);
}
if (UPDATE_CHUNK_NBT) {
return chunkStorage.readChunk(chunkPos)
.thenApply(optionalNbt -> optionalNbt
Expand Down Expand Up @@ -104,10 +100,7 @@ public CompletableFuture<Void> getChunkAtAsync(final int x, final int z) {
if (TICKING_LOAD_DURATION > 0) {
serverChunkCache.addRegionTicket(CHUNKY_TICKING, chunkPos, 1, Unit.INSTANCE);
}
serverChunkCache.runDistanceManagerUpdates();
final ChunkMap chunkManager = serverChunkCache.chunkMap;
final ChunkHolder chunkHolder = chunkManager.getVisibleChunkIfPresent(chunkPos.toLong());
final CompletableFuture<Void> chunkFuture = chunkHolder == null ? CompletableFuture.completedFuture(null) : CompletableFuture.allOf(chunkHolder.scheduleChunkGenerationTask(ChunkStatus.FULL, chunkManager));
final CompletableFuture<Void> chunkFuture = CompletableFuture.allOf(world.getChunkSource().getChunkFutureMainThread(x, z, ChunkStatus.FULL, true));
chunkFuture.whenCompleteAsync((ignored, throwable) -> serverChunkCache.removeRegionTicket(CHUNKY, chunkPos, 0, Unit.INSTANCE), world.getServer());
return chunkFuture;
}
Expand Down
3 changes: 1 addition & 2 deletions neoforge/src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ChunkMap
public net.minecraft.server.level.ChunkMap readChunk(Lnet/minecraft/world/level/ChunkPos;)Ljava/util/concurrent/CompletableFuture;
public net.minecraft.server.level.ChunkMap getVisibleChunkIfPresent(J)Lnet/minecraft/server/level/ChunkHolder;
public net.minecraft.server.level.ChunkMap pendingUnloads
# ServerChunkCache
public net.minecraft.server.level.ServerChunkCache runDistanceManagerUpdates()Z
public net.minecraft.server.level.ServerChunkCache getChunkFutureMainThread(IILnet/minecraft/world/level/chunk/status/ChunkStatus;Z)Ljava/util/concurrent/CompletableFuture;