General update
This commit is contained in:
@@ -28,14 +28,18 @@ val PlayerInteractEntityEvent.interactItem: ItemStack?
|
||||
@UnsafeImplementation
|
||||
val PlayerInteractEvent.clickedBlockExceptAir: Block?
|
||||
get() {
|
||||
val p: Player = this.player
|
||||
return when (this.action) {
|
||||
Action.RIGHT_CLICK_BLOCK -> this.clickedBlock
|
||||
Action.RIGHT_CLICK_AIR -> {
|
||||
return clickedBlock ?: kotlin.run {
|
||||
return@run if (this.action == Action.RIGHT_CLICK_AIR) {
|
||||
|
||||
val p: Player = this.player
|
||||
|
||||
// check for sight blocking entities
|
||||
for (nearbyEntity: Entity in p.getNearbyEntities(5.0, 5.0, 5.0))
|
||||
if (p.hasLineOfSight(nearbyEntity)) return null
|
||||
if (p.hasLineOfSight(nearbyEntity)) return@run null
|
||||
|
||||
// get first block in line of sight which is not air
|
||||
p.getLineOfSight(null, 5).find { block -> !block.type.isAir }
|
||||
}
|
||||
else -> null
|
||||
|
||||
} else null
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user