Skip to content

Commit

Permalink
Tweaked impl. of entity_set power type (again)
Browse files Browse the repository at this point in the history
* Ticking temp. entities is now similar to how ticking in `action_over_time` power type works
* Changed default value of `tick_rate` field from `100` to `1`
  • Loading branch information
eggohito committed Jan 1, 2024
1 parent b9233ba commit db82b4e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/io/github/apace100/apoli/power/EntitySetPower.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class EntitySetPower extends Power {
private final Set<UUID> tempUuids = new HashSet<>();
private final Map<UUID, Integer> tempEntities = new ConcurrentHashMap<>();

private Integer startTicks = null;
private boolean removedTemps = false;

public EntitySetPower(PowerType<?> type, LivingEntity entity, Consumer<Pair<Entity, Entity>> actionOnAdd, Consumer<Pair<Entity, Entity>> actionOnRemove, int tickRate) {
Expand All @@ -54,15 +55,19 @@ public void tick() {
PowerHolderComponent.syncPower(this.entity, this.type);
}

else {
else if (startTicks == null) {
startTicks = entity.age % tickRate;
}

else if (entity.age % tickRate == startTicks) {
tickTempEntities();
}

}

private void tickTempEntities() {

if (tempEntities.isEmpty() || entity.age % tickRate != 0) {
if (tempEntities.isEmpty()) {
return;
}

Expand Down Expand Up @@ -302,7 +307,7 @@ public static PowerFactory createFactory() {
new SerializableData()
.add("action_on_add", ApoliDataTypes.BIENTITY_ACTION, null)
.add("action_on_remove", ApoliDataTypes.BIENTITY_ACTION, null)
.add("tick_rate", SerializableDataTypes.POSITIVE_INT, 100),
.add("tick_rate", SerializableDataTypes.POSITIVE_INT, 1),
data -> (powerType, livingEntity) -> new EntitySetPower(
powerType,
livingEntity,
Expand Down

0 comments on commit db82b4e

Please sign in to comment.