Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/Multiloader-1.20' into M…
Browse files Browse the repository at this point in the history
…ultiloader-1.19.4
  • Loading branch information
fayer3 committed Nov 11, 2023
2 parents f38f805 + cf3e6e1 commit 9ebe6ac
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 63 deletions.
23 changes: 19 additions & 4 deletions common/src/main/java/org/vivecraft/MixinConfig.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package org.vivecraft;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.service.MixinService;
import org.vivecraft.client.Xplat;
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.mixin.RenderSectionManagerVRMixin;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class MixinConfig implements IMixinConfigPlugin {

Expand Down Expand Up @@ -46,14 +47,28 @@ public void postApply(String targetClassName, ClassNode targetClass, String mixi
public void onLoad(String mixinPackage) {
}

private final Set<String> appliedModFixes = Collections.newSetFromMap(new ConcurrentHashMap<>());

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (!Xplat.isModLoadedSuccess()) {
LogManager.getLogger().log(Level.WARN, "not loading '" + mixinClassName + "' because mod failed to load completely");
VRSettings.logger.info("not loading '{}' because mod failed to load completely", mixinClassName);
return false;
}

// only try to apply mod mixins if the target class was found
if (mixinClassName.startsWith("org.vivecraft.mod_compat_vr")) {
try {
MixinService.getService().getBytecodeProvider().getClassNode(targetClassName);
} catch (ClassNotFoundException | IOException e) {
return false;
}
String mod = mixinClassName.split("\\.")[3];
if (appliedModFixes.add(mod)) {
VRSettings.logger.info("Vivecraft: applying '{}' fixes", mod);
}
}

String neededClass = "";
// apply iris sodium version specific mixins only when the right class is there
if (mixinClassName.equals(IrisChunkProgramOverridesMixinSodium_0_4_9.class.getName())) {
Expand All @@ -76,7 +91,7 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
MixinService.getService().getBytecodeProvider().getClassNode(neededClass);
return true;
} catch (ClassNotFoundException | IOException e) {
LogManager.getLogger().log(Level.INFO, "Vivecraft: skipping mixin '" + mixinClassName + "'");
VRSettings.logger.info("Vivecraft: skipping mixin '{}'", mixinClassName);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.logging.LogUtils;
import net.minecraft.SharedConstants;
import org.vivecraft.client.Xplat;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.settings.VRSettings;
import org.vivecraft.server.config.ServerConfig;

import java.io.BufferedReader;
Expand Down Expand Up @@ -54,7 +54,7 @@ public static boolean checkForUpdates() {
conn.connect();

if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
LogUtils.getLogger().error("Error " + conn.getResponseCode() + " fetching Vivecraft updates");
VRSettings.logger.error("Error " + conn.getResponseCode() + " fetching Vivecraft updates");
return false;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public static boolean checkForUpdates() {
// no carriage returns please
changelog = changelog.replaceAll("\\r", "");
if (hasUpdate) {
LogUtils.getLogger().info("Vivecraft update found: " + newestVersion);
VRSettings.logger.info("Vivecraft update found: " + newestVersion);
}
} catch (IOException e) {
e.printStackTrace();
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/org/vivecraft/client/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.phys.Vec3;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.lwjgl.openvr.HmdMatrix44;
import org.vivecraft.client.Xplat;
import org.vivecraft.client_vr.render.VRShaders;
import org.vivecraft.client_vr.settings.VRSettings;
import org.vivecraft.client_vr.utils.LoaderUtils;
import org.vivecraft.common.utils.lwjgl.*;
import org.vivecraft.common.utils.math.Quaternion;
Expand Down Expand Up @@ -644,7 +644,7 @@ public static void spawnParticles(ParticleOptions type, int count, Vec3 position
try {
minecraft.level.addParticle(type, position.x + d0, position.y + d1, position.z + d2, d3, d4, d5);
} catch (Throwable throwable) {
LogManager.getLogger().warn("Could not spawn particle effect {}", type);
VRSettings.logger.warn("Could not spawn particle effect {}", type);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ private void uploadGeometry(RenderType layer, BufferBuilder.RenderedBuffer rende

public void cancelBuilding() {
building = false;
builderFutures.forEach(CompletableFuture::join);
builderFutures.clear();
if (bufferBuilders != null) {
for (BufferBuilder vertBuffer : bufferBuilders.values()) {
((BufferBuilderExtension) vertBuffer).vivecraft$freeBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.Mth;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vivecraft.client.utils.LangHelper;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.VRState;
Expand Down Expand Up @@ -43,7 +43,7 @@

public class VRSettings {
public static final int VERSION = 2;
public static final Logger logger = LogManager.getLogger();
public static final Logger logger = LoggerFactory.getLogger("Vivecraft");
public static VRSettings inst;
public JsonObject defaults = new JsonObject();
public static final int UNKNOWN_VERSION = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class BufferBuilderMixin implements BufferBuilderExtension {
@Override
public void vivecraft$freeBuffer() {
MemoryTrackerAccessor.getAllocator().free(MemoryUtil.memAddress0(buffer));
buffer = null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,117 +332,119 @@ public void moveRelative(float pAmount, Vec3 pRelative) {
return;
}

double d0 = pRelative.y;
double d1 = pRelative.x;
double d2 = pRelative.z;
double up = pRelative.y;
double strafe = pRelative.x;
double forward = pRelative.z;
VRPlayer vrplayer = this.vivecraft$dataholder.vrPlayer;

if (vrplayer.getFreeMove()) {
double d3 = d1 * d1 + d2 * d2;
double d4 = 0.0D;
double d5 = 0.0D;
double d6 = 0.0D;
double d7 = 1.0D;
double speed = strafe * strafe + forward * forward;
double mX = 0.0D;
double mZ = 0.0D;
double mY = 0.0D;
double addFactor = 1.0D;

if (d3 >= (double) 1.0E-4F || ClientDataHolderVR.katvr) {
d3 = Mth.sqrt((float) d3);
if (speed >= (double) 1.0E-4F || ClientDataHolderVR.katvr) {
speed = Mth.sqrt((float) speed);

if (d3 < 1.0D && !ClientDataHolderVR.katvr) {
d3 = 1.0D;
if (speed < 1.0D && !ClientDataHolderVR.katvr) {
speed = 1.0D;
}

d3 = (double) pAmount / d3;
d1 = d1 * d3;
d2 = d2 * d3;
Vec3 vec3 = new Vec3(d1, 0.0D, d2);
VRPlayer vrplayer1 = this.vivecraft$dataholder.vrPlayer;
speed = (double) pAmount / speed;
strafe = strafe * speed;
forward = forward * speed;
Vec3 direction = new Vec3(strafe, 0.0D, forward);
boolean isFlyingOrSwimming = !this.isPassenger() && (this.getAbilities().flying || this.isSwimming());

if (ClientDataHolderVR.katvr) {
jkatvr.query();
d3 = jkatvr.getSpeed() * jkatvr.walkDirection() * this.vivecraft$dataholder.vrSettings.movementSpeedMultiplier;
vec3 = new Vec3(0.0D, 0.0D, d3);
speed = jkatvr.getSpeed() * jkatvr.walkDirection() * this.vivecraft$dataholder.vrSettings.movementSpeedMultiplier;
direction = new Vec3(0.0D, 0.0D, speed);

if (isFlyingOrSwimming) {
vec3 = vec3.xRot(vrplayer1.vrdata_world_pre.hmd.getPitch() * ((float) Math.PI / 180F));
direction = direction.xRot(vrplayer.vrdata_world_pre.hmd.getPitch() * ((float) Math.PI / 180F));
}

vec3 = vec3.yRot(-jkatvr.getYaw() * ((float) Math.PI / 180F) + this.vivecraft$dataholder.vrPlayer.vrdata_world_pre.rotation_radians);
direction = direction.yRot(-jkatvr.getYaw() * ((float) Math.PI / 180F) + vrplayer.vrdata_world_pre.rotation_radians);
} else if (ClientDataHolderVR.infinadeck) {
jinfinadeck.query();
d3 = jinfinadeck.getSpeed() * jinfinadeck.walkDirection() * this.vivecraft$dataholder.vrSettings.movementSpeedMultiplier;
vec3 = new Vec3(0.0D, 0.0D, d3);
speed = jinfinadeck.getSpeed() * jinfinadeck.walkDirection() * this.vivecraft$dataholder.vrSettings.movementSpeedMultiplier;
direction = new Vec3(0.0D, 0.0D, speed);

if (isFlyingOrSwimming) {
vec3 = vec3.xRot(vrplayer1.vrdata_world_pre.hmd.getPitch() * ((float) Math.PI / 180F));
direction = direction.xRot(vrplayer.vrdata_world_pre.hmd.getPitch() * ((float) Math.PI / 180F));
}

vec3 = vec3.yRot(-jinfinadeck.getYaw() * ((float) Math.PI / 180F) + this.vivecraft$dataholder.vrPlayer.vrdata_world_pre.rotation_radians);
direction = direction.yRot(-jinfinadeck.getYaw() * ((float) Math.PI / 180F) + vrplayer.vrdata_world_pre.rotation_radians);
} else if (this.vivecraft$dataholder.vrSettings.seated) {
int j = 0;
int c = 0;
if (this.vivecraft$dataholder.vrSettings.seatedUseHMD) {
j = 1;
c = 1;
}

if (isFlyingOrSwimming) {
vec3 = vec3.xRot(vrplayer1.vrdata_world_pre.getController(j).getPitch() * ((float) Math.PI / 180F));
direction = direction.xRot(vrplayer.vrdata_world_pre.getController(c).getPitch() * ((float) Math.PI / 180F));
}

vec3 = vec3.yRot(-vrplayer1.vrdata_world_pre.getController(j).getYaw() * ((float) Math.PI / 180F));
direction = direction.yRot(-vrplayer.vrdata_world_pre.getController(c).getYaw() * ((float) Math.PI / 180F));
} else {

VRSettings.FreeMove freeMoveType = !this.isPassenger() && this.getAbilities().flying && this.vivecraft$dataholder.vrSettings.vrFreeMoveFlyMode != VRSettings.FreeMove.AUTO ? this.vivecraft$dataholder.vrSettings.vrFreeMoveFlyMode : this.vivecraft$dataholder.vrSettings.vrFreeMoveMode;

if (isFlyingOrSwimming) {
switch (freeMoveType) {
case CONTROLLER:
vec3 = vec3.xRot(vrplayer1.vrdata_world_pre.getController(1).getPitch() * ((float) Math.PI / 180F));
direction = direction.xRot(vrplayer.vrdata_world_pre.getController(1).getPitch() * ((float) Math.PI / 180F));
break;
case HMD:
case RUN_IN_PLACE:
case ROOM:
vec3 = vec3.xRot(vrplayer1.vrdata_world_pre.hmd.getPitch() * ((float) Math.PI / 180F));
direction = direction.xRot(vrplayer.vrdata_world_pre.hmd.getPitch() * ((float) Math.PI / 180F));
break;
}
}
if (this.vivecraft$dataholder.jumpTracker.isjumping()) {
vec3 = vec3.yRot(-vrplayer1.vrdata_world_pre.hmd.getYaw() * ((float) Math.PI / 180F));
direction = direction.yRot(-vrplayer.vrdata_world_pre.hmd.getYaw() * ((float) Math.PI / 180F));
} else {
switch (freeMoveType) {
case CONTROLLER:
vec3 = vec3.yRot(-vrplayer1.vrdata_world_pre.getController(1).getYaw() * ((float) Math.PI / 180F));
direction = direction.yRot(-vrplayer.vrdata_world_pre.getController(1).getYaw() * ((float) Math.PI / 180F));
break;

case HMD:
vec3 = vec3.yRot(-vrplayer1.vrdata_world_pre.hmd.getYaw() * ((float) Math.PI / 180F));
direction = direction.yRot(-vrplayer.vrdata_world_pre.hmd.getYaw() * ((float) Math.PI / 180F));
break;

case RUN_IN_PLACE:
vec3 = vec3.yRot((float) (-this.vivecraft$dataholder.runTracker.getYaw() * (double) ((float) Math.PI / 180F)));
vec3 = vec3.scale(this.vivecraft$dataholder.runTracker.getSpeed());
direction = direction.yRot((float) (-this.vivecraft$dataholder.runTracker.getYaw() * (double) ((float) Math.PI / 180F)));
direction = direction.scale(this.vivecraft$dataholder.runTracker.getSpeed());
break;

case ROOM:
vec3 = vec3.yRot((180.0F + this.vivecraft$dataholder.vrSettings.worldRotation) * ((float) Math.PI / 180F));
direction = direction.yRot((180.0F + this.vivecraft$dataholder.vrSettings.worldRotation) * ((float) Math.PI / 180F));
break;
}
}
}

d4 = vec3.x;
d6 = vec3.y;
d5 = vec3.z;
mX = direction.x;
mY = direction.y;
mZ = direction.z;

if (!this.getAbilities().flying && !this.wasTouchingWater) {
d7 = this.vivecraft$dataholder.vrSettings.inertiaFactor.getFactor();
addFactor = this.vivecraft$dataholder.vrSettings.inertiaFactor.getFactor();
}

float f = 1.0F;
float yAdd = 1.0F;

if (this.getAbilities().flying) {
f = 5.0F;
yAdd = 5.0F;
}

this.setDeltaMovement(this.getDeltaMovement().x + d4 * d7, this.getDeltaMovement().y + d6 * (double) f, this.getDeltaMovement().z + d5 * d7);
this.vivecraft$additionX = d4;
this.vivecraft$additionZ = d5;
this.setDeltaMovement(this.getDeltaMovement().x + mX * addFactor, this.getDeltaMovement().y + mY * (double) yAdd, this.getDeltaMovement().z + mZ * addFactor);
this.vivecraft$additionX = mX;
this.vivecraft$additionZ = mZ;
}

if (!this.getAbilities().flying && !this.wasTouchingWater) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.render.helpers.RenderHelper;
import org.vivecraft.client_xr.render_pass.RenderPassType;

@Mixin(MobRenderer.class)
Expand All @@ -16,7 +16,7 @@ public class MobRendererVRMixin {
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getRopeHoldPosition(F)Lnet/minecraft/world/phys/Vec3;"), method = "renderLeash")
public Vec3 vivecraft$leash(Entity instance, float f) {
if (!RenderPassType.isVanilla() && instance == Minecraft.getInstance().player) {
return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.getController(0).getPosition();
return RenderHelper.getControllerRenderPos(0);
}
return instance.getRopeHoldPosition(f);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.vivecraft.mod_compat_vr.alexmobs.mixin;

import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Pseudo
@Mixin(targets = "com.github.alexthe666.alexsmobs.client.event.ClientEvents")
public class ClientEventsMixin {
@Inject(at = @At("HEAD"), method = "onGetFluidRenderType", remap = false, cancellable = true)
private void vivecraft$fixNoPlayer(CallbackInfo ci) {
if (Minecraft.getInstance().player == null) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.vivecraft.mod_compat_vr.blur.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.vivecraft.client_vr.VRState;

@Pseudo
@Mixin(targets = {
"com.tterrag.blur.Blur",
"de.cheaterpaul.blur.BlurClient"
})
public class BlurMixin {
@Inject(at = @At("HEAD"), method = "getProgress", cancellable = true, remap = false)
private static void vivecraft$noBlurInVR(CallbackInfoReturnable<Float> cir) {
if (VRState.vrRunning) {
cir.setReturnValue(0.0F);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.vivecraft.mod_compat_vr.cataclysm.mixin;

import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Pseudo
@Mixin(targets = "com.github.L_Ender.cataclysm.client.event.ClientEvent")
public class ClientEventMixin {
@Inject(at = @At("HEAD"), method = "onGetFluidRenderType", remap = false, cancellable = true)
private void vivecraft$fixNoPlayer(CallbackInfo ci) {
if (Minecraft.getInstance().player == null) {
ci.cancel();
}
}
}
Loading

0 comments on commit 9ebe6ac

Please sign in to comment.