Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.vmstudio.visor.extensions.client.render.GameRendererExtension;
import org.vmstudio.visor.core.client.render.VRRenderState;
import org.vmstudio.visor.core.client.settings.VRClientSettings;
import org.vmstudio.visor.core.client.tasks.types.movement.vehicle.TasVehicle;
import org.vmstudio.visor.core.client.tasks.types.movement.vehicle.TaskVehicle;
import org.vmstudio.visor.core.client.network.ClientNetworking;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -317,7 +317,7 @@ public void updatePlayerLook(LocalPlayer player, PlayerPoseType stage) {
LocalPlayerPose data = getPoseData(stage);

if (player.isPassenger()) {
var vehicleLookDir = TasVehicle.getVehicleLookDirection(player);
var vehicleLookDir = TaskVehicle.getVehicleLookDirection(player);

if (vehicleLookDir != null) {
player.setXRot((float) Math.toDegrees(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import org.vmstudio.visor.core.client.settings.VRClientSettings;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.Pose;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;
Expand All @@ -33,8 +36,12 @@ public class TaskRoomSwim extends VisorTask {
private static final float SWIM_SPEED = 1.3f;
private static final float FRICTION = 0.9f;
private static final float SWIM_MOTION_SCALE = 0.12f;
private static final float MIN_SWIM_THRESHOLD = 0.3f;
private static final float SPRINTING_THRESHOLD = 1.0f;
private static final float WATER_SPEED_CAP = 0.10f;
private static final float WATER_SWIMMING_SPEED_CAP = 0.13f;
private static final float LAVA_SPEED_CAP = 0.02f;
private static final float LAVA_SWIMMING_SPEED_CAP = 0.03f;
private static final float MIN_SWIM_THRESHOLD = 0.075f;
private static final float SPRINTING_THRESHOLD = 0.115f;

private Vector3fc motion = new Vector3f();
private float lastDist;
Expand Down Expand Up @@ -81,9 +88,15 @@ protected void onRun(LocalPlayer player) {
this.motion = this.motion.add(swimMotion.mul(SWIM_MOTION_SCALE), new Vector3f());
}

this.lastDist = handDistance;
float maxSwimSpeed = getMaxSwimSpeed(player);
float motionLength = this.motion.length();
if (motionLength > maxSwimSpeed) {
this.motion = this.motion.normalize(new Vector3f())
.mul(maxSwimSpeed);
motionLength = maxSwimSpeed;
}

double motionLength = this.motion.length();
this.lastDist = handDistance;

player.setSwimming(motionLength > MIN_SWIM_THRESHOLD);
player.setSprinting(motionLength > SPRINTING_THRESHOLD);
Expand All @@ -94,7 +107,8 @@ protected void onRun(LocalPlayer player) {

@Override
protected void onClear(@Nullable LocalPlayer player) {

this.motion = new Vector3f();
this.lastDist = 0.0f;
}


Expand All @@ -107,8 +121,21 @@ public boolean isActive(LocalPlayer p) {
if (MC.screen != null) return false;
if (MC.gameMode == null) return false;
if (p == null || !p.isAlive()) return false;
if (p.isPassenger()) return false;
if (!p.isInWater() && !p.isInLava()) return false;
if (p.zza > 0.0F || p.xxa > 0.0F) return false;
if (p.zza != 0.0F || p.xxa != 0.0F) return false;

BlockPos playerBlockPos = p.blockPosition();
boolean hasFluidAtBody = p.level()
.getFluidState(playerBlockPos)
.is(FluidTags.WATER)
|| p.level().getFluidState(playerBlockPos).is(FluidTags.LAVA);
boolean hasFluidAboveBody = p.level()
.getFluidState(playerBlockPos.above())
.is(FluidTags.WATER)
|| p.level().getFluidState(playerBlockPos.above()).is(FluidTags.LAVA);

if (!hasFluidAtBody || !hasFluidAboveBody) return false;
return true;
}

Expand All @@ -121,4 +148,12 @@ public boolean isActive(LocalPlayer p) {
public @NotNull String getId() {
return ID;
}

private float getMaxSwimSpeed(LocalPlayer player) {
boolean swimmingPose = player.isSwimming() || player.getPose() == Pose.SWIMMING;
if (player.isInLava()) {
return swimmingPose ? LAVA_SWIMMING_SPEED_CAP : LAVA_SPEED_CAP;
}
return swimmingPose ? WATER_SWIMMING_SPEED_CAP : WATER_SPEED_CAP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.vmstudio.visor.core.client.render.context.RenderContext;
import org.vmstudio.visor.api.client.input.HandAction;
import org.vmstudio.visor.core.client.gui.overlays.builtin.VROverlayGameScreen;
import org.vmstudio.visor.core.client.tasks.types.movement.vehicle.TasVehicle;
import org.vmstudio.visor.core.client.tasks.types.movement.vehicle.TaskVehicle;
import org.vmstudio.visor.extensions.client.MinecraftExtension;
import org.vmstudio.visor.extensions.client.entity.LocalPlayerExtension;
import org.vmstudio.visor.core.client.render.VRRenderState;
Expand Down Expand Up @@ -423,9 +423,9 @@ public abstract class MinecraftMixin implements MinecraftExtension {
}
if (entity != this.player) {
// ride the new camera entity
TasVehicle.getInstance().onStartRiding(entity);
TaskVehicle.getInstance().onStartRiding(entity);
} else {
TasVehicle.getInstance().onStopRiding();
TaskVehicle.getInstance().onStopRiding();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.vmstudio.visor.core.client.VisorState;
import org.vmstudio.visor.core.client.network.ClientNetworking;
import org.vmstudio.visor.core.client.render.helpers.RenderPoseHelper;
import org.vmstudio.visor.core.client.tasks.types.movement.vehicle.TasVehicle;
import org.vmstudio.visor.core.client.tasks.types.movement.vehicle.TaskVehicle;
import org.vmstudio.visor.mixin.common.player.Common_PlayerMixin;
import org.vmstudio.visor.extensions.client.entity.LocalPlayerExtension;
import org.vmstudio.visor.extensions.client.render.ItemInHandRendererExtension;
Expand Down Expand Up @@ -82,7 +82,7 @@ public abstract class LocalPlayerMixin extends Common_PlayerMixin implements Loc
|| !visor$isLocalPlayer(this)) {
return;
}
TasVehicle.getInstance()
TaskVehicle.getInstance()
.onStartRiding(
entity
);
Expand All @@ -95,7 +95,7 @@ public abstract class LocalPlayerMixin extends Common_PlayerMixin implements Loc
|| !visor$isLocalPlayer(this)) {
return;
}
TasVehicle.getInstance()
TaskVehicle.getInstance()
.onStopRiding();
}

Expand Down Expand Up @@ -252,6 +252,11 @@ public abstract class LocalPlayerMixin extends Common_PlayerMixin implements Loc

var rotationElement = ClientContext.localPlayer
.getRotationElement(PlayerPoseType.TICK);
if (this.isSwimming()) {
rotationElement = ClientContext.localPlayer
.getPoseData(PlayerPoseType.TICK)
.getHmd();
}

//SWIMMING OR FLYING
if (!this.isPassenger()
Expand Down Expand Up @@ -285,7 +290,7 @@ public abstract class LocalPlayerMixin extends Common_PlayerMixin implements Loc

boolean shouldReset = (x + y + z) == 0;
if (this.isPassenger()) {
Vec3 premountPos = TasVehicle.getInstance().premountPosRoom;
Vec3 premountPos = TaskVehicle.getInstance().premountPosRoom;
premountPos = premountPos
.yRot(
ClientContext.localPlayer
Expand Down