Search in sources :

Example 16 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project Client by MatHax.

the class ClientPlayNetworkHandlerMixin method onChunkData.

@Inject(method = "onChunkData", at = @At("TAIL"))
private void onChunkData(ChunkDataS2CPacket packet, CallbackInfo info) {
    WorldChunk chunk = client.world.getChunk(packet.getX(), packet.getZ());
    MatHax.EVENT_BUS.post(ChunkDataEvent.get(chunk));
}
Also used : WorldChunk(net.minecraft.world.chunk.WorldChunk) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 17 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project polymer by Patbox.

the class ServerChunkManagerMixin method sendLightUpdates.

@Inject(method = "onLightUpdate", at = @At("TAIL"))
private void sendLightUpdates(LightType type, ChunkSectionPos pos, CallbackInfo ci) {
    if (type == LightType.BLOCK && this.world.getServer().getPlayerManager().getCurrentPlayerCount() > 0) {
        this.world.getServer().execute(() -> {
            boolean sendUpdate = false;
            int tooLow = pos.getSectionY() * 16 - 16;
            int tooHigh = pos.getSectionY() * 16 + 32;
            if (System.currentTimeMillis() - this.lastUpdates.getLong(pos.toChunkPos()) < 100) {
                return;
            }
            if (this.lastUpdates.size() > 200) {
                this.lastUpdates.clear();
            }
            for (int x = -1; x <= 1; x++) {
                for (int z = -1; z <= 1; z++) {
                    WorldChunk chunk = this.getWorldChunk(pos.getX() + x, pos.getZ() + z);
                    if (chunk != null) {
                        for (BlockPos blockPos : ((WorldChunkInterface) chunk).getVirtualBlocks()) {
                            if (blockPos.getY() < tooLow || blockPos.getY() > tooHigh) {
                                continue;
                            }
                            BlockState blockState = chunk.getBlockState(blockPos);
                            if (blockState.getBlock() instanceof VirtualBlock && BlockHelper.isLightSource(chunk.getBlockState(blockPos).getBlock())) {
                                sendUpdate = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (sendUpdate) {
                Packet<?> packet = new LightUpdateS2CPacket(pos.toChunkPos(), this.getLightingProvider(), true);
                Set<ServerPlayerEntity> players = this.threadedAnvilChunkStorage.getPlayersWatchingChunk(pos.toChunkPos(), false).collect(Collectors.toSet());
                if (players.size() > 0) {
                    this.lastUpdates.put(pos.toChunkPos(), System.currentTimeMillis());
                    for (ServerPlayerEntity player : players) {
                        player.networkHandler.sendPacket(packet);
                    }
                }
            }
        });
    }
}
Also used : BlockState(net.minecraft.block.BlockState) WorldChunk(net.minecraft.world.chunk.WorldChunk) VirtualBlock(eu.pb4.polymer.block.VirtualBlock) LightUpdateS2CPacket(net.minecraft.network.packet.s2c.play.LightUpdateS2CPacket) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) WorldChunkInterface(eu.pb4.polymer.interfaces.WorldChunkInterface) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 18 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project polymer by Patbox.

the class ServerPlayNetworkHandlerMixin method catchBlockUpdates.

@Inject(method = "sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("TAIL"))
private void catchBlockUpdates(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> listener, CallbackInfo cb) {
    try {
        if (packet instanceof BlockUpdateS2CPacket) {
            BlockUpdateS2CPacketAccessor b = (BlockUpdateS2CPacketAccessor) packet;
            BlockState blockState = b.getStateServer();
            if (blockState.getBlock() instanceof VirtualBlock) {
                BlockPos pos = ((BlockUpdateS2CPacketAccessor) packet).getPosServer();
                ((VirtualBlock) blockState.getBlock()).sendPacketsAfterCreation(this.player, pos, blockState);
            }
        } else if (packet instanceof ChunkDataS2CPacket) {
            WorldChunk wc = ((ChunkDataS2CPacketInterface) packet).getWorldChunk();
            WorldChunkInterface wci = (WorldChunkInterface) wc;
            if (wc != null) {
                for (BlockPos pos : wci.getVirtualBlocks()) {
                    BlockState blockState = wc.getBlockState(pos);
                    if (blockState.getBlock() instanceof VirtualBlock) {
                        ((VirtualBlock) blockState.getBlock()).sendPacketsAfterCreation(this.player, pos, blockState);
                    }
                }
            }
        } else if (packet instanceof ChunkDeltaUpdateS2CPacket) {
            ChunkDeltaUpdateS2CPacketAccessor chunk = (ChunkDeltaUpdateS2CPacketAccessor) packet;
            ChunkSectionPos chunkPos = chunk.getSectionPosServer();
            BlockState[] blockStates = chunk.getBlockStatesServer();
            short[] localPos = chunk.getPositionsServer();
            for (int i = 0; i < localPos.length; i++) {
                BlockState blockState = blockStates[i];
                if (blockState.getBlock() instanceof VirtualBlock) {
                    BlockPos blockPos = chunkPos.unpackBlockPos(localPos[i]);
                    ((VirtualBlock) blockState.getBlock()).sendPacketsAfterCreation(this.player, blockPos, blockState);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) ChunkDataS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket) BlockState(net.minecraft.block.BlockState) VirtualBlock(eu.pb4.polymer.block.VirtualBlock) WorldChunk(net.minecraft.world.chunk.WorldChunk) BlockPos(net.minecraft.util.math.BlockPos) ChunkSectionPos(net.minecraft.util.math.ChunkSectionPos) ChunkDeltaUpdateS2CPacket(net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket) WorldChunkInterface(eu.pb4.polymer.interfaces.WorldChunkInterface) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 19 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project ImmersivePortalsMod by qouteall.

the class ChunkDataSyncManager method sendWatchPackets.

private void sendWatchPackets(ServerPlayerEntity player, DimensionalChunkPos chunkPos, IEThreadedAnvilChunkStorage ieStorage) {
    McHelper.getServer().getProfiler().push("send_chunk_data");
    Chunk chunk = McHelper.getServer().getWorld(chunkPos.dimension).getChunk(chunkPos.x, chunkPos.z);
    assert chunk != null;
    assert !(chunk instanceof EmptyChunk);
    player.networkHandler.sendPacket(MyNetwork.createRedirectedMessage(chunkPos.dimension, new ChunkDataS2CPacket(((WorldChunk) chunk), 65535)));
    player.networkHandler.sendPacket(MyNetwork.createRedirectedMessage(chunkPos.dimension, new LightUpdateS2CPacket(chunkPos.getChunkPos(), ieStorage.getLightingProvider())));
    // update the entity trackers
    ((ThreadedAnvilChunkStorage) ieStorage).updateCameraPosition(player);
    McHelper.getServer().getProfiler().pop();
}
Also used : EmptyChunk(net.minecraft.world.chunk.EmptyChunk) WorldChunk(net.minecraft.world.chunk.WorldChunk) LightUpdateS2CPacket(net.minecraft.client.network.packet.LightUpdateS2CPacket) ChunkDataS2CPacket(net.minecraft.client.network.packet.ChunkDataS2CPacket) ThreadedAnvilChunkStorage(net.minecraft.server.world.ThreadedAnvilChunkStorage) IEThreadedAnvilChunkStorage(com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage) WorldChunk(net.minecraft.world.chunk.WorldChunk) EmptyChunk(net.minecraft.world.chunk.EmptyChunk) Chunk(net.minecraft.world.chunk.Chunk)

Example 20 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project FastAsyncWorldEdit by IntellectualSites.

the class FabricWorld method getFullBlock.

@Override
public BaseBlock getFullBlock(BlockVector3 position) {
    BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    // Avoid creation by using the CHECK mode -- if it's needed, it'll be re-created anyways
    BlockEntity tile = ((WorldChunk) getWorld().getChunk(pos)).getBlockEntity(pos, WorldChunk.CreationType.CHECK);
    if (tile != null) {
        net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
        tile.toTag(tag);
        return getBlock(position).toBaseBlock(NBTConverter.fromNative(tag));
    } else {
        return getBlock(position).toBaseBlock();
    }
}
Also used : WorldChunk(net.minecraft.world.chunk.WorldChunk) BlockPos(net.minecraft.util.math.BlockPos) CompoundTag(com.sk89q.jnbt.CompoundTag) BlockEntity(net.minecraft.block.entity.BlockEntity)

Aggregations

WorldChunk (net.minecraft.world.chunk.WorldChunk)34 BlockPos (net.minecraft.util.math.BlockPos)15 BlockState (net.minecraft.block.BlockState)9 ChunkPos (net.minecraft.util.math.ChunkPos)8 Inject (org.spongepowered.asm.mixin.injection.Inject)8 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)6 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)4 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)4 PerWorldConfig (at.haha007.edenclient.utils.config.PerWorldConfig)4 Collectors (java.util.stream.Collectors)4 PlayerTickCallback (at.haha007.edenclient.callbacks.PlayerTickCallback)3 CommandManager (at.haha007.edenclient.command.CommandManager)3 ChatColor (at.haha007.edenclient.utils.ChatColor)3 PlayerUtils.sendModMessage (at.haha007.edenclient.utils.PlayerUtils.sendModMessage)3 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)3 CommandContext (com.mojang.brigadier.context.CommandContext)3 Biome (com.seedfinding.mcbiome.biome.Biome)3 BiomeSource (com.seedfinding.mcbiome.source.BiomeSource)3 BlockEntity (net.minecraft.block.entity.BlockEntity)3 Direction (net.minecraft.util.math.Direction)3