Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/Multiloader-1.21' into M…
Browse files Browse the repository at this point in the history
…ultiloader-1.20.5
  • Loading branch information
fayer3 committed Jan 13, 2025
2 parents 1a32efc + afac174 commit 17467a5
Show file tree
Hide file tree
Showing 27 changed files with 330 additions and 189 deletions.
31 changes: 31 additions & 0 deletions common/src/main/java/org/vivecraft/client/ClientVRPlayers.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ public boolean isVRPlayer(UUID uuid) {
(VRState.VR_RUNNING && this.mc.player != null && uuid.equals(this.mc.player.getUUID()));
}

/**
* checks if the given player is in VR and using seated mode, without lerping the RotInfo
*
* @param uuid UUID of the player
* @return if the player is in VR and using seated modes
*/
public boolean isVRAndSeated(UUID uuid) {
return (this.vivePlayers.containsKey(uuid) && this.vivePlayers.get(uuid).seated) ||
(VRState.VR_RUNNING && this.mc.player != null && uuid.equals(this.mc.player.getUUID()) &&
ClientDataHolderVR.getInstance().vrSettings.seated
);
}

/**
* checks if the given player is in VR and using reversed hands, without lerping the RotInfo
*
Expand Down Expand Up @@ -280,6 +293,24 @@ public boolean hasHMD(UUID uuid) {
return this.donors.containsKey(uuid);
}

public int getHMD(UUID uuid) {
return this.donors.getOrDefault(uuid, 0);
}

/**
* gets the latest clientside player data, use this when not rendering, i.e. on tick
* @param uuid uuid of the player to get the data for
* @return latest available player data
*/
public RotInfo getLatestRotationsForPlayer(UUID uuid) {
return this.vivePlayers.containsKey(uuid) ? this.vivePlayers.get(uuid) : this.vivePlayersLast.get(uuid);
}

/**
* gets the clientside interpolated player data, this one should only be called during rendering
* @param uuid uuid of the player to get the data for
* @return interpolated data
*/
public RotInfo getRotationsForPlayer(UUID uuid) {
float partialTick = ClientUtils.getCurrentPartialTick();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
import org.vivecraft.client.gui.framework.GuiVROptionButton;
import org.vivecraft.client.gui.framework.GuiVROptionsBase;
import org.vivecraft.client.gui.framework.VROptionLayout;
import org.vivecraft.client_vr.gui.GuiRadial;
import org.vivecraft.client_vr.settings.VRSettings;

import java.util.Arrays;
import java.util.Optional;

public class GuiRadialConfiguration extends GuiVROptionsBase {
private static final VROptionLayout[] OPTIONS = new VROptionLayout[]{
new VROptionLayout(VRSettings.VrOptions.RADIAL_MODE_HOLD, VROptionLayout.Position.POS_LEFT, 0.0F, true, "")
Expand Down Expand Up @@ -87,70 +91,38 @@ public void init() {

super.init(OPTIONS, false);

int numButtons = this.dataHolder.vrSettings.vrRadialButtons;
int buttonWidthMin = 120;
// distance from the center, with 14 buttons, move them closer together
float dist = numButtons * (numButtons >= 14 ? 5F : 5.5F);
int centerX = this.width / 2;
int centerY = this.height / 2;
int centerY = this.height / 2 + 10;
this.arr = ArrayUtils.clone(this.dataHolder.vrSettings.vrRadialItems);
String[] altSet = ArrayUtils.clone(this.dataHolder.vrSettings.vrRadialItemsAlt);

if (this.isShift) {
this.arr = altSet;
}

for (int i = 0; i < numButtons; i++) {
KeyMapping keymapping = null;

for (KeyMapping keymapping1 : this.minecraft.options.keyMappings) {
if (i < this.arr.length && keymapping1.getName().equalsIgnoreCase(this.arr[i])) {
keymapping = keymapping1;
}
}

String label = "";

if (keymapping != null) {
label = I18n.get(keymapping.getName());
}

int buttonWidth = Math.max(buttonWidthMin, this.font.width(label));

// coords of the button, button 0 is at the top with x = 0, y = -dist
float distX = numButtons * 4 + buttonWidth * 0.5F;

// position buttons on equal y spacing
float btnIndex = (i < numButtons / 2 ? i : numButtons - i) / (float) (numButtons / 2);
int y = (int) (2.0F * dist * btnIndex - dist);

// position x so the buttons produce an ellipse
int x = (int) (distX * (Math.sqrt(1.0F - (y * y) / (dist * dist))));

// move in between buttons closer to the middle
if (Math.abs(y) > 20) {
x = (int) (x * 0.87F);
}

// second half of buttons should be on the left side
x *= i > numButtons / 2 ? -1 : 1;
for (int i = 0; i < this.dataHolder.vrSettings.vrRadialButtons; i++) {
// not all buttons need to be set
if (i >= this.arr.length) break;

String current = this.arr[i];
int index = i;
this.addRenderableWidget(new Button.Builder(Component.translatable(label),
(p) -> {
this.selectedIndex = index;
this.isselectmode = true;
this.reinit = true;
this.visibleList = this.list;
})
.size(buttonWidth, 20)
.pos(centerX + x - buttonWidth / 2, centerY + y)
.build());
Optional<KeyMapping> keyMapping = Arrays.stream(this.minecraft.options.keyMappings)
.filter(keymapping -> keymapping.getName().equalsIgnoreCase(current))
.findFirst();

String label = keyMapping.map(mapping -> I18n.get(mapping.getName())).orElse("");
this.addRenderableWidget(GuiRadial.createButton(label, (p) -> {
this.selectedIndex = index;
this.isselectmode = true;
this.reinit = true;
this.visibleList = this.list;
}, index, centerX, centerY));
}

// add button count button
this.addRenderableWidget(
new GuiVROptionButton(VRSettings.VrOptions.RADIAL_NUMBER.ordinal(),
centerX - 10, centerY, 20, 20,
centerX - 10, centerY - 10, 20, 20,
VRSettings.VrOptions.RADIAL_NUMBER, "" + this.dataHolder.vrSettings.vrRadialButtons,
(p) -> {
this.dataHolder.vrSettings.vrRadialButtons += 2;
Expand Down
29 changes: 13 additions & 16 deletions common/src/main/java/org/vivecraft/client/render/HMDLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,19 @@ public void render(

// check that the model actually is a vrPlayer model, some mods override the model
if (this.getParentModel().head.visible && this.getParentModel() instanceof VRPlayerModel<?> vrPlayerModel) {
ClientVRPlayers.RotInfo rotinfo = ClientVRPlayers.getInstance().getRotationsForPlayer(player.getUUID());
if (rotinfo != null) {
ResourceLocation hmd = switch (rotinfo.hmd) {
case 1 -> BLACK_HMD;
case 2 -> GOLD_HMD;
case 3, 4 -> DIAMOND_HMD;
default -> null;
};

if (hmd == null) return;

poseStack.pushPose();
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entitySolid(hmd));
vrPlayerModel.renderHMD(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
poseStack.popPose();
}
ResourceLocation hmd = switch (ClientVRPlayers.getInstance().getHMD(player.getUUID())) {
case 1 -> BLACK_HMD;
case 2 -> GOLD_HMD;
case 3, 4 -> DIAMOND_HMD;
default -> null;
};

if (hmd == null) return;

poseStack.pushPose();
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entitySolid(hmd));
vrPlayerModel.renderHMD(poseStack, vertexConsumer, packedLight, OverlayTexture.NO_OVERLAY);
poseStack.popPose();
}
}
}
113 changes: 65 additions & 48 deletions common/src/main/java/org/vivecraft/client_vr/gui/GuiRadial.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.vivecraft.client_vr.gui;

import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import org.vivecraft.client.gui.framework.TwoHandedScreen;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.provider.MCVR;
import org.vivecraft.client_vr.provider.openvr_lwjgl.VRInputAction;

import java.util.Arrays;

public class GuiRadial extends TwoHandedScreen {
private boolean isShift = false;
String[] arr;
Expand All @@ -19,67 +22,32 @@ public void init() {
String[] altSet = this.dh.vrSettings.vrRadialItemsAlt;
this.clearWidgets();

int numButtons = this.dh.vrSettings.vrRadialButtons;
int buttonWidthMin = 120;
// distance from the center, with 14 buttons, move them closer together
float dist = numButtons * (numButtons >= 14 ? 5F : 5.5F);
int centerX = this.width / 2;
int centerY = this.height / 2;

if (this.isShift) {
this.arr = altSet;
}

for (int i = 0; i < numButtons; i++) {
KeyMapping keymapping = null;

for (KeyMapping keymapping1 : this.minecraft.options.keyMappings) {
if (i < this.arr.length && keymapping1.getName().equalsIgnoreCase(this.arr[i])) {
keymapping = keymapping1;
}
}

String label = "?";

if (keymapping != null) {
label = I18n.get(keymapping.getName());
}

int buttonWidth = Math.max(buttonWidthMin, this.font.width(label));
// coords of the button, button 0 is at the top with x = 0, y = -dist
float distX = numButtons * 4 + buttonWidth * 0.5F;

// position buttons on equal y spacing
float btnIndex = (i < numButtons / 2 ? i : numButtons - i) / (float) (numButtons / 2);
int y = (int) (2.0F * dist * btnIndex - dist);

// position x so the buttons produce an ellipse
int x = (int) (distX * (Math.sqrt(1.0F - (y * y) / (dist * dist))));

// move in between buttons closer to the middle
if (Math.abs(y) > 20) {
x = (int) (x * 0.87F);
}

// second half of buttons should be on the left side
x *= i > numButtons / 2 ? -1 : 1;
for (int i = 0; i < this.dh.vrSettings.vrRadialButtons; i++) {
// not all buttons need to be set
if (i >= this.arr.length) break;

String current = this.arr[i];
int index = i;

if (!"?".equals(label)) {
this.addRenderableWidget(new Button.Builder(Component.translatable(label),
(p) -> {
Arrays.stream(this.minecraft.options.keyMappings)
.filter(keymapping -> keymapping.getName().equalsIgnoreCase(current))
.findFirst()
.ifPresent(keymapping -> {
String label = I18n.get(keymapping.getName());
this.addRenderableWidget(createButton(label, (p) -> {
VRInputAction vrinputaction = MCVR.get().getInputAction(this.arr[index]);

if (vrinputaction != null) {
vrinputaction.pressBinding();
vrinputaction.unpressBinding(2);
}
})
.size(buttonWidth, 20)
.pos(centerX + x - buttonWidth / 2, centerY + y - 10)
.build());
}
}, index, centerX, centerY));
});
}
}

Expand All @@ -95,4 +63,53 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
this.renderBackground(guiGraphics, mouseX, mouseY, partialTick);
super.render(guiGraphics, 0, 0, partialTick);
}

/**
* creates a Button withte given {@code action} and positions it in the radial circle
*
* @param label label of the button
* @param action action to call when pressing the button
* @param index button index in the circle
* @param centerX center of the circle on the screen, x coordinate
* @param centerY center of the circle on the screen, y coordinate
* @return Button positioned athte right spot
*/
public static Button createButton(
String label, Button.OnPress action, int index, int centerX, int centerY)
{
int buttonWidthMin = 120;
int numButtons = ClientDataHolderVR.getInstance().vrSettings.vrRadialButtons;

// distance from the center, with 14 buttons, move them closer together
float dist = numButtons * (numButtons >= 14 ? 5F : 5.5F);

int buttonWidth = Math.max(buttonWidthMin, Minecraft.getInstance().font.width(label) + 4);
// coords of the button, button 0 is at the top with x = 0, y = -dist
float distX = numButtons * 4 + buttonWidth * 0.5F;

// position buttons on equal y spacing
float btnIndex = (index < numButtons / 2 ? index : numButtons - index) / (float) (numButtons / 2);
int y = (int) (2.0F * dist * btnIndex - dist);

// position x so the buttons produce an ellipse
int x = (int) (distX * (Math.sqrt(1.0F - (y * y) / (dist * dist))));

// move in between buttons closer to the middle
if (Math.abs(y) > 20) {
x = (int) (x * 0.87F);
}

// don't go over the center
if (index != 0 && index != numButtons / 2) {
x = Math.max(buttonWidth / 2, x);
}

// second half of buttons should be on the left side
x *= index > numButtons / 2 ? -1 : 1;

return new Button.Builder(Component.translatable(label), action)
.size(buttonWidth, 20)
.pos(centerX + x - buttonWidth / 2, centerY + y - 10)
.build();
}
}
14 changes: 12 additions & 2 deletions common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java
Original file line number Diff line number Diff line change
Expand Up @@ -1343,9 +1343,18 @@ public void resetFBT() {
*/
public List<Triple<DeviceSource, Integer, Matrix4fc>> getTrackers() {
List<Triple<DeviceSource, Integer, Matrix4fc>> poses = new ArrayList<>();

Vector3f offset = new Vector3f();
if (!this.dh.vrSettings.seated && this.dh.vrSettings.allowStandingOriginOffset) {
if (this.dh.vr.isHMDTracking()) {
offset.set(this.dh.vrSettings.originOffset);
}
}

for (int i = 3; i < TRACKABLE_DEVICE_COUNT; i++) {
if (this.deviceSource[i].isValid()) {
poses.add(Triple.of(this.deviceSource[i], i, this.controllerPose[i]));
poses.add(Triple.of(this.deviceSource[i], i,
MathUtils.addTranslation(new Matrix4f(this.controllerPose[i]), offset)));
}
}

Expand All @@ -1356,7 +1365,8 @@ public List<Triple<DeviceSource, Integer, Matrix4fc>> getTrackers() {
if (tracker.isTracking() &&
poses.stream().noneMatch(t -> t.getLeft().is(DeviceSource.Source.OSC, finalI)))
{
poses.add(Triple.of(new DeviceSource(DeviceSource.Source.OSC, i), -1, tracker.pose));
poses.add(Triple.of(new DeviceSource(DeviceSource.Source.OSC, i), -1,
MathUtils.addTranslation(new Matrix4f(tracker.pose), offset)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,29 @@ public boolean hasCameraTracker() {
public List<Triple<DeviceSource, Integer, Matrix4fc>> getTrackers() {
List<Triple<DeviceSource, Integer, Matrix4fc>> trackers = super.getTrackers();
int trackerCount = this.fbtMode == FBTMode.ARMS_LEGS ? 3 : this.fbtMode == FBTMode.WITH_JOINTS ? 7 : 0;

Vector3f offset = new Vector3f();
if (!this.dh.vrSettings.seated && this.dh.vrSettings.allowStandingOriginOffset) {
if (this.dh.vr.isHMDTracking()) {
offset.set(this.dh.vrSettings.originOffset);
}
}

for (int i = 3; i < 3 + trackerCount; i++) {
int type = -1;
// check if we already know the role of the tracker
for (int t = 0; t < TRACKABLE_DEVICE_COUNT; t++) {
if (this.deviceSource[i].is(DeviceSource.Source.NULL, i)) {
if (this.deviceSource[t].is(DeviceSource.Source.NULL, i)) {
type = t;
break;
}
}
int finalI = i;
if (trackers.stream().noneMatch(t -> t.getLeft().is(DeviceSource.Source.NULL, finalI))) {
trackers.add(Triple.of(new DeviceSource(DeviceSource.Source.NULL, i), type,
new Matrix4f().rotation(this.deviceRotations[i]).setTranslation(this.deviceOffsets[i])));
new Matrix4f().rotation(this.deviceRotations[i])
.setTranslation(this.deviceOffsets[i].x + offset.x, this.deviceOffsets[i].y + offset.y,
this.deviceOffsets[i].z + offset.z)));
}
}
return trackers;
Expand Down
Loading

0 comments on commit 17467a5

Please sign in to comment.