From 2893438f64fa9e5a4c38d896c93244daa51aacd6 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 17 Jan 2024 00:18:13 +0100 Subject: feat: add distance option to autofish --- src/main/java/ftbsc/bscv/modules/self/AutoFish.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java index 9394233..bed4e9e 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java @@ -9,6 +9,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.network.play.server.SPlaySoundEffectPacket; import net.minecraft.util.Hand; import net.minecraft.util.SoundEvents; +import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -17,6 +18,7 @@ public class AutoFish extends AbstractModule { public final ForgeConfigSpec.ConfigValue recast; public final ForgeConfigSpec.ConfigValue delay; + public final ForgeConfigSpec.ConfigValue distance; // public final ForgeConfigSpec.ConfigValue reaction; public AutoFish() { @@ -33,13 +35,23 @@ public class AutoFish extends AbstractModule { .name("delay") .comment("how long in ms to wait before recasting hook") .build(this); + + this.distance = Setting.Decimal.builder() + .fallback(0.) + .name("distance") + .comment("ignore splashes further than X blocks, set to 0 to disable") + .build(this); } @SubscribeEvent public void onPacket(PacketEvent.Incoming event) { if (event.packet instanceof SPlaySoundEffectPacket) { SPlaySoundEffectPacket packet = (SPlaySoundEffectPacket) event.packet; - if (packet.getSound().equals(SoundEvents.FISHING_BOBBER_SPLASH)) { + Vector3d location = new Vector3d(packet.getX(), packet.getY(), packet.getZ()); + if ( + packet.getSound().equals(SoundEvents.FISHING_BOBBER_SPLASH) + && (this.distance.get() == 0 || MC.player.position().distanceTo(location) < this.distance.get()) + ) { MC.gameMode.useItem(MC.player, MC.level, Hand.MAIN_HAND); if (this.recast.get()) { new RecastThread(MC, this.delay.get()).start(); @@ -48,6 +60,7 @@ public class AutoFish extends AbstractModule { } } + // TODO don't spawn a thread, minecraft has a way to schedule actions for later private class RecastThread extends Thread { private long delay; private Minecraft mc; -- cgit v1.2.3-56-ga3b1