From 735e611b0aa70a05a28ec6ad36db2c728e4578ce Mon Sep 17 00:00:00 2001 From: froobynooby Date: Sun, 28 Apr 2024 15:36:33 +0930 Subject: [PATCH] Add option to exclude mounted entities --- .../java/com/froobworld/farmcontrol/config/FcConfig.java | 5 ++++- .../froobworld/farmcontrol/controller/ExclusionManager.java | 4 ++++ .../farmcontrol/controller/entity/SnapshotEntity.java | 6 ++++++ src/main/resources/resources/config-patches/8.patch | 5 +++++ src/main/resources/resources/config.yml | 5 ++++- 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/resources/config-patches/8.patch diff --git a/src/main/java/com/froobworld/farmcontrol/config/FcConfig.java b/src/main/java/com/froobworld/farmcontrol/config/FcConfig.java index b5f5c9c..4e6b518 100644 --- a/src/main/java/com/froobworld/farmcontrol/config/FcConfig.java +++ b/src/main/java/com/froobworld/farmcontrol/config/FcConfig.java @@ -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( @@ -106,6 +106,9 @@ public static class ExclusionSettings extends ConfigSection { @Entry(key = "pickupable") public final ConfigEntry pickupable = new ConfigEntry<>(); + @Entry(key = "mounted") + public final ConfigEntry mounted = new ConfigEntry<>(); + @Entry(key = "younger-than") public final ConfigEntry youngerThan = ConfigEntries.longEntry(); diff --git a/src/main/java/com/froobworld/farmcontrol/controller/ExclusionManager.java b/src/main/java/com/froobworld/farmcontrol/controller/ExclusionManager.java index e2cc612..6948eec 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/ExclusionManager.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/ExclusionManager.java @@ -26,6 +26,7 @@ public Predicate getExclusionPredicate(World world) { List 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; @@ -45,6 +46,9 @@ public Predicate getExclusionPredicate(World world) { if (excludePickupable && snapshotEntity.isPickupable()) { return true; } + if (excludeMounted && snapshotEntity.isMounted()) { + return true; + } if (snapshotEntity.getTicksLived() < excludeTicksLived) { return true; } diff --git a/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java b/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java index 05ea114..5ce4c08 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java @@ -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 classifications = new ArrayList<>(); public SnapshotEntity(Entity entity) { @@ -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(); @@ -118,6 +120,10 @@ public boolean isPickupable() { return pickupable; } + public boolean isMounted() { + return mounted; + } + public int getTicksLived() { return ticksLived; } diff --git a/src/main/resources/resources/config-patches/8.patch b/src/main/resources/resources/config-patches/8.patch new file mode 100644 index 0000000..686a53f --- /dev/null +++ b/src/main/resources/resources/config-patches/8.patch @@ -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)? \ No newline at end of file diff --git a/src/main/resources/resources/config.yml b/src/main/resources/resources/config.yml index 719d030..e83019b 100644 --- a/src/main/resources/resources/config.yml +++ b/src/main/resources/resources/config.yml @@ -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 @@ -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