Skip to content

Commit

Permalink
Merge branch 'Vivecraft:Multiloader-1.20' into Multiloader-1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
hammy275 authored Feb 10, 2024
2 parents f536442 + 471f215 commit f43f766
Show file tree
Hide file tree
Showing 30 changed files with 342 additions and 68 deletions.
3 changes: 2 additions & 1 deletion common/src/main/java/org/vivecraft/MixinConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.vivecraft.client_vr.settings.VRSettings;
import org.vivecraft.mod_compat_vr.iris.mixin.IrisChunkProgramOverridesMixinSodium_0_4_11;
import org.vivecraft.mod_compat_vr.iris.mixin.IrisChunkProgramOverridesMixinSodium_0_4_9;
import org.vivecraft.mod_compat_vr.sodium.SodiumHelper;
import org.vivecraft.mod_compat_vr.sodium.mixin.RenderSectionManagerVRMixin;

import java.io.IOException;
Expand Down Expand Up @@ -96,6 +97,6 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
}
}

return !mixinClassName.contains("NoSodium") || (!Xplat.isModLoaded("sodium") && !Xplat.isModLoaded("rubidium"));
return !mixinClassName.contains("NoSodium") || !SodiumHelper.isLoaded();
}
}
27 changes: 26 additions & 1 deletion common/src/main/java/org/vivecraft/client/VivecraftVRMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ public class VivecraftVRMod {
public final KeyMapping keyMenuButton = new KeyMapping("vivecraft.key.ingameMenuButton", -1, "key.categories.ui");
public final KeyMapping keyMoveThirdPersonCam = new KeyMapping("vivecraft.key.moveThirdPersonCam", -1, "key.categories.misc");
public final KeyMapping keyQuickHandheldCam = new KeyMapping("vivecraft.key.quickHandheldCam", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand1 = new KeyMapping("vivecraft.key.quickcommand1", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand2 = new KeyMapping("vivecraft.key.quickcommand2", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand3 = new KeyMapping("vivecraft.key.quickcommand3", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand4 = new KeyMapping("vivecraft.key.quickcommand4", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand5 = new KeyMapping("vivecraft.key.quickcommand5", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand6 = new KeyMapping("vivecraft.key.quickcommand6", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand7 = new KeyMapping("vivecraft.key.quickcommand7", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand8 = new KeyMapping("vivecraft.key.quickcommand8", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand9 = new KeyMapping("vivecraft.key.quickcommand9", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand10 = new KeyMapping("vivecraft.key.quickcommand10", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand11 = new KeyMapping("vivecraft.key.quickcommand11", -1, "key.categories.misc");
public final KeyMapping keyQuickCommand12 = new KeyMapping("vivecraft.key.quickcommand12", -1, "key.categories.misc");
public final KeyMapping[] keyQuickCommands = new KeyMapping[]{keyQuickCommand1, keyQuickCommand2, keyQuickCommand3, keyQuickCommand4, keyQuickCommand5, keyQuickCommand6, keyQuickCommand7, keyQuickCommand8, keyQuickCommand9, keyQuickCommand10, keyQuickCommand11, keyQuickCommand12};
public final KeyMapping keyQuickTorch = new KeyMapping("vivecraft.key.quickTorch", -1, "key.categories.gameplay");
public final KeyMapping keyRadialMenu = new KeyMapping("vivecraft.key.radialMenu", -1, "key.categories.ui");
public final KeyMapping keyRotateAxis = new KeyMapping("vivecraft.key.rotateAxis", -1, "key.categories.movement");
Expand Down Expand Up @@ -74,6 +87,19 @@ private void setupKeybindingSets() {
this.userKeyBindingSet.add(this.keyTogglePlayerList);
this.userKeyBindingSet.add(this.keyToggleHandheldCam);
this.userKeyBindingSet.add(this.keyQuickHandheldCam);
this.userKeyBindingSet.add(this.keyToggleKeyboard);
this.userKeyBindingSet.add(this.keyQuickCommand1);
this.userKeyBindingSet.add(this.keyQuickCommand2);
this.userKeyBindingSet.add(this.keyQuickCommand3);
this.userKeyBindingSet.add(this.keyQuickCommand4);
this.userKeyBindingSet.add(this.keyQuickCommand5);
this.userKeyBindingSet.add(this.keyQuickCommand6);
this.userKeyBindingSet.add(this.keyQuickCommand7);
this.userKeyBindingSet.add(this.keyQuickCommand8);
this.userKeyBindingSet.add(this.keyQuickCommand9);
this.userKeyBindingSet.add(this.keyQuickCommand10);
this.userKeyBindingSet.add(this.keyQuickCommand11);
this.userKeyBindingSet.add(this.keyQuickCommand12);

this.hiddenKeyBindingSet.add(GuiHandler.keyLeftClick);
this.hiddenKeyBindingSet.add(GuiHandler.keyRightClick);
Expand All @@ -90,7 +116,6 @@ private void setupKeybindingSets() {
this.hiddenKeyBindingSet.add(this.keyClimbeyJump);
this.hiddenKeyBindingSet.add(this.keyMenuButton);
this.hiddenKeyBindingSet.add(this.keyRadialMenu);
this.hiddenKeyBindingSet.add(this.keyToggleKeyboard);
this.hiddenKeyBindingSet.add(this.keyHotbarSwipeX);
this.hiddenKeyBindingSet.add(this.keyHotbarSwipeY);
this.hiddenKeyBindingSet.add(this.keyTrackpadTouch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public GuiVROptionSlider(int id, int x, int y, int width, int height, VRSettings

this.id = id;
this.enumOptions = option;

ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance();
if (dataholder.vrSettings.overrides.hasSetting(option) && dataholder.vrSettings.overrides.getSetting(option).isValueOverridden()) {
this.active = false;
}
}

public GuiVROptionSlider(int id, int x, int y, VRSettings.VrOptions option) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ protected void init(VRSettings.VrOptions[] settings, boolean clear) {
public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) {
if (this.reinit) {
this.reinit = false;
VRSettings.VrOptions selected = this.getFocused() instanceof GuiVROptionButton option ? option.getOption() : null;
this.init();
if (selected != null) {
List<?> items = this.children().stream().filter(listener -> listener instanceof GuiVROptionButton o && o.getOption() == selected).toList();
if (!items.isEmpty()) {
this.setFocused((GuiEventListener) items.get(0));
}
}
}

this.renderBackground(guiGraphics);
Expand Down Expand Up @@ -252,7 +259,14 @@ public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) {

return true;
} else {
return this.visibleList != null && this.visibleList.keyPressed(pKeyCode, pScanCode, pModifiers) || super.keyPressed(pKeyCode, pScanCode, pModifiers);
if (super.keyPressed(pKeyCode, pScanCode, pModifiers)) {
if (this.getFocused() instanceof AbstractWidget widget) {
this.actionPerformed(widget);
}
return true;
} else {
return this.visibleList != null && this.visibleList.keyPressed(pKeyCode, pScanCode, pModifiers);
}
}
}

Expand All @@ -261,20 +275,39 @@ public boolean charTyped(char pCodePoint, int pModifiers) {
}

private void renderTooltip(GuiGraphics guiGraphics, int pMouseX, int pMouseY) {
AbstractWidget hover = null;
GuiEventListener hover = null;

if (this.minecraft.getLastInputType().isKeyboard()) {
// only show focused tooltip when navigating with keyboard, so a click with the mouse removes it
hover = this.getFocused();
}
// find active button
for (GuiEventListener child : children()) {
if (child instanceof AbstractWidget && child.isMouseOver(pMouseX, pMouseY)) {
hover = (AbstractWidget) child;
if (hover == null) {
for (GuiEventListener child : children()) {
if (child instanceof AbstractWidget widget && this.isMouseOver(widget, pMouseX, pMouseY)) {
hover = child;
}
}
}
if (hover != null) {
if (hover instanceof GuiVROption guiHover) {
if (guiHover.getOption() != null) {
String tooltipString = "vivecraft.options." + guiHover.getOption().name() + ".tooltip";
String tooltip = "";
// check if it has a tooltip
if (I18n.exists(tooltipString)) {
String tooltip = I18n.get(tooltipString, (Object) null);
tooltip = I18n.get(tooltipString, (Object) null);
}

if (dataholder.vrSettings.overrides.hasSetting(guiHover.getOption())) {
VRSettings.ServerOverrides.Setting setting = dataholder.vrSettings.overrides.getSetting(guiHover.getOption());
if (setting.isValueOverridden()) {
tooltip = I18n.get("vivecraft.message.overriddenbyserver") + tooltip;
} else if (setting.isFloat() && (setting.isValueMinOverridden() || setting.isValueMaxOverridden())) {
tooltip = I18n.get("vivecraft.message.limitedbyserver", setting.getValueMin(), setting.getValueMax()) + tooltip;
}
}
if (!tooltip.isEmpty()) {
// add format reset at line ends
tooltip = tooltip.replace("\n", "§r\n");

Expand All @@ -293,4 +326,8 @@ private void renderTooltip(GuiGraphics guiGraphics, int pMouseX, int pMouseY) {
}
}
}

private boolean isMouseOver(AbstractWidget widget, double x, double y) {
return widget.visible && x >= widget.getX() && y >= widget.getY() && x < (widget.getX() + widget.getWidth()) && y < (widget.getY() + widget.getHeight());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class GuiKeyboardSettings extends GuiVROptionsBase {
KeyboardHandler.setOverlayShowing(false);
return false;
}),
new VROptionEntry(VRSettings.VrOptions.KEYBOARD_PRESS_BINDS),
new VROptionEntry(VRSettings.VrOptions.AUTO_OPEN_KEYBOARD),
new VROptionEntry(VRSettings.VrOptions.AUTO_CLOSE_KEYBOARD),
new VROptionEntry(VRSettings.VrOptions.PHYSICAL_KEYBOARD_SCALE),
new VROptionEntry(VRSettings.VrOptions.KEYBOARD_PRESS_BINDS),
new VROptionEntry(VRSettings.VrOptions.PHYSICAL_KEYBOARD_THEME)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CommandEntry extends Entry<CommandEntry> {

private CommandEntry(String command, GuiQuickCommandsList parent) {
this.txt = new EditBox(GuiQuickCommandsList.this.minecraft.font, parent.width / 2 - 100, 60, 200, 20, Component.literal(""));
this.txt.setMaxLength(256);
this.txt.setValue(command);
this.btnDelete = new Button.Builder(Component.literal("X"), (p) ->
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class GuiRenderOpticsSettings extends GuiVROptionsBase {
VRSettings.VrOptions.MIXED_REALITY_FOV,
VRSettings.VrOptions.MIXED_REALITY_RENDER_CAMERA_MODEL
};
static VRSettings.VrOptions[] CROPOptions = new VRSettings.VrOptions[]{
VRSettings.VrOptions.MIRROR_CROP
};
private float prevRenderScaleFactor = this.settings.renderScaleFactor;
private float prevHandCameraResScale = this.settings.handCameraResScale;

Expand Down Expand Up @@ -104,6 +107,8 @@ public void init() {
super.init(UDOptions, false);
} else if (this.dataholder.vrSettings.displayMirrorMode == VRSettings.MirrorMode.THIRD_PERSON) {
super.init(TUDOptions, false);
} else if (this.dataholder.vrSettings.displayMirrorMode == VRSettings.MirrorMode.CROPPED) {
super.init(CROPOptions, false);
}

super.addDefaultButtons();
Expand Down Expand Up @@ -136,11 +141,13 @@ protected void loadDefaults() {
protected void actionPerformed(AbstractWidget widget) {
if (widget instanceof GuiVROption guivroption) {

if (VRState.vrRunning && (guivroption.getId() == VRSettings.VrOptions.MIRROR_DISPLAY.ordinal() || guivroption.getId() == VRSettings.VrOptions.FSAA.ordinal() || guivroption.getId() == VRSettings.VrOptions.STENCIL_ON.ordinal())) {
if (guivroption.getId() == VRSettings.VrOptions.STENCIL_ON.ordinal() || (guivroption.getId() == VRSettings.VrOptions.MIRROR_DISPLAY.ordinal() && ShadersHelper.isShaderActive())) {
this.dataholder.vrRenderer.resizeFrameBuffers("Render Setting Changed");
} else {
this.dataholder.vrRenderer.reinitFrameBuffers("Render Setting Changed");
if (guivroption.getId() == VRSettings.VrOptions.MIRROR_DISPLAY.ordinal() || VRState.vrRunning && ( guivroption.getId() == VRSettings.VrOptions.FSAA.ordinal() || guivroption.getId() == VRSettings.VrOptions.STENCIL_ON.ordinal())) {
if (VRState.vrRunning) {
if (guivroption.getId() == VRSettings.VrOptions.STENCIL_ON.ordinal() || (guivroption.getId() == VRSettings.VrOptions.MIRROR_DISPLAY.ordinal() && ShadersHelper.isShaderActive())) {
this.dataholder.vrRenderer.resizeFrameBuffers("Render Setting Changed");
} else {
this.dataholder.vrRenderer.reinitFrameBuffers("Render Setting Changed");
}
}
this.reinit = true;
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/org/vivecraft/client_vr/VRState.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static void initializeVR() {

if (!garbageCollector.equals("ZGC") && !ClientDataHolderVR.getInstance().vrSettings.disableGarbageCollectorMessage) {
// At least 12 GiB RAM (minus 256 MiB for possible reserved) and 8 CPU threads
if (os.getTotalMemorySize() >= 1073741824L * 12L - 1048576L * 256L && Runtime.getRuntime().availableProcessors() >= 8) {
if (os.getTotalMemorySize() >= 1073741824L * 12L - 1048576L * 256L && Runtime.getRuntime().availableProcessors() >= 6) {
Minecraft.getInstance().setScreen(new GarbageCollectorScreen(garbageCollector));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public static void onScreenChanged(Screen previousGuiScreen, Screen newScreen, b
guiRotation_room = null;
guiScale = 1.0F;

if (KeyboardHandler.keyboardForGui) {
if (KeyboardHandler.keyboardForGui && dh.vrSettings.autoCloseKeyboard) {
KeyboardHandler.setOverlayShowing(false);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ public static boolean isKeyDown(int key) {
}

public static void pressKey(int key, int modifiers) {
Minecraft.getInstance().keyboardHandler.keyPress(Minecraft.getInstance().getWindow().getWindow(), key, 0, 1, modifiers);
pressedKeys.add(key);
Minecraft.getInstance().keyboardHandler.keyPress(Minecraft.getInstance().getWindow().getWindow(), key, 0, 1, modifiers);
}

public static void pressKey(int key) {
pressKey(key, 0);
}

public static void releaseKey(int key, int modifiers) {
Minecraft.getInstance().keyboardHandler.keyPress(Minecraft.getInstance().getWindow().getWindow(), key, 0, 0, modifiers);
pressedKeys.remove(key);
Minecraft.getInstance().keyboardHandler.keyPress(Minecraft.getInstance().getWindow().getWindow(), key, 0, 0, modifiers);
}

public static void releaseKey(int key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,4 +1173,8 @@ private void addActionParams(Map<String, ActionParams> map, KeyMapping keyBindin
public abstract VRRenderer createVRRenderer();

public abstract boolean isActive();

public boolean capFPS() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,9 @@ public boolean isActive() {
}
return vrActive;
}

@Override
public boolean capFPS() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,26 @@ private void initOpenVRCompositor() {
System.out.println("OpenVR Compositor initialized OK.");
}

private void checkPathValid(String path, String knownError, boolean alwaysThrow) throws RenderConfigException {
String pathFormatted = "";
boolean hasInvalidChars = false;
for (char c : path.toCharArray()) {
if (c > 127) {
hasInvalidChars = true;
pathFormatted += "§c" + c + "§r";
} else {
pathFormatted += c;
}
}

if (hasInvalidChars || alwaysThrow) {
String error = knownError + (hasInvalidChars ? "\nInvalid characters in path: \n" : "\n");
System.out.println(error + path);
throw new RenderConfigException(knownError, Component.empty().append(error).append(pathFormatted));
}
}


private void installApplicationManifest(boolean force) throws RenderConfigException {
File file1 = new File("openvr/vivecraft.vrmanifest");
Utils.loadAssetToFile("vivecraft.vrmanifest", file1, true);
Expand All @@ -881,28 +901,17 @@ private void installApplicationManifest(boolean force) throws RenderConfigExcept

System.out.println("Appkey: " + s);

// check if path is valid always, since if the application was already installed, it will not check it again
checkPathValid(file1.getAbsolutePath(), "Failed to install application manifest", false);

if (!force && VRApplications_IsApplicationInstalled(s)) {
System.out.println("Application manifest already installed");
} else {
int i = VRApplications_AddApplicationManifest(file1.getAbsolutePath(), true);

if (i != 0) {
// application needs to be installed, so abort
String pathFormatted = "";
boolean hasInvalidChars = false;
for (char c : file1.getAbsolutePath().toCharArray()) {
if (c > 127) {
hasInvalidChars = true;
pathFormatted += "§c" + c + "§r";
} else {
pathFormatted += c;
}
}

String error = VRApplications_GetApplicationsErrorNameFromEnum(i) + (hasInvalidChars ? "\nInvalid characters in path: \n" : "\n");
System.out.println("Failed to install application manifest: " + error + file1.getAbsolutePath());

throw new RenderConfigException("Failed to install application manifest", Component.empty().append(error).append(pathFormatted));
checkPathValid(file1.getAbsolutePath(), "Failed to install application manifest: " + VRApplications_GetApplicationsErrorNameFromEnum(i), true);
}

System.out.println("Application manifest installed successfully");
Expand Down Expand Up @@ -964,11 +973,14 @@ private void loadActionHandles() {
}
}

private void loadActionManifest() {
int i = VRInput_SetActionManifestPath((new File("openvr/input/action_manifest.json")).getAbsolutePath());
private void loadActionManifest() throws RenderConfigException {
String actionsPath = (new File("openvr/input/action_manifest.json")).getAbsolutePath();
// check if path is valid for steamvr, since it would just silently fail
checkPathValid(actionsPath, "Failed to install action manifest", false);
int i = VRInput_SetActionManifestPath(actionsPath);

if (i != 0) {
throw new RuntimeException("Failed to load action manifest: " + getInputErrorName(i));
throw new RenderConfigException("Failed to load action manifest", Component.literal(getInputErrorName(i)));
}
}

Expand Down
Loading

0 comments on commit f43f766

Please sign in to comment.