interaction manager: don't crash when attacking invalid (or despawned) entity

This commit is contained in:
Bixilon 2022-05-11 09:09:08 +02:00
parent f58b06026c
commit 9b6c462b75
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -111,9 +111,10 @@ class InteractInteractionHandler(
}
fun interactEntityAt(target: EntityTarget, hand: Hands): InteractionResults {
val entityId = connection.world.entities.getId(target.entity) ?: return InteractionResults.PASS
// used in armor stands
val player = connection.player
connection.sendPacket(EntityInteractPositionC2SP(connection, target.entity, Vec3(target.position), hand, player.isSneaking))
connection.sendPacket(EntityInteractPositionC2SP(entityId, Vec3(target.position), hand, player.isSneaking))
if (player.gamemode == Gamemodes.SPECTATOR) {
return InteractionResults.PASS
@ -133,7 +134,7 @@ class InteractInteractionHandler(
// ToDo: return hit.entity.interact(hand) (e.g. equipping saddle)
return InteractionResults.PASS
} finally {
connection.sendPacket(EntityEmptyInteractC2SP(connection, target.entity, hand, player.isSneaking))
connection.world.entities.getId(target.entity)?.let { connection.sendPacket(EntityEmptyInteractC2SP(it, hand, player.isSneaking)) }
}
}