Skip to content

Commit

Permalink
Add dontEnableIfInWater option to DAB (#144)
Browse files Browse the repository at this point in the history
* Add dontEnableIfInWater option to DAB

* Check using EntityTypeTag

* Simplify condition

* remove import
  • Loading branch information
HaHaWTH authored Oct 30, 2024
1 parent 57b84ca commit 4cbc1af
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
23 changes: 18 additions & 5 deletions patches/server/0008-Pufferfish-Dynamic-Activation-of-Brain.patch
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ index 71a3eadd2f1e00fa066dbfe9918d749d43435a18..03513d3b6118ac5d0a58788462dcbc98
}
diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/DynamicActivationofBrain.java b/src/main/java/org/dreeam/leaf/config/modules/opt/DynamicActivationofBrain.java
new file mode 100644
index 0000000000000000000000000000000000000000..ed8496e344284f79ff66c1d216090a218d95c311
index 0000000000000000000000000000000000000000..a2e60c43074df560eb01f150bf52b8d0f5af9b54
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/DynamicActivationofBrain.java
@@ -0,0 +1,67 @@
@@ -0,0 +1,71 @@
+package org.dreeam.leaf.config.modules.opt;
+
+import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -322,6 +322,7 @@ index 0000000000000000000000000000000000000000..ed8496e344284f79ff66c1d216090a21
+ public static int startDistanceSquared;
+ public static int maximumActivationPrio = 20;
+ public static int activationDistanceMod = 8;
+ public static boolean dontEnableIfInWater = false;
+ public static List<String> blackedEntities = new ArrayList<>();
+
+ @Override
Expand All @@ -331,6 +332,9 @@ index 0000000000000000000000000000000000000000..ed8496e344284f79ff66c1d216090a21
+ they're far away from the player""");
+
+ enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
+ dontEnableIfInWater = config.getBoolean(getBasePath() + ".dont-enable-if-in-water", dontEnableIfInWater, """
+ After enabling this, non-aquatic entities in the water will not be affected by DAB.
+ This could fix entities suffocate in the water.""");
+ startDistance = config.getInt(getBasePath() + ".start-distance", startDistance, """
+ This value determines how far away an entity has to be
+ from the player to start being effected by DEAR.""");
Expand Down Expand Up @@ -367,16 +371,25 @@ index 0000000000000000000000000000000000000000..ed8496e344284f79ff66c1d216090a21
+ }
+}
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 0b2f2fbe462ed628ef3d640824d4162e79279089..456f64fcae7a12ca141d8061f69797e58efa1899 100644
index 0b2f2fbe462ed628ef3d640824d4162e79279089..e469b2782932275caa4bb760eefff82916c47d3a 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -238,6 +238,25 @@ public class ActivationRange
@@ -38,7 +38,6 @@ import co.aikar.timings.MinecraftTimings;
import net.minecraft.world.entity.schedule.Activity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
-import org.galemc.gale.configuration.GaleGlobalConfiguration;
import org.galemc.gale.configuration.GaleWorldConfiguration;

public class ActivationRange
@@ -238,6 +237,26 @@ public class ActivationRange
}
// Paper end - Configurable marker ticking
ActivationRange.activateEntity(entity);
+
+ // Pufferfish start
+ if (org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.enabled && entity.getType().dabEnabled) {
+ if (org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.enabled && entity.getType().dabEnabled &&
+ (!org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.dontEnableIfInWater || entity.getType().is(net.minecraft.tags.EntityTypeTags.CAN_BREATHE_UNDER_WATER) || !entity.isInWaterOrBubble())) { // Leaf - Option for dontEnableIfInWater
+ if (!entity.activatedPriorityReset) {
+ entity.activatedPriorityReset = true;
+ entity.activatedPriority = org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.maximumActivationPrio;
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0011-Purpur-Server-Changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -24824,10 +24824,10 @@ index 0000000000000000000000000000000000000000..129acb8ad139decc6b1c023cb10bc32d
+ // Paper end - lifecycle events
+}
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 456f64fcae7a12ca141d8061f69797e58efa1899..530c5d656b6b362d0df85a897d7e8d0497250680 100644
index e469b2782932275caa4bb760eefff82916c47d3a..92a8d0a44a3e8b955807fc6b94564b6660bd94ad 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -216,6 +216,8 @@ public class ActivationRange
@@ -215,6 +215,8 @@ public class ActivationRange
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions patches/server/0015-Remove-Timings.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@ index 579c2e69d8f6ce8398eb1297d1d1ead98c9068a5..00000000000000000000000000000000
-
-}
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 530c5d656b6b362d0df85a897d7e8d0497250680..7fd2a463e9208635bd2d9f0b1a4291d60c5dedf2 100644
index 92a8d0a44a3e8b955807fc6b94564b6660bd94ad..dae16e2c3cc0f154dbe3a62e3050548fb649c3c2 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -34,7 +34,6 @@ import net.minecraft.world.entity.projectile.FireworkRocketEntity;
Expand All @@ -1849,7 +1849,7 @@ index 530c5d656b6b362d0df85a897d7e8d0497250680..7fd2a463e9208635bd2d9f0b1a4291d6
import net.minecraft.world.entity.schedule.Activity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
@@ -182,7 +181,6 @@ public class ActivationRange
@@ -181,7 +180,6 @@ public class ActivationRange
*/
public static void activateEntities(Level world)
{
Expand Down
2 changes: 1 addition & 1 deletion patches/server/0124-Optimize-Entity-distanceToSqr.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Fri, 29 Oct 2077 00:00:00 +0800
Subject: [PATCH] Optimize Entity distanceToSqr

This patch optimizes Entity#distanceToSqr call by using Math#fma which is around 1.2x to 4x faster than original method on CPUs support Fused Multiply-Add (FMA) operation,
This patch optimizes Entity#distanceToSqr call by using Math#fma which is around 1.2x to 4x faster than original method,
avoids multiple casting in Entity#distanceTo, using Math#hypot instead of Mojang's Mth#sqrt. Additionally, this patch makes
these methods more able to be inlined by the JIT compiler.

Expand Down

0 comments on commit 4cbc1af

Please sign in to comment.