From dc90307e80c296eee9cd33c40d84cebd0d3c2262 Mon Sep 17 00:00:00 2001 From: themode Date: Mon, 21 Feb 2022 04:30:47 +0100 Subject: [PATCH] Fix vehicle viewing --- .../net/minestom/server/utils/ViewEngine.java | 2 -- .../entity/EntityViewIntegrationTest.java | 20 ++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/utils/ViewEngine.java b/src/main/java/net/minestom/server/utils/ViewEngine.java index 895476811..13f2bdaff 100644 --- a/src/main/java/net/minestom/server/utils/ViewEngine.java +++ b/src/main/java/net/minestom/server/utils/ViewEngine.java @@ -113,8 +113,6 @@ public final class ViewEngine { } private void handleAutoView(Entity entity, Consumer viewer, Consumer viewable) { - if (entity.getVehicle() != null) - return; // Passengers are handled by the vehicle, inheriting its viewing settings if (this.entity instanceof Player && viewerOption.isAuto() && entity.isAutoViewable()) { if (viewer != null) viewer.accept(entity); // Send packet to this player } diff --git a/src/test/java/net/minestom/server/entity/EntityViewIntegrationTest.java b/src/test/java/net/minestom/server/entity/EntityViewIntegrationTest.java index ebcd6e6c0..d549889e1 100644 --- a/src/test/java/net/minestom/server/entity/EntityViewIntegrationTest.java +++ b/src/test/java/net/minestom/server/entity/EntityViewIntegrationTest.java @@ -97,7 +97,7 @@ public class EntityViewIntegrationTest { } @Test - public void vehicle(Env env) { + public void livingVehicle(Env env) { var instance = env.createFlatInstance(); var connection = env.createConnection(); var player = connection.connect(instance, new Pos(0, 40, 0)).join(); @@ -125,4 +125,22 @@ public class EntityViewIntegrationTest { assertTrue(passenger.isViewer(player)); } } + + @Test + public void vehicleInheritance(Env env) { + var instance = env.createFlatInstance(); + var p1 = env.createPlayer(instance, new Pos(0, 40, 0)); + var p2 = env.createPlayer(instance, new Pos(0, 40, 0)); + + var vehicle = new Entity(EntityType.ZOMBIE); + vehicle.setInstance(instance, new Pos(0, 40, 0)).join(); + vehicle.addPassenger(p1); + + var vehicle2 = new Entity(EntityType.ZOMBIE); + vehicle2.setInstance(instance, new Pos(0, 40, 0)).join(); + vehicle2.addPassenger(p2); + + assertEquals(2, vehicle.getViewers().size()); + assertEquals(2, vehicle2.getViewers().size()); + } }