General update

This commit is contained in:
bluefireoly
2020-08-27 20:51:46 +02:00
parent 64bbc55649
commit f46fa5d658
10 changed files with 356 additions and 30 deletions

View File

@@ -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
}
}