|
| 1 | +package com.ishland.c2me.rewrites.chunksystem.mixin; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 5 | +import net.minecraft.block.entity.BlockEntity; |
| 6 | +import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; |
| 7 | +import net.minecraft.registry.Registry; |
| 8 | +import net.minecraft.server.network.ServerPlayerEntity; |
| 9 | +import net.minecraft.server.world.ServerWorld; |
| 10 | +import net.minecraft.util.math.BlockPos; |
| 11 | +import net.minecraft.util.math.ChunkPos; |
| 12 | +import net.minecraft.world.HeightLimitView; |
| 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.UpgradeData; |
| 17 | +import net.minecraft.world.chunk.WorldChunk; |
| 18 | +import net.minecraft.world.gen.chunk.BlendingData; |
| 19 | +import org.jetbrains.annotations.Nullable; |
| 20 | +import org.spongepowered.asm.mixin.Mixin; |
| 21 | +import org.spongepowered.asm.mixin.injection.At; |
| 22 | + |
| 23 | +import java.util.List; |
| 24 | + |
| 25 | +@Mixin(WorldChunk.class) |
| 26 | +public abstract class MixinWorldChunk extends Chunk { |
| 27 | + |
| 28 | + public MixinWorldChunk(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry<Biome> biomeRegistry, long inhabitedTime, @Nullable ChunkSection[] sectionArray, @Nullable BlendingData blendingData) { |
| 29 | + super(pos, upgradeData, heightLimitView, biomeRegistry, inhabitedTime, sectionArray, blendingData); |
| 30 | + } |
| 31 | + |
| 32 | + @WrapOperation(method = "runPostProcessing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;getBlockEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/entity/BlockEntity;")) |
| 33 | + private BlockEntity syncBlockEntities(WorldChunk instance, BlockPos pos, Operation<BlockEntity> original, ServerWorld world) { |
| 34 | + BlockEntity blockEntity = original.call(instance, pos); |
| 35 | + if (blockEntity == null) return null; |
| 36 | + |
| 37 | + List<ServerPlayerEntity> playersWatchingChunk = world.getChunkManager().chunkLoadingManager.getPlayersWatchingChunk(this.getPos(), false); |
| 38 | + BlockEntityUpdateS2CPacket packet = BlockEntityUpdateS2CPacket.create(blockEntity); |
| 39 | + for (ServerPlayerEntity player : playersWatchingChunk) { |
| 40 | + player.networkHandler.sendPacket(packet); |
| 41 | + } |
| 42 | + |
| 43 | + return blockEntity; |
| 44 | + } |
| 45 | + |
| 46 | +} |
0 commit comments