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));
}
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);
}
}
}
});
}
}
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();
}
}
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();
}
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();
}
}
Aggregations