Skip to content

Commit

Permalink
fix: send post-processed chunk to player at any case
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Dec 9, 2024
1 parent 4e9eb83 commit 8df2b37
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.ishland.c2me.notickvd.mixin;

import com.ishland.c2me.base.common.threadstate.ThreadInstrumentation;
import com.ishland.c2me.base.mixin.access.IThreadedAnvilChunkStorage;
import com.ishland.c2me.rewrites.chunksystem.common.ChunkLoadingContext;
import com.ishland.c2me.rewrites.chunksystem.common.ChunkState;
import com.ishland.c2me.rewrites.chunksystem.common.NewChunkHolderVanillaInterface;
import com.ishland.c2me.rewrites.chunksystem.common.NewChunkStatus;
import com.ishland.c2me.rewrites.chunksystem.common.statuses.ServerAccessibleChunkSending;
import com.ishland.c2me.rewrites.chunksystem.common.threadstate.ChunkTaskWork;
import com.ishland.flowsched.scheduler.Cancellable;
import com.ishland.flowsched.scheduler.ItemHolder;
import com.ishland.flowsched.scheduler.KeyStatusPair;
Expand Down Expand Up @@ -56,7 +58,13 @@ private static void onCLInit(CallbackInfo ci) {
*/
@Overwrite(remap = false)
public CompletionStage<Void> upgradeToThis(ChunkLoadingContext context, Cancellable cancellable) {
return CompletableFuture.runAsync(() -> sendChunkToPlayer(context.tacs(), context.holder()), ((IThreadedAnvilChunkStorage) context.tacs()).getMainThreadExecutor());
return CompletableFuture.runAsync(() -> {
try (var ignored = ThreadInstrumentation.getCurrent().begin(new ChunkTaskWork(context, (ServerAccessibleChunkSending) (Object) this, true))) {
final WorldChunk chunk = (WorldChunk) context.holder().getItem().get().chunk();
chunk.runPostProcessing(((IThreadedAnvilChunkStorage) context.tacs()).getWorld());
sendChunkToPlayer(context.tacs(), context.holder());
}
}, ((IThreadedAnvilChunkStorage) context.tacs()).getMainThreadExecutor());
}

@Unique
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ Whether to allow POIs (Point of Interest) to be unloaded
""")
.getBoolean(true, false);

public static final boolean suppressGhostMushrooms = new ConfigSystem.ConfigAccessor()
.key("chunkSystem.suppressGhostMushrooms")
.comment("""
This option workarounds MC-276863, a bug that makes mushrooms appear in non-postprocessed chunks
This bug is amplified with notickvd as it exposes non-postprocessed chunks to players
This should not affect other worldgen behavior and game mechanics in general
""")
.getBoolean(true, false);

public static final boolean syncPlayerTickets = new ConfigSystem.ConfigAccessor()
.key("chunkSystem.syncPlayerTickets")
.comment("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,6 @@ public CompletionStage<Void> upgradeToThis(ChunkLoadingContext context, Cancella
Preconditions.checkState(chunk instanceof ProtoChunk, "Chunk must be a proto chunk");
ProtoChunk protoChunk = (ProtoChunk) chunk;

if (Config.suppressGhostMushrooms) {
ServerWorld serverWorld = ((IThreadedAnvilChunkStorage) context.tacs()).getWorld();
ChunkRegion chunkRegion = new ChunkRegion(serverWorld, context.chunks(), ChunkGenerationSteps.GENERATION.get(ChunkStatus.FULL), chunk);

ChunkPos chunkPos = context.holder().getKey();

ShortList[] postProcessingLists = protoChunk.getPostProcessingLists();
for (int i = 0; i < postProcessingLists.length; i++) {
if (postProcessingLists[i] != null) {
for (ShortListIterator iterator = postProcessingLists[i].iterator(); iterator.hasNext(); ) {
short short_ = iterator.nextShort();
BlockPos blockPos = ProtoChunk.joinBlockPos(short_, protoChunk.sectionIndexToCoord(i), chunkPos);
BlockState blockState = protoChunk.getBlockState(blockPos);

if (blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM) {
if (!blockState.canPlaceAt(chunkRegion, blockPos)) {
protoChunk.setBlockState(blockPos, Blocks.AIR.getDefaultState(), false); // TODO depends on the fact that the chunk system always locks the current chunk
}
}
}
}
}
}

return CompletableFuture.runAsync(() -> {
try (var ignored = ThreadInstrumentation.getCurrent().begin(new ChunkTaskWork(context, this, true))) {
ServerWorld serverWorld = ((IThreadedAnvilChunkStorage) context.tacs()).getWorld();
Expand Down

0 comments on commit 8df2b37

Please sign in to comment.