Skip to content

Commit

Permalink
fix: sync block entities when postprocessed
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Dec 9, 2024
1 parent 0937427 commit 3547963
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.ishland.c2me.rewrites.chunksystem.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.registry.Registry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.UpgradeData;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.gen.chunk.BlendingData;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import java.util.List;

@Mixin(WorldChunk.class)
public abstract class MixinWorldChunk extends Chunk {

public MixinWorldChunk(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry<Biome> biomeRegistry, long inhabitedTime, @Nullable ChunkSection[] sectionArray, @Nullable BlendingData blendingData) {
super(pos, upgradeData, heightLimitView, biomeRegistry, inhabitedTime, sectionArray, blendingData);
}

@WrapOperation(method = "runPostProcessing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;getBlockEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/entity/BlockEntity;"))
private BlockEntity syncBlockEntities(WorldChunk instance, BlockPos pos, Operation<BlockEntity> original, ServerWorld world) {
BlockEntity blockEntity = original.call(instance, pos);
if (blockEntity == null) return null;

List<ServerPlayerEntity> playersWatchingChunk = world.getChunkManager().chunkLoadingManager.getPlayersWatchingChunk(this.getPos(), false);
BlockEntityUpdateS2CPacket packet = BlockEntityUpdateS2CPacket.create(blockEntity);
for (ServerPlayerEntity player : playersWatchingChunk) {
player.networkHandler.sendPacket(packet);
}

return blockEntity;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"MixinSerializingRegionBasedStorage",
"MixinServerChunkManager",
"MixinThreadedAnvilChunkStorage",
"MixinWorldChunk",
"async_serialization.MixinBlender",
"async_serialization.MixinChunkRegion",
"async_serialization.MixinChunkSerializer",
Expand Down

0 comments on commit 3547963

Please sign in to comment.