Skip to content

Commit

Permalink
settings refactor
Browse files Browse the repository at this point in the history
should remove some static init oddities

and make it straightforward for other mods to add their own settings
  • Loading branch information
rfresh2 committed Sep 27, 2024
1 parent 31b5d8c commit bc7e6d4
Show file tree
Hide file tree
Showing 78 changed files with 1,769 additions and 1,954 deletions.
23 changes: 10 additions & 13 deletions common/src/main/java/xaeroplus/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import xaero.map.core.XaeroWorldMapCore;
import xaeroplus.event.ClientPlaySessionFinalizedEvent;
import xaeroplus.feature.render.DrawManager;
import xaeroplus.settings.XaeroPlusSetting;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.Settings;

import java.io.ByteArrayOutputStream;
import java.util.concurrent.ExecutorService;
Expand All @@ -26,7 +24,7 @@ public class Globals {
public static final DrawManager drawManager = new DrawManager();
// cache and only update this on new world loads
public static boolean nullOverworldDimensionFolder = false;
public static XaeroPlusSettingRegistry.DataFolderResolutionMode dataFolderResolutionMode = XaeroPlusSettingRegistry.DataFolderResolutionMode.IP;
public static Settings.DataFolderResolutionMode dataFolderResolutionMode = Settings.DataFolderResolutionMode.IP;
public static int minimapScaleMultiplier = 1;
public static int minimapSizeMultiplier = 1;
public static boolean shouldResetFBO = false;
Expand Down Expand Up @@ -60,15 +58,14 @@ public static ResourceKey<Level> getCurrentDimensionId() {
.setDaemon(true)
.build()));

public static void onAllSettingsLoaded() {
XaeroPlusSettingsReflectionHax.ALL_SETTINGS.get().forEach(XaeroPlusSetting::init);
nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue();
dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue();
minimapScaleMultiplier = (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue();
minimapSizeMultiplier = (int) XaeroPlusSettingRegistry.minimapSizeMultiplierSetting.getValue();
public static void initStickySettings() {
nullOverworldDimensionFolder = Settings.REGISTRY.nullOverworldDimensionFolder.get();
dataFolderResolutionMode = Settings.REGISTRY.dataFolderResolutionMode.get();
minimapScaleMultiplier = Settings.REGISTRY.minimapScaleMultiplierSetting.getAsInt();
minimapSizeMultiplier = Settings.REGISTRY.minimapSizeMultiplierSetting.getAsInt();
XaeroPlus.EVENT_BUS.registerConsumer((e) -> {
nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue();
dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue();
nullOverworldDimensionFolder = Settings.REGISTRY.nullOverworldDimensionFolder.get();
dataFolderResolutionMode = Settings.REGISTRY.dataFolderResolutionMode.get();
}, ClientPlaySessionFinalizedEvent.class);
}

Expand Down Expand Up @@ -99,7 +96,7 @@ public static void setNullOverworldDimFolderIfAble(final boolean b) {
}
}

public static void setDataFolderResolutionModeIfAble(XaeroPlusSettingRegistry.DataFolderResolutionMode mode) {
public static void setDataFolderResolutionModeIfAble(Settings.DataFolderResolutionMode mode) {
try {
var currentWMSession = XaeroWorldMapCore.currentSession;
var currentMMSession = HudSession.getCurrentSession();
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/xaeroplus/XaeroPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xaero.map.platform.Services;
import xaeroplus.settings.Settings;
import xaeroplus.settings.XaeroPlusSetting;

import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;

import static xaeroplus.settings.SettingHooks.loadXPSettings;

public class XaeroPlus {
public static final Logger LOGGER = LoggerFactory.getLogger("XaeroPlus");
public static final LambdaManager EVENT_BUS = LambdaManager.basic(new LambdaMetaFactoryGenerator());
public static final AtomicBoolean initialized = new AtomicBoolean(false);
public static final File configFile = Services.PLATFORM.getConfigDir().resolve("xaeroplus.txt").toFile();

public static void initializeSettings() {
loadXPSettings();
Settings.REGISTRY.getAllSettings().forEach(XaeroPlusSetting::init);
Globals.initStickySettings();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import xaero.map.gui.GuiSettings;
import xaero.map.gui.ISettingEntry;
import xaero.map.gui.ScreenSwitchSettingEntry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.SettingLocation;
import xaeroplus.settings.Settings;

public class GuiXaeroPlusChunkHighlightSettings extends GuiSettings {
public GuiXaeroPlusChunkHighlightSettings(Screen parent, Screen escapeScreen) {
super(Component.translatable("gui.xaeroplus.chunk_highlight_settings"), parent, escapeScreen);
this.entries = XaeroPlusSettingsReflectionHax.getChunkHighlightConfigSettingEntries().toArray(new ISettingEntry[0]);
this.entries = Settings.REGISTRY.getWorldmapConfigSettingEntries(SettingLocation.CHUNK_HIGHLIGHTS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
import xaero.map.gui.GuiSettings;
import xaero.map.gui.ISettingEntry;
import xaero.map.gui.ScreenSwitchSettingEntry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.SettingLocation;
import xaeroplus.settings.Settings;

public class GuiXaeroPlusWorldMapSettings extends GuiSettings {

public GuiXaeroPlusWorldMapSettings(Screen parent, Screen escapeScreen) {
super(Component.translatable("gui.xaeroplus.world_map_settings"), parent, escapeScreen);
var mainSettingsEntries = XaeroPlusSettingsReflectionHax.getWorldMapConfigSettingEntries();
var mainSettingsEntries = Settings.REGISTRY.getWorldmapConfigSettingEntries(SettingLocation.WORLD_MAP_MAIN);
var chunkHighlightSettingSwitchEntry = GuiXaeroPlusChunkHighlightSettings.getScreenSwitchSettingEntry(parent);
this.entries = new ISettingEntry[mainSettingsEntries.size() + 1];
this.entries = new ISettingEntry[mainSettingsEntries.length + 1];
this.entries[0] = chunkHighlightSettingSwitchEntry;
for (int i = 0; i < mainSettingsEntries.size(); i++) {
this.entries[i + 1] = mainSettingsEntries.get(i);
for (int i = 0; i < mainSettingsEntries.length; i++) {
this.entries[i + 1] = mainSettingsEntries[i];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import xaeroplus.XaeroPlus;
import xaeroplus.event.DimensionSwitchEvent;
import xaeroplus.event.XaeroWorldChangeEvent;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.Settings;
import xaeroplus.util.ChunkUtils;
import xaeroplus.util.ColorHelper;

Expand Down Expand Up @@ -83,7 +83,7 @@ public synchronized void drawMinimapFeatures(
-(chunkZ * 64) - (tileZ * 16) - insideZ,
0);
matrixStack.scale(16f, 16f, 1f);
if (XaeroPlusSettingRegistry.highlightShader.getValue()) {
if (Settings.REGISTRY.highlightShader.get()) {
drawMinimapFeaturesShader(matrixStack);
} else {
drawMinimapFeaturesImmediate(minViewMapTileChunkCoordX, maxViewMapTileChunkCoordX, minViewMapTileChunkCoordZ, maxViewMapTileChunkCoordZ,
Expand Down Expand Up @@ -175,7 +175,7 @@ public synchronized void drawWorldMapFeatures(
matrixStack.pushPose();
matrixStack.translate(-flooredCameraX, -flooredCameraZ, 1.0f);
matrixStack.scale(16f, 16f, 1f);
if (XaeroPlusSettingRegistry.highlightShader.getValue())
if (Settings.REGISTRY.highlightShader.get())
drawWorldMapFeaturesShader(matrixStack);
else
drawWorldMapFeaturesImmediate(minBlockX, maxBlockX, minBlockZ, maxBlockZ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import xaero.common.minimap.info.BuiltInInfoDisplays;
import xaero.common.minimap.info.render.compile.InfoDisplayCompiler;
import xaero.hud.minimap.world.MinimapWorld;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.Settings;
import xaeroplus.util.ChunkUtils;

@Mixin(value = BuiltInInfoDisplays.class, remap = false)
Expand All @@ -21,7 +21,7 @@ public class MixinBuiltInInfoDisplays {
target = "Lxaero/common/minimap/info/render/compile/InfoDisplayCompiler;addWords(ILjava/lang/String;)V"))
private static void hideAutoSubworldInfoWhenOwAutoWaypointsEnabled(final InfoDisplayCompiler instance, final int lineWidth, final String text, final Operation<Void> original,
@Local(name = "currentWorld") MinimapWorld currentWorld) {
if (XaeroPlusSettingRegistry.owAutoWaypointDimension.getValue()) {
if (Settings.REGISTRY.owAutoWaypointDimension.get()) {
ResourceKey<Level> actualDimension = ChunkUtils.getActualDimension();
if (actualDimension == Level.NETHER && currentWorld.getDimId() == Level.OVERWORLD) return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import xaero.common.events.ClientEvents;
import xaero.common.minimap.waypoints.WaypointSharingHandler;
import xaeroplus.XaeroPlus;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.Settings;

@Mixin(value = ClientEvents.class, remap = false)
public abstract class MixinClientEvents {
@Inject(method = "handleClientSystemChatReceivedEvent", at = @At("HEAD"), cancellable = true)
public void onSystemChatReceived(final Component component, final CallbackInfoReturnable<Boolean> cir) {
if (component == null) return;
if (XaeroPlusSettingRegistry.disableReceivingWaypoints.getValue()) {
if (Settings.REGISTRY.disableReceivingWaypoints.get()) {
// cancelling at head so we avoid hitting the logic to parse the waypoint string
cir.setReturnValue(false); // false will show the raw message in chat to the player
}
Expand All @@ -28,7 +28,7 @@ public void onSystemChatReceived(final Component component, final CallbackInfoRe
@Inject(method = "handleClientPlayerChatReceivedEvent", at = @At("HEAD"), cancellable = true)
public void onPlayerChatReceived(final ChatType.Bound chatType, final Component component, final GameProfile gameProfile, final CallbackInfoReturnable<Boolean> cir) {
if (component == null) return;
if (XaeroPlusSettingRegistry.disableReceivingWaypoints.getValue()) {
if (Settings.REGISTRY.disableReceivingWaypoints.get()) {
// cancelling at head so we avoid hitting the logic to parse the waypoint string
cir.setReturnValue(false); // false will show the raw message in chat to the player
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
import xaero.common.misc.KeySortableByOther;
import xaero.common.settings.ModOptions;
import xaeroplus.XaeroPlus;
import xaeroplus.settings.XaeroPlusSetting;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.Settings;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Optional;

@Mixin(value = GuiSettings.class, remap = false)
public abstract class MixinCommonGuiSettings extends ScreenBase {
Expand All @@ -50,7 +47,7 @@ protected MixinCommonGuiSettings(final IXaeroMinimap modMain, final Screen paren
public void adjustEntriesPerPage(final CallbackInfo ci) {
this.xaeroPlus$settingEntryWidth = 200; // default width
this.entriesPerPage = 12; // fills height = 240
if (XaeroPlusSettingRegistry.expandSettingEntries.getValue()) {
if (Settings.REGISTRY.expandSettingEntries.get()) {
if (this.height > 350) {
int extraRows = Math.min((height - 240) / 50, 6);
this.entriesPerPage = 12 + (2 * extraRows);
Expand All @@ -65,7 +62,7 @@ public void adjustEntriesPerPage(final CallbackInfo ci) {
value = "RETURN"
))
public void adjustForwardBackButtonPositionsForExtraRows(final CallbackInfo ci) {
if (!XaeroPlusSettingRegistry.expandSettingEntries.getValue()) return;
if (!Settings.REGISTRY.expandSettingEntries.get()) return;
int extraRows = (this.entriesPerPage - 12) / 2;
int yAdjust = (extraRows * 24);
this.nextButton.setY(this.nextButton.getY() + yAdjust);
Expand All @@ -89,11 +86,9 @@ public boolean settingListToRenderRedirect(final ArrayList instance, final Objec
option.setAccessible(true);
ModOptions modOptions = (ModOptions) option.get(settingEntry);
String settingName = modOptions.getEnumString();
Optional<XaeroPlusSetting> foundSetting = XaeroPlusSettingsReflectionHax.ALL_MINIMAP_SETTINGS.get().stream()
.filter(s -> s.getSettingName().equals(settingName))
.findFirst();
if (foundSetting.isPresent()) {
if (!foundSetting.get().isVisible()) {
var xpSetting = Settings.REGISTRY.getSettingByName(settingName);
if (xpSetting != null) {
if (!xpSetting.isVisible()) {
// skip adding setting
return false;
}
Expand Down Expand Up @@ -123,7 +118,7 @@ public boolean settingListToRenderRedirect(final ArrayList instance, final Objec
)
public AbstractWidget adjustSettingEntryWidth(final ISettingEntry instance, final int x, final int y, final int w, final boolean canEditIngameSettings, final Operation<AbstractWidget> original,
@Local(name = "i") int i) {
if (!XaeroPlusSettingRegistry.expandSettingEntries.getValue()) return original.call(instance, x, y, w, canEditIngameSettings);
if (!Settings.REGISTRY.expandSettingEntries.get()) return original.call(instance, x, y, w, canEditIngameSettings);
int xOffset = ((i % 2 == 0) ? -1 : 1) * ((xaeroPlus$settingEntryWidth - 200) / 2);
return original.call(instance, x + xOffset, y, xaeroPlus$settingEntryWidth, canEditIngameSettings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xaero.common.IXaeroMinimap;
import xaero.common.misc.Internet;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.Settings;

@Mixin(value = Internet.class, remap = false)
public class MixinCommonInternet {

@Inject(method = "checkModVersion", at = @At("HEAD"), cancellable = true, remap = false)
private static void disableInternetAccessCheck(final IXaeroMinimap modMain, final CallbackInfo ci) {
if (XaeroPlusSettingRegistry.disableXaeroInternetAccess.getValue()) ci.cancel();
if (Settings.REGISTRY.disableXaeroInternetAccess.get()) ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xaero.common.controls.ControlsHandler;
import xaeroplus.settings.XaeroPlusBooleanSetting;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.BooleanSetting;
import xaeroplus.settings.Settings;

@Mixin(value = ControlsHandler.class, remap = false)
public class MixinControlsHandler {

@Inject(method = "keyDown", at = @At("RETURN"))
public void keyDown(KeyMapping kb, boolean tickEnd, boolean isRepeat, CallbackInfo ci) {
if (!tickEnd) {
XaeroPlusBooleanSetting setting = XaeroPlusSettingsReflectionHax.keybindingMapSupplier.get().get(kb);
BooleanSetting setting = Settings.REGISTRY.getKeybindingSetting(kb);
if (setting == null) return;
setting.setValue(!setting.getValue());
setting.setValue(!setting.get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import xaero.common.gui.GuiEntityRadarSettings;
import xaero.common.gui.GuiMinimapSettings;
import xaero.common.gui.ISettingEntry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.SettingLocation;
import xaeroplus.settings.Settings;

@Mixin(value = GuiEntityRadarSettings.class, remap = false)
public abstract class MixinGuiEntityRadarSettings extends GuiMinimapSettings {
Expand All @@ -22,8 +23,7 @@ public MixinGuiEntityRadarSettings(final IXaeroMinimap modMain, final Component

@Inject(method = "<init>", at = @At("RETURN"))
public void init(final IXaeroMinimap modMain, final Screen backScreen, final Screen escScreen, final CallbackInfo ci) {
final ConfigSettingEntry[] configSettingEntries = XaeroPlusSettingsReflectionHax.getMinimapEntityRadarSettingEntries()
.toArray(new ConfigSettingEntry[0]);
final ConfigSettingEntry[] configSettingEntries = Settings.REGISTRY.getMinimapConfigSettingEntries(SettingLocation.MINIMAP_ENTITY_RADAR);
final int oldLen = this.entries.length;
final int newLen = configSettingEntries.length;
final int totalNewLen = oldLen + configSettingEntries.length;
Expand Down
Loading

0 comments on commit bc7e6d4

Please sign in to comment.