Skip to content

Commit

Permalink
Merge pull request #152 from CallumJohnson/feature/near_entity_option…
Browse files Browse the repository at this point in the history
…al_amount

Added optional 'amount' (minimum entities matched) arg to 'near_entity'.
  • Loading branch information
WillFP authored May 11, 2024
2 parents a4e6c74 + 71c3ca9 commit e53e2ff
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ object ConditionNearEntity : Condition<Collection<TestableEntity>>("near_entity"
val location = dispatcher.location ?: return false
val radius = config.getDoubleFromExpression("radius", dispatcher.get())

return location.world.getNearbyEntities(location, radius, radius, radius).any {
// Default to require there to be at least 1 entity if no minimum is defined by the user.
val nearbyEntityMinimumRequirement = config.getIntOrNull("amount") ?: 1
val nearbyEntitiesWhichMatchCriteria = location.world.getNearbyEntities(location, radius, radius, radius).count {
compileData.any { test -> test.matches(it) }
}

return nearbyEntitiesWhichMatchCriteria >= nearbyEntityMinimumRequirement
}

override fun makeCompileData(config: Config, context: ViolationContext): Collection<TestableEntity> {
Expand Down

0 comments on commit e53e2ff

Please sign in to comment.