|
| 1 | +package dev.isxander.debugify.mixins.basic.mc297837; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 5 | +import dev.isxander.debugify.fixes.BugFix; |
| 6 | +import dev.isxander.debugify.fixes.FixCategory; |
| 7 | +import net.minecraft.server.level.ServerPlayer; |
| 8 | +import net.minecraft.world.entity.Entity; |
| 9 | +import net.minecraft.world.entity.LivingEntity; |
| 10 | +import net.minecraft.world.waypoints.WaypointTransmitter; |
| 11 | +import org.spongepowered.asm.mixin.Mixin; |
| 12 | +import org.spongepowered.asm.mixin.injection.At; |
| 13 | + |
| 14 | +@BugFix(id = "MC-297837", category = FixCategory.BASIC, env = BugFix.Env.CLIENT, description = "Locator bar shows players above you as being below you when they are high enough") |
| 15 | +@Mixin(WaypointTransmitter.class) |
| 16 | +public class WaypointTransmitterMixin { |
| 17 | + /** |
| 18 | + * {@link WaypointTransmitter#isReallyFar(LivingEntity, ServerPlayer)} was being used to determine whether |
| 19 | + * waypoints should use azimuth distance (far away) or chunk/block distance (close/closer by). |
| 20 | + * <p> |
| 21 | + * The azimuth distance provides only relative yRot, which means the pitch uses the horizon, |
| 22 | + * not the waypoint itself. |
| 23 | + * <p> |
| 24 | + * Even when the waypoint is in the same chunk as the entity, the azimuth distance was used because it was |
| 25 | + * over 332 blocks away, just vertically, not horizontally, as I assume it was intended. |
| 26 | + * <p> |
| 27 | + * This mixin fixes the bug by using the block distance instead of the azimuth distance, |
| 28 | + * by changing the distance calculation to only use horizontal distance. |
| 29 | + */ |
| 30 | + @WrapOperation(method = "isReallyFar", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;distanceTo(Lnet/minecraft/world/entity/Entity;)F")) |
| 31 | + private static float useOnlyHorizontalDistance(LivingEntity entity1, Entity entity2, Operation<Float> original) { |
| 32 | + double xDist = entity1.getX() - entity2.getX(); |
| 33 | + double zDist = entity1.getZ() - entity2.getZ(); |
| 34 | + return (float) Math.hypot(xDist, zDist); |
| 35 | + } |
| 36 | + |
| 37 | +} |
0 commit comments