Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/Multiloader-1.20.4' into…
Browse files Browse the repository at this point in the history
… Multiloader-1.20
  • Loading branch information
fayer3 committed Jul 7, 2024
2 parents 5fef1a4 + 4130790 commit e282e6b
Show file tree
Hide file tree
Showing 30 changed files with 347 additions and 195 deletions.
16 changes: 14 additions & 2 deletions common/src/main/java/org/vivecraft/client/Xplat.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public interface Xplat {
* <a href="https://plugins.jetbrains.com/plugin/16210-architectury">You should also get the IntelliJ plugin to help with @ExpectPlatform.</a>
*/

enum ModLoader{
FABRIC("fabric"),
FORGE("forge"),
NEOFORGE("neoforge");

public final String name;

ModLoader(String name) {
this.name = name;
}
}

@ExpectPlatform
static boolean isModLoaded(String name) {
return false;
Expand All @@ -43,8 +55,8 @@ static boolean isDedicatedServer() {
}

@ExpectPlatform
static String getModloader() {
return "";
static ModLoader getModloader() {
throw new AssertionError();
}

@ExpectPlatform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class GuiRoomscaleSettings extends GuiVROptionsBase {
VRSettings.VrOptions.BOW_MODE,
VRSettings.VrOptions.BACKPACK_SWITCH,
VRSettings.VrOptions.ALLOW_CRAWLING,
VRSettings.VrOptions.REALISTIC_DISMOUNT
VRSettings.VrOptions.REALISTIC_DISMOUNT,
VRSettings.VrOptions.REALISTIC_BLOCK_INTERACT,
VRSettings.VrOptions.REALISTIC_ENTITY_INTERACT
};

public GuiRoomscaleSettings(Screen guiScreen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GuiSeatedOptions extends GuiVROptionsBase {
new VROptionEntry(VRSettings.VrOptions.WALK_UP_BLOCKS),
new VROptionEntry(VRSettings.VrOptions.WORLD_ROTATION_INCREMENT),
new VROptionEntry(VRSettings.VrOptions.VEHICLE_ROTATION),
new VROptionEntry(VRSettings.VrOptions.DUMMY),
new VROptionEntry(VRSettings.VrOptions.REVERSE_HANDS),
new VROptionEntry(VRSettings.VrOptions.SEATED_FREE_MOVE, true),
new VROptionEntry(VRSettings.VrOptions.RIGHT_CLICK_DELAY, false),
new VROptionEntry("vivecraft.options.screen.teleport.button", (button, mousePos) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public HMDLayer(RenderLayerParent<AbstractClientPlayer, PlayerModel<AbstractClie

@Override
public void render(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, AbstractClientPlayer entity, float f, float g, float h, float j, float k, float l) {
if (this.getParentModel() instanceof VRPlayerModel<?> vrPlayerModel) {
if (this.getParentModel().head.visible && this.getParentModel() instanceof VRPlayerModel<?> vrPlayerModel) {
VRPlayersClient.RotInfo rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(entity.getUUID());
ResourceLocation hmd;
switch (rotinfo.hmd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
import net.minecraft.world.phys.Vec3;
import org.vivecraft.client.VRPlayersClient;
Expand Down Expand Up @@ -34,6 +35,10 @@ public VRPlayerRenderer(EntityRendererProvider.Context context, boolean slim, bo
this.addLayer(new HMDLayer(this));
}

public boolean hasLayerType(RenderLayer<?,?> renderLayer) {
return this.layers.stream().anyMatch(layer -> layer.getClass() == renderLayer.getClass());
}

@Override
public void render(AbstractClientPlayer entityIn, float pEntityYaw, float pPartialTicks, PoseStack matrixStackIn, MultiBufferSource pBuffer, int pPackedLight) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static boolean checkForUpdates() {
}

try {
String apiURL = "https://api.modrinth.com/v2/project/vivecraft/version?loaders=[%22" + Xplat.getModloader() + "%22]&game_versions=[%22" + SharedConstants.VERSION_STRING + "%22]";
String apiURL = "https://api.modrinth.com/v2/project/vivecraft/version?loaders=[%22" + Xplat.getModloader().name + "%22]&game_versions=[%22" + SharedConstants.VERSION_STRING + "%22]";
HttpURLConnection conn = (HttpURLConnection) new URL(apiURL).openConnection();
// 10 seconds read and connect timeout
conn.setConnectTimeout(10000);
Expand Down Expand Up @@ -76,7 +76,7 @@ public static boolean checkForUpdates() {
// sort the versions, modrinth doesn't guarantee them to be sorted.
Collections.sort(versions);

String currentVersionNumber = Xplat.getModVersion() + "-" + Xplat.getModloader();
String currentVersionNumber = Xplat.getModVersion() + "-" + Xplat.getModloader().name;
Version current = new Version(currentVersionNumber, currentVersionNumber, "");

for (Version v : versions) {
Expand Down
11 changes: 10 additions & 1 deletion common/src/main/java/org/vivecraft/client_vr/VRState.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.vivecraft.mod_compat_vr.ShadersHelper;
import org.vivecraft.mod_compat_vr.optifine.OptifineHelper;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryManagerMXBean;

Expand All @@ -44,7 +45,14 @@ public static void initializeVR() {
// TODO: move this into the init, does mean all callocs need to be done later
// check that the right lwjgl version is loaded that we ship the openvr part of
if (!Version.getVersion().startsWith("3.3.1")) {
throw new RenderConfigException("VR Init Error", Component.translatable("vivecraft.messages.rendersetupfailed", I18n.get("vivecraft.messages.invalidlwjgl", Version.getVersion(), "3.3.1"), "OpenVR_LWJGL"));
String suppliedJar = "";
try {
suppliedJar = new File(Version.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName();
} catch (Exception e) {
VRSettings.logger.error("couldn't check lwjgl source:", e);
}

throw new RenderConfigException("VR Init Error", Component.translatable("vivecraft.messages.rendersetupfailed", I18n.get("vivecraft.messages.invalidlwjgl", Version.getVersion(), "3.3.1", suppliedJar), "OpenVR_LWJGL"));
}

dh.vr = new MCOpenVR(Minecraft.getInstance(), dh);
Expand Down Expand Up @@ -113,6 +121,7 @@ public static void initializeVR() {
} catch (RenderConfigException renderConfigException) {
vrEnabled = false;
destroyVR(true);
renderConfigException.printStackTrace();
Minecraft.getInstance().setScreen(new ErrorScreen(renderConfigException.title, renderConfigException.error));
} catch (Throwable e) {
vrEnabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public interface MinecraftExtension {

void vivecraft$notifyMirror(String buttonDisplayString, boolean b, int i);
void vivecraft$drawProfiler();
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void doProcess(LocalPlayer player) {
}
}

if (!this.active[j]) {
if (this.dh.vrSettings.realisticEntityInteractEnabled && !this.active[j]) {
int k = Mth.floor(vec3.x);
int l = Mth.floor(vec3.y);
int i = Mth.floor(vec3.z);
Expand All @@ -204,7 +204,7 @@ public void doProcess(LocalPlayer player) {
}
}

if (!this.active[j]) {
if (this.dh.vrSettings.realisticBlockInteractEnabled && !this.active[j]) {
BlockPos blockpos = null;
blockpos = BlockPos.containing(vec3);
BlockState blockstate = this.mc.level.getBlockState(blockpos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public void poll(long frameIndex) {

this.updateAim();

this.controllerPose[0].M[0][3] = 0.3F;
this.controllerPose[0].M[0][3] = this.dh.vrSettings.reverseHands ? -0.3F : 0.3F;
this.controllerPose[0].M[1][3] = 1.2F;
this.controllerPose[0].M[2][3] = -0.5F;

this.controllerPose[1].M[0][3] = -0.3F;
this.controllerPose[1].M[0][3] = this.dh.vrSettings.reverseHands ? 0.3F : -0.3F;
this.controllerPose[1].M[1][3] = 1.2F;
this.controllerPose[1].M[2][3] = -0.5F;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static void applyFirstPersonItemTransforms(PoseStack pMatrixStack, Vivecr
rotation.mul(Axis.XP.rotationDegrees(-45.0F));
rotation.mul(Axis.XP.rotationDegrees((float) gunAngle));
} else if (rendertype == VivecraftItemTransformType.Shield) {
boolean reverse = dh.vrSettings.reverseHands && !dh.vrSettings.seated;
boolean reverse = dh.vrSettings.reverseHands;
if (reverse) {
k *= -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,25 @@ public static Vec3 getControllerRenderPos(int c) {
return dataHolder.vrPlayer.vrdata_world_render.getController(c).getPosition();
} else {
Vec3 out = null;
int mainHand = InteractionHand.MAIN_HAND.ordinal();
if (dataHolder.vrSettings.reverseHands) {
c = 1 - c;
mainHand = InteractionHand.OFF_HAND.ordinal();
}

if (mc.getCameraEntity() != null && mc.level != null) {
Vec3 dir = dataHolder.vrPlayer.vrdata_world_render.hmd.getDirection();
dir = dir.yRot((float) Math.toRadians(c == 0 ? -35.0D : 35.0D));
dir = new Vec3(dir.x, 0.0D, dir.z);
dir = dir.normalize();
if (TelescopeTracker.isTelescope(mc.player.getUseItem())) {
if (c == 0 && mc.player.getUsedItemHand() == InteractionHand.MAIN_HAND) {
out = dataHolder.vrPlayer.vrdata_world_render.eye0.getPosition()
.add(dataHolder.vrPlayer.vrdata_world_render.hmd.getDirection()
.scale(0.2 * dataHolder.vrPlayer.vrdata_world_render.worldScale));
}
if (c == 1 && mc.player.getUsedItemHand() == InteractionHand.OFF_HAND) {
out = dataHolder.vrPlayer.vrdata_world_render.eye1.getPosition()
.add(dataHolder.vrPlayer.vrdata_world_render.hmd.getDirection()
.scale(0.2 * dataHolder.vrPlayer.vrdata_world_render.worldScale));
}
if (TelescopeTracker.isTelescope(mc.player.getUseItem()) && TelescopeTracker.isTelescope(c == mainHand ? mc.player.getMainHandItem() : mc.player.getOffhandItem())) {
// move the controller in front of the eye when using the spyglass
VRData.VRDevicePose eye = c == 0 ? dataHolder.vrPlayer.vrdata_world_render.eye0 :
dataHolder.vrPlayer.vrdata_world_render.eye1;

out = eye.getPosition()
.add(dataHolder.vrPlayer.vrdata_world_render.hmd.getDirection()
.scale(0.2 * dataHolder.vrPlayer.vrdata_world_render.worldScale));
}
if (out == null) {
out = dataHolder.vrPlayer.vrdata_world_render.getEye(RenderPass.CENTER).getPosition().add(
Expand All @@ -125,11 +127,11 @@ public static void setupRenderingAtController(int controller, PoseStack matrix)
getSmoothCameraPosition(dataHolder.currentPass, dataHolder.vrPlayer.getVRDataWorld()));
matrix.translate(aimSource.x, aimSource.y, aimSource.z);
float sc = dataHolder.vrPlayer.vrdata_world_render.worldScale;
if (mc.level != null && TelescopeTracker.isTelescope(mc.player.getUseItem())) {
if (dataHolder.vrSettings.seated && mc.level != null && TelescopeTracker.isTelescope(mc.player.getUseItem()) && TelescopeTracker.isTelescope(controller == 0 ? mc.player.getMainHandItem() : mc.player.getOffhandItem())) {
matrix.mulPoseMatrix(dataHolder.vrPlayer.vrdata_world_render.hmd.getMatrix().inverted()
.transposed().toMCMatrix());
MethodHolder.rotateDegXp(matrix, 90);
matrix.translate(controller == 0 ? 0.075 * sc : -0.075 * sc, -0.025 * sc, 0.0325 * sc);
matrix.translate(controller == (dataHolder.vrSettings.reverseHands ? 1 : 0) ? 0.075 * sc : -0.075 * sc, -0.025 * sc, 0.0325 * sc);
} else {
matrix.mulPoseMatrix(dataHolder.vrPlayer.vrdata_world_render.getController(controller)
.getMatrix().inverted().transposed().toMCMatrix());
Expand Down Expand Up @@ -229,6 +231,12 @@ public static void drawScreen(float f, Screen screen, GuiGraphics guiGraphics) {
posestack.translate(0.0D, 0.0D, -11000.0D);
RenderSystem.applyModelViewMatrix();

Matrix4f guiProjection = (new Matrix4f()).setOrtho(
0.0F, (float) (mc.getWindow().getWidth() / mc.getWindow().getGuiScale()),
(float) (mc.getWindow().getHeight() / mc.getWindow().getGuiScale()), 0.0F,
1000.0F, 21000.0F);
RenderSystem.setProjectionMatrix(guiProjection, VertexSorting.ORTHOGRAPHIC_Z);

RenderSystem.blendFuncSeparate(
GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
Expand Down
Loading

0 comments on commit e282e6b

Please sign in to comment.