Skip to content

Commit 5054bef

Browse files
committed
fix: ghost mushroom attempt 1
Related to #336
1 parent d84ef12 commit 5054bef

File tree

7 files changed

+70
-28
lines changed

7 files changed

+70
-28
lines changed

c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/common/Config.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ public class Config {
1313
" Lower this for a better latency and higher this for a faster loading")
1414
.getLong(GlobalExecutors.GLOBAL_EXECUTOR_PARALLELISM * 2L, GlobalExecutors.GLOBAL_EXECUTOR_PARALLELISM * 2L, ConfigSystem.LongChecks.POSITIVE_VALUES_ONLY);
1515

16-
public static final boolean compatibilityMode = new ConfigSystem.ConfigAccessor()
17-
.key("noTickViewDistance.compatibilityMode")
18-
.comment("Whether to use compatibility mode to send chunks \n" +
19-
" This may fix some mod compatibility issues")
20-
.getBoolean(true, true);
21-
2216
public static final boolean enableExtRenderDistanceProtocol = new ConfigSystem.ConfigAccessor()
2317
.key("noTickViewDistance.enableExtRenderDistanceProtocol")
2418
.comment("""

c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinServerAccessible.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,4 @@ private static boolean needSendChunks() {
2727
return true;
2828
}
2929

30-
@Dynamic
31-
@WrapOperation(method = "lambda$upgradeToThis$0", at = @At(value = "INVOKE", target = "Lcom/ishland/c2me/rewrites/chunksystem/common/statuses/ServerAccessible;sendChunkToPlayer(Lnet/minecraft/server/world/ServerChunkLoadingManager;Lcom/ishland/flowsched/scheduler/ItemHolder;)V", remap = true), remap = false)
32-
private static void wrapSendChunks(ServerChunkLoadingManager tacs, ItemHolder<?, ?, ?, ?> holder, Operation<Void> original) {
33-
if (Config.compatibilityMode) {
34-
((IThreadedAnvilChunkStorage) tacs).getMainThreadExecutor().submit(() -> original.call(tacs, holder));
35-
} else {
36-
original.call(tacs, holder);
37-
}
38-
}
39-
4030
}

c2me-notickvd/src/main/java/com/ishland/c2me/notickvd/mixin/MixinThreadedAnvilChunkStorage.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ private WorldChunk redirectSendWatchPacketsGetWorldChunk(ChunkHolder chunkHolder
5353
@Inject(method = "makeChunkAccessible", at = @At("RETURN"))
5454
private void onMakeChunkAccessible(ChunkHolder chunkHolder, CallbackInfoReturnable<CompletableFuture<OptionalChunk<WorldChunk>>> cir) {
5555
cir.getReturnValue().thenAccept(either -> either.ifPresent(worldChunk -> {
56-
if (Config.compatibilityMode) {
57-
this.mainThreadExecutor.send(() -> this.sendToPlayers(worldChunk));
58-
} else {
59-
this.sendToPlayers(worldChunk);
60-
}
56+
this.mainThreadExecutor.send(() -> this.sendToPlayers(worldChunk));
6157
}));
6258
}
6359

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ishland.c2me.rewrites.chunksystem.common.ducks;
2+
3+
public interface IPartialPostProcessing {
4+
5+
void c2me$runBorderPostProcessing();
6+
7+
}

c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/common/statuses/ServerAccessible.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.ishland.c2me.rewrites.chunksystem.common.Config;
1010
import com.ishland.c2me.rewrites.chunksystem.common.NewChunkHolderVanillaInterface;
1111
import com.ishland.c2me.rewrites.chunksystem.common.NewChunkStatus;
12+
import com.ishland.c2me.rewrites.chunksystem.common.ducks.IPartialPostProcessing;
1213
import com.ishland.c2me.rewrites.chunksystem.common.fapi.LifecycleEventInvoker;
1314
import com.ishland.flowsched.scheduler.ItemHolder;
1415
import com.ishland.flowsched.scheduler.KeyStatusPair;
@@ -85,15 +86,13 @@ private static boolean needSendChunks() {
8586
}
8687

8788
private static void sendChunkToPlayer(ServerChunkLoadingManager tacs, ItemHolder<ChunkPos, ChunkState, ChunkLoadingContext, NewChunkHolderVanillaInterface> holder) {
88-
final Chunk chunk = holder.getItem().get().chunk();
89-
if (chunk instanceof WorldChunk worldChunk) {
90-
CompletableFuture<?> completableFuturexx = holder.getUserData().get().getPostProcessingFuture();
91-
if (completableFuturexx.isDone()) {
89+
holder.submitOp(CompletableFuture.runAsync(() -> {
90+
final Chunk chunk = holder.getItem().get().chunk();
91+
if (chunk instanceof WorldChunk worldChunk) {
92+
((IPartialPostProcessing) worldChunk).c2me$runBorderPostProcessing();
9293
((IThreadedAnvilChunkStorage) tacs).invokeSendToPlayers(worldChunk);
93-
} else {
94-
completableFuturexx.thenAcceptAsync(v -> ((IThreadedAnvilChunkStorage) tacs).invokeSendToPlayers(worldChunk), ((IThreadedAnvilChunkStorage) tacs).getMainThreadExecutor());
9594
}
96-
}
95+
}, ((IThreadedAnvilChunkStorage) tacs).getMainThreadExecutor()::submit));
9796
}
9897

9998
private static WorldChunk toFullChunk(ProtoChunk protoChunk, ServerWorld serverWorld) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.ishland.c2me.rewrites.chunksystem.mixin;
2+
3+
import com.ishland.c2me.rewrites.chunksystem.common.ducks.IPartialPostProcessing;
4+
import it.unimi.dsi.fastutil.shorts.ShortListIterator;
5+
import net.minecraft.block.Block;
6+
import net.minecraft.block.BlockState;
7+
import net.minecraft.block.Blocks;
8+
import net.minecraft.registry.Registry;
9+
import net.minecraft.util.math.BlockPos;
10+
import net.minecraft.util.math.ChunkPos;
11+
import net.minecraft.world.HeightLimitView;
12+
import net.minecraft.world.World;
13+
import net.minecraft.world.biome.Biome;
14+
import net.minecraft.world.chunk.Chunk;
15+
import net.minecraft.world.chunk.ChunkSection;
16+
import net.minecraft.world.chunk.ProtoChunk;
17+
import net.minecraft.world.chunk.UpgradeData;
18+
import net.minecraft.world.chunk.WorldChunk;
19+
import net.minecraft.world.gen.chunk.BlendingData;
20+
import org.jetbrains.annotations.Nullable;
21+
import org.spongepowered.asm.mixin.Final;
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.Shadow;
24+
25+
@Mixin(WorldChunk.class)
26+
public abstract class MixinWorldChunk extends Chunk implements IPartialPostProcessing {
27+
28+
@Shadow @Final private World world;
29+
30+
public MixinWorldChunk(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry<Biome> biomeRegistry, long inhabitedTime, @Nullable ChunkSection[] sectionArray, @Nullable BlendingData blendingData) {
31+
super(pos, upgradeData, heightLimitView, biomeRegistry, inhabitedTime, sectionArray, blendingData);
32+
}
33+
34+
@Override
35+
public void c2me$runBorderPostProcessing() {
36+
ChunkPos chunkPos = this.getPos();
37+
38+
for (int i = 0; i < this.postProcessingLists.length; i++) {
39+
if (this.postProcessingLists[i] != null) {
40+
for (ShortListIterator iterator = this.postProcessingLists[i].iterator(); iterator.hasNext(); ) {
41+
short short_ = iterator.nextShort();
42+
BlockPos blockPos = ProtoChunk.joinBlockPos(short_, this.sectionIndexToCoord(i), chunkPos);
43+
BlockState blockState = this.getBlockState(blockPos);
44+
45+
if (blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM) {
46+
if (!blockState.canPlaceAt(world, blockPos)) {
47+
this.world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Block.NO_REDRAW | Block.FORCE_STATE);
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
55+
}

c2me-rewrites-chunk-system/src/main/resources/c2me-rewrites-chunk-system.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"MixinNoiseChunkGenerator",
1313
"MixinServerChunkManager",
1414
"MixinThreadedAnvilChunkStorage",
15+
"MixinWorldChunk",
1516
"async_serialization.MixinBlender",
1617
"async_serialization.MixinChunkRegion",
1718
"async_serialization.MixinChunkSerializer",

0 commit comments

Comments
 (0)