Skip to content

Commit

Permalink
Merge the 2 reset cache methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Jul 26, 2024
1 parent 52605da commit ecff458
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ClientNeoForgeMod(IEventBus modEventBus, ModContainer container) {
NeoForge.EVENT_BUS.addListener((final ClientPlayerNetworkEvent.LoggingOut event) -> {
ModConfigs.getFileMap().values().forEach(config -> {
if (config.getSpec() instanceof ModConfigSpec spec) {
spec.resetWorldCaches();
spec.resetCaches(ModConfigSpec.RestartType.WORLD);
}
});
});
Expand Down
22 changes: 7 additions & 15 deletions src/main/java/net/neoforged/neoforge/common/ModConfigSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,6 @@ public UnmodifiableConfig getValues() {
return this.values;
}

public void afterReload() {
this.resetCaches(getValues().valueMap().values());
}

private void resetCaches(final Iterable<Object> configValues) {
forEachValue(configValues, configValue -> {
// Only clear the caches of configs that don't need a restart
if (configValue.getSpec().restartType == RestartType.NONE) {
configValue.clearCache();
}
});
}

private void forEachValue(Iterable<Object> configValues, Consumer<ConfigValue<?>> consumer) {
configValues.forEach(value -> {
if (value instanceof ConfigValue<?> configValue) {
Expand All @@ -170,10 +157,15 @@ private void forEachValue(Iterable<Object> configValues, Consumer<ConfigValue<?>
});
}

public void afterReload() {
// Only clear the caches of configs that don't need a restart
this.resetCaches(RestartType.NONE);
}

@ApiStatus.Internal
public void resetWorldCaches() {
public void resetCaches(RestartType restartType) {
forEachValue(getValues().valueMap().values(), configValue -> {
if (configValue.getSpec().restartType == RestartType.WORLD) {
if (configValue.getSpec().restartType == restartType) {
configValue.clearCache();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public void serverStopping(ServerStoppingEvent evt) {
// Reset WORLD type config caches
ModConfigs.getFileMap().values().forEach(config -> {
if (config.getSpec() instanceof ModConfigSpec spec) {
spec.resetWorldCaches();
spec.resetCaches(ModConfigSpec.RestartType.WORLD);
}
});
}
Expand Down

0 comments on commit ecff458

Please sign in to comment.