Skip to content

Commit

Permalink
Fix Sinytra Connector Extras
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubydesic committed Sep 28, 2024
1 parent 8be7800 commit 500230d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Double> original) {
return VSGameUtilsKt.squaredDistanceBetweenInclShips(this.minecraft.level, instance, vec3, original);
}

@Inject(method = "render", at = @At("HEAD"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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>?
): 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
Expand Down

0 comments on commit 500230d

Please sign in to comment.