Skip to content

Commit aab90f7

Browse files
committed
Rewrite config, Add configurable beacon effect ranges
1 parent 9d4c174 commit aab90f7

File tree

18 files changed

+273
-214
lines changed

18 files changed

+273
-214
lines changed

atdeprecated-server/minecraft-patches/features/0001-Setup-config.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ index cf72cb8b418239b56c755486b03a321672e16bc3..d9178fe7a52f7b98c82a03533e4c942e
1212
JvmProfiler.INSTANCE.start(Environment.SERVER);
1313
}
1414

15-
+ fun.mntale.atdeprecated.config.Config.init(); // // atDeprecated - atDeprecated config
15+
+ fun.mntale.atdeprecated.config.AtCoreConfig.init(); // atDeprecated - atDeprecated config
1616
me.earthme.luminol.config.ConfigManager.initConfigs(); // Luminol - Luminol config
1717
io.papermc.paper.plugin.PluginInitializerManager.load(optionSet); // Paper
1818
Bootstrap.bootStrap();
@@ -24,7 +24,7 @@ index c6c6432c2efeb7b95c2894b188cd966321ae3186..270cf5a1fce8eda5cd11e221b0026cd7
2424
this.paperConfigurations.initializeGlobalConfiguration(this.registryAccess());
2525
this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
2626
// Paper end - initialize global and world-defaults configuration
27-
+ fun.mntale.atdeprecated.config.Config.load(); // atDeprecated - load config file
27+
+ fun.mntale.atdeprecated.config.AtCoreConfig.load(); // atDeprecated - load config file
2828
me.earthme.luminol.config.ConfigManager.loadConfigFiles(); // Luminol - load config file
2929
if (false) this.server.spark.enableEarlyIfRequested(); // Paper - spark // Luminol - Force disable builtin spark
3030
// Paper start - fix converting txt to json file; convert old users earlier after PlayerList creation but before file load/save
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: MidnightTale <[email protected]>
3+
Date: Thu, 24 Jul 2025 04:10:47 +0700
4+
Subject: [PATCH] Add config for beacon ranges
5+
6+
7+
diff --git a/net/minecraft/world/level/block/entity/BeaconBlockEntity.java b/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
8+
index b27a40e69046414d5302882b72ac8b3f848e18df..2a6d1801eed11ae39eb062bb9557213cb25dcd4d 100644
9+
--- a/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
10+
+++ b/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
11+
@@ -143,7 +143,11 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
12+
13+
public double getEffectRange() {
14+
if (this.effectRange < 0) {
15+
- return this.levels * 10 + 10;
16+
+ List<Integer> ranges = fun.mntale.atdeprecated.config.AtCoreConfig.BEACON_CONFIG.getParsedRanges();
17+
+ if (this.levels > 0 && this.levels <= ranges.size()) {
18+
+ return ranges.get(this.levels - 1);
19+
+ }
20+
+ return 0;
21+
} else {
22+
return effectRange;
23+
}
24+
@@ -338,7 +342,11 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
25+
}
26+
27+
private static double computeBeaconRange(final int beaconLevel) {
28+
- return beaconLevel * 10 + 10; // Diff from applyEffects
29+
+ List<Integer> ranges = fun.mntale.atdeprecated.config.AtCoreConfig.BEACON_CONFIG.getParsedRanges();
30+
+ if (beaconLevel > 0 && beaconLevel <= ranges.size()) {
31+
+ return ranges.get(beaconLevel - 1);
32+
+ }
33+
+ return 0;
34+
}
35+
36+
public static List<Player> getHumansInRange(final Level level, final BlockPos pos, final int beaconLevel, final @Nullable BeaconBlockEntity blockEntity) {

atdeprecated-server/minecraft-patches/removes/0001-Better-beacon-range.patch

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package fun.mntale.atdeprecated.config;
2+
3+
import fun.mntale.atdeprecated.config.modules.features.BeaconConfig;
4+
import fun.mntale.atdeprecated.config.modules.removed.RemovedConfig;
5+
import java.io.File;
6+
7+
public class AtCoreConfig {
8+
private static final ConfigManager configManager = new ConfigManager(new File("atdeprecated/atdeprecated-global.toml"));
9+
10+
public static final BeaconConfig BEACON_CONFIG = new BeaconConfig();
11+
public static final RemovedConfig REMOVED_CONFIG = new RemovedConfig();
12+
13+
public static void init() {
14+
registerModules();
15+
configManager.preload();
16+
}
17+
18+
public static void load() {
19+
configManager.load();
20+
}
21+
22+
private static void registerModules() {
23+
configManager.registerModule(BEACON_CONFIG);
24+
configManager.registerModule(REMOVED_CONFIG);
25+
}
26+
}

atdeprecated-server/src/main/java/fun/mntale/atdeprecated/config/Config.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package fun.mntale.atdeprecated.config;
2+
3+
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
4+
import fun.mntale.atdeprecated.config.annotations.ConfigInfo;
5+
import fun.mntale.atdeprecated.config.annotations.RemovedEntry;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
import java.lang.reflect.Field;
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
public class ConfigManager {
14+
private final File configFile;
15+
private final List<IConfigModule> modules = new ArrayList<>();
16+
private CommentedFileConfig config;
17+
18+
public ConfigManager(File configFile) {
19+
this.configFile = configFile;
20+
}
21+
22+
public void registerModule(IConfigModule module) {
23+
modules.add(module);
24+
}
25+
26+
public void preload() {
27+
if (!configFile.exists()) {
28+
try {
29+
configFile.getParentFile().mkdirs();
30+
configFile.createNewFile();
31+
} catch (IOException e) {
32+
throw new RuntimeException("Failed to create config file", e);
33+
}
34+
}
35+
config = CommentedFileConfig.of(configFile);
36+
config.load();
37+
}
38+
39+
public void load() {
40+
for (IConfigModule module : modules) {
41+
loadModule(module);
42+
}
43+
save();
44+
}
45+
46+
private void loadModule(IConfigModule module) {
47+
for (Field field : module.getClass().getDeclaredFields()) {
48+
if (field.isAnnotationPresent(ConfigInfo.class)) {
49+
loadValue(module, field);
50+
}
51+
if (field.isAnnotationPresent(RemovedEntry.class)) {
52+
for (RemovedEntry removed : field.getAnnotationsByType(RemovedEntry.class)) {
53+
String path = String.join(".", removed.category()) + "." + removed.name();
54+
if (config.contains(path)) {
55+
config.remove(path);
56+
}
57+
}
58+
}
59+
}
60+
}
61+
62+
private void loadValue(IConfigModule module, Field field) {
63+
ConfigInfo info = field.getAnnotation(ConfigInfo.class);
64+
String path = module.getCategory().getKey() + "." + module.getBaseName() + "." + (info.name().isEmpty() ? field.getName() : info.name());
65+
Object value = config.get(path);
66+
try {
67+
if (value == null) {
68+
config.set(path, field.get(module));
69+
config.setComment(path, info.comments());
70+
} else {
71+
field.set(module, value);
72+
}
73+
} catch (IllegalAccessException e) {
74+
throw new RuntimeException("Failed to access config field", e);
75+
}
76+
}
77+
78+
public void save() {
79+
for (IConfigModule module : modules) {
80+
for (Field field : module.getClass().getDeclaredFields()) {
81+
if (field.isAnnotationPresent(ConfigInfo.class)) {
82+
ConfigInfo info = field.getAnnotation(ConfigInfo.class);
83+
String path = module.getCategory().getKey() + "." + module.getBaseName() + "." + (info.name().isEmpty() ? field.getName() : info.name());
84+
try {
85+
config.set(path, field.get(module));
86+
config.setComment(path, info.comments());
87+
} catch (IllegalAccessException e) {
88+
throw new RuntimeException("Failed to access config field", e);
89+
}
90+
}
91+
}
92+
}
93+
config.save();
94+
}
95+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package fun.mntale.atdeprecated.config;
2+
3+
public enum EnumConfigCategory {
4+
FIXES("fixes"),
5+
OPTIMIZATIONS("optimizations"),
6+
MISC("misc"),
7+
FEATURES("features"),
8+
EXPERIMENT("experiment"),
9+
REMOVED("removed");
10+
11+
private final String key;
12+
13+
EnumConfigCategory(String key) {
14+
this.key = key;
15+
}
16+
17+
public String getKey() {
18+
return key;
19+
}
20+
}

atdeprecated-server/src/main/java/fun/mntale/atdeprecated/config/Global.java

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package fun.mntale.atdeprecated.config;
2+
3+
public interface IConfigModule {
4+
EnumConfigCategory getCategory();
5+
String getBaseName();
6+
}

atdeprecated-server/src/main/java/fun/mntale/atdeprecated/config/Manager.java

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)