feat: add distance option to autofish

This commit is contained in:
əlemi 2024-01-17 00:18:13 +01:00
parent 63cfbaa56c
commit 2893438f64
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -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<Boolean> recast;
public final ForgeConfigSpec.ConfigValue<Integer> delay;
public final ForgeConfigSpec.ConfigValue<Double> distance;
// public final ForgeConfigSpec.ConfigValue<Long> 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;