Skip to content

Commit

Permalink
entity_in_radius condition (Update Apoli Upstream)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed Jun 2, 2024
1 parent f5432cf commit 29c046d
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,38 @@ public void registerConditions() {
}
return false;
}));
register(new ConditionFactory(GenesisMC.apoliIdentifier("entity_in_radius"), (condition, entity) -> {
FactoryJsonObject biEntityCondition = condition.getJsonObject("bientity_condition");
Shape shape = condition.getEnumValueOrDefault("shape", Shape.class, Shape.CUBE);

Comparison comparison = Comparison.fromString(condition.getString("comparison"));
int compareTo = condition.getNumber("compare_to").getInt();

double radius = condition.getNumber("radius").getDouble();
int countThreshold = switch (comparison) {
case EQUAL, LESS_THAN_OR_EQUAL, GREATER_THAN ->
compareTo + 1;
case LESS_THAN, GREATER_THAN_OR_EQUAL ->
compareTo;
default ->
-1;
};

int count = 0;
for (net.minecraft.world.entity.Entity target : Shape.getEntities(shape, entity.getHandle().level(), entity.getHandle().getPosition(1.0F), radius)) {

if (ConditionExecutor.testBiEntity(biEntityCondition, entity, target.getBukkitEntity())) {
++count;
}

if (count == countThreshold) {
break;
}

}

return comparison.compare(count, compareTo);
}));
register(new ConditionFactory(GenesisMC.apoliIdentifier("time_of_day"), (condition, entity) -> {
String comparison = condition.getString("comparison");
double compare_to = condition.getNumber("compare_to").getFloat();
Expand Down

0 comments on commit 29c046d

Please sign in to comment.