Porting-Dead-Mods / Cable-Facades

Other
1 stars 2 forks source link

The client receives and renders all facades present in the world #12

Open SuperMartijn642 opened 3 hours ago

SuperMartijn642 commented 3 hours ago

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. https://github.com/Porting-Dead-Mods/Cable-Facades/blob/9a492c25ea993c81b58df4d1c33e1d1960e24b92/src/main/java/com/portingdeadmods/cable_facades/events/GameEvents.java#L29-L38

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.

SuperMartijn642 commented 3 hours ago

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. https://github.com/Porting-Dead-Mods/Cable-Facades/blob/efb789ce462b0d23d753abcb95d88417901ddef0/src/main/java/com/portingdeadmods/cable_facades/mixins/BlockStateBaseMixin.java#L55 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.