Skip to content

Commit ebd3b85

Browse files
committed
fix: ghost mushroom attempt 3
Related to #336
1 parent d33bd29 commit ebd3b85

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.ishland.c2me.fixes.worldgen.vanilla_bugs;
2+
3+
import com.ishland.c2me.base.common.ModuleMixinPlugin;
4+
import com.ishland.c2me.fixes.worldgen.vanilla_bugs.common.Config;
5+
6+
public class MixinPlugin extends ModuleMixinPlugin {
7+
8+
@Override
9+
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
10+
if (!super.shouldApplyMixin(targetClassName, mixinClassName)) return false;
11+
12+
if (mixinClassName.startsWith("com.ishland.c2me.fixes.worldgen.vanilla_bugs.mixin.mc_276863."))
13+
return Config.suppressGhostMushrooms;
14+
15+
return true;
16+
}
17+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package com.ishland.c2me.fixes.worldgen.vanilla_bugs;
22

3+
import com.ishland.c2me.fixes.worldgen.vanilla_bugs.common.Config;
4+
35
public class ModuleEntryPoint {
46

57
private static final boolean enabled = true;
68

9+
static {
10+
Config.init();
11+
}
12+
713
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.ishland.c2me.fixes.worldgen.vanilla_bugs.common;
2+
3+
import com.ishland.c2me.base.common.config.ConfigSystem;
4+
5+
public class Config {
6+
7+
public static final boolean suppressGhostMushrooms = new ConfigSystem.ConfigAccessor()
8+
.key("fixes.suppressGhostMushrooms")
9+
.comment("""
10+
This option workarounds MC-276863, a bug that makes mushrooms appear in non-postprocessed chunks
11+
This bug is amplified with notickvd as it exposes non-postprocessed chunks to players
12+
13+
This should not affect other worldgen behavior and game mechanics in general
14+
""")
15+
.getBoolean(true, false);
16+
17+
public static void init() {
18+
// intentionally empty
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.ishland.c2me.fixes.worldgen.vanilla_bugs.mixin.mc_276863;
2+
3+
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
4+
import it.unimi.dsi.fastutil.shorts.ShortList;
5+
import it.unimi.dsi.fastutil.shorts.ShortListIterator;
6+
import net.minecraft.block.Block;
7+
import net.minecraft.block.BlockState;
8+
import net.minecraft.block.Blocks;
9+
import net.minecraft.server.world.ServerWorld;
10+
import net.minecraft.util.collection.BoundedRegionArray;
11+
import net.minecraft.util.math.BlockPos;
12+
import net.minecraft.util.math.ChunkPos;
13+
import net.minecraft.world.ChunkRegion;
14+
import net.minecraft.world.chunk.AbstractChunkHolder;
15+
import net.minecraft.world.chunk.Chunk;
16+
import net.minecraft.world.chunk.ChunkGenerating;
17+
import net.minecraft.world.chunk.ChunkGenerationContext;
18+
import net.minecraft.world.chunk.ChunkGenerationStep;
19+
import net.minecraft.world.chunk.ProtoChunk;
20+
import org.spongepowered.asm.mixin.Mixin;
21+
import org.spongepowered.asm.mixin.injection.At;
22+
23+
import java.util.concurrent.CompletableFuture;
24+
25+
@Mixin(ChunkGenerating.class)
26+
public class MixinChunkGenerating {
27+
28+
@ModifyReturnValue(method = "light", at = @At("RETURN"))
29+
private static CompletableFuture<Chunk> applyPostprocessingAfterLighting(CompletableFuture<Chunk> original, ChunkGenerationContext context, ChunkGenerationStep step, BoundedRegionArray<AbstractChunkHolder> chunks, Chunk chunk) {
30+
ServerWorld serverWorld = context.world();
31+
ChunkRegion chunkRegion = new ChunkRegion(serverWorld, chunks, step, chunk);
32+
33+
return original.thenApply(chunk1 -> {
34+
ChunkPos chunkPos = chunk1.getPos();
35+
36+
ShortList[] postProcessingLists = chunk1.getPostProcessingLists();
37+
for (int i = 0; i < postProcessingLists.length; i++) {
38+
if (postProcessingLists[i] != null) {
39+
for (ShortListIterator iterator = postProcessingLists[i].iterator(); iterator.hasNext(); ) {
40+
short short_ = iterator.nextShort();
41+
BlockPos blockPos = ProtoChunk.joinBlockPos(short_, chunk1.sectionIndexToCoord(i), chunkPos);
42+
BlockState blockState = chunk1.getBlockState(blockPos);
43+
44+
if (blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM) {
45+
if (!blockState.canPlaceAt(chunkRegion, blockPos)) {
46+
chunkRegion.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Block.NO_REDRAW | Block.FORCE_STATE);
47+
}
48+
}
49+
}
50+
}
51+
}
52+
53+
return chunk1;
54+
});
55+
}
56+
57+
}

c2me-fixes-worldgen-vanilla-bugs/src/main/resources/c2me-fixes-worldgen-vanilla-bugs.mixins.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"parent": "c2me.mixins.json",
33
"required": true,
44
"package": "com.ishland.c2me.fixes.worldgen.vanilla_bugs.mixin",
5-
"plugin": "com.ishland.c2me.base.common.ModuleMixinPlugin",
5+
"plugin": "com.ishland.c2me.fixes.worldgen.vanilla_bugs.MixinPlugin",
66
"mixins": [
7-
"ensure_chunk_status_before_callback.MixinChunkHolder"
7+
"ensure_chunk_status_before_callback.MixinChunkHolder",
8+
"mc_276863.MixinChunkGenerating"
89
]
910
}

0 commit comments

Comments
 (0)