Skip to content

Commit

Permalink
fix: suppress ghost mushrooms outside of simulation distance
Browse files Browse the repository at this point in the history
Fixes #336

Squashed commit of the following:

commit db66b24
Author: ishland <ishlandmc@yeah.net>
Date:   Sun Sep 22 11:19:46 2024 +0800

    change: allow disabling mushroom mitigation

commit 1839d3c
Author: ishland <ishlandmc@yeah.net>
Date:   Sun Sep 22 10:44:27 2024 +0800

    fix: ghost mushroom attempt 5

    Related to #336

commit 3eb1b5e
Author: ishland <ishlandmc@yeah.net>
Date:   Sun Sep 22 10:37:23 2024 +0800

    Revert "fix: ghost mushroom attempt 3"

    This reverts commit ebd3b85.

commit 6698474
Author: ishland <ishlandmc@yeah.net>
Date:   Sun Sep 22 10:37:18 2024 +0800

    Revert "fix: ghost mushroom attempt 4"

    This reverts commit 48d9f3b.

commit 48d9f3b
Author: ishland <ishlandmc@yeah.net>
Date:   Sat Sep 21 16:45:25 2024 +0800

    fix: ghost mushroom attempt 4

    Related to #336

commit ebd3b85
Author: ishland <ishlandmc@yeah.net>
Date:   Sat Sep 21 16:34:30 2024 +0800

    fix: ghost mushroom attempt 3

    Related to #336

commit d33bd29
Author: ishland <ishlandmc@yeah.net>
Date:   Sat Sep 21 15:53:19 2024 +0800

    Revert "fix: ghost mushroom attempt 1"

    This reverts commit 5054bef.

commit 50710be
Author: ishland <ishlandmc@yeah.net>
Date:   Sat Sep 21 15:53:14 2024 +0800

    Revert "fix: ghost mushroom attempt 2: ensure post-processed chunk is open"

    This reverts commit 4f74581.

commit cc0e89c
Merge: 4f74581 716d21c
Author: ishland <ishlandmc@yeah.net>
Date:   Thu Sep 19 16:53:35 2024 +0800

    Merge branch 'ver/1.21.1' into fix/336-ghost-mushroom

commit 4f74581
Author: ishland <ishlandmc@yeah.net>
Date:   Thu Sep 19 16:47:00 2024 +0800

    fix: ghost mushroom attempt 2: ensure post-processed chunk is open

    Related to #336

commit 5054bef
Author: ishland <ishlandmc@yeah.net>
Date:   Wed Sep 18 23:18:53 2024 +0800

    fix: ghost mushroom attempt 1

    Related to #336
  • Loading branch information
ishland committed Nov 1, 2024
1 parent 9b4649a commit 2a57d4d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ 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 void init() {
// intentionally empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@
import com.ishland.c2me.rewrites.chunksystem.common.fapi.LifecycleEventInvoker;
import com.ishland.flowsched.scheduler.ItemHolder;
import com.ishland.flowsched.scheduler.KeyStatusPair;
import it.unimi.dsi.fastutil.shorts.ShortList;
import it.unimi.dsi.fastutil.shorts.ShortListIterator;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ChunkLevels;
import net.minecraft.server.world.ServerChunkLoadingManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkGenerationStep;
import net.minecraft.world.chunk.ChunkGenerationSteps;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.ProtoChunk;
import net.minecraft.world.chunk.WorldChunk;
Expand Down Expand Up @@ -56,6 +64,31 @@ public CompletionStage<Void> upgradeToThis(ChunkLoadingContext context) {
final Chunk chunk = context.holder().getItem().get().chunk();
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(() -> {
ServerWorld serverWorld = ((IThreadedAnvilChunkStorage) context.tacs()).getWorld();
final WorldChunk worldChunk = toFullChunk(protoChunk, serverWorld);
Expand Down

0 comments on commit 2a57d4d

Please sign in to comment.