Skip to content

Commit

Permalink
fix: ive had enough ghost mushrooms
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Dec 13, 2024
1 parent ca05d57 commit bd3e75b
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
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.Config;
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;
import it.unimi.dsi.fastutil.shorts.ShortList;
import it.unimi.dsi.fastutil.shorts.ShortListIterator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
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.ChunkGenerationSteps;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.ProtoChunk;
import net.minecraft.world.chunk.WorldChunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -24,6 +37,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

Expand Down Expand Up @@ -56,7 +70,41 @@ 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());
ArrayList<BlockPos> blocksToRemove = new ArrayList<>();
if (Config.suppressGhostMushrooms) {
ServerWorld serverWorld = ((IThreadedAnvilChunkStorage) context.tacs()).getWorld();
ChunkState state = context.holder().getItem().get();
ChunkRegion chunkRegion = new ChunkRegion(serverWorld, context.chunks(), ChunkGenerationSteps.GENERATION.get(ChunkStatus.FULL), state.protoChunk());
Chunk chunk = state.chunk();

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

ShortList[] postProcessingLists = chunk.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_, chunk.sectionIndexToCoord(i), chunkPos);
BlockState blockState = chunk.getBlockState(blockPos);

if (blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM) {
if (!blockState.canPlaceAt(chunkRegion, blockPos)) {
blocksToRemove.add(blockPos);
}
}
}
}
}
}
return CompletableFuture.runAsync(() -> {
try (var ignored = ThreadInstrumentation.getCurrent().begin(new ChunkTaskWork(context, (ServerAccessibleChunkSending) (Object) this, true))) {
ServerWorld serverWorld = ((IThreadedAnvilChunkStorage) context.tacs()).getWorld();
for (BlockPos blockPos : blocksToRemove) {
serverWorld.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Block.NO_REDRAW | Block.FORCE_STATE);
}
sendChunkToPlayer(context.tacs(), context.holder());
}
}, ((IThreadedAnvilChunkStorage) context.tacs()).getMainThreadExecutor());
}

@Unique
Expand Down

0 comments on commit bd3e75b

Please sign in to comment.