Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 119
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	mcxr-core/build.gradle.kts
#	mcxr-core/src/main/java/net/sorenon/mcxr/core/MCXRCore.java
#	mcxr-play/build.gradle.kts
#	mcxr-play/src/main/java/net/sorenon/mcxr/play/MCXROptionsScreen.java
#	mcxr-play/src/main/java/net/sorenon/mcxr/play/input/XrInput.java
#	mcxr-play/src/main/java/net/sorenon/mcxr/play/openxr/OpenXRState.java
#	mcxr-play/src/main/java/net/sorenon/mcxr/play/openxr/OpenXRSwapchain.java
#	mcxr-play/src/main/java/net/sorenon/mcxr/play/openxr/OpenXRSystem.java
#	mcxr-play/src/main/java/net/sorenon/mcxr/play/rendering/VrFirstPersonRenderer.java
#	mcxr-play/src/main/java/org/lwjgl/openxr/XR.java
  • Loading branch information
thejudge156 committed Jun 8, 2022
2 parents 4604a09 + ee64bec commit 57cba3f
Show file tree
Hide file tree
Showing 328 changed files with 195 additions and 79,594 deletions.
57 changes: 32 additions & 25 deletions mcxr-core/src/main/java/net/sorenon/mcxr/core/MCXRCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -22,7 +20,6 @@
import net.sorenon.mcxr.core.mixin.ServerLoginNetworkHandlerAcc;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.joml.Quaternionf;
import org.joml.Vector3f;

public class MCXRCore implements ModInitializer {
Expand Down Expand Up @@ -85,45 +82,55 @@ public void onInitialize() {
pose1.read(buf);
pose2.read(buf);
pose3.read(buf);
server.execute(() -> {
setPlayerPoses(player, pose1, pose2, pose3, 0);
for(ServerPlayer player2 : server.getPlayerList().getPlayers()) {
if(player2 != player) {
FriendlyByteBuf buf2 = PacketByteBufs.create();
buf2.writeUUID(player.getUUID());
pose1.write(buf2);
pose2.write(buf2);
pose3.write(buf2);
ServerPlayNetworking.send(player2, POSES, buf2);
}
}
});
var height = buf.readFloat();
server.execute(() -> setPlayerPoses(player, pose1, pose2, pose3, height, 0));
});

ServerPlayNetworking.registerGlobalReceiver(TELEPORT,
(server, player, handler, buf, responseSender) -> {
double x = buf.readDouble();
double y = buf.readDouble();
double z = buf.readDouble();
server.execute(() -> player.setPos(x, y, z));
server.execute(() -> {
PlayerExt acc = (PlayerExt) player;
Pose pose;

if (player.getMainArm() == HumanoidArm.LEFT) {
pose = acc.getRightHandPose();
} else {
pose = acc.getLeftHandPose();
}

Vector3f dir = pose.getOrientation().transform(new Vector3f(0, -1, 0));

var pos = Teleport.tp(player, JOMLUtil.convert(pose.getPos()), JOMLUtil.convert(dir));
if (pos != null) {
player.setPos(pos);
} else {
LOGGER.warn("Player {} attempted an invalid teleport", player.toString());
}
});
});
}

public void setPlayerPoses(Player player, Pose headPose, Pose leftHandPose, Pose rightHandPose, float f) {
public void setPlayerPoses(Player player,
Pose headPose,
Pose leftHandPose,
Pose rightHandPose,
float height,
float stoopid) {
PlayerExt acc = (PlayerExt) player;

acc.getHeadPose().set(headPose);
acc.getLeftHandPose().set(leftHandPose);
acc.getRightHandPose().set(rightHandPose);
acc.setHeight(height);

if (f != 0) {
acc.getLeftHandPose().orientation.rotateX(f);
acc.getRightHandPose().orientation.rotateX(f);
if (stoopid != 0) {
acc.getLeftHandPose().orientation.rotateX(stoopid);
acc.getRightHandPose().orientation.rotateX(stoopid);

FriendlyByteBuf buf = PacketByteBufs.create();
acc.getHeadPose().write(buf);
acc.getLeftHandPose().write(buf);
acc.getRightHandPose().write(buf);
buf.writeFloat(height);

ClientPlayNetworking.send(POSES, buf);
}
Expand Down
8 changes: 4 additions & 4 deletions mcxr-core/src/main/java/net/sorenon/mcxr/core/Teleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class Teleport {

public static Pair<Vec3, Vec3> tpStage1(Player player, Vec3 start, Vec3 direction) {
public static Pair<Vec3, Vec3> fireRayFromHand(Player player, Vec3 start, Vec3 direction) {
var level = player.level;

var hitResult = level.clip(new ClipContext(start, start.add(direction.scale(7)), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, player));
Expand Down Expand Up @@ -42,7 +42,7 @@ public static Pair<Vec3, Vec3> tpStage1(Player player, Vec3 start, Vec3 directio
return new Pair<>(hitPos, null);
}

public static Pair<Vec3, Boolean> tpStage2(Player player, Vec3 hitPos1) {
public static Pair<Vec3, Boolean> fireFallRay(Player player, Vec3 hitPos1) {
var level = player.level;

var hitResult = level.clip(new ClipContext(hitPos1, hitPos1.subtract(0, 5, 0), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, player));
Expand All @@ -63,7 +63,7 @@ public static Pair<Vec3, Boolean> tpStage2(Player player, Vec3 hitPos1) {

@Nullable
public static Vec3 tp(Player player, Vec3 start, Vec3 direction) {
var stage1 = tpStage1(player, start, direction);
var stage1 = fireRayFromHand(player, start, direction);
var hitPos1 = stage1.getA();
var finalPos1 = stage1.getB();

Expand All @@ -73,7 +73,7 @@ public static Vec3 tp(Player player, Vec3 start, Vec3 direction) {

hitPos1 = hitPos1.subtract(direction.scale(0.05));

var stage2 = tpStage2(player, hitPos1);
var stage2 = fireFallRay(player, hitPos1);
var hitPos2 = stage2.getA();

if (stage2.getB()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ default Pose getPoseForArm(HumanoidArm arm) {
boolean isXR();

ThreadLocal<HumanoidArm> getOverrideTransform();

void setHeight(float height);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public abstract class PlayerEntityMixin extends LivingEntity implements PlayerEx
@Unique
public Pose rightHandPose = new Pose();

@Unique
public float height = 0;

@Unique
public ThreadLocal<HumanoidArm> overrideTransform = ThreadLocal.withInitial(() -> null);

Expand Down Expand Up @@ -79,6 +82,7 @@ void overrideDims(net.minecraft.world.entity.Pose pose, CallbackInfoReturnable<E
final float minHeight = 0.5f * scale;
final float currentHeight = this.getBbHeight();
final float wantedHeight = (headPose.pos.y - (float) this.position().y + 0.125f * scale);
// final float wantedHeight = height + 0.125f * scale;
final float deltaHeight = wantedHeight - currentHeight;

if (deltaHeight <= 0) {
Expand Down Expand Up @@ -132,4 +136,9 @@ public boolean isXR() {
public ThreadLocal<HumanoidArm> getOverrideTransform() {
return this.overrideTransform;
};

@Override
public void setHeight(float height) {
this.height = height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static int getMainHand() {

@Override
public void onInitializeClient() {
Configuration.OPENXR_EXPLICIT_INIT.set(true);
PlayOptions.init();
PlayOptions.load();
PlayOptions.save();
Expand Down
12 changes: 7 additions & 5 deletions mcxr-play/src/main/java/net/sorenon/mcxr/play/gui/QuickChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class QuickChat extends ChatScreen {

private final static Logger LOGGER = LogManager.getLogger("questcraft");
private final static Logger LOGGER = LogManager.getLogger("mcxr-play");

public QuickChat(String string) {
super(string);
Expand Down Expand Up @@ -46,8 +46,9 @@ protected void init() {
"Hello","How are you?", "I'm alright.",
"Go to sleep please!", "I Have Phantoms!",
"Ready to play?", "Ready when you are!",
"Questcraft", "Are you on Quest 1 or 2?",
"Quest 1", "Quest 2", "I'm Lagging!",
"MCXR", "What VR headset are you using?",
"Oculus Quest", "Index", "Vive", "Oculus Rift",
"I'm Lagging!",
"Wait for me!", "Have fun!", "Where are you?",
"AFK", "BRB", "I'm Back", "/home", "/sethome",
"/spawn", "/gamemode creative", "/gamemode survival"
Expand All @@ -58,8 +59,9 @@ protected void init() {
"Hello","How are you?", "I'm alright.",
"Go to sleep please!", "I Have Phantoms!",
"Ready to play?", "Ready when you are!",
"Questcraft", "Are you on Quest 1 or 2?",
"Quest 1", "Quest 2", "I'm Lagging!",
"MCXR", "What VR headset are you using?",
"Oculus Quest", "Index", "Vive", "Oculus Rift",
"I'm Lagging!",
"Wait for me!", "Have fun!", "Where are you?",
"AFK", "BRB", "I'm Back", "/home", "/sethome",
"/spawn", "/gamemode creative", "/gamemode survival"
Expand Down
32 changes: 5 additions & 27 deletions mcxr-play/src/main/java/net/sorenon/mcxr/play/input/XrInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@


import com.mojang.blaze3d.platform.InputConstants;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.player.Player;
import net.minecraft.network.chat.Component;
import net.sorenon.mcxr.core.JOMLUtil;
import net.sorenon.mcxr.core.MCXRCore;
import net.sorenon.mcxr.core.Pose;
import net.sorenon.mcxr.core.Teleport;
import net.sorenon.mcxr.play.MCXRGuiManager;
import net.sorenon.mcxr.play.MCXRPlayClient;
import net.sorenon.mcxr.play.PlayOptions;
Expand Down Expand Up @@ -54,6 +50,8 @@ public final class XrInput {

private static long lastPollTime = 0;

public static boolean teleport = false;


private XrInput() {
}
Expand Down Expand Up @@ -149,28 +147,7 @@ public static void pollActions() {
}

if (actionSet.teleport.changedSinceLastSync && !actionSet.teleport.currentState) {
Player player = Minecraft.getInstance().player;
if (player != null) {
int handIndex = 0;
if (player.getMainArm() == HumanoidArm.LEFT) {
handIndex = 1;
}

Pose pose = XrInput.handsActionSet.gripPoses[handIndex].getMinecraftPose();

Vector3f dir = pose.getOrientation().rotateX((float) java.lang.Math.toRadians(PlayOptions.handPitchAdjust), new Quaternionf()).transform(new Vector3f(0, -1, 0));

var pos = Teleport.tp(player, JOMLUtil.convert(pose.getPos()), JOMLUtil.convert(dir));

if (pos != null) {
var buf = PacketByteBufs.create();
buf.writeDouble(pos.x);
buf.writeDouble(pos.y);
buf.writeDouble(pos.z);
ClientPlayNetworking.send(MCXRCore.TELEPORT, buf);
player.setPos(pos);
}
}
XrInput.teleport = true;
}

if (PlayOptions.smoothTurning) {
Expand Down Expand Up @@ -223,6 +200,7 @@ public static void pollActions() {
}
}
}

if (actionSet.hotbarRight.currentState && actionSet.hotbarRight.changedSinceLastSync) {
if (Minecraft.getInstance().player != null) {
int selected = Minecraft.getInstance().player.getInventory().selected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;
import net.minecraft.client.gui.components.toasts.TutorialToast;
import net.sorenon.mcxr.play.MCXRPlayClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

// TutorialTost Mixin:
// Simply removes the tutorial toasts. They are very annoying in QuestCraft and are persistat.
// Simply removes the tutorial toasts. They are very annoying in VR and are persistent.
@Mixin(TutorialToast.class)
public class TutorialToastMixin {

@Shadow private Toast.Visibility visibility;

@Inject(at=@At("TAIL"), method = "render", cancellable = true)
public void renderMixin(PoseStack poseStack, ToastComponent toastComponent, long l, CallbackInfoReturnable<Toast.Visibility> cir) {
cir.cancel();
this.visibility = Toast.Visibility.HIDE;
if (MCXRPlayClient.MCXR_GAME_RENDERER.isXrMode()) {
cir.cancel();
this.visibility = Toast.Visibility.HIDE;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.sorenon.mcxr.core.JOMLUtil;
import net.sorenon.mcxr.core.MCXRCore;
import net.sorenon.mcxr.core.Pose;
import net.sorenon.mcxr.core.Teleport;
import net.sorenon.mcxr.core.accessor.PlayerExt;
import net.sorenon.mcxr.core.mixin.LivingEntityAcc;
import net.sorenon.mcxr.play.MCXRGuiManager;
import net.sorenon.mcxr.play.MCXRPlayClient;
import net.sorenon.mcxr.play.PlayOptions;
import net.sorenon.mcxr.play.accessor.MinecraftExt;
import net.sorenon.mcxr.play.input.actionsets.VanillaGameplayActionSet;
import net.sorenon.mcxr.play.rendering.MCXRCamera;
import net.sorenon.mcxr.play.rendering.MCXRMainTarget;
import net.sorenon.mcxr.play.rendering.RenderPass;
import net.sorenon.mcxr.play.rendering.XrRenderTarget;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFW;
import net.sorenon.mcxr.play.input.XrInput;
Expand Down Expand Up @@ -175,7 +183,8 @@ private Struct renderXrGame(long predictedDisplayTime, MemoryStack stack) {

//Update the server-side player poses
if (Minecraft.getInstance().player != null && MCXRCore.getCoreConfig().supportsMCXR()) {
PlayerExt acc = (PlayerExt) Minecraft.getInstance().player;
Player player = Minecraft.getInstance().player;
PlayerExt acc = (PlayerExt) player;
if (!acc.isXR()) {
FriendlyByteBuf buf = PacketByteBufs.create();
buf.writeBoolean(true);
Expand All @@ -187,8 +196,29 @@ private Struct renderXrGame(long predictedDisplayTime, MemoryStack stack) {
MCXRPlayClient.viewSpacePoses.getMinecraftPose(),
XrInput.handsActionSet.gripPoses[0].getMinecraftPose(),
XrInput.handsActionSet.gripPoses[1].getMinecraftPose(),
MCXRPlayClient.viewSpacePoses.getPhysicalPose().getPos().y,
(float) Math.toRadians(PlayOptions.handPitchAdjust)
);

if (XrInput.teleport) {
XrInput.teleport = false;
int handIndex = 0;
if (player.getMainArm() == HumanoidArm.LEFT) {
handIndex = 1;
}

Pose pose = XrInput.handsActionSet.gripPoses[handIndex].getMinecraftPose();

Vector3f dir = pose.getOrientation().rotateX((float) java.lang.Math.toRadians(PlayOptions.handPitchAdjust), new Quaternionf()).transform(new Vector3f(0, -1, 0));

var pos = Teleport.tp(player, JOMLUtil.convert(pose.getPos()), JOMLUtil.convert(dir));
if (pos != null) {
ClientPlayNetworking.send(MCXRCore.TELEPORT, PacketByteBufs.empty());
player.setPos(pos);
}
}
} else {
XrInput.teleport = false;
}
});

Expand Down
Loading

0 comments on commit 57cba3f

Please sign in to comment.