From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Wed, 22 Mar 2023 00:18:15 +0100 Subject: [PATCH] Variable entity wake-up duration License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-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 be563b466b9b9312254596ea3b8e116b28cf250c..7355c828ab66c23d878e4981be9e44c7d0b13d63 100644 --- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java +++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java @@ -255,4 +255,26 @@ public class GaleWorldConfiguration extends ConfigurationPart { } + public GameplayMechanics gameplayMechanics; + public class GameplayMechanics extends ConfigurationPart { + + // Gale start - variable entity wake-up duration + /** + * This value is σ (the standard deviation) of the inactivity duration ratio, + * so that the regular time interval before will be multiplied by a factor normal(μ = 1, σ). + *
+ * A value of around 0.2 makes entities wake up from inactivity at more randomized times + * and therefore appear more natural in groups. + *
+ * Any value < 0 behaves like 0. + * + */ + public double entityWakeUpDurationRatioStandardDeviation = 0.2; + // Gale end - variable entity wake-up duration + + } + } diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java index 2bff2b6cff78f1ad4cbc6abbc1a37464f543ccb7..8a6bc6d4dc5825e0d125ce3853bd3d7714ac113f 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 ); /**