Fix vehicle viewing

This commit is contained in:
themode 2022-02-21 04:30:47 +01:00
parent 6ef04ae618
commit dc90307e80
2 changed files with 19 additions and 3 deletions

View File

@ -113,8 +113,6 @@ public final class ViewEngine {
}
private void handleAutoView(Entity entity, Consumer<Entity> viewer, Consumer<Player> 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
}

View File

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