Fix null exceptions when an entity says it has a vehicle but actually doesn't. #118

This commit is contained in:
Sollace 2023-05-29 10:41:02 +01:00
parent 5ad9b46430
commit a444395c28
2 changed files with 13 additions and 8 deletions

View file

@ -383,15 +383,17 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
return Equine.<E, Living<E>>of(entity, e -> e instanceof Living<?>).orElse(null); return Equine.<E, Living<E>>of(entity, e -> e instanceof Living<?>).orElse(null);
} }
public static void updateVelocity(Entity entity) { public static void updateVelocity(@Nullable Entity entity) {
if (entity != null) {
entity.velocityModified = true; entity.velocityModified = true;
//if (entity instanceof ServerPlayerEntity ply) { //if (entity instanceof ServerPlayerEntity ply) {
// ply.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(ply)); // ply.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(ply));
//} //}
} }
}
public static void transmitPassengers(Entity entity) { public static void transmitPassengers(@Nullable Entity entity) {
if (entity.world instanceof ServerWorld sw) { if (entity != null && entity.world instanceof ServerWorld sw) {
sw.getChunkManager().sendToNearbyPlayers(entity, new EntityPassengersSetS2CPacket(entity)); sw.getChunkManager().sendToNearbyPlayers(entity, new EntityPassengersSetS2CPacket(entity));
} }
} }

View file

@ -312,6 +312,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
if (isClient()) { if (isClient()) {
if (entity.hasVehicle() && entity.isSneaking()) { if (entity.hasVehicle() && entity.isSneaking()) {
@Nullable
Entity vehicle = entity.getVehicle(); Entity vehicle = entity.getVehicle();
if (vehicle instanceof Trap) { if (vehicle instanceof Trap) {
@ -326,7 +327,9 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
} else { } else {
setCarrier((UUID)null); setCarrier((UUID)null);
entity.stopRiding(); entity.stopRiding();
if (vehicle != null) {
entity.refreshPositionAfterTeleport(vehicle.getPos()); entity.refreshPositionAfterTeleport(vehicle.getPos());
}
Living.transmitPassengers(vehicle); Living.transmitPassengers(vehicle);
} }
} }