Cable Facades

Cable Facades

876k Downloads

The client receives and renders all facades present in the world

SuperMartijn642 opened this issue ยท 6 comments

commented

Currently, the server stores all facades present in a world in a map. The entire contents of that map are sent to the client when a player joins. This means facades anywhere in the world are sent to the client.
This may lead to a lot of network traffic and excessive memory usage (or at least more than necessary) on the client.

@SubscribeEvent
public static void onJoin(PlayerEvent.PlayerLoggedInEvent event) {
if (event.getEntity() instanceof ServerPlayer player) {
ServerLevel level = (ServerLevel) player.level();
CableFacadeSavedData data = CableFacadeSavedData.get(level);
if (!data.getCamouflagedBlocks().isEmpty()) {
ModMessages.sendToPlayer(new CamouflagedBlocksS2CPacket(data.getCamouflagedBlocks()), player);
}
}
}

Additionally, since the client does not check the distance of facades in the client's map when rendering them. Every facade in the client's field of view, no matter the distance, gets rendered.

Ideally, the facades would be indexed per chunk on the server and only facades for chunks tracked by the client would be sent to the client. This could be achieved by storing a Map<ChunkPos,Map<BlockPos,Block>> on the server per world or storing a Map<BlockPos,Block> on chunks which have at least one facade, and then sending facades for the respective chunk during the ChunkWatchEvent#Watch event.
The client would then also store facades in a Map<ChunkPos,Map<BlockPos,Block>> and clear facades for the respective chunk during the ChunkWatchEvent#UnWatch event.

commented

Additionally, the RemoveCamoPacket packet is currently send to all players on the server no matter the dimension or location of the player whenever a facade is removed because the block it is on is removed.

ModMessages.sendToClients(new RemoveCamoPacket(blockPos));

If the proposed changes are made such that the client only stores facades for chunks it tracks, the remove packet should also be sent to just the players tracking the respective chunk. This can be done by using the PacketDistributor#TRACKING_CHUNK target.

commented

This explains the lag I was having when I tested the mod. A lot of very small, but very frequent frame drops. Removing the facades helped, but the frame drops were still there, for some reason, After I removed the mod, the lag was gone

commented

Yup, will try to adress this today

commented

I just updated to version 1.0.5 and so far it looks like the performance has been improved significantly!

commented

oh this is great to hear

commented

Oki, all of this should be implemented now