From 500230d35ac3be3ded81b764926a672a3aa0da63 Mon Sep 17 00:00:00 2001 From: Rubydesic Date: Fri, 27 Sep 2024 22:39:45 -0400 Subject: [PATCH] Fix Sinytra Connector Extras --- .../client/renderer/MixinGameRenderer.java | 14 +++----------- .../valkyrienskies/mod/common/VSGameUtils.kt | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/client/renderer/MixinGameRenderer.java b/common/src/main/java/org/valkyrienskies/mod/mixin/client/renderer/MixinGameRenderer.java index ab7aebbd2..0afd14a9d 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/client/renderer/MixinGameRenderer.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/client/renderer/MixinGameRenderer.java @@ -94,23 +94,15 @@ public HitResult modifyCrosshairTargetBlocks(final Entity receiver, final double return pick.call(receiver, maxDistance, tickDelta, includeFluids); } - @Redirect( + @WrapOperation( method = "pick", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;distanceToSqr(Lnet/minecraft/world/phys/Vec3;)D" ) ) - public double correctDistanceChecks(final Vec3 instance, final Vec3 vec) { - return VSGameUtilsKt.squaredDistanceBetweenInclShips( - this.minecraft.level, - vec.x, - vec.y, - vec.z, - instance.x, - instance.y, - instance.z - ); + public double correctDistanceChecks(final Vec3 instance, final Vec3 vec3, final Operation original) { + return VSGameUtilsKt.squaredDistanceBetweenInclShips(this.minecraft.level, instance, vec3, original); } @Inject(method = "render", at = @At("HEAD")) diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/VSGameUtils.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/VSGameUtils.kt index 4e8525774..6fcc20fc5 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/VSGameUtils.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/VSGameUtils.kt @@ -1,5 +1,6 @@ package org.valkyrienskies.mod.common +import com.llamalad7.mixinextras.injector.wrapoperation.Operation import net.minecraft.client.Minecraft import net.minecraft.client.multiplayer.ClientLevel import net.minecraft.core.BlockPos @@ -124,6 +125,24 @@ val Player.playerWrapper get() = (this as PlayerDuck).vs_getPlayer() fun Entity.squaredDistanceToInclShips(x: Double, y: Double, z: Double) = level().squaredDistanceBetweenInclShips(x, y, z, this.x, this.y, this.z) +/** + * Meant to be used with @WrapOperation to replace distance checks in a compatible way + */ +fun Level?.squaredDistanceBetweenInclShips( + v1: Vec3, + v2: Vec3, + originalDistance: Operation? +): Double { + if (originalDistance == null) { + return squaredDistanceBetweenInclShips(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z) // fast path + } + + val inWorldV1 = toWorldCoordinates(v1) + val inWorldV2 = toWorldCoordinates(v2) + + return originalDistance.call(inWorldV1, inWorldV2) +} + /** * Calculates the squared distance between to points. * x1/y1/z1 are transformed into world coordinates if they are on a ship