Skip to content

Commit

Permalink
Added region based comment (#165)
Browse files Browse the repository at this point in the history
* Region based comment helper functions

* (Region based comment) Dont save entity

* (Region based comment) Pufferfish DAB

* (Region based comment) Cache EntityType

* (Region based comment) Cache EntityType

* (Region based comment) Pufferfish EntityTTL

* (Region based comment) Faster sequence

* (Region based comment) FastRNG

* (Region based comment) 0042

* (Region based comment) 0721

* (Region based comment) 0009

* (Region based comment) V1rtUal tHReaD

* (Region based comment) ZSSM

* [ci skip] (Region based comment) 0079

* [ci skip] (Region based comment) 0089 0090

* [ci skip] (Region based comment) 0049 0118 0138

* [ci skip] (Region based comment) 0006 0017 0018 0080 0081

* [ci skip] (Region based comment) 0019 0038 0059 0108 0117 0127

* ALL PATCHES ARE DONE

* [ci skip] NZDD
  • Loading branch information
HaHaWTH authored Nov 14, 2024
1 parent 7eaacd4 commit fa9c4a7
Show file tree
Hide file tree
Showing 35 changed files with 328 additions and 171 deletions.
38 changes: 32 additions & 6 deletions patches/server/0003-Leaf-Config.patch
Original file line number Diff line number Diff line change
Expand Up @@ -423,31 +423,37 @@ index 0000000000000000000000000000000000000000..fdbdf3f6a5071ce629d2881e861075db
+}
diff --git a/src/main/java/org/dreeam/leaf/config/LeafGlobalConfig.java b/src/main/java/org/dreeam/leaf/config/LeafGlobalConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..db7bdee965c988777dab3db38f09511c72fed921
index 0000000000000000000000000000000000000000..794bc822d987ee2bb69b953ea70ae3ee08124ac5
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/LeafGlobalConfig.java
@@ -0,0 +1,111 @@
@@ -0,0 +1,137 @@
+package org.dreeam.leaf.config;
+
+import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
+import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
+
+import java.io.File;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+public class LeafGlobalConfig {
+
+ protected static ConfigFile configFile;
+ private static final String CURRENT_REGION = Locale.getDefault().getCountry().toUpperCase(Locale.ROOT); // It will be in uppercase by default, just make sure
+ protected static final boolean isCN = CURRENT_REGION.equals("CN");
+
+ public LeafGlobalConfig(boolean init) throws Exception {
+ configFile = ConfigFile.loadConfig(new File(LeafConfig.I_CONFIG_FOLDER, LeafConfig.I_GLOBAL_CONFIG_FILE));
+ configFile.set("config-version", 3.0);
+ configFile.addComments("config-version", """
+ configFile.addComments("config-version", pickStringRegionBased("""
+ Leaf Config
+ Github Repo: https://github.com/Winds-Studio/Leaf
+ Discord: https://discord.com/invite/gfgAwdSEuM
+ QQ Group: 619278377""");
+ GitHub Repo: https://github.com/Winds-Studio/Leaf
+ Discord: https://discord.com/invite/gfgAwdSEuM""",
+ """
+ Leaf Config
+ GitHub Repo: https://github.com/Winds-Studio/Leaf
+ QQ Group: 619278377"""));
+
+ // Pre-structure to force order
+ structureConfig();
Expand Down Expand Up @@ -537,4 +543,24 @@ index 0000000000000000000000000000000000000000..db7bdee965c988777dab3db38f09511c
+ public void addComment(String path, String comment) {
+ configFile.addComment(path, comment);
+ }
+
+ public void addCommentIfCN(String path, String comment) {
+ if (isCN) {
+ configFile.addComment(path, comment);
+ }
+ }
+
+ public void addCommentIfNonCN(String path, String comment) {
+ if (!isCN) {
+ configFile.addComment(path, comment);
+ }
+ }
+
+ public void addCommentRegionBased(String path, String en, String cn) {
+ configFile.addComment(path, isCN ? cn : en);
+ }
+
+ public String pickStringRegionBased(String en, String cn) {
+ return isCN ? cn : en;
+ }
+}
22 changes: 14 additions & 8 deletions patches/server/0006-Pufferfish-Sentry.patch
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ index fdbdf3f6a5071ce629d2881e861075dbeef11b42..41b24849b6601cdf89ee6cb4125a7127

diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/SentryDSN.java b/src/main/java/org/dreeam/leaf/config/modules/misc/SentryDSN.java
new file mode 100644
index 0000000000000000000000000000000000000000..b37aa469c0e1d1b18c1f43a364e00276ce8652e0
index 0000000000000000000000000000000000000000..0234fc0d3054d8348da49a8006ec99d6d09114fe
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/SentryDSN.java
@@ -0,0 +1,37 @@
@@ -0,0 +1,43 @@
+package org.dreeam.leaf.config.modules.misc;
+
+import org.apache.logging.log4j.Level;
Expand All @@ -241,17 +241,23 @@ index 0000000000000000000000000000000000000000..b37aa469c0e1d1b18c1f43a364e00276
+ @Override
+ public void onLoaded() {
+ String sentryEnvironment = System.getenv("SENTRY_DSN");
+ String sentryConfig = config.getString(sentryDsnConfigPath = getBasePath() + ".dsn", sentryDsn, """
+ String sentryConfig = config.getString(sentryDsnConfigPath = getBasePath() + ".dsn", sentryDsn, config.pickStringRegionBased("""
+ Sentry DSN for improved error logging, leave blank to disable,
+ Obtain from https://sentry.io/""");
+ Obtain from https://sentry.io/""",
+ """
+ Sentry DSN (出现严重错误时将发送至配置的Sentry DSN地址) (留空关闭)"""));
+
+ sentryDsn = sentryEnvironment == null
+ ? sentryConfig
+ : sentryEnvironment;
+ logLevel = config.getString(getBasePath() + ".log-level", logLevel, """
+ Logs with a level higher than or equal to this level will be recorded""");
+ onlyLogThrown = config.getBoolean(getBasePath() + ".only-log-thrown", onlyLogThrown, """
+ Only log with a Throwable will be recorded after enabling this""");
+ logLevel = config.getString(getBasePath() + ".log-level", logLevel, config.pickStringRegionBased("""
+ Logs with a level higher than or equal to this level will be recorded.""",
+ """
+ 大于等于该等级的日志会被记录."""));
+ onlyLogThrown = config.getBoolean(getBasePath() + ".only-log-thrown", onlyLogThrown, config.pickStringRegionBased("""
+ Only log with a Throwable will be recorded after enabling this.""",
+ """
+ 是否仅记录带有 Throwable 的日志."""));
+
+ if (sentryDsn != null && !sentryDsn.isBlank()) {
+ gg.pufferfish.pufferfish.sentry.SentryManager.init(Level.getLevel(logLevel));
Expand Down
12 changes: 8 additions & 4 deletions patches/server/0007-Pufferfish-Optimize-mob-spawning.patch
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ index d8b4196adf955f8d414688dc451caac2d9c609d9..80a43def4912a3228cd95117d5c2aac6
// Paper - rewrite chunk system
diff --git a/src/main/java/org/dreeam/leaf/config/modules/async/AsyncMobSpawning.java b/src/main/java/org/dreeam/leaf/config/modules/async/AsyncMobSpawning.java
new file mode 100644
index 0000000000000000000000000000000000000000..8a3726a747ff4640f9936a9eae1dca34e5203029
index 0000000000000000000000000000000000000000..9a9cbb8ab1281fa1e8e98ed2d6fec4f68cfd002a
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/async/AsyncMobSpawning.java
@@ -0,0 +1,30 @@
@@ -0,0 +1,34 @@
+package org.dreeam.leaf.config.modules.async;
+
+import org.dreeam.leaf.config.ConfigModules;
Expand All @@ -175,12 +175,16 @@ index 0000000000000000000000000000000000000000..8a3726a747ff4640f9936a9eae1dca34
+
+ @Override
+ public void onLoaded() {
+ config.addComment(getBasePath(), """
+ config.addCommentRegionBased(getBasePath(), """
+ Whether or not asynchronous mob spawning should be enabled.
+ On servers with many entities, this can improve performance by up to 15%. You must have
+ paper's per-player-mob-spawns setting set to true for this to work.
+ One quick note - this does not actually spawn mobs async (that would be very unsafe).
+ This just offloads some expensive calculations that are required for mob spawning.""");
+ This just offloads some expensive calculations that are required for mob spawning.""",
+ """
+ 是否异步化生物生成.
+ 在实体较多的服务器上, 异步生成可最高带来15%的性能提升.
+ 须在Paper配置文件中打开 per-player-mob-spawns 才能生效.""");
+
+ // This prevents us from changing the value during a reload.
+ if (!asyncMobSpawningInitialized) {
Expand Down
32 changes: 21 additions & 11 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 491a4c38cbb393c1a565d75a87c0444e321938c0..e1fd6ad56c0fbaf59c9d9ac985ab5301
}
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..a2e60c43074df560eb01f150bf52b8d0f5af9b54
index 0000000000000000000000000000000000000000..7e1e06ff65d1e186e6ec41917945d3d90fe72008
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/DynamicActivationofBrain.java
@@ -0,0 +1,71 @@
@@ -0,0 +1,81 @@
+package org.dreeam.leaf.config.modules.opt;
+
+import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -327,27 +327,37 @@ index 0000000000000000000000000000000000000000..a2e60c43074df560eb01f150bf52b8d0
+
+ @Override
+ public void onLoaded() {
+ config.addComment(getBasePath(), """
+ config.addCommentRegionBased(getBasePath(), """
+ Optimizes entity brains when
+ they're far away from the player""");
+ they're far away from the player""",
+ """
+ 根据距离动态优化生物 AI""");
+
+ enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
+ dontEnableIfInWater = config.getBoolean(getBasePath() + ".dont-enable-if-in-water", dontEnableIfInWater, """
+ dontEnableIfInWater = config.getBoolean(getBasePath() + ".dont-enable-if-in-water", dontEnableIfInWater, config.pickStringRegionBased("""
+ 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 could fix entities suffocate in the water.""",
+ """
+ 启用此项后, 在水中的非水生生物将不会被 DAB 影响.
+ 可以避免距离玩家较远的生物在水里淹死."""));
+ startDistance = config.getInt(getBasePath() + ".start-distance", startDistance, config.pickStringRegionBased("""
+ This value determines how far away an entity has to be
+ from the player to start being effected by DEAR.""");
+ maximumActivationPrio = config.getInt(getBasePath() + ".max-tick-freq", maximumActivationPrio, """
+ from the player to start being effected by DEAR.""",
+ """
+ 生物距离玩家多少格 DAB 开始生效"""));
+ maximumActivationPrio = config.getInt(getBasePath() + ".max-tick-freq", maximumActivationPrio, config.pickStringRegionBased("""
+ This value defines how often in ticks, the furthest entity
+ will get their pathfinders and behaviors ticked. 20 = 1s""");
+ will get their pathfinders and behaviors ticked. 20 = 1s""",
+ """
+ 最远处的实体每隔多少刻tick一次"""));
+ activationDistanceMod = config.getInt(getBasePath() + ".activation-dist-mod", activationDistanceMod, """
+ This value defines how much distance modifies an entity's
+ tick frequency. freq = (distanceToPlayer^2) / (2^value)",
+ If you want further away entities to tick less often, use 7.
+ If you want further away entities to tick more often, try 9.""");
+ blackedEntities = config.getList(getBasePath() + ".blacklisted-entities", blackedEntities,
+ "A list of entities to ignore for activation");
+ config.pickStringRegionBased("A list of entities to ignore for activation",
+ "不会被 DAB 影响的实体列表"));
+
+ startDistanceSquared = startDistance * startDistance;
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Original license: GPL v3
Original project: https://github.com/pufferfish-gg/Pufferfish

diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 96e7e9ef8bf9ab6902638ac4ba270a1f98a36cdf..6d88b2888d2028cb88e34dce3d7963dd818b58d7 100644
index df932757d6a2f6812a1be16a3a71c4c4c75768b5..aa6d06c5b873ae92d7de6c091a8b9d27221ef7f8 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -233,11 +233,13 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
Expand All @@ -27,10 +27,10 @@ index 96e7e9ef8bf9ab6902638ac4ba270a1f98a36cdf..6d88b2888d2028cb88e34dce3d7963dd
if (this.targetSelector.inactiveTick(this.activatedPriority, true)) { // Pufferfish - pass activated priority
diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleInactiveGoalSelectorTick.java b/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleInactiveGoalSelectorTick.java
new file mode 100644
index 0000000000000000000000000000000000000000..3e2b97faa4fddcd0dfbfedc8e7515f89b7cdb3bb
index 0000000000000000000000000000000000000000..785215c05111424bbcd2d9708ed05b35530bb9c5
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleInactiveGoalSelectorTick.java
@@ -0,0 +1,20 @@
@@ -0,0 +1,23 @@
+package org.dreeam.leaf.config.modules.opt;
+
+import org.dreeam.leaf.config.ConfigModules;
Expand All @@ -46,8 +46,11 @@ index 0000000000000000000000000000000000000000..3e2b97faa4fddcd0dfbfedc8e7515f89
+
+ @Override
+ public void onLoaded() {
+ enabled = config.getBoolean(getBasePath() + ".inactive-goal-selector-throttle", enabled, """
+ enabled = config.getBoolean(getBasePath() + ".inactive-goal-selector-throttle", enabled, config.pickStringRegionBased("""
+ Throttles the AI goal selector in entity inactive ticks.
+ This can improve performance by a few percent, but has minor gameplay implications.""");
+ This can improve performance by a few percent, but has minor gameplay implications.""",
+ """
+ 是否在实体不活跃 tick 时阻塞 AI 目标选择器.
+ 有助于提升性能, 但对游戏有轻微影响."""));
+ }
+}
13 changes: 8 additions & 5 deletions patches/server/0010-Pufferfish-Entity-TTL.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Original license: GPL v3
Original project: https://github.com/pufferfish-gg/Pufferfish

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index be9815bdf5652a7856fd72d3fca3e2562b2fb8c6..815db5b0a24f1628d646893ebad466dcee2ab0bd 100644
index 22d3d963dc9806643608d077324b27832641ce57..60fbed7a31fbeca07eae8ea6b0fb97705961bb7e 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -849,6 +849,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down Expand Up @@ -37,10 +37,10 @@ index b2d8a858d8767bd6ca52e0b8db84757986c6ed61..f9440014ab2fe753c16b9383f5fffbb8
@Nullable
diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/EntityTTL.java b/src/main/java/org/dreeam/leaf/config/modules/opt/EntityTTL.java
new file mode 100644
index 0000000000000000000000000000000000000000..656655343653b1854a93fb074c4fa04bda98754d
index 0000000000000000000000000000000000000000..dbab6168992fb9bb50f7cbc49a0cc7aa7e357666
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/EntityTTL.java
@@ -0,0 +1,36 @@
@@ -0,0 +1,39 @@
+package org.dreeam.leaf.config.modules.opt;
+
+import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -58,11 +58,14 @@ index 0000000000000000000000000000000000000000..656655343653b1854a93fb074c4fa04b
+
+ @Override
+ public void onLoaded() {
+ config.addComment(getBasePath(), """
+ config.addCommentRegionBased(getBasePath(), """
+ These values define a entity's maximum lifespan. If an
+ entity is in this list and it has survived for longer than
+ that number of ticks, then it will be removed. Setting a value to
+ -1 disables this feature.""");
+ -1 disables this feature.""",
+ """
+ 这些值定义了实体的最大生命周期.
+ 如果实体存活时间超过指定的 tick 将被移除, 设置为 -1 可禁用此功能.""");
+
+ // Set some defaults
+ config.getInt(getBasePath() + ".SNOWBALL", -1);
Expand Down
13 changes: 8 additions & 5 deletions patches/server/0017-Remove-vanilla-username-check.patch
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ index f58dec12326734c61f4bc2298a87fb38f1ac1dc4..66eff9ddee09f44935df6d8ed3eb2494
}
diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/RemoveVanillaUsernameCheck.java b/src/main/java/org/dreeam/leaf/config/modules/misc/RemoveVanillaUsernameCheck.java
new file mode 100644
index 0000000000000000000000000000000000000000..ecae8c5d114b2d0510b61c78e3fc705b61f6d126
index 0000000000000000000000000000000000000000..f094806fdc4f98924aab69b5dffb3a3ffbc2e21d
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/RemoveVanillaUsernameCheck.java
@@ -0,0 +1,20 @@
@@ -0,0 +1,23 @@
+package org.dreeam.leaf.config.modules.misc;
+
+import org.dreeam.leaf.config.ConfigModules;
Expand All @@ -65,8 +65,11 @@ index 0000000000000000000000000000000000000000..ecae8c5d114b2d0510b61c78e3fc705b
+
+ @Override
+ public void onLoaded() {
+ enabled = config.getBoolean(getBasePath(), enabled, """
+ Remove Vanilla username check
+ allowing all characters as username""");
+ enabled = config.getBoolean(getBasePath(), enabled, config.pickStringRegionBased("""
+ Remove Vanilla username check,
+ allowing all characters as username.""",
+ """
+ 移除原版的用户名验证,
+ 让所有字符均可作为玩家名."""));
+ }
+}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ index a1e39d4476e932da3d4e0c363ce22eb5be2b8e6c..e4911a420c81a371142f556584cc05a4
this.connection.disconnect(chatmessage);
diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/RemoveSpigotCheckBungee.java b/src/main/java/org/dreeam/leaf/config/modules/misc/RemoveSpigotCheckBungee.java
new file mode 100644
index 0000000000000000000000000000000000000000..18672fc1415fdc4d8021e5dcd5aa19739500f7fa
index 0000000000000000000000000000000000000000..f7dad48d09759db5254dc7dbcef64f801a0a1546
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/RemoveSpigotCheckBungee.java
@@ -0,0 +1,20 @@
@@ -0,0 +1,22 @@
+package org.dreeam.leaf.config.modules.misc;
+
+import org.dreeam.leaf.config.ConfigModules;
Expand All @@ -38,8 +38,10 @@ index 0000000000000000000000000000000000000000..18672fc1415fdc4d8021e5dcd5aa1973
+
+ @Override
+ public void onLoaded() {
+ enabled = config.getBoolean(getBasePath(), enabled, """
+ enabled = config.getBoolean(getBasePath(), enabled, config.pickStringRegionBased("""
+ Enable player enter backend server through proxy
+ without backend server enabling its bungee mode""");
+ without backend server enabling its bungee mode.""",
+ """
+ 使服务器无需打开 bungee 模式即可让玩家加入后端服务器."""));
+ }
+}
Loading

0 comments on commit fa9c4a7

Please sign in to comment.