9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-19 14:59:29 +00:00
Files
Gale/patches/server/0057-Variable-entity-wake-up-duration.patch
2023-08-21 21:46:38 +02:00

95 lines
5.1 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 22 Mar 2023 00:18:15 +0100
Subject: [PATCH] Variable entity wake-up duration
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
index 2f9687ad6c50cdcebc7908583b1093d1a0fa9737..b3822132cbb34dde90754aa2ee5439433ea4df4b 100644
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
@@ -258,6 +258,23 @@ public class GaleWorldConfiguration extends ConfigurationPart {
public GameplayMechanics gameplayMechanics;
public class GameplayMechanics extends ConfigurationPart {
+ // Gale start - variable entity wake-up duration
+ /**
+ * This value is <code>σ</code> (the standard deviation) of the inactivity duration ratio,
+ * so that the regular time interval before will be multiplied by a factor <code>normal(μ = 1, σ)</code>.
+ * <br>
+ * A value of around 0.2 makes entities wake up from inactivity at more randomized times
+ * and therefore appear more natural in groups.
+ * <br>
+ * Any value < 0 behaves like 0.
+ * <ul>
+ * <li><i>Default</i>: 0.2</li>
+ * <li><i>Vanilla</i>: 0</li>
+ * </ul>
+ */
+ public double entityWakeUpDurationRatioStandardDeviation = 0.2;
+ // Gale end - variable entity wake-up duration
+
public boolean tryRespawnEnderDragonAfterEndCrystalPlace = true; // Gale - Pufferfish - make ender dragon respawn attempt after placing end crystals configurable
}
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 0d04d7f9a9df7140cc35534a3f301f2815faed51..50cd68e40c67b83af4e8008ce93782a060658dd4 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -38,6 +38,7 @@ 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.GaleWorldConfiguration;
public class ActivationRange
{
@@ -70,28 +71,41 @@ public class ActivationRange
if (entity.activationType == ActivationType.VILLAGER) {
if (inactiveFor > config.wakeUpInactiveVillagersEvery && world.wakeupInactiveRemainingVillagers > 0) {
world.wakeupInactiveRemainingVillagers--;
- return config.wakeUpInactiveVillagersFor;
+ return getWakeUpDurationWithVariance(entity, config.wakeUpInactiveVillagersFor); // Gale - variable entity wake-up duration
}
} else if (entity.activationType == ActivationType.ANIMAL) {
if (inactiveFor > config.wakeUpInactiveAnimalsEvery && world.wakeupInactiveRemainingAnimals > 0) {
world.wakeupInactiveRemainingAnimals--;
- return config.wakeUpInactiveAnimalsFor;
+ return getWakeUpDurationWithVariance(entity, config.wakeUpInactiveAnimalsFor); // Gale - variable entity wake-up duration
}
} else if (entity.activationType == ActivationType.FLYING_MONSTER) {
if (inactiveFor > config.wakeUpInactiveFlyingEvery && world.wakeupInactiveRemainingFlying > 0) {
world.wakeupInactiveRemainingFlying--;
- return config.wakeUpInactiveFlyingFor;
+ return getWakeUpDurationWithVariance(entity, config.wakeUpInactiveFlyingFor); // Gale - variable entity wake-up duration
}
} else if (entity.activationType == ActivationType.MONSTER || entity.activationType == ActivationType.RAIDER) {
if (inactiveFor > config.wakeUpInactiveMonstersEvery && world.wakeupInactiveRemainingMonsters > 0) {
world.wakeupInactiveRemainingMonsters--;
- return config.wakeUpInactiveMonstersFor;
+ return getWakeUpDurationWithVariance(entity, config.wakeUpInactiveMonstersFor); // Gale - variable entity wake-up duration
}
}
return -1;
}
// Paper end
+ // Gale start - variable entity wake-up duration
+ private static final java.util.Random wakeUpDurationRandom = new java.util.Random();
+
+ private static int getWakeUpDurationWithVariance(Entity entity, int wakeUpDuration) {
+ GaleWorldConfiguration config = entity.level().galeConfig();
+ double deviation = config.gameplayMechanics.entityWakeUpDurationRatioStandardDeviation;
+ if (deviation <= 0) {
+ return wakeUpDuration;
+ }
+ return (int) Math.min(Integer.MAX_VALUE, Math.max(1, Math.round(wakeUpDuration * wakeUpDurationRandom.nextGaussian(1, deviation))));
+ }
+ // Gale end - variable entity wake-up duration
+
static AABB maxBB = new AABB( 0, 0, 0, 0, 0, 0 );
/**