From a444395c283f8d715ca9a56ae7f14de7882d8cbb Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 29 May 2023 10:41:02 +0100 Subject: [PATCH] Fix null exceptions when an entity says it has a vehicle but actually doesn't. #118 --- .../minelittlepony/unicopia/entity/Living.java | 16 +++++++++------- .../unicopia/entity/player/Pony.java | 5 ++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Living.java b/src/main/java/com/minelittlepony/unicopia/entity/Living.java index 955f9c2c..5d4cf6a8 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Living.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Living.java @@ -383,15 +383,17 @@ public abstract class Living implements Equine, Caste return Equine.>of(entity, e -> e instanceof Living).orElse(null); } - public static void updateVelocity(Entity entity) { - entity.velocityModified = true; - //if (entity instanceof ServerPlayerEntity ply) { - // ply.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(ply)); - //} + public static void updateVelocity(@Nullable Entity entity) { + if (entity != null) { + entity.velocityModified = true; + //if (entity instanceof ServerPlayerEntity ply) { + // ply.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(ply)); + //} + } } - public static void transmitPassengers(Entity entity) { - if (entity.world instanceof ServerWorld sw) { + public static void transmitPassengers(@Nullable Entity entity) { + if (entity != null && entity.world instanceof ServerWorld sw) { sw.getChunkManager().sendToNearbyPlayers(entity, new EntityPassengersSetS2CPacket(entity)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index da0d1d58..b311959f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -312,6 +312,7 @@ public class Pony extends Living implements Copyable, Update if (isClient()) { if (entity.hasVehicle() && entity.isSneaking()) { + @Nullable Entity vehicle = entity.getVehicle(); if (vehicle instanceof Trap) { @@ -326,7 +327,9 @@ public class Pony extends Living implements Copyable, Update } else { setCarrier((UUID)null); entity.stopRiding(); - entity.refreshPositionAfterTeleport(vehicle.getPos()); + if (vehicle != null) { + entity.refreshPositionAfterTeleport(vehicle.getPos()); + } Living.transmitPassengers(vehicle); } }