From 1de357e0f7e0cda53eb73b9e2c852b5d397723b6 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:07:31 +0200 Subject: [PATCH 01/14] initial --- .../org/vivecraft/client/ClientConfig.java | 472 ++++++++++++++++++ .../gui/settings/GuiClientSettings.java | 33 ++ .../gui/settings/GuiListValueEditScreen.java | 2 +- .../gui/settings/GuiServerSettings.java | 4 +- .../gui/settings/VivecraftMainSettings.java | 4 + .../client/gui/widgets/SettingsList.java | 2 +- .../config => common}/ConfigBuilder.java | 51 +- .../ServerGamePacketListenerImplMixin.java | 2 +- .../mixin/server/ServerPlayerMixin.java | 2 +- .../world/entity/ai/goal/SwellGoalMixin.java | 2 +- .../entity/projectile/AbstractArrowMixin.java | 2 +- .../org/vivecraft/server/AimFixHandler.java | 1 - .../server/{config => }/ServerConfig.java | 3 +- .../vivecraft/server/ServerNetworking.java | 1 - .../java/org/vivecraft/server/ServerUtil.java | 3 +- fabric/build.gradle | 4 +- .../org/vivecraft/fabric/VivecraftMod.java | 4 +- forge/build.gradle | 2 +- .../java/org/vivecraft/forge/Vivecraft.java | 4 +- 19 files changed, 578 insertions(+), 20 deletions(-) create mode 100644 common/src/main/java/org/vivecraft/client/ClientConfig.java create mode 100644 common/src/main/java/org/vivecraft/client/gui/settings/GuiClientSettings.java rename common/src/main/java/org/vivecraft/{server/config => common}/ConfigBuilder.java (87%) rename common/src/main/java/org/vivecraft/server/{config => }/ServerConfig.java (99%) diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java new file mode 100644 index 000000000..ad6e319aa --- /dev/null +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -0,0 +1,472 @@ +package org.vivecraft.client; + +import com.electronwill.nightconfig.core.CommentedConfig; +import com.electronwill.nightconfig.core.Config; +import com.electronwill.nightconfig.core.ConfigSpec; +import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import org.vivecraft.client_vr.gui.PhysicalKeyboard; +import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.ConfigBuilder; + +import java.util.List; + +public class ClientConfig { + + //Keyboard + public static ConfigBuilder.BooleanValue physicalKeyboard; + public static ConfigBuilder.BooleanValue autoOpenKeyboard; + public static ConfigBuilder.BooleanValue alwaysSimulateKeyboard; + public static ConfigBuilder.StringValue keyboardKeys; + public static ConfigBuilder.StringValue keyboardKeysShift; + public static ConfigBuilder.DoubleValue physicalKeyboardScale; + public static ConfigBuilder.EnumValue physicalKeyboardTheme; + + //MR + public static ConfigBuilder.DoubleValue mrMovingCamOffsetZ; + public static ConfigBuilder.DoubleValue mrMovingCamOffsetY; + public static ConfigBuilder.DoubleValue mrMovingCamOffsetX; + public static ConfigBuilder.StringValue mixedRealityKeyColor; + public static ConfigBuilder.BooleanValue mixedRealityAlphaMask; + public static ConfigBuilder.DoubleValue mixedRealityFov; + public static ConfigBuilder.DoubleValue mrMovingCamOffsetRotW; + public static ConfigBuilder.DoubleValue mrMovingCamOffsetRotZ; + public static ConfigBuilder.DoubleValue mrMovingCamOffsetRotY; + public static ConfigBuilder.DoubleValue mrMovingCamOffsetRotX; + public static ConfigBuilder.BooleanValue mixedRealityRenderCameraModel; + public static ConfigBuilder.BooleanValue mixedRealityUndistorted; + public static ConfigBuilder.BooleanValue mixedRealityUnityLike; + public static ConfigBuilder.BooleanValue mixedRealityRenderHands; + + //Roomscale + public static ConfigBuilder.BooleanValue realisticSneakEnabled; + public static ConfigBuilder.DoubleValue sneakThreshold; + public static ConfigBuilder.BooleanValue realisticJumpEnabled; + public static ConfigBuilder.DoubleValue jumpThreshold; + public static ConfigBuilder.BooleanValue autoSprint; + public static ConfigBuilder.DoubleValue autoSprintThreshold; + public static ConfigBuilder.BooleanValue allowCrawling; + public static ConfigBuilder.DoubleValue crawlThreshold; + public static ConfigBuilder.BooleanValue realisticClimbEnabled; + public static ConfigBuilder.BooleanValue realisticRowEnabled; + public static ConfigBuilder.BooleanValue realisticSwimEnabled; + public static ConfigBuilder.DoubleValue movementSpeedMultiplier; + public static ConfigBuilder.DoubleValue walkMultiplier; + public static ConfigBuilder.EnumValue weaponCollision; + public static ConfigBuilder.EnumValue bowMode; + public static ConfigBuilder.BooleanValue walkUpBlocks; + public static ConfigBuilder.BooleanValue backpackSwitching; + public static ConfigBuilder.BooleanValue vrTouchHotbar; + public static ConfigBuilder.BooleanValue guiAppearOverBlock; + public static ConfigBuilder.BooleanValue physicalGuiEnabled; + public static ConfigBuilder.EnumValue inertiaFactor; + public static ConfigBuilder.BooleanValue vehicleRotation; + + //Display + public static ConfigBuilder.EnumValue displayMirrorMode; + public static ConfigBuilder.BooleanValue useCrosshairOcclusion; + public static ConfigBuilder.DoubleValue menuCrosshairScale; + public static ConfigBuilder.BooleanValue crosshairScalesWithDistance; + public static ConfigBuilder.BooleanValue menuBackground; + public static ConfigBuilder.BooleanValue menuAlwaysFollowFace; + public static ConfigBuilder.EnumValue renderInGameCrosshairMode; + public static ConfigBuilder.EnumValue shaderGUIRender; + public static ConfigBuilder.BooleanValue hideGUI; + public static ConfigBuilder.DoubleValue crosshairScale; + + + //HUD + public static ConfigBuilder.BooleanValue lowHealthIndicator; + public static ConfigBuilder.DoubleValue hudDistance; + public static ConfigBuilder.DoubleValue hudPitchOffset; + public static ConfigBuilder.DoubleValue hudYawOffset; + public static ConfigBuilder.BooleanValue stencilOn; + public static ConfigBuilder.DoubleValue headHudScale; + public static ConfigBuilder.DoubleValue headToHmdLength; + public static ConfigBuilder.BooleanValue hudOcclusion; + public static ConfigBuilder.DoubleValue hudOpacity; + public static ConfigBuilder.EnumValue vrHudLockMode; + + //Camera + public static ConfigBuilder.DoubleValue handCameraResScale; + public static ConfigBuilder.IntValue handCameraFov; + + //Update + public static ConfigBuilder.BooleanValue firstRun; + public static ConfigBuilder.StringValue lastUpdate; + public static ConfigBuilder.BooleanValue alwaysShowUpdates; + public static ConfigBuilder.EnumValue chatNotifications; + public static ConfigBuilder.BooleanValue showServerPluginMessage; + public static ConfigBuilder.StringValue chatNotificationSound; + + //Teleport + public static ConfigBuilder.BooleanValue limitedTeleport; + public static ConfigBuilder.IntValue teleportLimitDown; + public static ConfigBuilder.IntValue teleportLimitHoriz; + public static ConfigBuilder.IntValue teleportLimitUp; + + //Seated + public static ConfigBuilder.BooleanValue seated; + public static ConfigBuilder.BooleanValue seatedhmd; + public static ConfigBuilder.BooleanValue seatedHudAltMode; + public static ConfigBuilder.BooleanValue seatedFreeMove; + public static ConfigBuilder.EnumValue vrFreeMoveFlyMode; //TODO check + public static ConfigBuilder.EnumValue vrFreeMoveMode; + + + //General + public static ConfigBuilder.BooleanValue vrHotswitchingEnabled; + public static ConfigBuilder.BooleanValue vrEnabled; + public static ConfigBuilder.IntValue worldRotation; + public static ConfigBuilder.DoubleValue vrWorldRotationIncrement; + public static ConfigBuilder.IntValue worldScale; + public static ConfigBuilder.IntValue version; + public static ConfigBuilder.BooleanValue reverseHands; + public static ConfigBuilder.BooleanValue allowStandingOriginOffset; + public static ConfigBuilder.BooleanValue forceHardwareDetection; + public static ConfigBuilder.StringValue badStereoProviderPluginID; + public static ConfigBuilder.BooleanValue analogMovement; + public static ConfigBuilder.DoubleValue autoCalibration; + public static ConfigBuilder.StringValue stereoProviderPluginID; + public static ConfigBuilder.DoubleValue manualCalibration; + public static ConfigBuilder.EnumValue rightclickDelay; + public static ConfigBuilder.BooleanValue thirdPersonItems; + public static ConfigBuilder.BooleanValue forceStandingFreeMove; + public static ConfigBuilder.BooleanValue allowAdvancedBindings; + public static ConfigBuilder.DoubleValue xSensitivity; + public static ConfigBuilder.DoubleValue ySensitivity; + public static ConfigBuilder.BooleanValue useFsaa; + public static ConfigBuilder.BooleanValue displayMirrorLeftEye; + public static ConfigBuilder.BooleanValue disableFun; + public static ConfigBuilder.EnumValue menuWorldSelection; + public static ConfigBuilder.DoubleValue renderScaleFactor; + public static ConfigBuilder.BooleanValue insideBlockSolidColor; + public static ConfigBuilder.EnumValue renderBlockOutlineMode; + + + + //Radial + public static ConfigBuilder.BooleanValue radialModeHold; + public static ConfigBuilder.StringValue RADIAL_1; + public static ConfigBuilder.StringValue RADIAL_2; + public static ConfigBuilder.StringValue RADIAL_3; + public static ConfigBuilder.StringValue RADIAL_4; + public static ConfigBuilder.StringValue RADIAL_5; + public static ConfigBuilder.StringValue RADIAL_6; + public static ConfigBuilder.StringValue RADIAL_7; + public static ConfigBuilder.StringValue RADIAL_8; + public static ConfigBuilder.StringValue RADIAL_9; + + //QuickCommand + public static ConfigBuilder.StringValue QUICKCOMMAND_0; + public static ConfigBuilder.StringValue QUICKCOMMAND_1; + public static ConfigBuilder.StringValue QUICKCOMMAND_2; + public static ConfigBuilder.StringValue QUICKCOMMAND_3; + public static ConfigBuilder.StringValue QUICKCOMMAND_4; + public static ConfigBuilder.StringValue QUICKCOMMAND_5; + public static ConfigBuilder.StringValue QUICKCOMMAND_6; + public static ConfigBuilder.StringValue QUICKCOMMAND_7; + public static ConfigBuilder.StringValue QUICKCOMMAND_8; + public static ConfigBuilder.StringValue QUICKCOMMAND_9; + + //Misc + public static ConfigBuilder.BooleanValue smoothTick; + public static ConfigBuilder.DoubleValue vrFixedCamrotW; + public static ConfigBuilder.DoubleValue vrFixedCamrotZ; + public static ConfigBuilder.DoubleValue vrFixedCamrotY; + public static ConfigBuilder.DoubleValue vrFixedCamrotX; + //"originOffset": "0.0,0.0,0.0", + public static ConfigBuilder.DoubleValue monoFOV; + public static ConfigBuilder.BooleanValue bcbOn; + public static ConfigBuilder.IntValue hrtfSelection; + public static ConfigBuilder.DoubleValue smoothRunTickCount; + public static ConfigBuilder.DoubleValue fovReductionMin; + public static ConfigBuilder.StringValue externalCameraAngleOrder; + public static ConfigBuilder.DoubleValue keyholeX; + public static ConfigBuilder.BooleanValue vrFixedCamposZ; + public static ConfigBuilder.DoubleValue vrFixedCamposX; + public static ConfigBuilder.BooleanValue vrFixedCamposY; + public static ConfigBuilder.DoubleValue fovRedutioncOffset; + public static ConfigBuilder.BooleanValue fovReduction; + + private static CommentedFileConfig config; + private static ConfigBuilder builder; + + public static List getConfigValues(){ + return builder.getConfigValues(); + } + + public static void init(ConfigSpec.CorrectionListener listener){ + Config.setInsertionOrderPreserved(true); + config = CommentedFileConfig + .builder(Xplat.getConfigPath("vivecraft-client-config.toml")) + .autosave() + .concurrent() + .build(); + + config.load(); + + if (listener == null) { + listener = (action, path, incorrectValue, correctedValue) -> { + if (incorrectValue != null) { + System.out.println("Corrected " + String.join(".", path) + ": was " + incorrectValue + ", is now " + correctedValue); + } + }; + } + + fixConfig(config, listener); + + config.save(); + } + + private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListener listener) { + + builder = new ConfigBuilder(config, new ConfigSpec()); + + builder + .push("Keyboard"); + physicalKeyboard = builder + .push("Physical") + .comment("Enables the Physical Keyboard") + .define(true); + autoOpenKeyboard = builder + .push("Open") + .comment("Automatically open the keyboard") + .define(false); + alwaysSimulateKeyboard = builder + .push("Simulate") + .comment("Always simulate the Keyboard") + .define(false); + keyboardKeys = builder + .push("Keys") + .comment("Keyboard key Layout") + .define("`1234567890-=qwertyuiop[]\\asdfghjkl;':\"zxcvbnm,./?<>"); + keyboardKeysShift = builder + .push("ShiftKeys") + .comment("Keyboard key Layout for shift") + .define("~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL;':\\\"ZXCVBNM,./?<>"); + physicalKeyboardScale = builder + .push("scale") + .comment("The scale for the Physical Keyboard") + .defineInRange(1.0d, 0.75d, 1.5d); + physicalKeyboardTheme = builder + .push("Theme") + .comment("Keyboard theme used for the Physical Keyboard") + .define(PhysicalKeyboard.KeyboardTheme.DEFAULT); + builder.pop(); + + builder + .push("roomscale"); + realisticSneakEnabled = builder + .push("sneak") + .comment("Enable room scale sneaking") + .define(true); + sneakThreshold = builder + .push("sneakthreshold") + .comment("Threshold for when the player starts sneaking") + .defineInRange(0.4, 0, 2); //2 should be enough range + allowCrawling = builder + .push("crawl") + .comment("Enable room scale crawling") + .define(true); + crawlThreshold = builder + .push("crawlthreshold") + .comment("Threshold for when the player starts crawling") + .defineInRange(0.82, 0, 2); //2 should be enough range + weaponCollision = builder + .push("weaponcollision") + .comment("Weapon Collision mode used") + .define(VRSettings.WeaponCollision.AUTO); + bowMode = builder + .push("bow") + .comment("Bow mode") + .define(VRSettings.BowMode.ON); + vrTouchHotbar = builder + .push("hotbar") + .comment("Allow selecting items from by touching the hotbar") + .define(true); + physicalGuiEnabled = builder + .push("gui") + .comment("Allow interactions by touching the gui") + .define(true); + realisticJumpEnabled = builder + .push("jump") + .comment("Enable room scale jumping") + .define(true); + jumpThreshold = builder + .push("jumpthreshhold") + .comment("Threshhold for automatically jumping") + .defineInRange(0.05d, 0d, 2d); //2 should be enough + realisticRowEnabled = builder + .push("row") + .comment("Enable room scale rowing") + .define(true); + realisticClimbEnabled = builder + .push("climbing") + .comment("Enable room scale climbing") + .define(true); + realisticSwimEnabled = builder + .push("swimming") + .comment("Enable room scale swimming") + .define(true); + autoSprint = builder + .push("sprint") + .comment("Automatically sprint") + .define(true); + autoSprintThreshold = builder + .push("sprintthreshhold") + .comment("Threshhold for automatically sprinting") + .defineInRange(0.9d, 0.5d, 1d); + insideBlockSolidColor = builder + .push("insideblock") + .comment("If the the inside of a block should be solid black") + .define(false); + guiAppearOverBlock = builder + .push("guiblock") + .comment("Places the gui over the accessed block") + .define(true); + movementSpeedMultiplier = builder + .push("movementspeed") + .comment("Movement Speed modifier") + .defineInRange(1.0d, 0.15d, 1.3d); + walkMultiplier = builder + .push("walkspeed") + .comment("Walk Speed modifier") + .defineInRange(1.0d, 1d, 10d); + menuAlwaysFollowFace = builder + .push("followface") + .comment("Makes the menu follow the players head") + .define(false); + vrHudLockMode = builder + .push("hudlock") + .comment("Determines where the hotbar is locked") + .define(VRSettings.HUDLock.HEAD); + backpackSwitching = builder + .push("backpack") + .comment("Enables backpack switching") + .define(true); + walkUpBlocks = builder + .push("walkup") + .comment("Enable auto step up") + .define(true); + builder.pop(); + + builder + .push("seated"); + seated = builder + .push("enable") + .comment("Enables seated mode") + .define(false); + seatedhmd = builder + .push("hmd") + .comment("") + .define(false); + seatedFreeMove = builder + .push("freemove") + .comment("Allow free move while playing as seated") + .define(true); + seatedHudAltMode = builder + .push("altmode") + .comment("Enables the alternative HUD position when playing as seated") + .define(false); + builder.pop(); + + builder + .push("display"); + useCrosshairOcclusion = builder + .push("crosshairocclusion") + .comment("Occludes the crosshair") + .define(true); + displayMirrorMode = builder + .push("mirror") + .comment("Mirror mode") + .define(VRSettings.MirrorMode.SINGLE); + lowHealthIndicator = builder + .push("health") + .comment("Enables the flashing of red on screen when on low health") + .define(true); + hudDistance = builder + .push("hud") + .comment("The distance between the player and the HUD") + .defineInRange(1.25d, 0.25d, 5.0d); + hudPitchOffset = builder + .push("hudpitch") + .comment("The pitch offset of the hud") + .defineInRange(-2.0d, -5d,5d); //TODO what limit is fine here? int.max seems to much? + hudYawOffset = builder + .push("hudyaw") + .comment("The yaw offset of the hud") + .defineInRange(0.0d, -5d,5d); //TODO what limit is fine here? int.max seems to much? + headHudScale = builder + .push("hudscale") + .comment("The scale of the hud") + .defineInRange(1.0d, 0.35d, 2.5d); + hudOpacity = builder + .push("hudopacity") + .comment("The opacity of the hud") + .defineInRange(1.0d, 0.15d, 1.0d); + stencilOn = builder + .push("stencil") + .comment("Enables the eye stencil") + .define(true); + headToHmdLength = builder + .push("hmdhead") + .comment("The distance between the head and the hmd") + .defineInRange(0.10d, 0d, 1.0d); + useFsaa = builder + .push("fsaa") + .comment("Enable FSAA") + .define(false); + renderScaleFactor = builder + .push("scale") + .comment("The scale used to render") + .defineInRange(1.0d, 0.1d, 9d); + shaderGUIRender = builder + .push("shaders") + .comment("Changes how shaders are applied on GUI's") + .define(VRSettings.ShaderGUIRender.AFTER_SHADER); + displayMirrorLeftEye = builder + .push("lefteye") + .comment("Use the left eye instead of the right eye for the mirror") + .define(false); + hideGUI = builder //TODO remove as it is a dummy storage field + .push("hide") + .comment("Hides the gui") + .define(false); + builder.pop(); + + builder + .push("test"); + vrHotswitchingEnabled = builder + .push("hotswitch") + .comment("") + .define(true); + + worldScale = builder + .push("worldscale") + .comment("") + .defineInRange(1,0, 29); + + worldRotation = builder + .push("worldrotation") + .comment("") + .defineInRange(0,0, 360); + builder.pop(); + + builder + .push("camera"); + + handCameraResScale = builder + .push("resolution") + .comment("") + .defineInRange(1.0d, 0.5d, 3.0d); + + handCameraFov = builder + .push("fov") + .comment("") + .defineInRange(70, 1, 179); + builder.pop(); + + builder.correct(listener); + + } +} diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiClientSettings.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiClientSettings.java new file mode 100644 index 000000000..e153e971b --- /dev/null +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiClientSettings.java @@ -0,0 +1,33 @@ +package org.vivecraft.client.gui.settings; + +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import org.vivecraft.client.ClientConfig; +import org.vivecraft.client.gui.widgets.SettingsList; +import org.vivecraft.common.ConfigBuilder; + +import java.util.LinkedList; +import java.util.List; + +public class GuiClientSettings extends GuiListScreen { + public GuiClientSettings(Screen lastScreen) { + super(Component.translatable("vivecraft.options.screen.client"), lastScreen); + } + + @Override + protected List getEntries() { + List entries = new LinkedList<>(); + String lastCategory = null; + for (ConfigBuilder.ConfigValue cv : ClientConfig.getConfigValues()) { + String path = cv.getPath(); + String category = path.substring(0, path.lastIndexOf(".")); + String name = path.substring(path.lastIndexOf(".") + 1); + if (!category.equals(lastCategory)) { + lastCategory = category; + entries.add(new SettingsList.CategoryEntry(Component.literal(category))); + } + entries.add(SettingsList.ConfigToEntry(cv, Component.literal(name))); + } + return entries; + } +} diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiListValueEditScreen.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiListValueEditScreen.java index a1acf982a..d65145797 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiListValueEditScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiListValueEditScreen.java @@ -12,7 +12,7 @@ import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import org.vivecraft.client.gui.widgets.SettingsList; -import org.vivecraft.server.config.ConfigBuilder; +import org.vivecraft.common.ConfigBuilder; import java.util.ArrayList; import java.util.LinkedList; diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiServerSettings.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiServerSettings.java index 209a37852..f3a73ebdb 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiServerSettings.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiServerSettings.java @@ -3,8 +3,8 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import org.vivecraft.client.gui.widgets.SettingsList; -import org.vivecraft.server.config.ConfigBuilder; -import org.vivecraft.server.config.ServerConfig; +import org.vivecraft.common.ConfigBuilder; +import org.vivecraft.server.ServerConfig; import java.util.LinkedList; import java.util.List; diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java b/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java index 4cd6a1627..26f32fec7 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java @@ -27,6 +27,10 @@ protected List getEntries() { Component.translatable("vivecraft.options.screen.server"), Button.builder(Component.translatable("vivecraft.options.screen.server"), button -> this.minecraft.setScreen(new GuiServerSettings(this))).size(SettingsList.WidgetEntry.valueButtonWidth, 20).build())); + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.client"), + Button.builder(Component.translatable("vivecraft.options.screen.client"), button -> this.minecraft.setScreen(new GuiClientSettings(this))).size(SettingsList.WidgetEntry.valueButtonWidth, 20).build())); + entries.add(new SettingsList.CategoryEntry(Component.literal("Vivecraft Buttons"))); entries.add(new SettingsList.WidgetEntry( diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/SettingsList.java b/common/src/main/java/org/vivecraft/client/gui/widgets/SettingsList.java index f2e303a81..67c3d3d42 100644 --- a/common/src/main/java/org/vivecraft/client/gui/widgets/SettingsList.java +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/SettingsList.java @@ -17,7 +17,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; -import org.vivecraft.server.config.ConfigBuilder; +import org.vivecraft.common.ConfigBuilder; public class SettingsList extends ContainerObjectSelectionList { final Screen parent; diff --git a/common/src/main/java/org/vivecraft/server/config/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java similarity index 87% rename from common/src/main/java/org/vivecraft/server/config/ConfigBuilder.java rename to common/src/main/java/org/vivecraft/common/ConfigBuilder.java index b6d9e6623..054087853 100644 --- a/common/src/main/java/org/vivecraft/server/config/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -1,7 +1,8 @@ -package org.vivecraft.server.config; +package org.vivecraft.common; import com.electronwill.nightconfig.core.CommentedConfig; import com.electronwill.nightconfig.core.ConfigSpec; +import com.electronwill.nightconfig.core.EnumGetMethod; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.*; import net.minecraft.network.chat.Component; @@ -65,6 +66,13 @@ private void addDefaultValueComment(List path, double defaultValue, doub + new Formatter(Locale.US).format("default: %.2f, min: %.2f, max: %.2f", defaultValue, min, max)); } + private > void addDefaultValueComment(List path, T defaultValue) { + String oldComment = config.getComment(path); + config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") + + new Formatter(Locale.US).format("default: %.2s", defaultValue.name())); + } + + /** * corrects the attached config, with the built spec * @param listener listener to send correction to @@ -168,6 +176,17 @@ public StringValue define(String defaultValue) { return value; } + public > EnumValue define(T defaultValue) { + List path = stack.stream().toList(); + spec.defineEnum(path, defaultValue, EnumGetMethod.NAME); + stack.removeLast(); + addDefaultValueComment(path, defaultValue); + + EnumValue value = new EnumValue<>(config, path, defaultValue); + configValues.add(value); + return value; + } + /** * same as {@link #defineInRange defineInRange(T defaultValue, T min, T max)} but returns a {@link DoubleValue} */ @@ -202,7 +221,7 @@ public static class ConfigValue { // the config, this setting is part of private final CommentedConfig config; private final List path; - private final T defaultValue; + protected final T defaultValue; // cache te value to minimize config lookups private T cachedValue = null; @@ -403,4 +422,32 @@ public void fromNormalized(double value) { this.set(Math.round(newValue * 100.0) / 100.0); } } + + public static class EnumValue> extends ConfigValue { + + public EnumValue(CommentedConfig config, List path, T defaultValue) { + super(config, path, defaultValue); + } + + public void cycle() { + T[] enumConstants = defaultValue.getDeclaringClass().getEnumConstants(); + int newIndex = this.get().ordinal() + 1; + if (enumConstants.length == newIndex) { + newIndex = 0; + } + this.set(enumConstants[newIndex]); + } + + @Override + public AbstractWidget getWidget(int width, int height) { + return CycleButton + .builder((newValue) -> Component.literal("" + newValue)) + .withInitialValue(get()) + // toArray is needed here, because the button uses Objects, and the collection is of other types + .withValues(defaultValue.getDeclaringClass().getEnumConstants()) + .displayOnlyValue() + .withTooltip((bool) -> getComment() != null ? Tooltip.create(Component.literal(getComment())) : null) + .create(0, 0, width, height, Component.empty(), (button, newValue) -> set((T) newValue)); + } + } } diff --git a/common/src/main/java/org/vivecraft/mixin/server/ServerGamePacketListenerImplMixin.java b/common/src/main/java/org/vivecraft/mixin/server/ServerGamePacketListenerImplMixin.java index b48ce1858..f0189dd88 100644 --- a/common/src/main/java/org/vivecraft/mixin/server/ServerGamePacketListenerImplMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/server/ServerGamePacketListenerImplMixin.java @@ -19,7 +19,7 @@ import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.server.network.ServerPlayerConnection; import org.vivecraft.server.ServerVRPlayers; -import org.vivecraft.server.config.ServerConfig; +import org.vivecraft.server.ServerConfig; import org.vivecraft.server.ServerNetworking; import static org.vivecraft.common.network.CommonNetworkHelper.PacketDiscriminators.CLIMBING; diff --git a/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java b/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java index dfad0c50e..2ff28370f 100644 --- a/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import org.vivecraft.server.config.ServerConfig; +import org.vivecraft.server.ServerConfig; import org.vivecraft.server.ServerVRPlayers; import org.vivecraft.server.ServerVivePlayer; diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/ai/goal/SwellGoalMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/ai/goal/SwellGoalMixin.java index 1f4d14ba3..d34099e49 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/entity/ai/goal/SwellGoalMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/ai/goal/SwellGoalMixin.java @@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.vivecraft.server.config.ServerConfig; +import org.vivecraft.server.ServerConfig; import org.vivecraft.server.ServerVRPlayers; import org.vivecraft.server.ServerVivePlayer; diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractArrowMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractArrowMixin.java index dca7c218f..380a6110b 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractArrowMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractArrowMixin.java @@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.vivecraft.common.utils.Utils; -import org.vivecraft.server.config.ServerConfig; +import org.vivecraft.server.ServerConfig; import org.vivecraft.server.ServerVRPlayers; import org.vivecraft.server.ServerVivePlayer; diff --git a/common/src/main/java/org/vivecraft/server/AimFixHandler.java b/common/src/main/java/org/vivecraft/server/AimFixHandler.java index 1dae32793..8094c96ae 100644 --- a/common/src/main/java/org/vivecraft/server/AimFixHandler.java +++ b/common/src/main/java/org/vivecraft/server/AimFixHandler.java @@ -12,7 +12,6 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.world.phys.Vec3; -import org.vivecraft.server.config.ServerConfig; public class AimFixHandler extends ChannelInboundHandlerAdapter { diff --git a/common/src/main/java/org/vivecraft/server/config/ServerConfig.java b/common/src/main/java/org/vivecraft/server/ServerConfig.java similarity index 99% rename from common/src/main/java/org/vivecraft/server/config/ServerConfig.java rename to common/src/main/java/org/vivecraft/server/ServerConfig.java index 1e6f9d8d1..ded45f743 100644 --- a/common/src/main/java/org/vivecraft/server/config/ServerConfig.java +++ b/common/src/main/java/org/vivecraft/server/ServerConfig.java @@ -1,4 +1,4 @@ -package org.vivecraft.server.config; +package org.vivecraft.server; import com.electronwill.nightconfig.core.CommentedConfig; import com.electronwill.nightconfig.core.Config; @@ -7,6 +7,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import org.vivecraft.client.Xplat; +import org.vivecraft.common.ConfigBuilder; import java.util.*; diff --git a/common/src/main/java/org/vivecraft/server/ServerNetworking.java b/common/src/main/java/org/vivecraft/server/ServerNetworking.java index b14b43aa5..bbb869735 100644 --- a/common/src/main/java/org/vivecraft/server/ServerNetworking.java +++ b/common/src/main/java/org/vivecraft/server/ServerNetworking.java @@ -17,7 +17,6 @@ import org.vivecraft.common.network.VrPlayerState; import org.vivecraft.common.CommonDataHolder; import org.vivecraft.mixin.server.ChunkMapAccessor; -import org.vivecraft.server.config.ServerConfig; import java.util.*; diff --git a/common/src/main/java/org/vivecraft/server/ServerUtil.java b/common/src/main/java/org/vivecraft/server/ServerUtil.java index c011bdfed..67281b639 100644 --- a/common/src/main/java/org/vivecraft/server/ServerUtil.java +++ b/common/src/main/java/org/vivecraft/server/ServerUtil.java @@ -7,8 +7,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import org.vivecraft.client.utils.UpdateChecker; -import org.vivecraft.server.config.ConfigBuilder; -import org.vivecraft.server.config.ServerConfig; +import org.vivecraft.common.ConfigBuilder; import java.util.List; import java.util.concurrent.Executors; diff --git a/fabric/build.gradle b/fabric/build.gradle index 1b8ae74df..50bef8374 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -48,8 +48,8 @@ dependencies { modCompileOnly "maven.modrinth:indium:1.0.21+mc1.20.1" //mod menu - modApi("com.terraformersmc:modmenu:6.3.1") - modRuntimeOnly("com.terraformersmc:modmenu:6.3.1") + modApi("com.terraformersmc:modmenu:7.2.2") + modRuntimeOnly("com.terraformersmc:modmenu:7.2.2") /* // for immersive portals compat diff --git a/fabric/src/main/java/org/vivecraft/fabric/VivecraftMod.java b/fabric/src/main/java/org/vivecraft/fabric/VivecraftMod.java index 2a50bfb85..d2e1e9083 100644 --- a/fabric/src/main/java/org/vivecraft/fabric/VivecraftMod.java +++ b/fabric/src/main/java/org/vivecraft/fabric/VivecraftMod.java @@ -2,7 +2,8 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import org.vivecraft.server.config.ServerConfig; +import org.vivecraft.client.ClientConfig; +import org.vivecraft.server.ServerConfig; import org.vivecraft.server.ServerUtil; public class VivecraftMod implements ModInitializer { @@ -10,6 +11,7 @@ public class VivecraftMod implements ModInitializer { public void onInitialize() { // init server config ServerConfig.init(null); + ClientConfig.init(null); // add server config commands CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> diff --git a/forge/build.gradle b/forge/build.gradle index bbb03a162..3fae20c7c 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -46,7 +46,7 @@ dependencies { common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } - modRuntimeOnly("maven.modrinth:rubidium:0.6.5") + modRuntimeOnly("maven.modrinth:rubidium:0.6.4") modRuntimeOnly("maven.modrinth:oculus:1.20-1.6.4") forgeRuntimeLibrary("org.lwjgl:lwjgl-openvr:3.3.1") diff --git a/forge/src/main/java/org/vivecraft/forge/Vivecraft.java b/forge/src/main/java/org/vivecraft/forge/Vivecraft.java index 559617feb..eea2dcadb 100644 --- a/forge/src/main/java/org/vivecraft/forge/Vivecraft.java +++ b/forge/src/main/java/org/vivecraft/forge/Vivecraft.java @@ -3,8 +3,9 @@ import net.minecraftforge.client.ConfigScreenHandler; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; +import org.vivecraft.client.ClientConfig; import org.vivecraft.client.gui.settings.VivecraftMainSettings; -import org.vivecraft.server.config.ServerConfig; +import org.vivecraft.server.ServerConfig; @Mod(Vivecraft.MODID) public class Vivecraft { @@ -13,6 +14,7 @@ public class Vivecraft { public Vivecraft() { // init server config ServerConfig.init(null); + ClientConfig.init(null); ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> new VivecraftMainSettings(screen))); } From 4129558e1a7279227dbfa6b6288cd2573f7cf0dd Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:46:48 +0200 Subject: [PATCH 02/14] Update ClientConfig.java --- .../org/vivecraft/client/ClientConfig.java | 167 +++++++++++------- 1 file changed, 103 insertions(+), 64 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index ad6e319aa..b17fe9418 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -58,7 +58,7 @@ public class ClientConfig { public static ConfigBuilder.BooleanValue vrTouchHotbar; public static ConfigBuilder.BooleanValue guiAppearOverBlock; public static ConfigBuilder.BooleanValue physicalGuiEnabled; - public static ConfigBuilder.EnumValue inertiaFactor; + public static ConfigBuilder.EnumValue inertiaFactor; //TODO just use a number? public static ConfigBuilder.BooleanValue vehicleRotation; //Display @@ -72,6 +72,7 @@ public class ClientConfig { public static ConfigBuilder.EnumValue shaderGUIRender; public static ConfigBuilder.BooleanValue hideGUI; public static ConfigBuilder.DoubleValue crosshairScale; + public static ConfigBuilder.DoubleValue renderScaleFactor; //HUD @@ -138,12 +139,10 @@ public class ClientConfig { public static ConfigBuilder.BooleanValue displayMirrorLeftEye; public static ConfigBuilder.BooleanValue disableFun; public static ConfigBuilder.EnumValue menuWorldSelection; - public static ConfigBuilder.DoubleValue renderScaleFactor; public static ConfigBuilder.BooleanValue insideBlockSolidColor; public static ConfigBuilder.EnumValue renderBlockOutlineMode; - //Radial public static ConfigBuilder.BooleanValue radialModeHold; public static ConfigBuilder.StringValue RADIAL_1; @@ -223,25 +222,25 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe builder = new ConfigBuilder(config, new ConfigSpec()); builder - .push("Keyboard"); + .push("keyboard"); physicalKeyboard = builder - .push("Physical") + .push("physical") .comment("Enables the Physical Keyboard") .define(true); autoOpenKeyboard = builder - .push("Open") + .push("open") .comment("Automatically open the keyboard") .define(false); alwaysSimulateKeyboard = builder - .push("Simulate") + .push("simulate") .comment("Always simulate the Keyboard") .define(false); keyboardKeys = builder - .push("Keys") + .push("keys") .comment("Keyboard key Layout") .define("`1234567890-=qwertyuiop[]\\asdfghjkl;':\"zxcvbnm,./?<>"); keyboardKeysShift = builder - .push("ShiftKeys") + .push("shiftkeys") .comment("Keyboard key Layout for shift") .define("~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL;':\\\"ZXCVBNM,./?<>"); physicalKeyboardScale = builder @@ -249,7 +248,7 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .comment("The scale for the Physical Keyboard") .defineInRange(1.0d, 0.75d, 1.5d); physicalKeyboardTheme = builder - .push("Theme") + .push("theme") .comment("Keyboard theme used for the Physical Keyboard") .define(PhysicalKeyboard.KeyboardTheme.DEFAULT); builder.pop(); @@ -264,6 +263,22 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("sneakthreshold") .comment("Threshold for when the player starts sneaking") .defineInRange(0.4, 0, 2); //2 should be enough range + realisticJumpEnabled = builder + .push("jump") + .comment("Enable room scale jumping") + .define(true); + jumpThreshold = builder + .push("jumpthreshhold") + .comment("Threshhold for automatically jumping") + .defineInRange(0.05d, 0d, 2d); //2 should be enough + autoSprint = builder + .push("sprint") + .comment("Automatically sprint") + .define(true); + autoSprintThreshold = builder + .push("sprintthreshhold") + .comment("Threshhold for automatically sprinting") + .defineInRange(0.9d, 0.5d, 1d); allowCrawling = builder .push("crawl") .comment("Enable room scale crawling") @@ -288,14 +303,6 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("gui") .comment("Allow interactions by touching the gui") .define(true); - realisticJumpEnabled = builder - .push("jump") - .comment("Enable room scale jumping") - .define(true); - jumpThreshold = builder - .push("jumpthreshhold") - .comment("Threshhold for automatically jumping") - .defineInRange(0.05d, 0d, 2d); //2 should be enough realisticRowEnabled = builder .push("row") .comment("Enable room scale rowing") @@ -308,18 +315,6 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("swimming") .comment("Enable room scale swimming") .define(true); - autoSprint = builder - .push("sprint") - .comment("Automatically sprint") - .define(true); - autoSprintThreshold = builder - .push("sprintthreshhold") - .comment("Threshhold for automatically sprinting") - .defineInRange(0.9d, 0.5d, 1d); - insideBlockSolidColor = builder - .push("insideblock") - .comment("If the the inside of a block should be solid black") - .define(false); guiAppearOverBlock = builder .push("guiblock") .comment("Places the gui over the accessed block") @@ -332,14 +327,6 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("walkspeed") .comment("Walk Speed modifier") .defineInRange(1.0d, 1d, 10d); - menuAlwaysFollowFace = builder - .push("followface") - .comment("Makes the menu follow the players head") - .define(false); - vrHudLockMode = builder - .push("hudlock") - .comment("Determines where the hotbar is locked") - .define(VRSettings.HUDLock.HEAD); backpackSwitching = builder .push("backpack") .comment("Enables backpack switching") @@ -348,6 +335,14 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("walkup") .comment("Enable auto step up") .define(true); + inertiaFactor = builder + .push("inertia") + .comment("The inertia") + .define(VRSettings.InertiaFactor.NORMAL); + vehicleRotation = builder + .push("vehicleRotation") + .comment("Rotate vehicles") + .define(true); builder.pop(); builder @@ -360,26 +355,30 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("hmd") .comment("") .define(false); - seatedFreeMove = builder - .push("freemove") - .comment("Allow free move while playing as seated") - .define(true); seatedHudAltMode = builder .push("altmode") .comment("Enables the alternative HUD position when playing as seated") .define(false); + seatedFreeMove = builder + .push("freemove") + .comment("Allow free move while playing as seated") + .define(true); + vrFreeMoveMode = builder + .push("vrFreeMoveMode") + .comment("Movement mode when using free move") + .define(VRSettings.FreeMove.CONTROLLER); + vrFreeMoveFlyMode = builder + .push("vrFreeMoveFlyMode") + .comment("Movement mode when flying in free move") + .define(VRSettings.FreeMove.AUTO); builder.pop(); builder - .push("display"); - useCrosshairOcclusion = builder - .push("crosshairocclusion") - .comment("Occludes the crosshair") - .define(true); - displayMirrorMode = builder - .push("mirror") - .comment("Mirror mode") - .define(VRSettings.MirrorMode.SINGLE); + .push("hud"); + vrHudLockMode = builder + .push("hudlock") + .comment("Determines where the hotbar is locked") + .define(VRSettings.HUDLock.HEAD); lowHealthIndicator = builder .push("health") .comment("Enables the flashing of red on screen when on low health") @@ -404,6 +403,10 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("hudopacity") .comment("The opacity of the hud") .defineInRange(1.0d, 0.15d, 1.0d); + hudOcclusion = builder + .push("hudOcclusion") + .comment("Should the hud use occlusion") + .define(true); stencilOn = builder .push("stencil") .comment("Enables the eye stencil") @@ -412,10 +415,18 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("hmdhead") .comment("The distance between the head and the hmd") .defineInRange(0.10d, 0d, 1.0d); - useFsaa = builder - .push("fsaa") - .comment("Enable FSAA") - .define(false); + builder.pop(); + + builder + .push("display"); + useCrosshairOcclusion = builder + .push("crosshairocclusion") + .comment("Occludes the crosshair") + .define(true); + displayMirrorMode = builder + .push("mirror") + .comment("Mirror mode") + .define(VRSettings.MirrorMode.SINGLE); renderScaleFactor = builder .push("scale") .comment("The scale used to render") @@ -424,42 +435,70 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("shaders") .comment("Changes how shaders are applied on GUI's") .define(VRSettings.ShaderGUIRender.AFTER_SHADER); - displayMirrorLeftEye = builder - .push("lefteye") - .comment("Use the left eye instead of the right eye for the mirror") - .define(false); hideGUI = builder //TODO remove as it is a dummy storage field .push("hide") .comment("Hides the gui") .define(false); + menuAlwaysFollowFace = builder + .push("followface") + .comment("Makes the menu follow the players head") + .define(false); + menuCrosshairScale = builder + .push("menuCrosshairScale") + .comment("The scale for the crosshair in the menus") + .defineInRange(1.0d, 0.25d, 2.5d); + crosshairScalesWithDistance = builder + .push("crosshairScalesWithDistance") + .comment("Scale for the crosshair with distance") + .define(false); + menuBackground = builder + .push("menuBackground") + .comment("Use a background in menus") + .define(false); + renderInGameCrosshairMode = builder + .push("renderInGameCrosshairMode") + .comment("The style of the crosshair") + .define(VRSettings.RenderPointerElement.ALWAYS); + crosshairScale = builder + .push("crosshairScale") + .comment("The scale of the crosshair") + .defineInRange(1.0d, 0.25d, 1.0d); builder.pop(); builder - .push("test"); + .push("general"); vrHotswitchingEnabled = builder .push("hotswitch") .comment("") .define(true); - worldScale = builder .push("worldscale") .comment("") .defineInRange(1,0, 29); - worldRotation = builder .push("worldrotation") .comment("") .defineInRange(0,0, 360); + useFsaa = builder + .push("fsaa") + .comment("Enable FSAA") + .define(false); + insideBlockSolidColor = builder + .push("insideblock") + .comment("If the the inside of a block should be solid black") + .define(false); + displayMirrorLeftEye = builder + .push("lefteye") + .comment("Use the left eye instead of the right eye for the mirror") + .define(false); builder.pop(); builder .push("camera"); - handCameraResScale = builder .push("resolution") .comment("") .defineInRange(1.0d, 0.5d, 3.0d); - handCameraFov = builder .push("fov") .comment("") From 3dde42d44cba343a9325fa43bd9632155692bd3a Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:39:38 +0200 Subject: [PATCH 03/14] more configs --- .../org/vivecraft/client/ClientConfig.java | 298 ++++++++++++------ .../client/gui/widgets/QuadWidget.java | 174 ++++++++++ .../client/gui/widgets/VectorWidget.java | 120 +++++++ .../org/vivecraft/common/ConfigBuilder.java | 174 +++++++++- 4 files changed, 668 insertions(+), 98 deletions(-) create mode 100644 common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java create mode 100644 common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index b17fe9418..acf36be7a 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -4,9 +4,12 @@ import com.electronwill.nightconfig.core.Config; import com.electronwill.nightconfig.core.ConfigSpec; import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import org.joml.Quaterniond; +import org.joml.Vector3d; import org.vivecraft.client_vr.gui.PhysicalKeyboard; import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.common.ConfigBuilder; +import org.vivecraft.common.utils.math.Quaternion; import java.util.List; @@ -90,6 +93,8 @@ public class ClientConfig { //Camera public static ConfigBuilder.DoubleValue handCameraResScale; public static ConfigBuilder.IntValue handCameraFov; + public static ConfigBuilder.VectorValue vrFixedCampos; + public static ConfigBuilder.QuatValue vrFixedCamrot; //Update public static ConfigBuilder.BooleanValue firstRun; @@ -100,7 +105,7 @@ public class ClientConfig { public static ConfigBuilder.StringValue chatNotificationSound; //Teleport - public static ConfigBuilder.BooleanValue limitedTeleport; + public static ConfigBuilder.BooleanValue limitedTeleport; //Server setting? public static ConfigBuilder.IntValue teleportLimitDown; public static ConfigBuilder.IntValue teleportLimitHoriz; public static ConfigBuilder.IntValue teleportLimitUp; @@ -110,6 +115,7 @@ public class ClientConfig { public static ConfigBuilder.BooleanValue seatedhmd; public static ConfigBuilder.BooleanValue seatedHudAltMode; public static ConfigBuilder.BooleanValue seatedFreeMove; + public static ConfigBuilder.BooleanValue forceStandingFreeMove; public static ConfigBuilder.EnumValue vrFreeMoveFlyMode; //TODO check public static ConfigBuilder.EnumValue vrFreeMoveMode; @@ -120,18 +126,16 @@ public class ClientConfig { public static ConfigBuilder.IntValue worldRotation; public static ConfigBuilder.DoubleValue vrWorldRotationIncrement; public static ConfigBuilder.IntValue worldScale; + public static ConfigBuilder.VectorValue originOffset; public static ConfigBuilder.IntValue version; public static ConfigBuilder.BooleanValue reverseHands; public static ConfigBuilder.BooleanValue allowStandingOriginOffset; - public static ConfigBuilder.BooleanValue forceHardwareDetection; - public static ConfigBuilder.StringValue badStereoProviderPluginID; + public static ConfigBuilder.IntValue forceHardwareDetection; + public static ConfigBuilder.EnumValue stereoProviderPluginID; public static ConfigBuilder.BooleanValue analogMovement; - public static ConfigBuilder.DoubleValue autoCalibration; - public static ConfigBuilder.StringValue stereoProviderPluginID; public static ConfigBuilder.DoubleValue manualCalibration; public static ConfigBuilder.EnumValue rightclickDelay; public static ConfigBuilder.BooleanValue thirdPersonItems; - public static ConfigBuilder.BooleanValue forceStandingFreeMove; public static ConfigBuilder.BooleanValue allowAdvancedBindings; public static ConfigBuilder.DoubleValue xSensitivity; public static ConfigBuilder.DoubleValue ySensitivity; @@ -141,6 +145,7 @@ public class ClientConfig { public static ConfigBuilder.EnumValue menuWorldSelection; public static ConfigBuilder.BooleanValue insideBlockSolidColor; public static ConfigBuilder.EnumValue renderBlockOutlineMode; + public static ConfigBuilder.IntValue hrtfSelection; //TODO remove? //Radial @@ -168,22 +173,11 @@ public class ClientConfig { public static ConfigBuilder.StringValue QUICKCOMMAND_9; //Misc - public static ConfigBuilder.BooleanValue smoothTick; - public static ConfigBuilder.DoubleValue vrFixedCamrotW; - public static ConfigBuilder.DoubleValue vrFixedCamrotZ; - public static ConfigBuilder.DoubleValue vrFixedCamrotY; - public static ConfigBuilder.DoubleValue vrFixedCamrotX; - //"originOffset": "0.0,0.0,0.0", public static ConfigBuilder.DoubleValue monoFOV; public static ConfigBuilder.BooleanValue bcbOn; - public static ConfigBuilder.IntValue hrtfSelection; - public static ConfigBuilder.DoubleValue smoothRunTickCount; public static ConfigBuilder.DoubleValue fovReductionMin; public static ConfigBuilder.StringValue externalCameraAngleOrder; public static ConfigBuilder.DoubleValue keyholeX; - public static ConfigBuilder.BooleanValue vrFixedCamposZ; - public static ConfigBuilder.DoubleValue vrFixedCamposX; - public static ConfigBuilder.BooleanValue vrFixedCamposY; public static ConfigBuilder.DoubleValue fovRedutioncOffset; public static ConfigBuilder.BooleanValue fovReduction; @@ -221,6 +215,97 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe builder = new ConfigBuilder(config, new ConfigSpec()); + builder.push("general"); + vrEnabled = builder + .push("vrEnabled") + .comment("Enable VR") + .define(false); + vrHotswitchingEnabled = builder + .push("hotswitch") + .comment("Allow hotswitch between VR and nonVR") + .define(true); + worldScale = builder + .push("worldscale") + .comment("") + .defineInRange(1,0, 29); + worldRotation = builder + .push("worldrotation") + .comment("") + .defineInRange(0,0, 360); + vrWorldRotationIncrement = builder + .push("vrWorldRotationIncrement") + .comment("") + .defineInRange(45d,-1d, 4d); //TODO Looks wrong? + allowStandingOriginOffset = builder + .push("allowStandingOriginOffset") + .comment("") + .define(false); + originOffset = builder + .push("originOffset") + .comment("") + .define(new Vector3d( 0d, 0d, 0d)); + forceHardwareDetection = builder + .push("forceHardwareDetection") + .comment("0 = off, 1 = vive, 2 = oculus") //TODO enum? + .defineInRange(0, 0,2); + stereoProviderPluginID = builder + .push("stereoProviderPluginID") + .comment("") + .define(VRSettings.VRProvider.OPENVR); + analogMovement = builder + .push("analogMovement") + .comment("") + .define(true); + manualCalibration = builder + .push("manualCalibration") + .comment("") + .defineInRange(-1d, 0d, 5d); //TODO check + rightclickDelay = builder + .push("rightclickDelay") + .comment("") + .define(VRSettings.RightClickDelay.VANILLA); + thirdPersonItems = builder + .push("thirdPersonItems") + .comment("") + .define(false); + allowAdvancedBindings = builder + .push("allowAdvancedBindings") + .comment("") + .define(false); + xSensitivity = builder + .push("xSensitivity") + .comment("") + .defineInRange(1d, 0.1d, 5d); + ySensitivity = builder + .push("ySensitivity") + .comment("") + .defineInRange(1d, 0.1d, 5d); + useFsaa = builder + .push("fsaa") + .comment("Enable FSAA") + .define(false); + disableFun = builder + .push("disableFun") + .comment("") + .define(false); + menuWorldSelection = builder + .push("menuWorldSelection") + .comment("") + .define(VRSettings.MenuWorld.BOTH); + insideBlockSolidColor = builder + .push("insideblock") + .comment("If the the inside of a block should be solid black") + .define(false); + displayMirrorLeftEye = builder + .push("lefteye") + .comment("Use the left eye instead of the right eye for the mirror") + .define(false); + hrtfSelection = builder + .push("hrtfSelection") + .comment("") + .defineInRange(0, -1, 0); + builder.pop(); + builder .push("keyboard"); physicalKeyboard = builder @@ -253,8 +338,7 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .define(PhysicalKeyboard.KeyboardTheme.DEFAULT); builder.pop(); - builder - .push("roomscale"); + builder.push("roomscale"); realisticSneakEnabled = builder .push("sneak") .comment("Enable room scale sneaking") @@ -345,8 +429,7 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .define(true); builder.pop(); - builder - .push("seated"); + builder.push("seated"); seated = builder .push("enable") .comment("Enables seated mode") @@ -363,6 +446,10 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("freemove") .comment("Allow free move while playing as seated") .define(true); + forceStandingFreeMove = builder + .push("forceStandingFreeMove") + .comment("") + .define(false); vrFreeMoveMode = builder .push("vrFreeMoveMode") .comment("Movement mode when using free move") @@ -373,52 +460,7 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .define(VRSettings.FreeMove.AUTO); builder.pop(); - builder - .push("hud"); - vrHudLockMode = builder - .push("hudlock") - .comment("Determines where the hotbar is locked") - .define(VRSettings.HUDLock.HEAD); - lowHealthIndicator = builder - .push("health") - .comment("Enables the flashing of red on screen when on low health") - .define(true); - hudDistance = builder - .push("hud") - .comment("The distance between the player and the HUD") - .defineInRange(1.25d, 0.25d, 5.0d); - hudPitchOffset = builder - .push("hudpitch") - .comment("The pitch offset of the hud") - .defineInRange(-2.0d, -5d,5d); //TODO what limit is fine here? int.max seems to much? - hudYawOffset = builder - .push("hudyaw") - .comment("The yaw offset of the hud") - .defineInRange(0.0d, -5d,5d); //TODO what limit is fine here? int.max seems to much? - headHudScale = builder - .push("hudscale") - .comment("The scale of the hud") - .defineInRange(1.0d, 0.35d, 2.5d); - hudOpacity = builder - .push("hudopacity") - .comment("The opacity of the hud") - .defineInRange(1.0d, 0.15d, 1.0d); - hudOcclusion = builder - .push("hudOcclusion") - .comment("Should the hud use occlusion") - .define(true); - stencilOn = builder - .push("stencil") - .comment("Enables the eye stencil") - .define(true); - headToHmdLength = builder - .push("hmdhead") - .comment("The distance between the head and the hmd") - .defineInRange(0.10d, 0d, 1.0d); - builder.pop(); - - builder - .push("display"); + builder.push("display"); useCrosshairOcclusion = builder .push("crosshairocclusion") .comment("Occludes the crosshair") @@ -465,36 +507,50 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .defineInRange(1.0d, 0.25d, 1.0d); builder.pop(); - builder - .push("general"); - vrHotswitchingEnabled = builder - .push("hotswitch") - .comment("") + builder.push("hud"); + vrHudLockMode = builder + .push("hudlock") + .comment("Determines where the hotbar is locked") + .define(VRSettings.HUDLock.HEAD); + lowHealthIndicator = builder + .push("health") + .comment("Enables the flashing of red on screen when on low health") .define(true); - worldScale = builder - .push("worldscale") - .comment("") - .defineInRange(1,0, 29); - worldRotation = builder - .push("worldrotation") - .comment("") - .defineInRange(0,0, 360); - useFsaa = builder - .push("fsaa") - .comment("Enable FSAA") - .define(false); - insideBlockSolidColor = builder - .push("insideblock") - .comment("If the the inside of a block should be solid black") - .define(false); - displayMirrorLeftEye = builder - .push("lefteye") - .comment("Use the left eye instead of the right eye for the mirror") - .define(false); + hudDistance = builder + .push("hud") + .comment("The distance between the player and the HUD") + .defineInRange(1.25d, 0.25d, 5.0d); + hudPitchOffset = builder + .push("hudpitch") + .comment("The pitch offset of the hud") + .defineInRange(-2.0d, -5d,5d); //TODO what limit is fine here? int.max seems to much? + hudYawOffset = builder + .push("hudyaw") + .comment("The yaw offset of the hud") + .defineInRange(0.0d, -5d,5d); //TODO what limit is fine here? int.max seems to much? + headHudScale = builder + .push("hudscale") + .comment("The scale of the hud") + .defineInRange(1.0d, 0.35d, 2.5d); + hudOpacity = builder + .push("hudopacity") + .comment("The opacity of the hud") + .defineInRange(1.0d, 0.15d, 1.0d); + hudOcclusion = builder + .push("hudOcclusion") + .comment("Should the hud use occlusion") + .define(true); + stencilOn = builder + .push("stencil") + .comment("Enables the eye stencil") + .define(true); + headToHmdLength = builder + .push("hmdhead") + .comment("The distance between the head and the hmd") + .defineInRange(0.10d, 0d, 1.0d); builder.pop(); - builder - .push("camera"); + builder.push("camera"); handCameraResScale = builder .push("resolution") .comment("") @@ -503,6 +559,60 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("fov") .comment("") .defineInRange(70, 1, 179); + vrFixedCampos = builder + .push("vrFixedCampos") + .comment("") + .define(new Vector3d(-1.0d, 2.4d, 2.7d)); + vrFixedCamrot = builder + .push("vrFixedCamrot") + .comment("") + .define(new Quaterniond(.962d, .125d, .239d, .041d)); + builder.pop(); + + builder.push("update"); + firstRun = builder + .push("firstRun") + .comment("Is this the first time the game is run") + .define(true); //TODO remove? + lastUpdate = builder + .push("lastUpdate") + .comment("the latest version available") + .define(""); + alwaysShowUpdates = builder + .push("alwaysShowUpdates") + .comment("Show that updates are possible on each restart") + .define(true); + showServerPluginMessage = builder + .push("showServerPluginMessage") + .comment("Show messages from the server side plugin") + .define(true); + chatNotifications = builder + .push("chatNotifications") + .comment("Should messages in chat notify the player") + .define(VRSettings.ChatNotifications.NONE); + chatNotificationSound = builder + .push("chatNotificationSound") + .comment("The sound used for chat notifications") + .define("block.note_block.bell"); + builder.pop(); + + builder.push("teleport"); + limitedTeleport = builder + .push("limitedTeleport") + .comment("Limit teleportation") + .define(false); + teleportLimitUp = builder + .push("teleportLimitUp") + .comment("Limit for upwards teleportation") + .defineInRange(1,0,4); + teleportLimitDown = builder + .push("teleportLimitDown") + .comment("Limit for downwards teleportation") + .defineInRange(4,0, 16); + teleportLimitHoriz = builder + .push("teleportLimitHoriz") + .comment("Limit for side teleportation") + .defineInRange(16,0, 32); builder.pop(); builder.correct(listener); diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java b/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java new file mode 100644 index 000000000..3687549bc --- /dev/null +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java @@ -0,0 +1,174 @@ +package org.vivecraft.client.gui.widgets; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import org.joml.Quaterniond; +import org.vivecraft.common.ConfigBuilder; + +import java.util.function.Consumer; + +public class QuadWidget extends AbstractWidget { + + private final NumberEditBox xBox; + private final NumberEditBox yBox; + private final NumberEditBox zBox; + private final NumberEditBox wBox; + + public QuadWidget(int i, int j, int k, int l, Component component, ConfigBuilder.QuatValue value) { + super(i, j, k, l, component); + Quaterniond quaterniond = value.get(); + this.xBox = new NumberEditBox(Minecraft.getInstance().font, i , j, (k-4) / 4, l , Component.literal(quaterniond.x +""), quaterniond.x, d -> value.set(new Quaterniond(d, quaterniond.y, quaterniond.z, quaterniond.w))); + this.yBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k - 4) / 4) + 1, j, (k-4) / 4, l , Component.literal(quaterniond.y +""), quaterniond.y, d -> value.set(new Quaterniond(quaterniond.x, d, quaterniond.z, quaterniond.w))); + this.zBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k-4) / 4)*2 + 2, j, (k-4) / 4, l , Component.literal(quaterniond.z +""), quaterniond.z, d -> value.set(new Quaterniond(quaterniond.x, quaterniond.y, d, quaterniond.w))); + this.wBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k-4) / 4)*3 + 3, j, (k-4) / 4, l , Component.literal(quaterniond.w +""), quaterniond.w, d -> value.set(new Quaterniond(quaterniond.x, quaterniond.y, quaterniond.z, d))); + + } + + @Override + public void render(GuiGraphics guiGraphics, int i, int j, float f) { + this.xBox.render(guiGraphics, i, j, f); + this.yBox.render(guiGraphics, i, j, f); + this.zBox.render(guiGraphics, i, j, f); + this.wBox.render(guiGraphics, i, j, f); + + } + + @Override + protected void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) { + this.xBox.renderWidget(guiGraphics, i, j, f); + this.yBox.renderWidget(guiGraphics, i, j, f); + this.zBox.renderWidget(guiGraphics, i, j, f); + this.wBox.renderWidget(guiGraphics, i, j, f); + } + + @Override + public void renderTexture(GuiGraphics guiGraphics, ResourceLocation resourceLocation, int i, int j, int k, int l, int m, int n, int o, int p, int q) { + this.xBox.renderTexture(guiGraphics, resourceLocation, i, j, k, l, m, n, o, p, q); + this.yBox.renderTexture(guiGraphics, resourceLocation, i, j, k, l, m, n, o, p, q); + this.zBox.renderTexture(guiGraphics, resourceLocation, i, j, k, l, m, n, o, p, q); + this.wBox.renderTexture(guiGraphics, resourceLocation, i, j, k, l, m, n, o, p, q); + } + + @Override + public void setX(int i) { + super.setX(i); + this.xBox.setX(i); + this.yBox.setX(i + (width-4)/4 + 1); + this.zBox.setX(i + ((width-4)/4)*2 + 2); + this.wBox.setX(i + ((width-4)/4)*3 + 3); + } + + @Override + public void setY(int i) { + super.setY(i); + this.xBox.setY(i); + this.yBox.setY(i); + this.zBox.setY(i); + this.wBox.setY(i); + } + + @Override + public void setFocused(boolean bl) { + super.setFocused(bl); + this.xBox.setFocused(this.xBox.isHovered()); + this.yBox.setFocused(this.yBox.isHovered()); + this.zBox.setFocused(this.zBox.isHovered()); + this.wBox.setFocused(this.wBox.isHovered()); + + + } + + @Override + public boolean mouseClicked(double d, double e, int i) { + if (xBox.isMouseOver(d, e)) { + this.xBox.setFocused(true); + return this.xBox.mouseClicked(d,e,i); + } + if (yBox.isMouseOver(d, e)) { + this.yBox.setFocused(true); + return this.yBox.mouseClicked(d,e,i); + } + if (zBox.isMouseOver(d, e)) { + this.zBox.setFocused(true); + return this.zBox.mouseClicked(d,e,i); + } + if (wBox.isMouseOver(d, e)) { + this.wBox.setFocused(true); + return this.wBox.mouseClicked(d,e,i); + } + return super.mouseClicked(d, e, i); + } + + @Override + public boolean keyPressed(int i, int j, int k) { + if (this.xBox.isFocused()) { + return this.xBox.keyPressed(i, j, k); + } + if (this.yBox.isFocused()) { + return this.yBox.keyPressed(i, j, k); + } + if (this.zBox.isFocused()) { + return this.zBox.keyPressed(i, j, k); + } + if (this.wBox.isFocused()) { + return this.wBox.keyPressed(i, j, k); + } + return super.keyPressed(i, j, k); + } + + @Override + public boolean charTyped(char c, int i) { + if (this.xBox.isFocused()) { + return this.xBox.charTyped(c, i); + } + if (this.yBox.isFocused()) { + return this.yBox.charTyped(c, i); + } + if (this.zBox.isFocused()) { + return this.zBox.charTyped(c, i); + } + if (this.wBox.isFocused()) { + return this.wBox.charTyped(c, i); + } + return super.charTyped(c, i); + } + + @Override + protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) { + + } + + public static class NumberEditBox extends EditBox { + + private final Consumer doubleConsumer; + + public NumberEditBox(Font font, int i, int j, int k, int l, Component component, double doubleValue, Consumer doubleConsumer) { + super(font, i, j, k, l, component); + this.doubleConsumer = doubleConsumer; + this.setValue(doubleValue + ""); + } + + @Override + public boolean charTyped(char c, int i) { + if (c != 46 && (c < 48 || c > 57)) { + return false; + } + boolean ret = super.charTyped(c, i); + doubleConsumer.accept(Double.valueOf(this.getValue())); + return ret; + } + + @Override + public boolean keyPressed(int i, int j, int k) { + boolean ret = super.keyPressed(i, j, k); + doubleConsumer.accept(Double.valueOf(this.getValue())); + return ret; + } + } +} diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java b/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java new file mode 100644 index 000000000..af84dbbb0 --- /dev/null +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java @@ -0,0 +1,120 @@ +package org.vivecraft.client.gui.widgets; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import org.joml.Quaterniond; +import org.joml.Vector3d; +import org.vivecraft.common.ConfigBuilder; + +public class VectorWidget extends AbstractWidget { + private final QuadWidget.NumberEditBox xBox; + private final QuadWidget.NumberEditBox yBox; + private final QuadWidget.NumberEditBox zBox; + + public VectorWidget(int i, int j, int k, int l, Component component, ConfigBuilder.VectorValue value) { + super(i, j, k, l, component); + Vector3d vector = value.get(); + this.xBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i , j, (k-3) / 3, l , Component.literal(vector.x +""), vector.x, d -> value.set(new Vector3d(d, vector.y, vector.z))); + this.yBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i + ((k - 3) / 3) + 1, j, (k-3) / 3, l , Component.literal(vector.y +""), vector.y, d -> value.set(new Vector3d(vector.x, d, vector.z))); + this.zBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i + ((k-3) / 3)*2 + 2, j, (k-4) / 3, l , Component.literal(vector.z +""), vector.z, d -> value.set(new Vector3d(vector.x, vector.y, d))); + } + + @Override + public void render(GuiGraphics guiGraphics, int i, int j, float f) { + this.xBox.render(guiGraphics, i, j, f); + this.yBox.render(guiGraphics, i, j, f); + this.zBox.render(guiGraphics, i, j, f); + } + + @Override + protected void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) { + this.xBox.renderWidget(guiGraphics, i, j, f); + this.yBox.renderWidget(guiGraphics, i, j, f); + this.zBox.renderWidget(guiGraphics, i, j, f); + } + + @Override + public void renderTexture(GuiGraphics guiGraphics, ResourceLocation resourceLocation, int i, int j, int k, int l, int m, int n, int o, int p, int q) { + this.xBox.renderTexture(guiGraphics, resourceLocation, i, j, k, l, m, n, o, p, q); + this.yBox.renderTexture(guiGraphics, resourceLocation, i, j, k, l, m, n, o, p, q); + this.zBox.renderTexture(guiGraphics, resourceLocation, i, j, k, l, m, n, o, p, q); + } + + @Override + public void setX(int i) { + super.setX(i); + this.xBox.setX(i); + this.yBox.setX(i + (width-3)/3 + 1); + this.zBox.setX(i + ((width-3)/3)*2 + 2); + } + + @Override + public void setY(int i) { + super.setY(i); + this.xBox.setY(i); + this.yBox.setY(i); + this.zBox.setY(i); + } + + @Override + public void setFocused(boolean bl) { + super.setFocused(bl); + this.xBox.setFocused(this.xBox.isHovered()); + this.yBox.setFocused(this.yBox.isHovered()); + this.zBox.setFocused(this.zBox.isHovered()); + } + + @Override + public boolean mouseClicked(double d, double e, int i) { + if (xBox.isMouseOver(d, e)) { + this.xBox.setFocused(true); + return this.xBox.mouseClicked(d,e,i); + } + if (yBox.isMouseOver(d, e)) { + this.yBox.setFocused(true); + return this.yBox.mouseClicked(d,e,i); + } + if (zBox.isMouseOver(d, e)) { + this.zBox.setFocused(true); + return this.zBox.mouseClicked(d,e,i); + } + return super.mouseClicked(d, e, i); + } + + @Override + public boolean keyPressed(int i, int j, int k) { + if (this.xBox.isFocused()) { + return this.xBox.keyPressed(i, j, k); + } + if (this.yBox.isFocused()) { + return this.yBox.keyPressed(i, j, k); + } + if (this.zBox.isFocused()) { + return this.zBox.keyPressed(i, j, k); + } + return super.keyPressed(i, j, k); + } + + @Override + public boolean charTyped(char c, int i) { + if (this.xBox.isFocused()) { + return this.xBox.charTyped(c, i); + } + if (this.yBox.isFocused()) { + return this.yBox.charTyped(c, i); + } + if (this.zBox.isFocused()) { + return this.zBox.charTyped(c, i); + } + return super.charTyped(c, i); + } + + @Override + protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) { + + } +} diff --git a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java index 054087853..d6d07ce7b 100644 --- a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -7,8 +7,12 @@ import net.minecraft.client.gui.components.*; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; +import org.joml.Quaterniond; +import org.joml.Vector3d; import org.vivecraft.client.gui.settings.GuiListValueEditScreen; +import org.vivecraft.client.gui.widgets.QuadWidget; import org.vivecraft.client.gui.widgets.SettingsList; +import org.vivecraft.client.gui.widgets.VectorWidget; import java.util.*; import java.util.function.Predicate; @@ -69,9 +73,20 @@ private void addDefaultValueComment(List path, double defaultValue, doub private > void addDefaultValueComment(List path, T defaultValue) { String oldComment = config.getComment(path); config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") - + new Formatter(Locale.US).format("default: %.2s", defaultValue.name())); + + new Formatter(Locale.US).format("default: %s", defaultValue.name())); } + private void addDefaultValueComment(List path, Quaterniond defaultValue) { + String oldComment = config.getComment(path); + config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") + +"x: %.2f, y %.2f, z: %.2f, w: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z, defaultValue.w)); + } + + private void addDefaultValueComment(List path, Vector3d defaultValue) { + String oldComment = config.getComment(path); + config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") + +"x: %.2f, y: %.2f, z: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z)); + } /** * corrects the attached config, with the built spec @@ -187,6 +202,47 @@ public > EnumValue define(T defaultValue) { return value; } + public QuatValue define(Quaterniond defaultValue) { + List path = stack.stream().toList(); + stack.add("x"); + spec.define(stack.stream().toList(), defaultValue.x); + stack.removeLast(); + stack.add("y"); + spec.define(stack.stream().toList(), defaultValue.y); + stack.removeLast(); + stack.add("z"); + spec.define(stack.stream().toList(), defaultValue.z); + stack.removeLast(); + stack.add("w"); + spec.define(stack.stream().toList(), defaultValue.w); + stack.removeLast(); + stack.removeLast(); + + addDefaultValueComment(path, defaultValue); + QuatValue value = new QuatValue(config, path, defaultValue); + configValues.add(value); + return value; + } + + public VectorValue define(Vector3d defaultValue) { + List path = stack.stream().toList(); + stack.add("x"); + spec.define(stack.stream().toList(), defaultValue.x); + stack.removeLast(); + stack.add("y"); + spec.define(stack.stream().toList(), defaultValue.y); + stack.removeLast(); + stack.add("z"); + spec.define(stack.stream().toList(), defaultValue.z); + stack.removeLast(); + stack.removeLast(); + + addDefaultValueComment(path, defaultValue); + VectorValue value = new VectorValue(config, path, defaultValue); + configValues.add(value); + return value; + } + /** * same as {@link #defineInRange defineInRange(T defaultValue, T min, T max)} but returns a {@link DoubleValue} */ @@ -219,11 +275,11 @@ public IntValue defineInRange(int defaultValue, int min, int max) { public static class ConfigValue { // the config, this setting is part of - private final CommentedConfig config; - private final List path; + protected final CommentedConfig config; + protected final List path; protected final T defaultValue; // cache te value to minimize config lookups - private T cachedValue = null; + protected T cachedValue = null; public ConfigValue(CommentedConfig config, List path, T defaultValue) { this.config = config; @@ -450,4 +506,114 @@ public AbstractWidget getWidget(int width, int height) { .create(0, 0, width, height, Component.empty(), (button, newValue) -> set((T) newValue)); } } + + public static class QuatValue extends ConfigValue { + + public QuatValue(CommentedConfig config, List path, Quaterniond defaultValue) { + super(config, path, defaultValue); + } + + @Override + public Quaterniond get() { + if (cachedValue == null) { + List path2 = new ArrayList<>(path); + path2.add("x"); + double x = config.get(path2); + path2.set(path.size(), "y"); + double y = config.get(path2); + path2.set(path.size(), "z"); + double z = config.get(path2); + path2.set(path.size(), "w"); + double w = config.get(path2); + cachedValue = new Quaterniond(x, y, z, w); + } + return new Quaterniond(cachedValue); + } + + @Override + public void set(Quaterniond newValue) { + cachedValue = newValue; + List path2 = new ArrayList<>(path); + path2.add("x"); + config.set(path2, newValue.x); + path2.set(path.size(), "y"); + config.set(path2, newValue.y); + path2.set(path.size(), "z"); + config.set(path2, newValue.z); + path2.set(path.size(), "w"); + config.set(path2, newValue.w); + } + + @Override + public Quaterniond reset() { + List path2 = new ArrayList<>(path); + path2.add("x"); + config.set(path2, defaultValue.x); + path2.set(path.size(), "y"); + config.set(path2, defaultValue.y); + path2.set(path.size(), "z"); + config.set(path2, defaultValue.z); + path2.set(path.size(), "w"); + config.set(path2, defaultValue.w); + cachedValue = defaultValue; + return defaultValue; + } + + @Override + public AbstractWidget getWidget(int width, int height) { + return new QuadWidget(0,0, width, height, Component.literal(get().toString()), this); + } + } + + public class VectorValue extends ConfigValue { + + public VectorValue(CommentedConfig config, List path, Vector3d defaultValue) { + super(config, path, defaultValue); + } + + @Override + public Vector3d get() { + if (cachedValue == null) { + List path2 = new ArrayList<>(path); + path2.add("x"); + double x = config.get(path2); + path2.set(path.size(), "y"); + double y = config.get(path2); + path2.set(path.size(), "z"); + double z = config.get(path2); + cachedValue = new Vector3d(x, y, z); + } + return new Vector3d(cachedValue); + } + + @Override + public void set(Vector3d newValue) { + cachedValue = newValue; + List path2 = new ArrayList<>(path); + path2.add("x"); + config.set(path2, newValue.x); + path2.set(path.size(), "y"); + config.set(path2, newValue.y); + path2.set(path.size(), "z"); + config.set(path2, newValue.z); + } + + @Override + public Vector3d reset() { + List path2 = new ArrayList<>(path); + path2.add("x"); + config.set(path2, defaultValue.x); + path2.set(path.size(), "y"); + config.set(path2, defaultValue.y); + path2.set(path.size(), "z"); + config.set(path2, defaultValue.z); + cachedValue = defaultValue; + return defaultValue; + } + + @Override + public AbstractWidget getWidget(int width, int height) { + return new VectorWidget(0,0, width, height, Component.literal(get().toString()), this); + } + } } From 55ec7b12a335fd6746b89bb2d321919952df0fa3 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 13 Sep 2023 17:08:45 +0200 Subject: [PATCH 04/14] change to floats --- .../org/vivecraft/client/ClientConfig.java | 47 ++++++++++++++++--- .../client/gui/widgets/QuadWidget.java | 23 ++++----- .../org/vivecraft/common/ConfigBuilder.java | 19 ++++---- 3 files changed, 62 insertions(+), 27 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index acf36be7a..225528df2 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -5,10 +5,12 @@ import com.electronwill.nightconfig.core.ConfigSpec; import com.electronwill.nightconfig.core.file.CommentedFileConfig; import org.joml.Quaterniond; +import org.joml.Quaternionf; import org.joml.Vector3d; import org.vivecraft.client_vr.gui.PhysicalKeyboard; import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.common.ConfigBuilder; +import org.vivecraft.common.utils.math.Angle; import org.vivecraft.common.utils.math.Quaternion; import java.util.List; @@ -95,6 +97,7 @@ public class ClientConfig { public static ConfigBuilder.IntValue handCameraFov; public static ConfigBuilder.VectorValue vrFixedCampos; public static ConfigBuilder.QuatValue vrFixedCamrot; + public static ConfigBuilder.EnumValue externalCameraAngleOrder; //Update public static ConfigBuilder.BooleanValue firstRun; @@ -136,9 +139,11 @@ public class ClientConfig { public static ConfigBuilder.DoubleValue manualCalibration; public static ConfigBuilder.EnumValue rightclickDelay; public static ConfigBuilder.BooleanValue thirdPersonItems; + public static ConfigBuilder.BooleanValue bcbOn; //TODO rename shadow public static ConfigBuilder.BooleanValue allowAdvancedBindings; public static ConfigBuilder.DoubleValue xSensitivity; public static ConfigBuilder.DoubleValue ySensitivity; + public static ConfigBuilder.DoubleValue keyholeX; public static ConfigBuilder.BooleanValue useFsaa; public static ConfigBuilder.BooleanValue displayMirrorLeftEye; public static ConfigBuilder.BooleanValue disableFun; @@ -172,13 +177,10 @@ public class ClientConfig { public static ConfigBuilder.StringValue QUICKCOMMAND_8; public static ConfigBuilder.StringValue QUICKCOMMAND_9; - //Misc - public static ConfigBuilder.DoubleValue monoFOV; - public static ConfigBuilder.BooleanValue bcbOn; + //FOV + public static ConfigBuilder.DoubleValue monoFOV; //TODO Dummy public static ConfigBuilder.DoubleValue fovReductionMin; - public static ConfigBuilder.StringValue externalCameraAngleOrder; - public static ConfigBuilder.DoubleValue keyholeX; - public static ConfigBuilder.DoubleValue fovRedutioncOffset; + public static ConfigBuilder.DoubleValue fovRedutioncOffset; //TODO typo public static ConfigBuilder.BooleanValue fovReduction; private static CommentedFileConfig config; @@ -268,6 +270,10 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("thirdPersonItems") .comment("") .define(false); + bcbOn = builder + .push("bcbOn") + .comment("") + .define(true); allowAdvancedBindings = builder .push("allowAdvancedBindings") .comment("") @@ -280,6 +286,10 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("ySensitivity") .comment("") .defineInRange(1d, 0.1d, 5d); + keyholeX = builder + .push("keyholeX") + .comment("") + .defineInRange(15d, 0d, 40d); useFsaa = builder .push("fsaa") .comment("Enable FSAA") @@ -550,6 +560,25 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .defineInRange(0.10d, 0d, 1.0d); builder.pop(); + builder.push("fov"); + monoFOV = builder + .push("monoFOV") + .comment("") + .defineInRange(0.0d, 0d, 1.0d); + fovReduction = builder + .push("fovReduction") + .comment("") + .define(false); + fovReductionMin = builder + .push("fovReductionMin") + .comment("") + .defineInRange(0.25d, 0.1d, 0.7d); + fovRedutioncOffset = builder + .push("fovReductionOffset") + .comment("") + .defineInRange(0.1f,0d, 0.3d); + builder.pop(); + builder.push("camera"); handCameraResScale = builder .push("resolution") @@ -566,7 +595,11 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe vrFixedCamrot = builder .push("vrFixedCamrot") .comment("") - .define(new Quaterniond(.962d, .125d, .239d, .041d)); + .define(new Quaternionf(.962d, .125d, .239d, .041d)); + externalCameraAngleOrder = builder + .push("externalCameraAngleOrder") + .comment("") + .define(Angle.Order.XYZ); builder.pop(); builder.push("update"); diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java b/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java index 3687549bc..f217a5ecb 100644 --- a/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java @@ -9,6 +9,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.joml.Quaterniond; +import org.joml.Quaternionf; import org.vivecraft.common.ConfigBuilder; import java.util.function.Consumer; @@ -22,11 +23,11 @@ public class QuadWidget extends AbstractWidget { public QuadWidget(int i, int j, int k, int l, Component component, ConfigBuilder.QuatValue value) { super(i, j, k, l, component); - Quaterniond quaterniond = value.get(); - this.xBox = new NumberEditBox(Minecraft.getInstance().font, i , j, (k-4) / 4, l , Component.literal(quaterniond.x +""), quaterniond.x, d -> value.set(new Quaterniond(d, quaterniond.y, quaterniond.z, quaterniond.w))); - this.yBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k - 4) / 4) + 1, j, (k-4) / 4, l , Component.literal(quaterniond.y +""), quaterniond.y, d -> value.set(new Quaterniond(quaterniond.x, d, quaterniond.z, quaterniond.w))); - this.zBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k-4) / 4)*2 + 2, j, (k-4) / 4, l , Component.literal(quaterniond.z +""), quaterniond.z, d -> value.set(new Quaterniond(quaterniond.x, quaterniond.y, d, quaterniond.w))); - this.wBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k-4) / 4)*3 + 3, j, (k-4) / 4, l , Component.literal(quaterniond.w +""), quaterniond.w, d -> value.set(new Quaterniond(quaterniond.x, quaterniond.y, quaterniond.z, d))); + Quaternionf quaternionf = value.get(); + this.xBox = new NumberEditBox(Minecraft.getInstance().font, i , j, (k-4) / 4, l , Component.literal(quaternionf.x +""), quaternionf.x, d -> value.set(new Quaternionf(d, quaternionf.y, quaternionf.z, quaternionf.w))); + this.yBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k - 4) / 4) + 1, j, (k-4) / 4, l , Component.literal(quaternionf.y +""), quaternionf.y, d -> value.set(new Quaternionf(quaternionf.x, d, quaternionf.z, quaternionf.w))); + this.zBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k-4) / 4)*2 + 2, j, (k-4) / 4, l , Component.literal(quaternionf.z +""), quaternionf.z, d -> value.set(new Quaternionf(quaternionf.x, quaternionf.y, d, quaternionf.w))); + this.wBox = new NumberEditBox(Minecraft.getInstance().font, i + ((k-4) / 4)*3 + 3, j, (k-4) / 4, l , Component.literal(quaternionf.w +""), quaternionf.w, d -> value.set(new Quaternionf(quaternionf.x, quaternionf.y, quaternionf.z, d))); } @@ -146,12 +147,12 @@ protected void updateWidgetNarration(NarrationElementOutput narrationElementOutp public static class NumberEditBox extends EditBox { - private final Consumer doubleConsumer; + private final Consumer floatConsumer; - public NumberEditBox(Font font, int i, int j, int k, int l, Component component, double doubleValue, Consumer doubleConsumer) { + public NumberEditBox(Font font, int i, int j, int k, int l, Component component, float floatValue, Consumer floatConsumer) { super(font, i, j, k, l, component); - this.doubleConsumer = doubleConsumer; - this.setValue(doubleValue + ""); + this.floatConsumer = floatConsumer; + this.setValue(floatValue + ""); } @Override @@ -160,14 +161,14 @@ public boolean charTyped(char c, int i) { return false; } boolean ret = super.charTyped(c, i); - doubleConsumer.accept(Double.valueOf(this.getValue())); + floatConsumer.accept(Float.valueOf(this.getValue())); return ret; } @Override public boolean keyPressed(int i, int j, int k) { boolean ret = super.keyPressed(i, j, k); - doubleConsumer.accept(Double.valueOf(this.getValue())); + floatConsumer.accept(Float.valueOf(this.getValue())); return ret; } } diff --git a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java index d6d07ce7b..97784dfa7 100644 --- a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -8,6 +8,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import org.joml.Quaterniond; +import org.joml.Quaternionf; import org.joml.Vector3d; import org.vivecraft.client.gui.settings.GuiListValueEditScreen; import org.vivecraft.client.gui.widgets.QuadWidget; @@ -76,7 +77,7 @@ private > void addDefaultValueComment(List path, T def + new Formatter(Locale.US).format("default: %s", defaultValue.name())); } - private void addDefaultValueComment(List path, Quaterniond defaultValue) { + private void addDefaultValueComment(List path, Quaternionf defaultValue) { String oldComment = config.getComment(path); config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") +"x: %.2f, y %.2f, z: %.2f, w: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z, defaultValue.w)); @@ -202,7 +203,7 @@ public > EnumValue define(T defaultValue) { return value; } - public QuatValue define(Quaterniond defaultValue) { + public QuatValue define(Quaternionf defaultValue) { List path = stack.stream().toList(); stack.add("x"); spec.define(stack.stream().toList(), defaultValue.x); @@ -507,14 +508,14 @@ public AbstractWidget getWidget(int width, int height) { } } - public static class QuatValue extends ConfigValue { + public static class QuatValue extends ConfigValue { - public QuatValue(CommentedConfig config, List path, Quaterniond defaultValue) { + public QuatValue(CommentedConfig config, List path, Quaternionf defaultValue) { super(config, path, defaultValue); } @Override - public Quaterniond get() { + public Quaternionf get() { if (cachedValue == null) { List path2 = new ArrayList<>(path); path2.add("x"); @@ -525,13 +526,13 @@ public Quaterniond get() { double z = config.get(path2); path2.set(path.size(), "w"); double w = config.get(path2); - cachedValue = new Quaterniond(x, y, z, w); + cachedValue = new Quaternionf(x, y, z, w); } - return new Quaterniond(cachedValue); + return new Quaternionf(cachedValue); } @Override - public void set(Quaterniond newValue) { + public void set(Quaternionf newValue) { cachedValue = newValue; List path2 = new ArrayList<>(path); path2.add("x"); @@ -545,7 +546,7 @@ public void set(Quaterniond newValue) { } @Override - public Quaterniond reset() { + public Quaternionf reset() { List path2 = new ArrayList<>(path); path2.add("x"); config.set(path2, defaultValue.x); From 64192ae2234114b141af97cd9ccaf4ad95ad9398 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 13 Sep 2023 17:16:25 +0200 Subject: [PATCH 05/14] also the vector... --- .../org/vivecraft/client/ClientConfig.java | 9 ++--- .../client/gui/widgets/VectorWidget.java | 9 ++--- .../org/vivecraft/common/ConfigBuilder.java | 33 ++++++++++--------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index 225528df2..245a277a5 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -7,6 +7,7 @@ import org.joml.Quaterniond; import org.joml.Quaternionf; import org.joml.Vector3d; +import org.joml.Vector3f; import org.vivecraft.client_vr.gui.PhysicalKeyboard; import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.common.ConfigBuilder; @@ -245,7 +246,7 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe originOffset = builder .push("originOffset") .comment("") - .define(new Vector3d( 0d, 0d, 0d)); + .define(new Vector3f( 0f, 0f, 0f)); forceHardwareDetection = builder .push("forceHardwareDetection") .comment("0 = off, 1 = vive, 2 = oculus") //TODO enum? @@ -576,7 +577,7 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe fovRedutioncOffset = builder .push("fovReductionOffset") .comment("") - .defineInRange(0.1f,0d, 0.3d); + .defineInRange(0.1d,0d, 0.3d); builder.pop(); builder.push("camera"); @@ -591,11 +592,11 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe vrFixedCampos = builder .push("vrFixedCampos") .comment("") - .define(new Vector3d(-1.0d, 2.4d, 2.7d)); + .define(new Vector3f(-1.0f, 2.4f, 2.7f)); vrFixedCamrot = builder .push("vrFixedCamrot") .comment("") - .define(new Quaternionf(.962d, .125d, .239d, .041d)); + .define(new Quaternionf(.962f, .125f, .239f, .041f)); externalCameraAngleOrder = builder .push("externalCameraAngleOrder") .comment("") diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java b/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java index af84dbbb0..de59ae014 100644 --- a/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import org.joml.Quaterniond; import org.joml.Vector3d; +import org.joml.Vector3f; import org.vivecraft.common.ConfigBuilder; public class VectorWidget extends AbstractWidget { @@ -17,10 +18,10 @@ public class VectorWidget extends AbstractWidget { public VectorWidget(int i, int j, int k, int l, Component component, ConfigBuilder.VectorValue value) { super(i, j, k, l, component); - Vector3d vector = value.get(); - this.xBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i , j, (k-3) / 3, l , Component.literal(vector.x +""), vector.x, d -> value.set(new Vector3d(d, vector.y, vector.z))); - this.yBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i + ((k - 3) / 3) + 1, j, (k-3) / 3, l , Component.literal(vector.y +""), vector.y, d -> value.set(new Vector3d(vector.x, d, vector.z))); - this.zBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i + ((k-3) / 3)*2 + 2, j, (k-4) / 3, l , Component.literal(vector.z +""), vector.z, d -> value.set(new Vector3d(vector.x, vector.y, d))); + Vector3f vector = value.get(); + this.xBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i , j, (k-3) / 3, l , Component.literal(vector.x +""), vector.x, d -> value.set(new Vector3f(d, vector.y, vector.z))); + this.yBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i + ((k - 3) / 3) + 1, j, (k-3) / 3, l , Component.literal(vector.y +""), vector.y, d -> value.set(new Vector3f(vector.x, d, vector.z))); + this.zBox = new QuadWidget.NumberEditBox(Minecraft.getInstance().font, i + ((k-3) / 3)*2 + 2, j, (k-4) / 3, l , Component.literal(vector.z +""), vector.z, d -> value.set(new Vector3f(vector.x, vector.y, d))); } @Override diff --git a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java index 97784dfa7..c73fced1e 100644 --- a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -10,6 +10,7 @@ import org.joml.Quaterniond; import org.joml.Quaternionf; import org.joml.Vector3d; +import org.joml.Vector3f; import org.vivecraft.client.gui.settings.GuiListValueEditScreen; import org.vivecraft.client.gui.widgets.QuadWidget; import org.vivecraft.client.gui.widgets.SettingsList; @@ -83,7 +84,7 @@ private void addDefaultValueComment(List path, Quaternionf defaultValue) +"x: %.2f, y %.2f, z: %.2f, w: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z, defaultValue.w)); } - private void addDefaultValueComment(List path, Vector3d defaultValue) { + private void addDefaultValueComment(List path, Vector3f defaultValue) { String oldComment = config.getComment(path); config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") +"x: %.2f, y: %.2f, z: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z)); @@ -225,7 +226,7 @@ public QuatValue define(Quaternionf defaultValue) { return value; } - public VectorValue define(Vector3d defaultValue) { + public VectorValue define(Vector3f defaultValue) { List path = stack.stream().toList(); stack.add("x"); spec.define(stack.stream().toList(), defaultValue.x); @@ -519,13 +520,13 @@ public Quaternionf get() { if (cachedValue == null) { List path2 = new ArrayList<>(path); path2.add("x"); - double x = config.get(path2); + float x = config.get(path2); path2.set(path.size(), "y"); - double y = config.get(path2); + float y = config.get(path2); path2.set(path.size(), "z"); - double z = config.get(path2); + float z = config.get(path2); path2.set(path.size(), "w"); - double w = config.get(path2); + float w = config.get(path2); cachedValue = new Quaternionf(x, y, z, w); } return new Quaternionf(cachedValue); @@ -566,29 +567,29 @@ public AbstractWidget getWidget(int width, int height) { } } - public class VectorValue extends ConfigValue { + public class VectorValue extends ConfigValue { - public VectorValue(CommentedConfig config, List path, Vector3d defaultValue) { + public VectorValue(CommentedConfig config, List path, Vector3f defaultValue) { super(config, path, defaultValue); } @Override - public Vector3d get() { + public Vector3f get() { if (cachedValue == null) { List path2 = new ArrayList<>(path); path2.add("x"); - double x = config.get(path2); + float x = config.get(path2); path2.set(path.size(), "y"); - double y = config.get(path2); + float y = config.get(path2); path2.set(path.size(), "z"); - double z = config.get(path2); - cachedValue = new Vector3d(x, y, z); + float z = config.get(path2); + cachedValue = new Vector3f(x, y, z); } - return new Vector3d(cachedValue); + return new Vector3f(cachedValue); } @Override - public void set(Vector3d newValue) { + public void set(Vector3f newValue) { cachedValue = newValue; List path2 = new ArrayList<>(path); path2.add("x"); @@ -600,7 +601,7 @@ public void set(Vector3d newValue) { } @Override - public Vector3d reset() { + public Vector3f reset() { List path2 = new ArrayList<>(path); path2.add("x"); config.set(path2, defaultValue.x); From 899d0190c02e4dcd45603ad28bcb946709d7b06e Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:37:22 +0200 Subject: [PATCH 06/14] Update ClientConfig.java --- .../org/vivecraft/client/ClientConfig.java | 105 +++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index 245a277a5..8ec9d388c 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -164,7 +164,14 @@ public class ClientConfig { public static ConfigBuilder.StringValue RADIAL_6; public static ConfigBuilder.StringValue RADIAL_7; public static ConfigBuilder.StringValue RADIAL_8; - public static ConfigBuilder.StringValue RADIAL_9; + public static ConfigBuilder.StringValue RADIAL_ALT_1; + public static ConfigBuilder.StringValue RADIAL_ALT_2; + public static ConfigBuilder.StringValue RADIAL_ALT_3; + public static ConfigBuilder.StringValue RADIAL_ALT_4; + public static ConfigBuilder.StringValue RADIAL_ALT_5; + public static ConfigBuilder.StringValue RADIAL_ALT_6; + public static ConfigBuilder.StringValue RADIAL_ALT_7; + public static ConfigBuilder.StringValue RADIAL_ALT_8; //QuickCommand public static ConfigBuilder.StringValue QUICKCOMMAND_0; @@ -177,6 +184,8 @@ public class ClientConfig { public static ConfigBuilder.StringValue QUICKCOMMAND_7; public static ConfigBuilder.StringValue QUICKCOMMAND_8; public static ConfigBuilder.StringValue QUICKCOMMAND_9; + public static ConfigBuilder.StringValue QUICKCOMMAND_10; + public static ConfigBuilder.StringValue QUICKCOMMAND_11; //FOV public static ConfigBuilder.DoubleValue monoFOV; //TODO Dummy @@ -649,6 +658,100 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .defineInRange(16,0, 32); builder.pop(); + builder.push("radial"); + radialModeHold = builder + .push("radialModeHold") + .comment("") + .define(false); + RADIAL_1 = builder + .push("radial1") + .define("key.drop"); + RADIAL_2 = builder + .push("radial2") + .define("key.chat"); + RADIAL_3 = builder + .push("radial3") + .define("vivecraft.key.rotateRight"); + RADIAL_4 = builder + .push("radial4") + .define("key.pickItem"); + RADIAL_5 = builder + .push("radial5") + .define("vivecraft.key.toggleHandheldCam"); + RADIAL_6 = builder + .push("radial6") + .define("vivecraft.key.togglePlayerList"); + RADIAL_7 = builder + .push("radial7") + .define("vivecraft.key.rotateLeft"); + RADIAL_8 = builder + .push("radial8") + .define("vivecraft.key.quickTorch"); + RADIAL_ALT_1 = builder + .push("radialalt1") + .define(""); + RADIAL_ALT_2 = builder + .push("radialalt2") + .define(""); + RADIAL_ALT_3 = builder + .push("radialalt3") + .define(""); + RADIAL_ALT_4 = builder + .push("radialalt4") + .define(""); + RADIAL_ALT_5 = builder + .push("radialalt5") + .define(""); + RADIAL_ALT_6 = builder + .push("radialalt6") + .define(""); + RADIAL_ALT_7 = builder + .push("radialalt7") + .define(""); + RADIAL_ALT_8 = builder + .push("radialalt8") + .define(""); + builder.pop(); + + builder.push("quickcommands"); + QUICKCOMMAND_0 = builder + .push("command0") + .define("/gamemode survival"); + QUICKCOMMAND_1 = builder + .push("command1") + .define("/gamemode creative"); + QUICKCOMMAND_2 = builder + .push("command2") + .define("/help"); + QUICKCOMMAND_3 = builder + .push("command3") + .define("/home"); + QUICKCOMMAND_4 = builder + .push("command4") + .define("/sethome"); + QUICKCOMMAND_5 = builder + .push("command5") + .define("/spawn"); + QUICKCOMMAND_6 = builder + .push("command6") + .define("hi!"); + QUICKCOMMAND_7 = builder + .push("command7") + .define("bye!"); + QUICKCOMMAND_8 = builder + .push("command8") + .define("follow me!"); + QUICKCOMMAND_9 = builder + .push("command9") + .define("take this!"); + QUICKCOMMAND_10 = builder + .push("command10") + .define("thank you!"); + QUICKCOMMAND_11 = builder + .push("command11") + .define("praise the sun!"); + builder.pop(); + builder.correct(listener); } From 9adfeba65b81f67c8af593562137740bcb1da5b7 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 13 Sep 2023 22:12:31 +0200 Subject: [PATCH 07/14] rework radial and commands --- .../org/vivecraft/client/ClientConfig.java | 175 ++++++------------ .../gui/settings/GuiArrayValueEditScreen.java | 122 ++++++++++++ .../org/vivecraft/common/ConfigBuilder.java | 93 ++++++++++ 3 files changed, 275 insertions(+), 115 deletions(-) create mode 100644 common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index 8ec9d388c..a53ad5f2f 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -4,15 +4,12 @@ import com.electronwill.nightconfig.core.Config; import com.electronwill.nightconfig.core.ConfigSpec; import com.electronwill.nightconfig.core.file.CommentedFileConfig; -import org.joml.Quaterniond; import org.joml.Quaternionf; -import org.joml.Vector3d; import org.joml.Vector3f; import org.vivecraft.client_vr.gui.PhysicalKeyboard; import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.common.ConfigBuilder; import org.vivecraft.common.utils.math.Angle; -import org.vivecraft.common.utils.math.Quaternion; import java.util.List; @@ -156,36 +153,11 @@ public class ClientConfig { //Radial public static ConfigBuilder.BooleanValue radialModeHold; - public static ConfigBuilder.StringValue RADIAL_1; - public static ConfigBuilder.StringValue RADIAL_2; - public static ConfigBuilder.StringValue RADIAL_3; - public static ConfigBuilder.StringValue RADIAL_4; - public static ConfigBuilder.StringValue RADIAL_5; - public static ConfigBuilder.StringValue RADIAL_6; - public static ConfigBuilder.StringValue RADIAL_7; - public static ConfigBuilder.StringValue RADIAL_8; - public static ConfigBuilder.StringValue RADIAL_ALT_1; - public static ConfigBuilder.StringValue RADIAL_ALT_2; - public static ConfigBuilder.StringValue RADIAL_ALT_3; - public static ConfigBuilder.StringValue RADIAL_ALT_4; - public static ConfigBuilder.StringValue RADIAL_ALT_5; - public static ConfigBuilder.StringValue RADIAL_ALT_6; - public static ConfigBuilder.StringValue RADIAL_ALT_7; - public static ConfigBuilder.StringValue RADIAL_ALT_8; + public static ConfigBuilder.ArrayValue main; + public static ConfigBuilder.ArrayValue alt; //QuickCommand - public static ConfigBuilder.StringValue QUICKCOMMAND_0; - public static ConfigBuilder.StringValue QUICKCOMMAND_1; - public static ConfigBuilder.StringValue QUICKCOMMAND_2; - public static ConfigBuilder.StringValue QUICKCOMMAND_3; - public static ConfigBuilder.StringValue QUICKCOMMAND_4; - public static ConfigBuilder.StringValue QUICKCOMMAND_5; - public static ConfigBuilder.StringValue QUICKCOMMAND_6; - public static ConfigBuilder.StringValue QUICKCOMMAND_7; - public static ConfigBuilder.StringValue QUICKCOMMAND_8; - public static ConfigBuilder.StringValue QUICKCOMMAND_9; - public static ConfigBuilder.StringValue QUICKCOMMAND_10; - public static ConfigBuilder.StringValue QUICKCOMMAND_11; + public static ConfigBuilder.ArrayValue commands; //FOV public static ConfigBuilder.DoubleValue monoFOV; //TODO Dummy @@ -663,96 +635,69 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("radialModeHold") .comment("") .define(false); - RADIAL_1 = builder - .push("radial1") - .define("key.drop"); - RADIAL_2 = builder - .push("radial2") - .define("key.chat"); - RADIAL_3 = builder - .push("radial3") - .define("vivecraft.key.rotateRight"); - RADIAL_4 = builder - .push("radial4") - .define("key.pickItem"); - RADIAL_5 = builder - .push("radial5") - .define("vivecraft.key.toggleHandheldCam"); - RADIAL_6 = builder - .push("radial6") - .define("vivecraft.key.togglePlayerList"); - RADIAL_7 = builder - .push("radial7") - .define("vivecraft.key.rotateLeft"); - RADIAL_8 = builder - .push("radial8") - .define("vivecraft.key.quickTorch"); - RADIAL_ALT_1 = builder - .push("radialalt1") - .define(""); - RADIAL_ALT_2 = builder - .push("radialalt2") - .define(""); - RADIAL_ALT_3 = builder - .push("radialalt3") - .define(""); - RADIAL_ALT_4 = builder - .push("radialalt4") - .define(""); - RADIAL_ALT_5 = builder - .push("radialalt5") - .define(""); - RADIAL_ALT_6 = builder - .push("radialalt6") - .define(""); - RADIAL_ALT_7 = builder - .push("radialalt7") - .define(""); - RADIAL_ALT_8 = builder - .push("radialalt8") - .define(""); + main = builder + .push("main") + .define(getRadialItemsDefault(), String.class, s -> s); + alt = builder + .push("alt") + .define(getRadialItemsAltDefault(), String.class, s -> s); builder.pop(); builder.push("quickcommands"); - QUICKCOMMAND_0 = builder - .push("command0") - .define("/gamemode survival"); - QUICKCOMMAND_1 = builder - .push("command1") - .define("/gamemode creative"); - QUICKCOMMAND_2 = builder - .push("command2") - .define("/help"); - QUICKCOMMAND_3 = builder - .push("command3") - .define("/home"); - QUICKCOMMAND_4 = builder - .push("command4") - .define("/sethome"); - QUICKCOMMAND_5 = builder - .push("command5") - .define("/spawn"); - QUICKCOMMAND_6 = builder - .push("command6") - .define("hi!"); - QUICKCOMMAND_7 = builder - .push("command7") - .define("bye!"); - QUICKCOMMAND_8 = builder - .push("command8") - .define("follow me!"); - QUICKCOMMAND_9 = builder - .push("command9") - .define("take this!"); - QUICKCOMMAND_10 = builder - .push("command10") - .define("thank you!"); - QUICKCOMMAND_11 = builder - .push("command11") - .define("praise the sun!"); + commands = builder + .push("commands") + .define(getQuickCommandsDefaults(), String.class, s -> s); builder.pop(); builder.correct(listener); } + + public static String[] getRadialItemsDefault(){ + String[] out = new String[8]; + out[0] = "key.drop"; + out[1] = "key.chat"; + out[2] = "vivecraft.key.rotateRight"; + out[3] = "key.pickItem"; + out[4] = "vivecraft.key.toggleHandheldCam"; + out[5] = "vivecraft.key.togglePlayerList"; + out[6] = "vivecraft.key.rotateLeft"; + out[7] = "vivecraft.key.quickTorch"; + + return out; + } + + public static String[] getRadialItemsAltDefault(){ + String[] out = new String[8]; + out[0] = ""; + out[1] = ""; + out[2] = ""; + out[3] = ""; + out[4] = ""; + out[5] = ""; + out[6] = ""; + out[7] = ""; + + return out; + } + + public static String[] getQuickCommandsDefaults(){ + + String[] out = new String[12]; + out[0] = "/gamemode survival"; + out[1] = "/gamemode creative"; + out[2] = "/help"; + out[3] = "/home"; + out[4] = "/sethome"; + out[5] = "/spawn"; + out[6] = "hi!"; + out[7] = "bye!"; + out[8] = "follow me!"; + out[9] = "take this!"; + out[10] = "thank you!"; + out[11] = "praise the sun!"; + + return out; + + } } diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java new file mode 100644 index 000000000..7b733c48a --- /dev/null +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java @@ -0,0 +1,122 @@ +package org.vivecraft.client.gui.settings; + +import com.google.common.collect.ImmutableList; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import org.vivecraft.client.gui.widgets.SettingsList; +import org.vivecraft.common.ConfigBuilder; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.function.BooleanSupplier; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class GuiArrayValueEditScreen extends GuiListScreen{ + private final ConfigBuilder.ArrayValue arrayValue; + private final Function fromString; + private T[] elements; + + public GuiArrayValueEditScreen(Component title, Screen lastScreen, ConfigBuilder.ArrayValue arrayValue, Function fromString) { + super(title, lastScreen); + this.arrayValue = arrayValue; + this.fromString = fromString; + } + + @Override + protected void init() { + clearWidgets(); + double scrollAmount = list != null? list.getScrollAmount() : 0.0D; + + this.list = new SettingsList(this, minecraft, getEntries()); + list.setScrollAmount(scrollAmount); + this.addWidget(this.list); + + this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> { + arrayValue.set(getCurrentValues()); + this.minecraft.setScreen(this.lastScreen); + }).bounds(this.width / 2 - 155, this.height - 27, 150, 20).build()); + + this.addRenderableWidget(Button + .builder(CommonComponents.GUI_CANCEL, button -> this.minecraft.setScreen(this.lastScreen)) + .bounds(this.width / 2 + 5, this.height - 27, 150, 20) + .build()); + } + + @Override + protected List getEntries() { + List entries = new LinkedList<>(); + if (elements == null) { + elements = Arrays.copyOf(arrayValue.get(), arrayValue.get().length); + } + int i = 0; + for (T item : elements) { + EditBox box = new EditBox(Minecraft.getInstance().font, 0, 0, ArrayResetEntry.valueButtonWidth - 1, 20, Component.literal(item + "")); + box.setMaxLength(1000); + box.setValue(item + ""); + int index = i++; + entries.add(new ArrayResetEntry(Component.empty(), box, () -> !fromString.apply(box.getValue()).equals(arrayValue.getDefault()[index]), button -> {elements[index] = arrayValue.get()[index];reinit = true;})); + } + return entries; + } + + private T[] getCurrentValues(){ + return (T[]) list.children().stream().map(entry -> { + if (entry instanceof ArrayResetEntry arrayResetEntry) { + return fromString.apply(arrayResetEntry.getString()); + } else { + return fromString.apply(""); + } + }).collect(Collectors.toList()).toArray(); + } + + private static class ArrayResetEntry extends SettingsList.WidgetEntry { + public static final int valueButtonWidth = 280; + private final BooleanSupplier canReset; + private final Button resetButton; + + public ArrayResetEntry(Component name, EditBox valueWidget, BooleanSupplier canReset, Button.OnPress resetAction) { + super(name, valueWidget); + this.canReset = canReset; + + this.resetButton = Button.builder(Component.literal("X"), resetAction) + .tooltip(Tooltip.create(Component.translatable("controls.reset"))) + .bounds(0, 0, 20, 20).build(); + } + + @Override + public void render(GuiGraphics guiGraphics, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f) { + this.valueWidget.setX(k + -50); + this.valueWidget.setY(j); + this.valueWidget.render(guiGraphics, n, o, f); + this.resetButton.setX(k + 230); + this.resetButton.setY(j); + this.resetButton.active = canReset.getAsBoolean(); + this.resetButton.render(guiGraphics, n, o, f); + } + + @Override + public List children() { + return ImmutableList.of(this.valueWidget, this.resetButton); + } + + @Override + public List narratables() { + return ImmutableList.of(this.valueWidget, this.resetButton); + } + + public String getString() { + return ((EditBox)valueWidget).getValue(); + } + } +} diff --git a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java index c73fced1e..58adec4ae 100644 --- a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -11,12 +11,15 @@ import org.joml.Quaternionf; import org.joml.Vector3d; import org.joml.Vector3f; +import org.vivecraft.client.gui.settings.GuiArrayValueEditScreen; import org.vivecraft.client.gui.settings.GuiListValueEditScreen; import org.vivecraft.client.gui.widgets.QuadWidget; import org.vivecraft.client.gui.widgets.SettingsList; import org.vivecraft.client.gui.widgets.VectorWidget; +import java.lang.reflect.Array; import java.util.*; +import java.util.function.Function; import java.util.function.Predicate; public class ConfigBuilder { @@ -245,6 +248,24 @@ public VectorValue define(Vector3f defaultValue) { return value; } + public ArrayValue define(T[] defaultValue, Class clazz, Function fromString) { + List path = stack.stream().toList(); + stack.add("size"); + spec.define(stack.stream().toList(), defaultValue.length); + stack.removeLast(); + for (int i = 0; i< defaultValue.length; i++) { + stack.add(i + ""); + spec.define(stack.stream().toList(), defaultValue[i]); + stack.removeLast(); + } + stack.removeLast(); + + ArrayValue value = new ArrayValue<>(config, path, defaultValue, clazz, fromString); + configValues.add(value); + return value; + + } + /** * same as {@link #defineInRange defineInRange(T defaultValue, T min, T max)} but returns a {@link DoubleValue} */ @@ -618,4 +639,76 @@ public AbstractWidget getWidget(int width, int height) { return new VectorWidget(0,0, width, height, Component.literal(get().toString()), this); } } + + public static class ArrayValue extends ConfigValue { + + private final Class clazz; + private final Function fromString; + + public ArrayValue(CommentedConfig config, List path, T[] defaultValue, Class clazz, Function fromString) { + super(config, path, defaultValue); + this.clazz = clazz; + this.fromString = fromString; + } + + @Override + public T[] get() { + if (cachedValue == null) { + List path2 = new ArrayList<>(path); + path2.add("size"); + int size = config.get(path2); + T[] array = (T[]) Array.newInstance(clazz, size); + for (int i = 0; i < size; i++) { + path2.set(path.size(), i + ""); + T value = config.get(path2); + array[i] = value; + } + cachedValue = array; + } + return cachedValue; + } + + @Override + public void set(T[] newValue) { + cachedValue = newValue; + List path2 = new ArrayList<>(path); + path2.add("size"); + config.set(path2, newValue.length); + for (int i = 0; i< newValue.length; i++) { + path2.set(path.size(), i + ""); + config.set(path2, newValue[i]); + } + } + + @Override + public T[] reset() { + List path2 = new ArrayList<>(path); + path2.add("size"); + config.set(path2, defaultValue.length); + for (int i = 0; i< defaultValue.length; i++) { + path2.set(path.size(), i + ""); + config.set(path2, defaultValue[i]); + } + cachedValue = defaultValue; + return defaultValue; + } + + public T[] getDefault() { + return defaultValue; + } + + @Override + public AbstractWidget getWidget(int width, int height) { + return Button + .builder( + Component.translatable("vivecraft.options.editarray"), + button -> Minecraft.getInstance() + .setScreen( + new GuiArrayValueEditScreen<>(Component.literal(getPath().substring(getPath().lastIndexOf("."))), Minecraft.getInstance().screen, this, fromString) + )) + .size(width, height) + .tooltip(Tooltip.create(Component.literal(getComment()))) + .build(); + } + } } From 2e5991d14a00c178448283846761f5be9ba15dbf Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:00:04 +0200 Subject: [PATCH 08/14] remove size and fix reset --- .../gui/settings/GuiArrayValueEditScreen.java | 2 +- .../java/org/vivecraft/common/ConfigBuilder.java | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java index 7b733c48a..6489faae6 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java @@ -65,7 +65,7 @@ protected List getEntries() { box.setMaxLength(1000); box.setValue(item + ""); int index = i++; - entries.add(new ArrayResetEntry(Component.empty(), box, () -> !fromString.apply(box.getValue()).equals(arrayValue.getDefault()[index]), button -> {elements[index] = arrayValue.get()[index];reinit = true;})); + entries.add(new ArrayResetEntry(Component.empty(), box, () -> !fromString.apply(box.getValue()).equals(arrayValue.getDefault()[index]), button -> {elements[index] = arrayValue.getDefault()[index];reinit = true;})); } return entries; } diff --git a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java index 58adec4ae..67281b369 100644 --- a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -250,9 +250,6 @@ public VectorValue define(Vector3f defaultValue) { public ArrayValue define(T[] defaultValue, Class clazz, Function fromString) { List path = stack.stream().toList(); - stack.add("size"); - spec.define(stack.stream().toList(), defaultValue.length); - stack.removeLast(); for (int i = 0; i< defaultValue.length; i++) { stack.add(i + ""); spec.define(stack.stream().toList(), defaultValue[i]); @@ -655,10 +652,9 @@ public ArrayValue(CommentedConfig config, List path, T[] defaultValue, C public T[] get() { if (cachedValue == null) { List path2 = new ArrayList<>(path); - path2.add("size"); - int size = config.get(path2); - T[] array = (T[]) Array.newInstance(clazz, size); - for (int i = 0; i < size; i++) { + path2.add("0"); + T[] array = (T[]) Array.newInstance(clazz, defaultValue.length); + for (int i = 0; i < defaultValue.length; i++) { path2.set(path.size(), i + ""); T value = config.get(path2); array[i] = value; @@ -672,8 +668,7 @@ public T[] get() { public void set(T[] newValue) { cachedValue = newValue; List path2 = new ArrayList<>(path); - path2.add("size"); - config.set(path2, newValue.length); + path2.add("0"); for (int i = 0; i< newValue.length; i++) { path2.set(path.size(), i + ""); config.set(path2, newValue[i]); @@ -683,7 +678,7 @@ public void set(T[] newValue) { @Override public T[] reset() { List path2 = new ArrayList<>(path); - path2.add("size"); + path2.add("0"); config.set(path2, defaultValue.length); for (int i = 0; i< defaultValue.length; i++) { path2.set(path.size(), i + ""); From b540ec89d5a6c3bfbe6a89b6a7b7ae8ceab98a3c Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:28:45 +0200 Subject: [PATCH 09/14] cast to double --- .../org/vivecraft/client/ClientConfig.java | 2 +- .../org/vivecraft/common/ConfigBuilder.java | 58 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index a53ad5f2f..6507e5a05 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -243,7 +243,7 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe manualCalibration = builder .push("manualCalibration") .comment("") - .defineInRange(-1d, 0d, 5d); //TODO check + .defineInRange(-1.0d, -1.0d, 5.0d); //TODO check rightclickDelay = builder .push("rightclickDelay") .comment("") diff --git a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java index 67281b369..c09cf6964 100644 --- a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -210,16 +210,16 @@ public > EnumValue define(T defaultValue) { public QuatValue define(Quaternionf defaultValue) { List path = stack.stream().toList(); stack.add("x"); - spec.define(stack.stream().toList(), defaultValue.x); + spec.define(stack.stream().toList(), (double) defaultValue.x); stack.removeLast(); stack.add("y"); - spec.define(stack.stream().toList(), defaultValue.y); + spec.define(stack.stream().toList(), (double) defaultValue.y); stack.removeLast(); stack.add("z"); - spec.define(stack.stream().toList(), defaultValue.z); + spec.define(stack.stream().toList(), (double) defaultValue.z); stack.removeLast(); stack.add("w"); - spec.define(stack.stream().toList(), defaultValue.w); + spec.define(stack.stream().toList(), (double) defaultValue.w); stack.removeLast(); stack.removeLast(); @@ -232,13 +232,13 @@ public QuatValue define(Quaternionf defaultValue) { public VectorValue define(Vector3f defaultValue) { List path = stack.stream().toList(); stack.add("x"); - spec.define(stack.stream().toList(), defaultValue.x); + spec.define(stack.stream().toList(), (double) defaultValue.x); stack.removeLast(); stack.add("y"); - spec.define(stack.stream().toList(), defaultValue.y); + spec.define(stack.stream().toList(), (double) defaultValue.y); stack.removeLast(); stack.add("z"); - spec.define(stack.stream().toList(), defaultValue.z); + spec.define(stack.stream().toList(), (double) defaultValue.z); stack.removeLast(); stack.removeLast(); @@ -538,13 +538,13 @@ public Quaternionf get() { if (cachedValue == null) { List path2 = new ArrayList<>(path); path2.add("x"); - float x = config.get(path2); + double x = config.get(path2); path2.set(path.size(), "y"); - float y = config.get(path2); + double y = config.get(path2); path2.set(path.size(), "z"); - float z = config.get(path2); + double z = config.get(path2); path2.set(path.size(), "w"); - float w = config.get(path2); + double w = config.get(path2); cachedValue = new Quaternionf(x, y, z, w); } return new Quaternionf(cachedValue); @@ -555,26 +555,26 @@ public void set(Quaternionf newValue) { cachedValue = newValue; List path2 = new ArrayList<>(path); path2.add("x"); - config.set(path2, newValue.x); + config.set(path2, (double) newValue.x); path2.set(path.size(), "y"); - config.set(path2, newValue.y); + config.set(path2, (double) newValue.y); path2.set(path.size(), "z"); - config.set(path2, newValue.z); + config.set(path2, (double) newValue.z); path2.set(path.size(), "w"); - config.set(path2, newValue.w); + config.set(path2, (double) newValue.w); } @Override public Quaternionf reset() { List path2 = new ArrayList<>(path); path2.add("x"); - config.set(path2, defaultValue.x); + config.set(path2, (double) defaultValue.x); path2.set(path.size(), "y"); - config.set(path2, defaultValue.y); + config.set(path2, (double) defaultValue.y); path2.set(path.size(), "z"); - config.set(path2, defaultValue.z); + config.set(path2, (double) defaultValue.z); path2.set(path.size(), "w"); - config.set(path2, defaultValue.w); + config.set(path2, (double) defaultValue.w); cachedValue = defaultValue; return defaultValue; } @@ -596,12 +596,12 @@ public Vector3f get() { if (cachedValue == null) { List path2 = new ArrayList<>(path); path2.add("x"); - float x = config.get(path2); + double x = config.get(path2); path2.set(path.size(), "y"); - float y = config.get(path2); + double y = config.get(path2); path2.set(path.size(), "z"); - float z = config.get(path2); - cachedValue = new Vector3f(x, y, z); + double z = config.get(path2); + cachedValue = new Vector3f((float) x, (float) y, (float) z); } return new Vector3f(cachedValue); } @@ -611,22 +611,22 @@ public void set(Vector3f newValue) { cachedValue = newValue; List path2 = new ArrayList<>(path); path2.add("x"); - config.set(path2, newValue.x); + config.set(path2, (double) newValue.x); path2.set(path.size(), "y"); - config.set(path2, newValue.y); + config.set(path2, (double) newValue.y); path2.set(path.size(), "z"); - config.set(path2, newValue.z); + config.set(path2, (double) newValue.z); } @Override public Vector3f reset() { List path2 = new ArrayList<>(path); path2.add("x"); - config.set(path2, defaultValue.x); + config.set(path2, (double) defaultValue.x); path2.set(path.size(), "y"); - config.set(path2, defaultValue.y); + config.set(path2, (double) defaultValue.y); path2.set(path.size(), "z"); - config.set(path2, defaultValue.z); + config.set(path2, (double) defaultValue.z); cachedValue = defaultValue; return defaultValue; } From 1e063852739f65902d5f4d04fac5aa2bbbbbf552 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Thu, 14 Sep 2023 10:17:21 +0200 Subject: [PATCH 10/14] MR + array and enum equals fix --- .../org/vivecraft/client/ClientConfig.java | 54 ++++++++++++++++--- .../org/vivecraft/common/ConfigBuilder.java | 19 +++---- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index 6507e5a05..2ea4e7fbd 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -25,16 +25,11 @@ public class ClientConfig { public static ConfigBuilder.EnumValue physicalKeyboardTheme; //MR - public static ConfigBuilder.DoubleValue mrMovingCamOffsetZ; - public static ConfigBuilder.DoubleValue mrMovingCamOffsetY; - public static ConfigBuilder.DoubleValue mrMovingCamOffsetX; + public static ConfigBuilder.VectorValue mrMovingCamOffset; + public static ConfigBuilder.QuatValue mrMovingCamOffsetRot; public static ConfigBuilder.StringValue mixedRealityKeyColor; public static ConfigBuilder.BooleanValue mixedRealityAlphaMask; - public static ConfigBuilder.DoubleValue mixedRealityFov; - public static ConfigBuilder.DoubleValue mrMovingCamOffsetRotW; - public static ConfigBuilder.DoubleValue mrMovingCamOffsetRotZ; - public static ConfigBuilder.DoubleValue mrMovingCamOffsetRotY; - public static ConfigBuilder.DoubleValue mrMovingCamOffsetRotX; + public static ConfigBuilder.IntValue mixedRealityFov; public static ConfigBuilder.BooleanValue mixedRealityRenderCameraModel; public static ConfigBuilder.BooleanValue mixedRealityUndistorted; public static ConfigBuilder.BooleanValue mixedRealityUnityLike; @@ -288,6 +283,10 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("insideblock") .comment("If the the inside of a block should be solid black") .define(false); + renderBlockOutlineMode = builder + .push("renderBlockOutlineMode") + .comment("") + .define(VRSettings.RenderPointerElement.ALWAYS); displayMirrorLeftEye = builder .push("lefteye") .comment("Use the left eye instead of the right eye for the mirror") @@ -649,6 +648,45 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .define(getQuickCommandsDefaults(), String.class, s -> s); builder.pop(); + builder.push("mixedReality"); + mrMovingCamOffset = builder + .push("mrMovingCamOffset") + .comment("") + .define(new Vector3f(0f, 0f, 0f)); + mrMovingCamOffsetRot = builder + .push("mrMovingCamOffsetRot") + .comment("") + .define(new Quaternionf()); + mixedRealityKeyColor = builder + .push("mixedRealityKeyColor") + .comment("") + .define("#000000"); + mixedRealityAlphaMask = builder + .push("mixedRealityAlphaMask") + .comment("") + .define(false); + mixedRealityFov = builder + .push("mixedRealityFov") + .comment("") + .defineInRange(40, 0, 179); + mixedRealityRenderCameraModel = builder + .push("mixedRealityRenderCameraModel") + .comment("") + .define(true); + mixedRealityUndistorted = builder + .push("mixedRealityUndistorted") + .comment("") + .define(true); + mixedRealityUnityLike = builder + .push("mixedRealityUnityLike") + .comment("") + .define(true); + mixedRealityRenderHands = builder + .push("mixedRealityRenderHands") + .comment("") + .define(false); + builder.pop(); + builder.correct(listener); } diff --git a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java index c09cf6964..69292b7cd 100644 --- a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -326,6 +326,9 @@ public T reset() { } public boolean isDefault() { + if (get() instanceof Object[]) { + return Arrays.equals((Object[]) get(), (Object[]) defaultValue); + } return Objects.equals(get(), defaultValue); } public String getComment() { @@ -505,25 +508,23 @@ public EnumValue(CommentedConfig config, List path, T defaultValue) { super(config, path, defaultValue); } - public void cycle() { - T[] enumConstants = defaultValue.getDeclaringClass().getEnumConstants(); - int newIndex = this.get().ordinal() + 1; - if (enumConstants.length == newIndex) { - newIndex = 0; + @Override + public T get() { + if (cachedValue == null) { + cachedValue = config.getEnumOrElse(path, defaultValue); } - this.set(enumConstants[newIndex]); + return cachedValue; } @Override public AbstractWidget getWidget(int width, int height) { return CycleButton - .builder((newValue) -> Component.literal("" + newValue)) + .builder(newValue -> Component.literal(newValue.toString())) .withInitialValue(get()) - // toArray is needed here, because the button uses Objects, and the collection is of other types .withValues(defaultValue.getDeclaringClass().getEnumConstants()) .displayOnlyValue() .withTooltip((bool) -> getComment() != null ? Tooltip.create(Component.literal(getComment())) : null) - .create(0, 0, width, height, Component.empty(), (button, newValue) -> set((T) newValue)); + .create(0, 0, width, height, Component.empty(), (button, newValue) -> set(newValue)); } } From b84e30d1728b54a0d10e79cd4a73abcd03008c1a Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Mon, 25 Sep 2023 19:48:50 +0200 Subject: [PATCH 11/14] new layout --- .../org/vivecraft/client/ClientConfig.java | 183 +++++++++++++++++- .../gui/settings/GuiConfigListScreen.java | 29 +++ .../gui/settings/VivecraftMainSettings.java | 79 ++++++++ 3 files changed, 287 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/org/vivecraft/client/gui/settings/GuiConfigListScreen.java diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index 2ea4e7fbd..37874e97e 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -4,6 +4,7 @@ import com.electronwill.nightconfig.core.Config; import com.electronwill.nightconfig.core.ConfigSpec; import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import net.minecraft.network.chat.Component; import org.joml.Quaternionf; import org.joml.Vector3f; import org.vivecraft.client_vr.gui.PhysicalKeyboard; @@ -72,7 +73,6 @@ public class ClientConfig { public static ConfigBuilder.DoubleValue crosshairScale; public static ConfigBuilder.DoubleValue renderScaleFactor; - //HUD public static ConfigBuilder.BooleanValue lowHealthIndicator; public static ConfigBuilder.DoubleValue hudDistance; @@ -102,7 +102,7 @@ public class ClientConfig { //Teleport public static ConfigBuilder.BooleanValue limitedTeleport; //Server setting? - public static ConfigBuilder.IntValue teleportLimitDown; + public static ConfigBuilder.IntValue teleportLimitDown; //Vector? public static ConfigBuilder.IntValue teleportLimitHoriz; public static ConfigBuilder.IntValue teleportLimitUp; @@ -120,7 +120,7 @@ public class ClientConfig { public static ConfigBuilder.BooleanValue vrHotswitchingEnabled; public static ConfigBuilder.BooleanValue vrEnabled; public static ConfigBuilder.IntValue worldRotation; - public static ConfigBuilder.DoubleValue vrWorldRotationIncrement; + public static ConfigBuilder.IntValue vrWorldRotationIncrement; public static ConfigBuilder.IntValue worldScale; public static ConfigBuilder.VectorValue originOffset; public static ConfigBuilder.IntValue version; @@ -167,6 +167,173 @@ public static List getConfigValues(){ return builder.getConfigValues(); } + public static ConfigBuilder.ConfigValue[] generalConfig() { + return new ConfigBuilder.ConfigValue[]{ + vrEnabled, + vrHotswitchingEnabled, + version, + worldScale, + worldRotation, + vrWorldRotationIncrement, + allowStandingOriginOffset, + originOffset, + forceHardwareDetection, + stereoProviderPluginID, + reverseHands, + analogMovement, + manualCalibration, + rightclickDelay, + thirdPersonItems, + bcbOn, + allowAdvancedBindings, + xSensitivity, + ySensitivity, + keyholeX, + useFsaa, + displayMirrorLeftEye, + disableFun, + menuWorldSelection, + insideBlockSolidColor, + renderBlockOutlineMode, + hrtfSelection + }; + } + + public static ConfigBuilder.ConfigValue[] keyboardConfig() { + return new ConfigBuilder.ConfigValue[]{ + physicalKeyboard, + autoOpenKeyboard, + alwaysSimulateKeyboard, + keyboardKeys, + keyboardKeysShift, + physicalKeyboardScale, + physicalKeyboardTheme + }; + } + + public static ConfigBuilder.ConfigValue[] mrConfig() { + return new ConfigBuilder.ConfigValue[]{ + mrMovingCamOffset, + mrMovingCamOffsetRot, + mixedRealityKeyColor, + mixedRealityAlphaMask, + mixedRealityFov, + mixedRealityRenderCameraModel, + mixedRealityUndistorted, + mixedRealityUnityLike, + mixedRealityRenderHands + }; + } + + public static ConfigBuilder.ConfigValue[] roomScaleConfig() { + return new ConfigBuilder.ConfigValue[]{ + realisticSneakEnabled, + sneakThreshold, + realisticJumpEnabled, + jumpThreshold, + autoSprint, + autoSprintThreshold, + allowCrawling, + crawlThreshold, + realisticClimbEnabled, + realisticRowEnabled, + realisticSwimEnabled, + movementSpeedMultiplier, + walkMultiplier, + weaponCollision, + bowMode, + walkUpBlocks, + backpackSwitching, + vrTouchHotbar, + guiAppearOverBlock, + physicalGuiEnabled, + inertiaFactor, + vehicleRotation + }; + } + + public static ConfigBuilder.ConfigValue[] displayConfig() { + return new ConfigBuilder.ConfigValue[]{ + displayMirrorMode, + useCrosshairOcclusion, + menuCrosshairScale, + crosshairScalesWithDistance, + menuBackground, + menuAlwaysFollowFace, + renderInGameCrosshairMode, + shaderGUIRender, + hideGUI, + crosshairScale, + renderScaleFactor + }; + } + + public static ConfigBuilder.ConfigValue[] hudConfig() { + return new ConfigBuilder.ConfigValue[]{ + lowHealthIndicator, + hudDistance, + hudPitchOffset, + hudYawOffset, + stencilOn, + headHudScale, + headToHmdLength, + hudOcclusion, + hudOpacity, + vrHudLockMode + }; + } + + public static ConfigBuilder.ConfigValue[] cameraConfig() { + return new ConfigBuilder.ConfigValue[]{ + handCameraResScale, + handCameraFov, + vrFixedCampos, + vrFixedCamrot, + externalCameraAngleOrder + }; + } + + public static ConfigBuilder.ConfigValue[] updateConfig() { + return new ConfigBuilder.ConfigValue[]{ + firstRun, + lastUpdate, + alwaysShowUpdates, + chatNotifications, + showServerPluginMessage, + chatNotificationSound + }; + } + + public static ConfigBuilder.ConfigValue[] teleportConfig() { + return new ConfigBuilder.ConfigValue[]{ + limitedTeleport, + teleportLimitDown, + teleportLimitHoriz, + teleportLimitUp + }; + } + + public static ConfigBuilder.ConfigValue[] seatedConfig() { + return new ConfigBuilder.ConfigValue[]{ + seated, + seatedhmd, + seatedHudAltMode, + seatedFreeMove, + forceStandingFreeMove, + vrFreeMoveFlyMode, + vrFreeMoveMode + }; + } + + public static ConfigBuilder.ConfigValue[] fovConfig() { + return new ConfigBuilder.ConfigValue[]{ + monoFOV, + fovReductionMin, + fovRedutioncOffset, + fovReduction + }; + } + public static void init(ConfigSpec.CorrectionListener listener){ Config.setInsertionOrderPreserved(true); config = CommentedFileConfig @@ -203,6 +370,10 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("hotswitch") .comment("Allow hotswitch between VR and nonVR") .define(true); + version = builder + .push("version") + .comment("Compatibility version used on servers") + .defineInRange(0, 0, 0); worldScale = builder .push("worldscale") .comment("") @@ -214,7 +385,7 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe vrWorldRotationIncrement = builder .push("vrWorldRotationIncrement") .comment("") - .defineInRange(45d,-1d, 4d); //TODO Looks wrong? + .defineInRange(45,0, 180); allowStandingOriginOffset = builder .push("allowStandingOriginOffset") .comment("") @@ -231,6 +402,10 @@ private static void fixConfig(CommentedConfig config, ConfigSpec.CorrectionListe .push("stereoProviderPluginID") .comment("") .define(VRSettings.VRProvider.OPENVR); + reverseHands = builder + .push("reverseHands") + .comment("Change the main hand to left") + .define(false); analogMovement = builder .push("analogMovement") .comment("") diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiConfigListScreen.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiConfigListScreen.java new file mode 100644 index 000000000..9d35b30a1 --- /dev/null +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiConfigListScreen.java @@ -0,0 +1,29 @@ +package org.vivecraft.client.gui.settings; + +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import org.vivecraft.client.gui.widgets.SettingsList; +import org.vivecraft.common.ConfigBuilder; + +import java.util.LinkedList; +import java.util.List; + +public class GuiConfigListScreen extends GuiListScreen{ + private final ConfigBuilder.ConfigValue[] config; + + public GuiConfigListScreen(Component title, Screen lastScreen, ConfigBuilder.ConfigValue ... config) { + super(title, lastScreen); + this.config = config; + } + + @Override + protected List getEntries() { + List entries = new LinkedList<>(); + for (ConfigBuilder.ConfigValue value : config) { + String path = value.getPath(); + String name = path.substring(path.lastIndexOf(".") + 1); + entries.add(SettingsList.ConfigToEntry(value, Component.literal(name))); + } + return entries; + } +} diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java b/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java index 26f32fec7..59c78d600 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java @@ -4,6 +4,7 @@ import net.minecraft.client.gui.components.*; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; +import org.vivecraft.client.ClientConfig; import org.vivecraft.client.gui.widgets.SettingsList; import org.vivecraft.client_vr.ClientDataHolderVR; @@ -51,6 +52,84 @@ protected List getEntries() { ClientDataHolderVR.getInstance().vrSettings.vrSettingsButtonPositionLeft = !ClientDataHolderVR.getInstance().vrSettings.vrSettingsButtonPositionLeft; ClientDataHolderVR.getInstance().vrSettings.saveOptions(); }))); + + entries.add(new SettingsList.CategoryEntry(Component.literal("Client Settings"))); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.general"), + Button.builder(Component.translatable("vivecraft.options.screen.general"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.general"), this, ClientConfig.generalConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.update"), + Button.builder(Component.translatable("vivecraft.options.screen.update"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.update"), this, ClientConfig.updateConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.roomscale"), + Button.builder(Component.translatable("vivecraft.options.screen.roomscale"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.roomscale"), this, ClientConfig.roomScaleConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.seated"), + Button.builder(Component.translatable("vivecraft.options.screen.seated"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.seated"), this, ClientConfig.seatedConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.teleport"), + Button.builder(Component.translatable("vivecraft.options.screen.teleport"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.teleport"), this, ClientConfig.teleportConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.display"), + Button.builder(Component.translatable("vivecraft.options.screen.display"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.display"), this, ClientConfig.displayConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.hud"), + Button.builder(Component.translatable("vivecraft.options.screen.hud"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.hud"), this, ClientConfig.hudConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.fov"), + Button.builder(Component.translatable("vivecraft.options.screen.fov"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.fov"), this, ClientConfig.fovConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.camera"), + Button.builder(Component.translatable("vivecraft.options.screen.camera"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.camera"), this, ClientConfig.cameraConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.mr"), + Button.builder(Component.translatable("vivecraft.options.screen.mr"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.mr"), this, ClientConfig.mrConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.WidgetEntry( + Component.translatable("vivecraft.options.screen.keyboard"), + Button.builder(Component.translatable("vivecraft.options.screen.keyboard"), button -> this.minecraft.setScreen(new GuiConfigListScreen(Component.translatable("vivecraft.options.screen.keyboard"), this, ClientConfig.keyboardConfig()))) + .size(SettingsList.WidgetEntry.valueButtonWidth, 20) + .build())); + + entries.add(new SettingsList.CategoryEntry(Component.literal("Radial"))); + + entries.add(SettingsList.ConfigToEntry(ClientConfig.radialModeHold, Component.literal(ClientConfig.radialModeHold.getPath()))); + entries.add(SettingsList.ConfigToEntry(ClientConfig.main, Component.literal(ClientConfig.main.getPath()))); + entries.add(SettingsList.ConfigToEntry(ClientConfig.alt, Component.literal(ClientConfig.alt.getPath()))); + + entries.add(new SettingsList.CategoryEntry(Component.literal("Quick Commands"))); + entries.add(SettingsList.ConfigToEntry(ClientConfig.commands, Component.literal(ClientConfig.commands.getPath()))); + return entries; } } From b2a641897ecd6ec3c8e7200e52dd0b5b087dc95d Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:05:13 +0200 Subject: [PATCH 12/14] Update VivecraftMainSettings.java --- .../vivecraft/client/gui/settings/VivecraftMainSettings.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java b/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java index 59c78d600..23fbf64f7 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/VivecraftMainSettings.java @@ -40,12 +40,14 @@ protected List getEntries() { ClientDataHolderVR.getInstance().vrSettings.vrToggleButtonEnabled = !ClientDataHolderVR.getInstance().vrSettings.vrToggleButtonEnabled; ClientDataHolderVR.getInstance().vrSettings.saveOptions(); }))); + entries.add(new SettingsList.WidgetEntry( Component.translatable("vivecraft.options.VR_SETTINGS_BUTTON_VISIBLE"), CycleButton.onOffBuilder(ClientDataHolderVR.getInstance().vrSettings.vrSettingsButtonEnabled).displayOnlyValue().create(0,0, SettingsList.WidgetEntry.valueButtonWidth,20, Component.empty(), (cycleButton, object) -> { ClientDataHolderVR.getInstance().vrSettings.vrSettingsButtonEnabled = !ClientDataHolderVR.getInstance().vrSettings.vrSettingsButtonEnabled; ClientDataHolderVR.getInstance().vrSettings.saveOptions(); }))); + entries.add(new SettingsList.WidgetEntry( Component.translatable("vivecraft.options.VR_SETTINGS_BUTTON_POSITION"), new CycleButton.Builder(bool -> bool ? Component.translatable("vivecraft.options.left") : Component.translatable("vivecraft.options.right")).withValues(ImmutableList.of(Boolean.TRUE, Boolean.FALSE)).withInitialValue(ClientDataHolderVR.getInstance().vrSettings.vrSettingsButtonPositionLeft).displayOnlyValue().create(0,0, SettingsList.WidgetEntry.valueButtonWidth,20, Component.empty(), (cycleButton, object) -> { @@ -128,6 +130,7 @@ protected List getEntries() { entries.add(SettingsList.ConfigToEntry(ClientConfig.alt, Component.literal(ClientConfig.alt.getPath()))); entries.add(new SettingsList.CategoryEntry(Component.literal("Quick Commands"))); + entries.add(SettingsList.ConfigToEntry(ClientConfig.commands, Component.literal(ClientConfig.commands.getPath()))); return entries; From 619727de44411d24da3fce4a6929537556d044c5 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Wed, 11 Oct 2023 21:30:45 +0200 Subject: [PATCH 13/14] Update WidgetBuilder.java --- .../server/config/WidgetBuilder.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/common/src/main/java/org/vivecraft/server/config/WidgetBuilder.java b/common/src/main/java/org/vivecraft/server/config/WidgetBuilder.java index 6b5ee9fcb..72b9c892e 100644 --- a/common/src/main/java/org/vivecraft/server/config/WidgetBuilder.java +++ b/common/src/main/java/org/vivecraft/server/config/WidgetBuilder.java @@ -3,7 +3,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.*; import net.minecraft.network.chat.Component; +import org.vivecraft.client.gui.settings.GuiArrayValueEditScreen; import org.vivecraft.client.gui.settings.GuiListValueEditScreen; +import org.vivecraft.client.gui.widgets.QuadWidget; +import org.vivecraft.client.gui.widgets.VectorWidget; +import org.vivecraft.common.ConfigBuilder; import java.util.function.Supplier; @@ -91,4 +95,35 @@ public static Supplier getEditListWidget(ConfigBuilder.ListV .tooltip(Tooltip.create(Component.literal(listValue.getComment()))) .build(); } + + public static > Supplier getEnumWidget(ConfigBuilder.EnumValue enumValue, int width, int height) { + return () -> CycleButton + .builder(newValue -> Component.literal(newValue.toString())) + .withInitialValue(enumValue.get()) + .withValues(enumValue.get().getDeclaringClass().getEnumConstants()) + .displayOnlyValue() + .withTooltip((bool) -> enumValue.getComment() != null ? Tooltip.create(Component.literal(enumValue.getComment())) : null) + .create(0, 0, width, height, Component.empty(), (button, newValue) -> enumValue.set(newValue)); + } + + public static Supplier getQuatWidget(ConfigBuilder.QuatValue quatValue, int width, int height) { + return () -> new QuadWidget(0,0, width, height, Component.literal(quatValue.get().toString()), quatValue); + } + + public static Supplier getVectorWidget(ConfigBuilder.VectorValue vectorValue, int width, int height) { + return () -> new VectorWidget(0,0, width, height, Component.literal(vectorValue.get().toString()), vectorValue); + } + + public static Supplier getArrayWidget(ConfigBuilder.ArrayValue arrayValue, int width, int height) { + return () -> Button + .builder( + Component.translatable("vivecraft.options.editarray"), + button -> Minecraft.getInstance() + .setScreen( + new GuiArrayValueEditScreen<>(Component.literal(arrayValue.getPath().substring(arrayValue.getPath().lastIndexOf("."))), Minecraft.getInstance().screen, arrayValue, arrayValue.fromString) + )) + .size(width, height) + .tooltip(Tooltip.create(Component.literal(arrayValue.getComment()))) + .build(); + } } From 76d00665d1fbd59a80f8d87e4bb414113d463606 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Thu, 12 Oct 2023 17:55:15 +0200 Subject: [PATCH 14/14] style updates --- .../org/vivecraft/client/ClientConfig.java | 1 - .../gui/settings/GuiArrayValueEditScreen.java | 3 +-- .../gui/settings/GuiListValueEditScreen.java | 2 +- .../client/gui/widgets/QuadWidget.java | 1 - .../client/gui/widgets/SettingsList.java | 1 - .../client/gui/widgets/VectorWidget.java | 2 -- .../org/vivecraft/common/ConfigBuilder.java | 23 +++++++------------ 7 files changed, 10 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client/ClientConfig.java b/common/src/main/java/org/vivecraft/client/ClientConfig.java index 37874e97e..16dd469c5 100644 --- a/common/src/main/java/org/vivecraft/client/ClientConfig.java +++ b/common/src/main/java/org/vivecraft/client/ClientConfig.java @@ -4,7 +4,6 @@ import com.electronwill.nightconfig.core.Config; import com.electronwill.nightconfig.core.ConfigSpec; import com.electronwill.nightconfig.core.file.CommentedFileConfig; -import net.minecraft.network.chat.Component; import org.joml.Quaternionf; import org.joml.Vector3f; import org.vivecraft.client_vr.gui.PhysicalKeyboard; diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java index 6489faae6..c00620071 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiArrayValueEditScreen.java @@ -14,7 +14,6 @@ import org.vivecraft.client.gui.widgets.SettingsList; import org.vivecraft.common.ConfigBuilder; -import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -96,7 +95,7 @@ public ArrayResetEntry(Component name, EditBox valueWidget, BooleanSupplier canR @Override public void render(GuiGraphics guiGraphics, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f) { - this.valueWidget.setX(k + -50); + this.valueWidget.setX(k - 50); this.valueWidget.setY(j); this.valueWidget.render(guiGraphics, n, o, f); this.resetButton.setX(k + 230); diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiListValueEditScreen.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiListValueEditScreen.java index 74552fc5b..61d38d14b 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiListValueEditScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiListValueEditScreen.java @@ -100,7 +100,7 @@ public ListValueEntry(Component name, EditBox valueWidget, Button.OnPress delete @Override public void render(GuiGraphics guiGraphics, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f) { - this.valueWidget.setX(k + -50); + this.valueWidget.setX(k - 50); this.valueWidget.setY(j); this.valueWidget.render(guiGraphics, n, o, f); this.deleteButton.setX(k + 230); diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java b/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java index f217a5ecb..db8e4c261 100644 --- a/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/QuadWidget.java @@ -8,7 +8,6 @@ import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import org.joml.Quaterniond; import org.joml.Quaternionf; import org.vivecraft.common.ConfigBuilder; diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/SettingsList.java b/common/src/main/java/org/vivecraft/client/gui/widgets/SettingsList.java index d06c62a6f..c717138f6 100644 --- a/common/src/main/java/org/vivecraft/client/gui/widgets/SettingsList.java +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/SettingsList.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.List; import java.util.function.BooleanSupplier; -import java.util.function.Supplier; public class SettingsList extends ContainerObjectSelectionList { final Screen parent; diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java b/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java index de59ae014..8c9b341dc 100644 --- a/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/VectorWidget.java @@ -6,8 +6,6 @@ import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -import org.joml.Quaterniond; -import org.joml.Vector3d; import org.joml.Vector3f; import org.vivecraft.common.ConfigBuilder; diff --git a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java index 46ba41025..1f4185cdc 100644 --- a/common/src/main/java/org/vivecraft/common/ConfigBuilder.java +++ b/common/src/main/java/org/vivecraft/common/ConfigBuilder.java @@ -3,11 +3,7 @@ import com.electronwill.nightconfig.core.CommentedConfig; import com.electronwill.nightconfig.core.ConfigSpec; import com.electronwill.nightconfig.core.EnumGetMethod; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import org.joml.Quaternionf; import org.joml.Vector3f; @@ -19,8 +15,6 @@ import java.util.function.Predicate; import java.util.function.Supplier; -; - public class ConfigBuilder { private final CommentedConfig config; @@ -80,19 +74,19 @@ private void addDefaultValueComment(List path, double defaultValue, doub private > void addDefaultValueComment(List path, T defaultValue) { String oldComment = config.getComment(path); config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") - + new Formatter(Locale.US).format("default: %s", defaultValue.name())); + + new Formatter(Locale.US).format("default: %s", defaultValue.name())); } private void addDefaultValueComment(List path, Quaternionf defaultValue) { String oldComment = config.getComment(path); config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") - +"x: %.2f, y %.2f, z: %.2f, w: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z, defaultValue.w)); + + "x: %.2f, y %.2f, z: %.2f, w: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z, defaultValue.w)); } private void addDefaultValueComment(List path, Vector3f defaultValue) { String oldComment = config.getComment(path); config.setComment(path, (oldComment == null ? "" : oldComment + "\n ") - +"x: %.2f, y: %.2f, z: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z)); + + "x: %.2f, y: %.2f, z: %.2f".formatted(defaultValue.x, defaultValue.y, defaultValue.z)); } /** @@ -258,7 +252,7 @@ public VectorValue define(Vector3f defaultValue) { public ArrayValue define(T[] defaultValue, Class clazz, Function fromString) { List path = stack.stream().toList(); - for (int i = 0; i< defaultValue.length; i++) { + for (int i = 0; i < defaultValue.length; i++) { stack.add(i + ""); spec.define(stack.stream().toList(), defaultValue[i]); stack.removeLast(); @@ -268,7 +262,6 @@ public ArrayValue define(T[] defaultValue, Class clazz, Function(config, path, defaultValue, clazz, fromString); configValues.add(value); return value; - } /** @@ -337,7 +330,7 @@ public boolean isDefault() { if (get() instanceof Object[]) { return Arrays.equals((Object[]) get(), (Object[]) defaultValue); } - return Objects.equals(get(), defaultValue); + return Objects.equals(get(), defaultValue); } public String getComment() { @@ -540,7 +533,7 @@ public Supplier getWidget(int width, int height) { } } - public class VectorValue extends ConfigValue { + public static class VectorValue extends ConfigValue { public VectorValue(CommentedConfig config, List path, Vector3f defaultValue) { super(config, path, defaultValue); @@ -624,7 +617,7 @@ public void set(T[] newValue) { cachedValue = newValue; List path2 = new ArrayList<>(path); path2.add("0"); - for (int i = 0; i< newValue.length; i++) { + for (int i = 0; i < newValue.length; i++) { path2.set(path.size(), i + ""); config.set(path2, newValue[i]); } @@ -635,7 +628,7 @@ public T[] reset() { List path2 = new ArrayList<>(path); path2.add("0"); config.set(path2, defaultValue.length); - for (int i = 0; i< defaultValue.length; i++) { + for (int i = 0; i < defaultValue.length; i++) { path2.set(path.size(), i + ""); config.set(path2, defaultValue[i]); }