Skip to content

Commit

Permalink
Add option to exclude mounted entities
Browse files Browse the repository at this point in the history
  • Loading branch information
froobynooby committed Apr 28, 2024
1 parent 5833a84 commit 735e611
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Objects;

public class FcConfig extends NabConfiguration {
private static final int CURRENT_VERSION = 8;
private static final int CURRENT_VERSION = 9;

public FcConfig(FarmControl farmControl) {
super(
Expand Down Expand Up @@ -106,6 +106,9 @@ public static class ExclusionSettings extends ConfigSection {
@Entry(key = "pickupable")
public final ConfigEntry<Boolean> pickupable = new ConfigEntry<>();

@Entry(key = "mounted")
public final ConfigEntry<Boolean> mounted = new ConfigEntry<>();

@Entry(key = "younger-than")
public final ConfigEntry<Long> youngerThan = ConfigEntries.longEntry();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public Predicate<SnapshotEntity> getExclusionPredicate(World world) {
List<String> excludeType = exclusionSettings.type.get();
long excludeTicksLived = exclusionSettings.youngerThan.get();
boolean excludePickupable = exclusionSettings.pickupable.get();
boolean excludeMounted = exclusionSettings.mounted.get();
return snapshotEntity -> {
if (excludeLeashed && snapshotEntity.isLeashed()) {
return true;
Expand All @@ -45,6 +46,9 @@ public Predicate<SnapshotEntity> getExclusionPredicate(World world) {
if (excludePickupable && snapshotEntity.isPickupable()) {
return true;
}
if (excludeMounted && snapshotEntity.isMounted()) {
return true;
}
if (snapshotEntity.getTicksLived() < excludeTicksLived) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class SnapshotEntity {
private final boolean isPatrolLeader;
private final int ticksLived;
private final boolean pickupable;
private final boolean mounted;
private final List<Object> classifications = new ArrayList<>();

public SnapshotEntity(Entity entity) {
Expand All @@ -37,6 +38,7 @@ public SnapshotEntity(Entity entity) {
this.isPatrolLeader = entity instanceof Raider && ((Raider) entity).isPatrolLeader();
this.pickupable = entity instanceof AbstractArrow && ((AbstractArrow) entity).getPickupStatus() == AbstractArrow.PickupStatus.ALLOWED;
this.ticksLived = entity.getTicksLived();
this.mounted = !entity.getPassengers().isEmpty();
classifications.add(entity.getType());
if (entity instanceof Colorable) {
DyeColor colour = ((Colorable) entity).getColor();
Expand Down Expand Up @@ -118,6 +120,10 @@ public boolean isPickupable() {
return pickupable;
}

public boolean isMounted() {
return mounted;
}

public int getTicksLived() {
return ticksLived;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/resources/config-patches/8.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[add-field]
before=younger-than
key=world-settings.default.exclusion-settings.mounted
value=true
comment=# Should we not perform actions on mobs that are mounted (e.g. a boat with a villager in it)?
5 changes: 4 additions & 1 deletion src/main/resources/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# GitHub: https://github.com/froobynooby/FarmControl

# Please don't change this!
version: 8
version: 9

# Every how many ticks should we run the profile check / action cycle?
cycle-period: 600
Expand Down Expand Up @@ -81,6 +81,9 @@ world-settings:
# Should we not perform actions on projectiles that can be picked up by a player?
pickupable: true

# Should we not perform actions on mobs that are mounted (e.g. a boat with a villager in it)?
mounted: true

# Should we not perform actions on mobs that are younger than this value (in ticks)?
younger-than: 0

Expand Down

0 comments on commit 735e611

Please sign in to comment.