Fix gamerule
This commit is contained in:
@@ -335,10 +335,25 @@ public final class LobbySystemsMod implements ModInitializer {
|
||||
}
|
||||
|
||||
List<GameRuleEntry> entries = new ArrayList<>();
|
||||
int skippedRules = 0;
|
||||
|
||||
for (GameRule<?> rule : BuiltInRegistries.GAME_RULE) {
|
||||
Identifier id = BuiltInRegistries.GAME_RULE.getKey(rule);
|
||||
if (id == null) continue;
|
||||
entries.add(new GameRuleEntry(id.toString(), gameRuleValue(level, rule)));
|
||||
try {
|
||||
// Minecraft 26.x stores gamerule values directly in GameRules.
|
||||
// Some registered rules may be unavailable for the level's enabled
|
||||
// feature set, so each rule is read independently and safely.
|
||||
if (!rule.isEnabled(level.enabledFeatures())) {
|
||||
skippedRules++;
|
||||
continue;
|
||||
}
|
||||
|
||||
Identifier id = rule.getIdentifierWithFallback();
|
||||
entries.add(new GameRuleEntry(id.toString(), gameRuleValue(level, rule)));
|
||||
} catch (RuntimeException e) {
|
||||
skippedRules++;
|
||||
LOGGER.warn("Unable to read gamerule '{}' for dimension '{}'; skipping it.",
|
||||
safeGameRuleId(rule), level.dimension().identifier(), e);
|
||||
}
|
||||
}
|
||||
entries.sort(Comparator.comparing(GameRuleEntry::name));
|
||||
|
||||
@@ -350,7 +365,8 @@ public final class LobbySystemsMod implements ModInitializer {
|
||||
sendCommandMessage(source, Component.literal(
|
||||
"§6§lLobby Systems Gamerules §r§7[§f" + page + "§7/§f" + totalPages + "§7]"
|
||||
+ "\n§7Dimension: §f" + level.dimension().identifier()
|
||||
+ " §8| §7Rules: §f" + entries.size()));
|
||||
+ " §8| §7Rules: §f" + entries.size()
|
||||
+ (skippedRules > 0 ? " §8| §7Skipped: §e" + skippedRules : "")));
|
||||
|
||||
for (int i = start; i < end; i++) {
|
||||
GameRuleEntry entry = entries.get(i);
|
||||
@@ -366,12 +382,19 @@ public final class LobbySystemsMod implements ModInitializer {
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private static String gameRuleValue(ServerLevel level, GameRule<?> rule) {
|
||||
Object value = level.getGameRules().get((GameRule) rule);
|
||||
private static <T> String gameRuleValue(ServerLevel level, GameRule<T> rule) {
|
||||
T value = level.getGameRules().get(rule);
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
private static String safeGameRuleId(GameRule<?> rule) {
|
||||
try {
|
||||
return rule.getIdentifierWithFallback().toString();
|
||||
} catch (RuntimeException ignored) {
|
||||
return String.valueOf(rule);
|
||||
}
|
||||
}
|
||||
|
||||
private static int showDimensionGameMode(CommandSourceStack source, String dimensionId) {
|
||||
String mode = DIMENSION_GAMEMODES.get(dimensionId);
|
||||
if (mode == null) {
|
||||
|
||||
Reference in New Issue
Block a user