]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Send all boundingboxes to remote clients
authorIrtimaled <irtimaled@gmail.com>
Fri, 9 Aug 2019 05:45:44 +0000 (22:45 -0700)
committerIrtimaled <irtimaled@gmail.com>
Fri, 9 Aug 2019 07:20:28 +0000 (00:20 -0700)
src/main/java/com/irtimaled/bbor/common/CommonProxy.java
src/main/java/com/irtimaled/bbor/common/interop/CommonInterop.java
src/main/java/com/irtimaled/bbor/mixin/network/play/client/MixinCPacketCustomPayload.java

index ffa20b2bfc83097e84ff85aba7bb9fd01fd133b8..c447f11b95fb10774d2ca6ce32faa5428d3b126f 100644 (file)
@@ -124,23 +124,26 @@ public class CommonProxy {
     }
 
     private void sendToPlayer(int playerId, ServerPlayer player) {
-        BoundingBoxCache boundingBoxCache = getCache(player.getDimensionId());
-        if (boundingBoxCache == null) return;
+        for (Map.Entry<Integer, BoundingBoxCache> entry : dimensionCache.entrySet()) {
+            int dimensionId = entry.getKey();
+            BoundingBoxCache boundingBoxCache = entry.getValue();
+            if (boundingBoxCache == null) return;
 
-        Set<AbstractBoundingBox> playerBoundingBoxes = playerBoundingBoxesCache.computeIfAbsent(playerId, k -> new HashSet<>());
+            Set<AbstractBoundingBox> playerBoundingBoxes = playerBoundingBoxesCache.computeIfAbsent(playerId, k -> new HashSet<>());
 
-        Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxMap = boundingBoxCache.getBoundingBoxes();
-        for (AbstractBoundingBox key : boundingBoxMap.keySet()) {
-            if (playerBoundingBoxes.contains(key)) {
-                continue;
-            }
+            Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxMap = boundingBoxCache.getBoundingBoxes();
+            for (AbstractBoundingBox key : boundingBoxMap.keySet()) {
+                if (playerBoundingBoxes.contains(key)) {
+                    continue;
+                }
 
-            Set<AbstractBoundingBox> boundingBoxes = boundingBoxMap.get(key);
-            PayloadBuilder payload = AddBoundingBox.getPayload(player.getDimensionId(), key, boundingBoxes);
-            if (payload != null)
-                player.sendPacket(payload);
+                Set<AbstractBoundingBox> boundingBoxes = boundingBoxMap.get(key);
+                PayloadBuilder payload = AddBoundingBox.getPayload(dimensionId, key, boundingBoxes);
+                if (payload != null)
+                    player.sendPacket(payload);
 
-            playerBoundingBoxes.add(key);
+                playerBoundingBoxes.add(key);
+            }
         }
     }
 
index 72dc2c8c74da9ae454e0155851c3d289a05317ac..ed16c7c5dfcd8f165f5d5e1d1312d415b5c7302b 100644 (file)
@@ -58,6 +58,10 @@ public class CommonInterop {
         EventBus.publish(new PlayerLoggedOut(player.getEntityId()));
     }
 
+    public static void playerSubscribed(EntityPlayerMP player) {
+        EventBus.publish(new PlayerSubscribed(player.getEntityId(), new ServerPlayer(player)));
+    }
+
     public static void tryHarvestBlock(Block block, BlockPos pos, World world) {
         if (block instanceof BlockMobSpawner) {
             EventBus.publish(new MobSpawnerBroken(world.dimension.getType().getId(), new Coords(pos)));
index 7c29961c707a34bd48c54f878736431316edc432..a53d2db102849d5bdb527b3ad110bb2bccff8a6a 100644 (file)
@@ -1,10 +1,7 @@
 package com.irtimaled.bbor.mixin.network.play.client;
 
-import com.irtimaled.bbor.common.EventBus;
-import com.irtimaled.bbor.common.events.PlayerSubscribed;
+import com.irtimaled.bbor.common.interop.CommonInterop;
 import com.irtimaled.bbor.common.messages.SubscribeToServer;
-import com.irtimaled.bbor.common.models.ServerPlayer;
-import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.network.NetHandlerPlayServer;
 import net.minecraft.network.play.INetHandlerPlayServer;
 import net.minecraft.network.play.client.CPacketCustomPayload;
@@ -22,8 +19,7 @@ public class MixinCPacketCustomPayload {
     @Redirect(method = "processPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/INetHandlerPlayServer;processCustomPayload(Lnet/minecraft/network/play/client/CPacketCustomPayload;)V"))
     private void processPacket(INetHandlerPlayServer netHandlerPlayServer, CPacketCustomPayload packet) {
         if (this.channel.toString().equals(SubscribeToServer.NAME)) {
-            EntityPlayerMP player = ((NetHandlerPlayServer) netHandlerPlayServer).player;
-            EventBus.publish(new PlayerSubscribed(player.getEntityId(), new ServerPlayer(player)));
+            CommonInterop.playerSubscribed(((NetHandlerPlayServer) netHandlerPlayServer).player);
         } else {
             netHandlerPlayServer.processCustomPayload(packet);
         }