Skip to content
This repository was archived by the owner on Mar 18, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.19
minecraft_version=1.18.2
loader_version=0.14.6

# Mod Properties
Expand All @@ -13,8 +13,8 @@ org.gradle.jvmargs=-Xmx1G
maven_group = net.sorenon

# Dependencies
fabric_version=0.55.1+1.19
fabric_version=0.58.0+1.18.2
pehkui_version=3.3.2
joml_version=1.10.4
night_config_version=3.6.5
quilt_mappings=1
quilt_mappings=22
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sorenon.mcxr.core.mixin.hands.client;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.InteractionHand;
Expand All @@ -15,17 +16,17 @@
@Mixin(MultiPlayerGameMode.class)
public class MultiPlayerGameModeMixin {

@Inject(method = "performUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;"))
void preUse(LocalPlayer localPlayer, InteractionHand interactionHand, BlockHitResult blockHitResult, CallbackInfoReturnable<InteractionResult> cir) {
PlayerExt playerExt = ((PlayerExt) localPlayer);
@Inject(method = "useItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;"))
void preUse(LocalPlayer player, ClientLevel world, InteractionHand hand, BlockHitResult hitResult, CallbackInfoReturnable<InteractionResult> cir) {
PlayerExt playerExt = ((PlayerExt) player);
if (playerExt.isXR() && MCXRCore.getCoreConfig().handBasedItemUsage()) {
playerExt.getOverrideTransform().set(MCXRCore.handToArm(localPlayer, interactionHand));
playerExt.getOverrideTransform().set(MCXRCore.handToArm(player, hand));
}
}

@Inject(method = "performUseItemOn", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;"))
void postUse(LocalPlayer localPlayer, InteractionHand interactionHand, BlockHitResult blockHitResult, CallbackInfoReturnable<InteractionResult> cir) {
PlayerExt playerExt = ((PlayerExt) localPlayer);
@Inject(method = "useItemOn", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/item/ItemStack;useOn(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;"))
void postUse(LocalPlayer player, ClientLevel world, InteractionHand hand, BlockHitResult hitResult, CallbackInfoReturnable<InteractionResult> cir) {
PlayerExt playerExt = ((PlayerExt) player);
if (playerExt.isXR()) {
playerExt.getOverrideTransform().set(null);
}
Expand Down
2 changes: 1 addition & 1 deletion mcxr-core/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"depends": {
"fabricloader": ">=0.14.6",
"fabric": "*",
"minecraft": "1.19.x",
"minecraft": "1.18.x",
"java": ">=17"
},
"suggests": {
Expand Down
1 change: 0 additions & 1 deletion mcxr-desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ dependencies {

modImplementation("net.fabricmc.fabric-api:fabric-api:${properties["fabric_version"].toString()}")

include(implementation("org.lwjgl:lwjgl-openxr:3.3.1")!!)
implementation("org.joml:joml:${properties["joml_version"].toString()}")
implementation("com.electronwill.night-config:core:${properties["night_config_version"].toString()}")
implementation("com.electronwill.night-config:toml:${properties["night_config_version"].toString()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import org.lwjgl.glfw.GLFWNativeX11;
import org.lwjgl.opengl.GL30;
import org.lwjgl.openxr.*;
import org.lwjgl.system.Configuration;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.Platform;
import org.lwjgl.system.Struct;
import org.lwjgl.system.*;
import org.lwjgl.system.linux.X11;
import org.lwjgl.system.windows.User32;

Expand All @@ -36,11 +33,17 @@ public class MCXRDesktop implements ClientModInitializer, MCXRPlatform {

@Override
public void onInitializeClient() {
Configuration.OPENXR_EXPLICIT_INIT.set(true);

PLATFORM = this;
PLATFORM.loadNatives();
}

@Override
public SharedLibrary getOpenXRLib() {
return Library.loadNative(XR.class, "openxr_loader", false);

}

@Override
public void loadNatives() {
XR.create("openxr_loader");
Expand All @@ -53,7 +56,7 @@ public Struct createGraphicsBinding(MemoryStack stack) {
long windowHandle = window.getWindow();
if (Platform.get() == Platform.WINDOWS) {
return XrGraphicsBindingOpenGLWin32KHR.calloc(stack).set(
KHROpenGLEnable.XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR,
KHROpenglEnable.XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR,
NULL,
User32.GetDC(GLFWNativeWin32.glfwGetWin32Window(windowHandle)),
GLFWNativeWGL.glfwGetWGLContext(windowHandle)
Expand All @@ -73,7 +76,7 @@ public Struct createGraphicsBinding(MemoryStack stack) {
long fbConfig = fbConfigBuf.get();

return XrGraphicsBindingOpenGLXlibKHR.calloc(stack).set(
KHROpenGLEnable.XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR,
KHROpenglEnable.XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR,
NULL,
xDisplay,
(int) Objects.requireNonNull(glXGetVisualFromFBConfig(xDisplay, fbConfig)).visualid(),
Expand All @@ -91,8 +94,8 @@ public List<String> tryEnableExtensions(XrExtensionProperties.Buffer availableEx
while (availableExtensions.hasRemaining()) {
XrExtensionProperties prop = availableExtensions.get();
String extensionName = prop.extensionNameString();
if (extensionName.equals(KHROpenGLEnable.XR_KHR_OPENGL_ENABLE_EXTENSION_NAME)) {
return List.of(KHROpenGLEnable.XR_KHR_OPENGL_ENABLE_EXTENSION_NAME);
if (extensionName.equals(KHROpenglEnable.XR_KHR_OPENGL_ENABLE_EXTENSION_NAME)) {
return List.of(KHROpenglEnable.XR_KHR_OPENGL_ENABLE_EXTENSION_NAME);
}
}

Expand All @@ -119,7 +122,7 @@ public int[] enumerateSwapchainImages(OpenXRInstance instance, XrSwapchain handl
int imageCount = intBuf.get(0);
XrSwapchainImageOpenGLKHR.Buffer swapchainImageBuffer = XrSwapchainImageOpenGLKHR.calloc(imageCount, stack);
for (XrSwapchainImageOpenGLKHR image : swapchainImageBuffer) {
image.type(KHROpenGLEnable.XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR);
image.type(KHROpenglEnable.XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR);
}

instance.checkPanic(XR10.xrEnumerateSwapchainImages(handle, intBuf, XrSwapchainImageBaseHeader.create(swapchainImageBuffer.address(), swapchainImageBuffer.capacity())), "xrEnumerateSwapchainImages");
Expand All @@ -140,8 +143,8 @@ public void framebufferTextureLayer(int color, int index) {
@Override
public void checkGraphicsRequirements(OpenXRInstance instance, long system) {
try (var stack = stackPush()) {
XrGraphicsRequirementsOpenGLKHR graphicsRequirements = XrGraphicsRequirementsOpenGLKHR.calloc(stack).type(KHROpenGLEnable.XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR);
instance.checkPanic(KHROpenGLEnable.xrGetOpenGLGraphicsRequirementsKHR(instance.handle, system, graphicsRequirements), "xrGetOpenGLGraphicsRequirementsKHR");
XrGraphicsRequirementsOpenGLKHR graphicsRequirements = XrGraphicsRequirementsOpenGLKHR.calloc(stack).type(KHROpenglEnable.XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR);
instance.checkPanic(KHROpenglEnable.xrGetOpenGLGraphicsRequirementsKHR(instance.handle, system, graphicsRequirements), "xrGetOpenGLGraphicsRequirementsKHR");
}
}
}
2 changes: 1 addition & 1 deletion mcxr-desktop/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"depends": {
"fabricloader": ">=0.14.6",
"fabric": "*",
"minecraft": "1.19.x",
"minecraft": "1.18.x",
"java": ">=17"
},
"icon": "assets/mcxr-play/icon.png"
Expand Down
2 changes: 0 additions & 2 deletions mcxr-play/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ dependencies {
exclude(group = "net.fabricmc.fabric-api")
}

compileOnly("org.lwjgl:lwjgl-openxr:3.3.1")

implementation("org.joml:joml:${properties["joml_version"].toString()}")
implementation("com.electronwill.night-config:core:${properties["night_config_version"].toString()}")
implementation("com.electronwill.night-config:toml:${properties["night_config_version"].toString()}")
Expand Down
12 changes: 12 additions & 0 deletions mcxr-play/src/main/java/net/sorenon/mcxr/play/MCXRNativeLoad.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

package net.sorenon.mcxr.play;

public class MCXRNativeLoad {
static {
System.loadLibrary("mcxr_loader");
}

public static native long getJVMPtr();
public static native long getApplicationActivityPtr();
public static native void renderImage(int colorAttachment, int index);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package net.sorenon.mcxr.play;

import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.fabric.mixin.resource.loader.client.GameOptionsMixin;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import net.minecraft.client.Option;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.main.GameConfig;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.sorenon.mcxr.play.input.XrInput;
import net.minecraft.network.chat.TranslatableComponent;
import net.sorenon.mcxr.play.openxr.OpenXRInstance;
import net.sorenon.mcxr.play.openxr.OpenXRState;
import net.sorenon.mcxr.play.openxr.OpenXRSystem;
Expand All @@ -30,7 +28,7 @@ public class MCXROptionsScreen extends Screen {
private Button reloadButton;

public MCXROptionsScreen(@Nullable Screen previous) {
super(Component.translatable("mcxr.options.title"));
super(new TranslatableComponent("mcxr.options.title"));
this.previous = previous;
}

Expand All @@ -43,7 +41,7 @@ protected void init() {
this.height / 6 - 12 - 4 + 24,
150,
20,
Component.translatable("mcxr.menu.reload"),
new TranslatableComponent("mcxr.menu.reload"),
button -> MCXRPlayClient.OPEN_XR_STATE.tryInitialize()));
if (PlayOptions.xrUninitialized) {
reloadButton.active = false;
Expand All @@ -54,27 +52,27 @@ protected void init() {
this.height / 6 - 12 - 4 + 24,
150,
20,
PlayOptions.xrUninitialized ? Component.translatable("mcxr.options.initialize") : Component.translatable("mcxr.options.uninitialize"),
PlayOptions.xrUninitialized ? new TranslatableComponent("mcxr.options.initialize") : new TranslatableComponent("mcxr.options.uninitialize"),
button -> {
PlayOptions.xrUninitialized = !PlayOptions.xrUninitialized;
PlayOptions.save();
reloadButton.active = !PlayOptions.xrUninitialized;
if (!PlayOptions.xrUninitialized) {
MCXRPlayClient.OPEN_XR_STATE.tryInitialize();
}
button.setMessage(PlayOptions.xrUninitialized ? Component.translatable("mcxr.options.initialize") : Component.translatable("mcxr.options.uninitialize"));
button.setMessage(PlayOptions.xrUninitialized ? new TranslatableComponent("mcxr.options.initialize") : new TranslatableComponent("mcxr.options.uninitialize"));
}));

this.addRenderableWidget(new Button(
this.width / 2 - 100,
this.height / 6 - 12 - 4,
200,
20,
PlayOptions.xrPaused ? Component.translatable("mcxr.options.unpause") : Component.translatable("mcxr.options.pause"),
PlayOptions.xrPaused ? new TranslatableComponent("mcxr.options.unpause") : new TranslatableComponent("mcxr.options.pause"),
button -> {
PlayOptions.xrPaused = !PlayOptions.xrPaused;
PlayOptions.save();
button.setMessage(PlayOptions.xrPaused ? Component.translatable("mcxr.options.unpause") : Component.translatable("mcxr.options.pause"));
button.setMessage(PlayOptions.xrPaused ?new TranslatableComponent("mcxr.options.unpause") : new TranslatableComponent("mcxr.options.pause"));
}));
//TODO merge end

Expand All @@ -83,72 +81,72 @@ protected void init() {
this.height / 6 + 54 + 12,
150,
20,
Component.translatable("mcxr.options.walk_direction", PlayOptions.walkDirection.toComponent()),
new TranslatableComponent("mcxr.options.walk_direction"),
button -> {
PlayOptions.walkDirection = PlayOptions.walkDirection.iterate();
PlayOptions.save();
button.setMessage(Component.translatable("mcxr.options.walk_direction", PlayOptions.walkDirection.toComponent()));
button.setMessage(new TranslatableComponent("mcxr.options.walk_direction"));
}));
this.addRenderableWidget(new Button(
this.width / 2 - 155,
this.height / 6 + 54 + 24 + 12,
150,
20,
Component.translatable("mcxr.options.swim_direction", PlayOptions.swimDirection.toComponent()),
new TranslatableComponent("mcxr.options.swim_direction"),
button -> {
PlayOptions.swimDirection = PlayOptions.swimDirection.iterate();
PlayOptions.save();
button.setMessage(Component.translatable("mcxr.options.swim_direction", PlayOptions.swimDirection.toComponent()));
button.setMessage(new TranslatableComponent("mcxr.options.swim_direction"));
}));

this.addRenderableWidget(new Button(
this.width / 2 - 155,
this.height / 6 + 54 + 24 * 2 + 12,
150,
20,
Component.translatable("mcxr.options.fly_direction", PlayOptions.flyDirection.toComponent()),
new TranslatableComponent("mcxr.options.fly_direction"),
button -> {
PlayOptions.flyDirection = PlayOptions.flyDirection.iterate();
PlayOptions.save();
button.setMessage(Component.translatable("mcxr.options.fly_direction", PlayOptions.flyDirection.toComponent()));
button.setMessage(new TranslatableComponent("mcxr.options.fly_direction"));
}));

this.addRenderableWidget(new Button(
this.width / 2 - 155,
this.height / 6 + 54 + 24 * 3 + 12,
150,
20,
MCXRPlayClient.heightAdjustStand ? Component.translatable("mcxr.options.unlock_playerheight") : Component.translatable("mcxr.options.lock_playerheight"),
MCXRPlayClient.heightAdjustStand ? new TranslatableComponent("mcxr.options.unlock_playerheight") : new TranslatableComponent("mcxr.options.lock_playerheight"),
button -> {
MCXRPlayClient.heightAdjustStand = !MCXRPlayClient.heightAdjustStand;
button.setMessage(MCXRPlayClient.heightAdjustStand ? Component.translatable("mcxr.options.unlock_playerheight") : Component.translatable("mcxr.options.lock_playerheight"));
button.setMessage(MCXRPlayClient.heightAdjustStand ? new TranslatableComponent("mcxr.options.unlock_playerheight") : new TranslatableComponent("mcxr.options.lock_playerheight"));
}));

assert this.minecraft != null;
this.addRenderableWidget(Minecraft.getInstance().options.mainHand().createButton(this.minecraft.options, this.width / 2 - 155 + 160, this.height / 6 + 54 + 12, 150));
this.addRenderableWidget(Option.MAIN_HAND.createButton(this.minecraft.options, this.width / 2 - 155 + 160, this.height / 6 + 54 + 12, 150));

this.addRenderableWidget(new Button(
this.width / 2 - 155 + 160,
this.height / 6 + 54 + 24 + 12,
150,
20,
PlayOptions.smoothTurning ? Component.translatable("mcxr.options.enable_snap_turning") : Component.translatable("mcxr.options.enable_smooth_turning"),
PlayOptions.smoothTurning ? new TranslatableComponent("mcxr.options.enable_snap_turning") : new TranslatableComponent("mcxr.options.enable_smooth_turning"),
button -> {
PlayOptions.smoothTurning = !PlayOptions.smoothTurning;
PlayOptions.save();
button.setMessage(PlayOptions.smoothTurning ? Component.translatable("mcxr.options.enable_snap_turning") : Component.translatable("mcxr.options.enable_smooth_turning"));
button.setMessage(PlayOptions.smoothTurning ? new TranslatableComponent("mcxr.options.enable_snap_turning") : new TranslatableComponent("mcxr.options.enable_smooth_turning"));
}));

this.addRenderableWidget(new Button(
this.width / 2 - 155 + 160,
this.height / 6 + 54 + 24 * 2 + 12,
150,
20,
PlayOptions.immersiveControls ? Component.translatable("mcxr.options_disable_immersive_controls") : Component.translatable("mcxr.options_enable_immersive_controls"),
PlayOptions.immersiveControls ? new TranslatableComponent("mcxr.options_disable_immersive_controls") : new TranslatableComponent("mcxr.options_enable_immersive_controls"),
button -> {
PlayOptions.immersiveControls = !PlayOptions.immersiveControls;
PlayOptions.save();
button.setMessage(PlayOptions.immersiveControls ? Component.translatable("mcxr.options_disable_immersive_controls") : Component.translatable("mcxr.options_enable_immersive_controls"));
button.setMessage(PlayOptions.immersiveControls ? new TranslatableComponent("mcxr.options_disable_immersive_controls") : new TranslatableComponent("mcxr.options_enable_immersive_controls"));
}));

//TODO MCXR if (true ||
Expand Down Expand Up @@ -236,6 +234,6 @@ private static List<String> wordWrap(String string, int wrapLength) {
}

private static List<Component> wordWrapText(String string, int wrapLength) {
return WordUtils.wrap(string, wrapLength, null, true).lines().map(s -> (Component) (Component.literal(s))).toList();
return WordUtils.wrap(string, wrapLength, null, true).lines().map(s -> (Component) (new TranslatableComponent(s))).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import org.lwjgl.openxr.XrExtensionProperties;
import org.lwjgl.openxr.XrSwapchain;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.SharedLibrary;
import org.lwjgl.system.Struct;

import java.util.List;

public interface MCXRPlatform {

SharedLibrary getOpenXRLib();

void loadNatives();

Struct createGraphicsBinding(MemoryStack stack);
Expand Down
Loading