Skip to content

Commit

Permalink
Fixed Fishing Helper at large coordinates caused by float precision loss
Browse files Browse the repository at this point in the history
Bump version to 1.7.3
  • Loading branch information
kevinthegreat1 committed Aug 23, 2022
1 parent 7d2aac6 commit 32b7e2b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs = -Xmx1G
loader_version = 0.14.7

# Mod Properties
mod_version = 1.7.2
mod_version = 1.7.3
maven_group = com.kevinthegreat.skyblockmod
archives_base_name = SkyblockMod

Expand Down
26 changes: 10 additions & 16 deletions src/main/java/com/kevinthegreat/skyblockmod/misc/Fishing.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,34 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;

public class Fishing {
public boolean on = true;
private long startTime;
private Vec2f normalYawVector;
private Vec3d normalYawVector;

public void start(PlayerEntity player) {
startTime = System.currentTimeMillis();
float yawRad = (player.getYaw() + 90) * 0.017453292F;
normalYawVector = new Vec2f(MathHelper.cos(yawRad), MathHelper.sin(yawRad));
normalYawVector = new Vec3d(MathHelper.cos(yawRad), 0, MathHelper.sin(yawRad));
}

public void reset() {
startTime = 0;
}

public void onSound(PlaySoundIdS2CPacket packet) {
public void onSound(MinecraftClient minecraftClient, PlaySoundIdS2CPacket packet) {
if (on && startTime != 0 && System.currentTimeMillis() >= startTime + 2000 && (packet.getSoundId().getPath().equals("entity.generic.splash") || packet.getSoundId().getPath().equals("entity.player.splash"))) {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (player != null) {
FishingBobberEntity fishHook = player.fishHook;
if (fishHook != null) {
Vec2f hookToSound = new Vec2f((float) (packet.getX() - fishHook.getX()), (float) (packet.getZ() - fishHook.getZ()));
if (MathHelper.abs(normalYawVector.x * hookToSound.y - normalYawVector.y * hookToSound.x) < 0.2F && MathHelper.abs(normalYawVector.dot(hookToSound)) < 4 && player.getPos().squaredDistanceTo(packet.getX(), packet.getY(), packet.getZ()) > 1) {
MinecraftClient.getInstance().inGameHud.setTitleTicks(2, 10, 4);
MinecraftClient.getInstance().inGameHud.setTitle(Text.of("§aReel in now!"));
reset();
}
} else {
ClientPlayerEntity player = minecraftClient.player;
if (player != null && player.fishHook != null) {
Vec3d soundToFishHook = player.fishHook.getPos().subtract(packet.getX(), 0, packet.getZ());
if (Math.abs(normalYawVector.x * soundToFishHook.z - normalYawVector.z * soundToFishHook.x) < 0.2D && Math.abs(normalYawVector.dotProduct(soundToFishHook)) < 4D && player.getPos().squaredDistanceTo(packet.getX(), packet.getY(), packet.getZ()) > 1D) {
minecraftClient.inGameHud.setTitleTicks(0, 10, 5);
minecraftClient.inGameHud.setTitle(Text.of("§aReel in now!"));
reset();
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.kevinthegreat.skyblockmod.mixins;

import com.kevinthegreat.skyblockmod.SkyblockMod;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket;
import org.spongepowered.asm.mixin.Final;
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.callback.CallbackInfo;

@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {
@Shadow
@Final
private MinecraftClient client;

@Inject(method = "onPlaySoundId", at = @At(value = "HEAD"))
private void onPlaySoundId(PlaySoundIdS2CPacket packet, CallbackInfo ci) {
SkyblockMod.skyblockMod.fishing.onSound(packet);
SkyblockMod.skyblockMod.fishing.onSound(client, packet);
}
}

0 comments on commit 32b7e2b

Please sign in to comment.