From 9e4634a5388953f662fc001583efcd9371b710f5 Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Thu, 26 Dec 2024 17:54:48 +0000 Subject: [PATCH 01/11] made bow firing power be actually based on how far the hand is pulled back --- .../client_vr/gameplay/trackers/BowTracker.java | 8 -------- .../client_vr/render/VivecraftItemRendering.java | 6 ------ .../vivecraft/mixin/server/ServerPlayerMixin.java | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java index ad2eee10a..676ede138 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java @@ -59,10 +59,6 @@ public boolean isNotched() { return this.canDraw || this.isDrawing; } - public boolean isCharged() { - return Util.getMillis() - this.startDrawTime >= MAX_DRAW_MILLIS; - } - public static boolean isBow(ItemStack itemStack) { if (itemStack == ItemStack.EMPTY) { return false; @@ -275,10 +271,6 @@ public void doProcess(LocalPlayer player) { } } - if (this.isCharged() && this.hapCounter % 4 == 0) { - this.dh.vr.triggerHapticPulse(bowHand, 200); - } - this.lastHapStep = hapStep; this.hapCounter++; } else { diff --git a/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java b/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java index db826698c..319e8cf48 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java @@ -224,12 +224,6 @@ public static void applyFirstPersonItemTransforms( // calculate bow model roll. float roll = Mth.RAD_TO_DEG * angle; - if (DH.bowTracker.isCharged()) { - // bow jitter - long j = Util.getMillis() - DH.bowTracker.startDrawTime; - translateX += 0.003F * Mth.sin(j); - } - poseStack.translate(0.0F, 0.0F, 0.1F); // un-do controller tracking poseStack.last().pose().multiply(MathUtils.toMcMat4( diff --git a/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java b/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java index 91324faaf..353c3c193 100644 --- a/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java @@ -20,6 +20,7 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.AbstractArrow; +import net.minecraft.world.item.BowItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.PotionUtils; @@ -110,6 +111,19 @@ protected ServerPlayerMixin(EntityType entityType, Level } } + @Override + public void releaseUsingItem() { + ServerVivePlayer serverVivePlayer = vivecraft$getVivePlayer(); + if (serverVivePlayer != null && serverVivePlayer.isVR()) { + if (serverVivePlayer.draw > 0.0F) { + if (!this.useItem.isEmpty()) { + this.useItemRemaining = Math.max(this.useItem.getUseDuration() - (int) (BowItem.MAX_DRAW_DURATION * serverVivePlayer.draw), 0); + } + } + } + super.releaseUsingItem(); + } + /** * inject into {@link Player#attack} */ From c342d5a733d50c9fb000c6ccff2dc6b8783b01e9 Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Fri, 27 Dec 2024 15:20:35 +0000 Subject: [PATCH 02/11] restore charged bow feedback for non-Vivecraft servers (where use-time mechanic is relevant) --- .../client_vr/gameplay/trackers/BowTracker.java | 12 ++++++++++++ .../client_vr/render/VivecraftItemRendering.java | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java index 676ede138..a52e0c2cc 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java @@ -59,6 +59,14 @@ public boolean isNotched() { return this.canDraw || this.isDrawing; } + public boolean isCharged() { + if (!ClientNetworking.SERVER_WANTS_DATA) { + return Util.getMillis() - this.startDrawTime >= MAX_DRAW_MILLIS; + } else { + return false; + } + } + public static boolean isBow(ItemStack itemStack) { if (itemStack == ItemStack.EMPTY) { return false; @@ -271,6 +279,10 @@ public void doProcess(LocalPlayer player) { } } + if (this.isCharged() && this.hapCounter % 4 == 0) { + this.dh.vr.triggerHapticPulse(bowHand, 200); + } + this.lastHapStep = hapStep; this.hapCounter++; } else { diff --git a/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java b/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java index 319e8cf48..db826698c 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java @@ -224,6 +224,12 @@ public static void applyFirstPersonItemTransforms( // calculate bow model roll. float roll = Mth.RAD_TO_DEG * angle; + if (DH.bowTracker.isCharged()) { + // bow jitter + long j = Util.getMillis() - DH.bowTracker.startDrawTime; + translateX += 0.003F * Mth.sin(j); + } + poseStack.translate(0.0F, 0.0F, 0.1F); // un-do controller tracking poseStack.last().pose().multiply(MathUtils.toMcMat4( From d015578ee8a4b902f43efd39e0a2cf89b5010ae7 Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Thu, 26 Dec 2024 22:56:50 +0000 Subject: [PATCH 03/11] adjusted swimming speed and buoyancy --- .../client_vr/gameplay/trackers/SwimTracker.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/SwimTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/SwimTracker.java index 3df513d1c..03125e799 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/SwimTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/SwimTracker.java @@ -2,15 +2,17 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.tags.FluidTags; import net.minecraft.world.phys.Vec3; import org.joml.Vector3f; import org.vivecraft.client_vr.ClientDataHolderVR; +import org.vivecraft.client_vr.settings.AutoCalibration; import org.vivecraft.common.utils.MathUtils; public class SwimTracker extends Tracker { - private static final float FRICTION = 0.9F; - private static final float RISE_SPEED = 0.005F; - private static final float SWIM_SPEED = 1.3F; + private static final float FRICTION = 0.85F; + private static final float RISE_SPEED = 0.0015F; + private static final float SWIM_SPEED = 1.0F; private Vector3f motion = new Vector3f(); private double lastDist; @@ -67,6 +69,10 @@ public void doProcess(LocalPlayer player) { this.motion = this.motion.add(velocity); } + if (player.getFluidHeight(FluidTags.WATER) > AutoCalibration.getPlayerHeight() - 0.1F) { + this.motion = this.motion.add(0.0f, RISE_SPEED, 0.0f); + } + this.lastDist = distance; player.setSwimming(this.motion.length() > 0.3D); player.setSprinting(this.motion.length() > 1.0D); From fc551883a4066619aac18d1b21754bc0fb1371fe Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Thu, 26 Dec 2024 23:01:30 +0000 Subject: [PATCH 04/11] fix boat player offset --- .../client_vr/gameplay/trackers/VehicleTracker.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/VehicleTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/VehicleTracker.java index 190887be4..7dcb7c939 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/VehicleTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/VehicleTracker.java @@ -49,11 +49,11 @@ public void reset(LocalPlayer player) { } public double getVehicleFloor(Entity vehicle, double original) { -// if (vehicle instanceof AbstractHorse) { - return original; // horses are fine. -// } else { -// return vehicle.getY(); -// } + if (vehicle instanceof Boat) { + return original + 0.6f; + } else { + return original; + } } public static Vector3f getSteeringDirection(LocalPlayer player) { From e9ea7bbd487662701d089922242971ab1f368504 Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Thu, 26 Dec 2024 23:51:06 +0000 Subject: [PATCH 05/11] enabled alternative rowing mechanic --- .../gameplay/trackers/RowTracker.java | 38 ++----------------- .../mixin/client_vr/world/BoatMixin.java | 14 ------- 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java index 755cae7ba..c85b41a86 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java @@ -15,10 +15,6 @@ public class RowTracker extends Tracker { private static final double TRANSMISSION_EFFICIENCY = 0.9D; public double[] forces = new double[]{0.0D, 0.0D}; - public float LOar; - public float ROar; - public float FOar; - private final Vec3[] lastUWPs = new Vec3[2]; public RowTracker(Minecraft mc, ClientDataHolderVR dh) { @@ -45,45 +41,17 @@ public boolean isActive(LocalPlayer player) { } public boolean isRowing() { - return this.ROar + this.LOar + this.FOar > 0.0F; + return this.forces[0] != 0.0D || this.forces[1] != 0.0D; } @Override public void reset(LocalPlayer player) { - this.LOar = 0.0F; - this.ROar = 0.0F; - this.FOar = 0.0F; + this.forces[0] = 0.0D; + this.forces[1] = 0.0D; } @Override public void doProcess(LocalPlayer player) { - float c0Move = this.dh.vr.controllerHistory[0].averageSpeed(0.5D); - float c1Move = this.dh.vr.controllerHistory[1].averageSpeed(0.5D); - - final float minSpeed = 0.5F; - final float maxSpeed = 2.0F; - - this.ROar = Math.max(c0Move - minSpeed, 0.0F); - this.LOar = Math.max(c1Move - minSpeed, 0.0F); - - this.FOar = this.ROar > 0.0F && this.LOar > 0.0F ? (this.ROar + this.LOar) / 2.0F : 0.0F; - - if (this.FOar > maxSpeed) { - this.FOar = maxSpeed; - } - - if (this.ROar > maxSpeed) { - this.ROar = maxSpeed; - } - - if (this.LOar > maxSpeed) { - this.LOar = maxSpeed; - } - - // TODO: Backwards paddlin' - } - - public void doProcessFinaltransmithastofixthis(LocalPlayer player) { Boat boat = (Boat) player.getVehicle(); Quaternionf boatRot = new Quaternionf().rotationYXZ( Mth.DEG_TO_RAD * -(boat.getYRot() % 360.0F), diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java index ffdd7a729..ff8cb78fa 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java @@ -89,13 +89,8 @@ public BoatMixin(EntityType entityType, Level level) { } else if (dataHolder.rowTracker.isRowing()) { // roomscale rowing - this.deltaRotation += dataHolder.rowTracker.LOar / 1.5F; - this.deltaRotation -= dataHolder.rowTracker.ROar / 1.5F; - - /* this.deltaRotation += dataHolder.rowTracker.forces[0] * 50; this.deltaRotation -= dataHolder.rowTracker.forces[1] * 50; - */ if (this.deltaRotation < 0F) { this.inputLeft = true; @@ -104,19 +99,10 @@ public BoatMixin(EntityType entityType, Level level) { this.inputRight = true; } - // clamp to vanilla speed - acceleration = Math.min(0.04F, 0.06F * dataHolder.rowTracker.FOar); - if (acceleration > 0F) { - this.inputUp = true; - } - - /* acceleration = (float) (dataHolder.rowTracker.forces[0] + dataHolder.rowTracker.forces[1]); if (acceleration > 0.005F) { this.inputUp = true; } - */ - } } return acceleration; From 7bacd28d8bda8fbaf8227444c05a50375dc1ae7b Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Fri, 27 Dec 2024 00:20:31 +0000 Subject: [PATCH 06/11] animated boat paddles to match arm position --- .../client_vr/extensions/BoatExtension.java | 8 ++++++ .../gameplay/trackers/RowTracker.java | 7 +++++- .../mixin/client_vr/model/BoatModelMixin.java | 25 +++++++++++++++++++ .../mixin/client_vr/world/BoatMixin.java | 25 ++++++++++++++++++- .../src/main/resources/vivecraft.mixins.json | 1 + 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 common/src/main/java/org/vivecraft/client_vr/extensions/BoatExtension.java create mode 100644 common/src/main/java/org/vivecraft/mixin/client_vr/model/BoatModelMixin.java diff --git a/common/src/main/java/org/vivecraft/client_vr/extensions/BoatExtension.java b/common/src/main/java/org/vivecraft/client_vr/extensions/BoatExtension.java new file mode 100644 index 000000000..c7d6a96c0 --- /dev/null +++ b/common/src/main/java/org/vivecraft/client_vr/extensions/BoatExtension.java @@ -0,0 +1,8 @@ +package org.vivecraft.client_vr.extensions; + +import net.minecraft.world.phys.Vec3; + +public interface BoatExtension { + + Vec3[] vivecraft$getPaddleAngles(); +} diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java index c85b41a86..59af84ed2 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java @@ -16,6 +16,7 @@ public class RowTracker extends Tracker { public double[] forces = new double[]{0.0D, 0.0D}; private final Vec3[] lastUWPs = new Vec3[2]; + public Vec3[] paddleAngles = new Vec3[]{null, null}; public RowTracker(Minecraft mc, ClientDataHolderVR dh) { super(mc, dh); @@ -48,6 +49,8 @@ public boolean isRowing() { public void reset(LocalPlayer player) { this.forces[0] = 0.0D; this.forces[1] = 0.0D; + this.paddleAngles[0] = null; + this.paddleAngles[1] = null; } @Override @@ -59,8 +62,10 @@ public void doProcess(LocalPlayer player) { 0.0F).normalize(); for (int paddle = 0; paddle <= 1; paddle++) { + Vec3 arm2Pad = this.getArmToPaddleVector(paddle, boat); + this.paddleAngles[paddle] = MathUtils.toMcVec3(boatRot.transformInverse(new Vector3f((float) arm2Pad.x, (float) arm2Pad.y, (float) arm2Pad.z))); + if (this.isPaddleUnderWater(paddle, boat)) { - Vec3 arm2Pad = this.getArmToPaddleVector(paddle, boat); Vec3 attach = this.getAttachmentPoint(paddle, boat); Vec3 underWaterPoint = attach.add(arm2Pad.normalize()).subtract(boat.position()); diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/model/BoatModelMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/model/BoatModelMixin.java new file mode 100644 index 000000000..5fc3126f8 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/model/BoatModelMixin.java @@ -0,0 +1,25 @@ +package org.vivecraft.mixin.client_vr.model; + +import net.minecraft.client.model.BoatModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.world.entity.vehicle.Boat; +import net.minecraft.world.phys.Vec3; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import org.vivecraft.client_vr.extensions.BoatExtension; + +@Mixin(BoatModel.class) +public abstract class BoatModelMixin { + @Inject(at = @At(value = "HEAD"), method = "animatePaddle(Lnet/minecraft/world/entity/vehicle/Boat;ILnet/minecraft/client/model/geom/ModelPart;F)V", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + private static void vivecraft$animatePaddle(Boat boat, int paddle, ModelPart mp, float f, CallbackInfo ci) { + Vec3 paddleAngle = ((BoatExtension) boat).vivecraft$getPaddleAngles()[paddle]; + if (paddleAngle != null) { + mp.xRot = (float) Math.atan2(paddleAngle.y, Math.sqrt(paddleAngle.x * paddleAngle.x + paddleAngle.z * paddleAngle.z)); + mp.yRot = (float) Math.atan2(paddleAngle.z, paddleAngle.x); + ci.cancel(); + } + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java index ff8cb78fa..f408f7336 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java @@ -6,16 +6,20 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.vehicle.Boat; import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; 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.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; +import org.vivecraft.client_vr.extensions.BoatExtension; import org.vivecraft.client_vr.settings.VRSettings; @Mixin(Boat.class) -public abstract class BoatMixin extends Entity { +public abstract class BoatMixin extends Entity implements BoatExtension { @Shadow private float deltaRotation; @@ -26,6 +30,11 @@ public abstract class BoatMixin extends Entity { @Shadow private boolean inputUp; + @Shadow + public abstract void setPaddleState(boolean pLeft, boolean pRight); + + public Vec3[] paddleAngles = new Vec3[]{null, null}; + public BoatMixin(EntityType entityType, Level level) { super(entityType, level); } @@ -103,8 +112,22 @@ public BoatMixin(EntityType entityType, Level level) { if (acceleration > 0.005F) { this.inputUp = true; } + + this.paddleAngles[0] = dataHolder.rowTracker.paddleAngles[0]; + this.paddleAngles[1] = dataHolder.rowTracker.paddleAngles[1]; } } return acceleration; } + + @Inject(at = @At(value = "HEAD"), method = "tick()V") + private void vivecraft$clearPaddleAngles(CallbackInfo ci) { + this.paddleAngles[0] = null; + this.paddleAngles[1] = null; + } + + @Override + public Vec3[] vivecraft$getPaddleAngles() { + return this.paddleAngles; + } } diff --git a/common/src/main/resources/vivecraft.mixins.json b/common/src/main/resources/vivecraft.mixins.json index 9fa99a819..1e7675692 100644 --- a/common/src/main/resources/vivecraft.mixins.json +++ b/common/src/main/resources/vivecraft.mixins.json @@ -56,6 +56,7 @@ "client_vr.gui.screens.inventory.CreativeModeInventoryScreenVRMixin", "client_vr.gui.screens.inventory.SignEditScreenVRMixin", "client_vr.lwjgl.OpenVRMixin", + "client_vr.model.BoatModelMixin", "client_vr.multiplayer.ClientPacketListenerVRMixin", "client_vr.multiplayer.MultiPlayerGameModeVRMixin", "client_vr.particle.ItemPickupParticleVRMixin", From fecbc91b97308fcebe29029d5a170f82473cd90d Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Fri, 27 Dec 2024 15:23:39 +0000 Subject: [PATCH 07/11] track when paddle is in the water and use this to start/stop vanilla rowing cycle --- .../client_vr/gameplay/trackers/RowTracker.java | 12 +++++++++++- .../mixin/client_vr/world/BoatMixin.java | 16 +++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java index 59af84ed2..5fd462fbd 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java @@ -17,6 +17,7 @@ public class RowTracker extends Tracker { public double[] forces = new double[]{0.0D, 0.0D}; private final Vec3[] lastUWPs = new Vec3[2]; public Vec3[] paddleAngles = new Vec3[]{null, null}; + public boolean[] paddleInWater = new boolean[]{false, false}; public RowTracker(Minecraft mc, ClientDataHolderVR dh) { super(mc, dh); @@ -42,7 +43,7 @@ public boolean isActive(LocalPlayer player) { } public boolean isRowing() { - return this.forces[0] != 0.0D || this.forces[1] != 0.0D; + return this.paddleAngles[0] != null || this.paddleAngles[1] != null; } @Override @@ -51,6 +52,8 @@ public void reset(LocalPlayer player) { this.forces[1] = 0.0D; this.paddleAngles[0] = null; this.paddleAngles[1] = null; + this.paddleInWater[0] = false; + this.paddleInWater[1] = false; } @Override @@ -65,7 +68,10 @@ public void doProcess(LocalPlayer player) { Vec3 arm2Pad = this.getArmToPaddleVector(paddle, boat); this.paddleAngles[paddle] = MathUtils.toMcVec3(boatRot.transformInverse(new Vector3f((float) arm2Pad.x, (float) arm2Pad.y, (float) arm2Pad.z))); + boolean inWater; if (this.isPaddleUnderWater(paddle, boat)) { + inWater = true; + Vec3 attach = this.getAttachmentPoint(paddle, boat); Vec3 underWaterPoint = attach.add(arm2Pad.normalize()).subtract(boat.position()); @@ -91,9 +97,13 @@ public void doProcess(LocalPlayer player) { this.lastUWPs[paddle] = underWaterPoint; } else { + inWater = false; + this.forces[paddle] = 0.0D; this.lastUWPs[paddle] = null; } + + this.paddleInWater[paddle] = inWater; } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java index f408f7336..4c7219ef0 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java @@ -39,7 +39,7 @@ public BoatMixin(EntityType entityType, Level level) { super(entityType, level); } - @ModifyExpressionValue(method = "controlBoat", at = @At(value = "CONSTANT", args = "floatValue=1F", ordinal = 0)) + @ModifyExpressionValue(method = "controlBoatq", at = @At(value = "CONSTANT", args = "floatValue=1F", ordinal = 0)) private float vivecraft$inputLeft(float leftInput) { return VRState.VR_RUNNING ? Minecraft.getInstance().player.input.leftImpulse : leftInput; } @@ -101,17 +101,11 @@ public BoatMixin(EntityType entityType, Level level) { this.deltaRotation += dataHolder.rowTracker.forces[0] * 50; this.deltaRotation -= dataHolder.rowTracker.forces[1] * 50; - if (this.deltaRotation < 0F) { - this.inputLeft = true; - } - if (this.deltaRotation > 0F) { - this.inputRight = true; - } - acceleration = (float) (dataHolder.rowTracker.forces[0] + dataHolder.rowTracker.forces[1]); - if (acceleration > 0.005F) { - this.inputUp = true; - } + + this.inputLeft = dataHolder.rowTracker.paddleInWater[0] && !dataHolder.rowTracker.paddleInWater[1]; + this.inputRight = dataHolder.rowTracker.paddleInWater[1] && !dataHolder.rowTracker.paddleInWater[0]; + this.inputUp = dataHolder.rowTracker.paddleInWater[0] || dataHolder.rowTracker.paddleInWater[1]; this.paddleAngles[0] = dataHolder.rowTracker.paddleAngles[0]; this.paddleAngles[1] = dataHolder.rowTracker.paddleAngles[1]; From 27e39be257d14408570a0c85cce7e61674ba40ac Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Fri, 27 Dec 2024 15:54:14 +0000 Subject: [PATCH 08/11] haptics for rowing --- .../client_vr/gameplay/trackers/RowTracker.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java index 5fd462fbd..079423aa7 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java @@ -9,6 +9,7 @@ import org.joml.Quaternionf; import org.joml.Vector3f; import org.vivecraft.client_vr.ClientDataHolderVR; +import org.vivecraft.client_vr.provider.ControllerType; import org.vivecraft.common.utils.MathUtils; public class RowTracker extends Tracker { @@ -103,6 +104,22 @@ public void doProcess(LocalPlayer player) { this.lastUWPs[paddle] = null; } + if (inWater) { + if (!this.paddleInWater[paddle]) { + this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, 0.8F); + } else { + float strength = (float) (Math.abs(this.forces[paddle]) / 0.1D); + if (strength > 0.05F) { + strength = strength * 0.7F + 0.3F; + this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, strength); + } + } + } else { + if (this.paddleInWater[paddle]) { + this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, 0.2F); + } + } + this.paddleInWater[paddle] = inWater; } } From 2329f12ed3a7ad6ea7426133ceaa44c4f2b4dfee Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Fri, 27 Dec 2024 15:55:33 +0000 Subject: [PATCH 09/11] simplify rowing calculation and tweak parameters --- .../client_vr/gameplay/trackers/RowTracker.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java index 079423aa7..67ddc519c 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java @@ -2,7 +2,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.core.BlockPos; import net.minecraft.util.Mth; import net.minecraft.world.entity.vehicle.Boat; import net.minecraft.world.phys.Vec3; @@ -13,7 +12,7 @@ import org.vivecraft.common.utils.MathUtils; public class RowTracker extends Tracker { - private static final double TRANSMISSION_EFFICIENCY = 0.9D; + private static final double TRANSMISSION_EFFICIENCY = 1.0D; public double[] forces = new double[]{0.0D, 0.0D}; private final Vec3[] lastUWPs = new Vec3[2]; @@ -74,15 +73,11 @@ public void doProcess(LocalPlayer player) { inWater = true; Vec3 attach = this.getAttachmentPoint(paddle, boat); - Vec3 underWaterPoint = attach.add(arm2Pad.normalize()).subtract(boat.position()); + Vec3 underWaterPoint = attach.add(arm2Pad.normalize()); if (this.lastUWPs[paddle] != null) { Vector3f forceVector = MathUtils.subtractToVector3f(this.lastUWPs[paddle], underWaterPoint); // intentionally reverse - forceVector = forceVector.sub( - (float) boat.getDeltaMovement().x, - (float) boat.getDeltaMovement().y, - (float) boat.getDeltaMovement().z); Vector3f forward = boatRot.transform(MathUtils.FORWARD, new Vector3f()); @@ -149,7 +144,7 @@ private Vec3 getAbsArmPos(int side) { private boolean isPaddleUnderWater(int paddle, Boat boat) { Vec3 attachAbs = this.getAttachmentPoint(paddle, boat); Vec3 armToPaddle = this.getArmToPaddleVector(paddle, boat).normalize(); - BlockPos blockPos = new BlockPos(attachAbs.add(armToPaddle)); - return boat.level.getBlockState(blockPos).getMaterial().isLiquid(); + Vec3 blockPos = attachAbs.add(armToPaddle); + return blockPos.subtract(boat.position()).y < 0.2F; } } From f18ec27da260bf2a0dd9f91ba276ab879be3c08b Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Fri, 27 Dec 2024 16:30:19 +0000 Subject: [PATCH 10/11] automatically detect which way the player is sitting in the boat and swap paddle hands accordingly --- .../gameplay/trackers/RowTracker.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java index 67ddc519c..b330f7668 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java @@ -18,6 +18,7 @@ public class RowTracker extends Tracker { private final Vec3[] lastUWPs = new Vec3[2]; public Vec3[] paddleAngles = new Vec3[]{null, null}; public boolean[] paddleInWater = new boolean[]{false, false}; + private int[] hands = new int[2]; public RowTracker(Minecraft mc, ClientDataHolderVR dh) { super(mc, dh); @@ -64,12 +65,22 @@ public void doProcess(LocalPlayer player) { Mth.DEG_TO_RAD * boat.getXRot(), 0.0F).normalize(); + Vector3f hand0 = boatRot.transformInverse(MathUtils.subtractToVector3f(this.getAbsArmPos(0), boat.position())); + Vector3f hand1 = boatRot.transformInverse(MathUtils.subtractToVector3f(this.getAbsArmPos(1), boat.position())); + if (hand0.x > hand1.x) { + hands[0] = 0; + hands[1] = 1; + } else { + hands[0] = 1; + hands[1] = 0; + } + for (int paddle = 0; paddle <= 1; paddle++) { - Vec3 arm2Pad = this.getArmToPaddleVector(paddle, boat); + Vec3 arm2Pad = this.getArmToPaddleVector(paddle, hands[paddle], boat); this.paddleAngles[paddle] = MathUtils.toMcVec3(boatRot.transformInverse(new Vector3f((float) arm2Pad.x, (float) arm2Pad.y, (float) arm2Pad.z))); boolean inWater; - if (this.isPaddleUnderWater(paddle, boat)) { + if (this.isPaddleUnderWater(paddle, hands[paddle], boat)) { inWater = true; Vec3 attach = this.getAttachmentPoint(paddle, boat); @@ -101,17 +112,17 @@ public void doProcess(LocalPlayer player) { if (inWater) { if (!this.paddleInWater[paddle]) { - this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, 0.8F); + this.dh.vr.triggerHapticPulse(ControllerType.values()[hands[paddle]], 0.05F, 100.0F, 0.8F); } else { float strength = (float) (Math.abs(this.forces[paddle]) / 0.1D); if (strength > 0.05F) { strength = strength * 0.7F + 0.3F; - this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, strength); + this.dh.vr.triggerHapticPulse(ControllerType.values()[hands[paddle]], 0.05F, 100.0F, strength); } } } else { if (this.paddleInWater[paddle]) { - this.dh.vr.triggerHapticPulse(paddle == 0 ? ControllerType.LEFT : ControllerType.RIGHT, 0.05F, 100.0F, 0.2F); + this.dh.vr.triggerHapticPulse(ControllerType.values()[hands[paddle]], 0.05F, 100.0F, 0.2F); } } @@ -119,9 +130,9 @@ public void doProcess(LocalPlayer player) { } } - private Vec3 getArmToPaddleVector(int paddle, Boat boat) { + private Vec3 getArmToPaddleVector(int paddle, int hand, Boat boat) { Vec3 attachAbs = this.getAttachmentPoint(paddle, boat); - Vec3 armAbs = this.getAbsArmPos(paddle == 0 ? 1 : 0); + Vec3 armAbs = this.getAbsArmPos(hand); return attachAbs.subtract(armAbs); } @@ -141,9 +152,9 @@ private Vec3 getAbsArmPos(int side) { return this.dh.vrPlayer.roomOrigin.add(arm.x, arm.y, arm.z); } - private boolean isPaddleUnderWater(int paddle, Boat boat) { + private boolean isPaddleUnderWater(int paddle, int hand, Boat boat) { Vec3 attachAbs = this.getAttachmentPoint(paddle, boat); - Vec3 armToPaddle = this.getArmToPaddleVector(paddle, boat).normalize(); + Vec3 armToPaddle = this.getArmToPaddleVector(paddle, hand, boat).normalize(); Vec3 blockPos = attachAbs.add(armToPaddle); return blockPos.subtract(boat.position()).y < 0.2F; } From 851d044a108079a21f52b4ffa212311f4b42ed2c Mon Sep 17 00:00:00 2001 From: micheal65536 <> Date: Wed, 15 Jan 2025 17:36:35 +0000 Subject: [PATCH 11/11] removed ProjectileMixin velocity override because we have bow use time override instead --- .../mixin/world/entity/projectile/ProjectileMixin.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ProjectileMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ProjectileMixin.java index 84e9f7432..ffb3959dd 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ProjectileMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ProjectileMixin.java @@ -4,9 +4,7 @@ import com.llamalad7.mixinextras.sugar.ref.LocalRef; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.Projectile; -import net.minecraft.world.entity.projectile.ThrownTrident; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -27,13 +25,6 @@ public class ProjectileMixin { // aim direction direction.set(serverVivePlayer.getAimDir()); - - if (projectile instanceof AbstractArrow && !(projectile instanceof ThrownTrident) && - !serverVivePlayer.isSeated() && serverVivePlayer.draw > 0.0F) - { - // modify velocity based on draw range - return velocity * serverVivePlayer.draw; - } } } return velocity;