summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-02-15 21:45:41 +0100
committer alemi <me@alemi.dev>2023-02-15 21:45:41 +0100
commit04aec8c2a30a4c39e1936c80e06c289cee52f04e (patch)
tree5c3e1735ec94c8b55a3bd7d9d515de986185fca4 /src/main/java
parent1a11a3e163205e4bb64b1a724af019fff86d400b (diff)
feat: added basic autofish
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/ftbsc/bscv/BoSCoVicino.java1
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/AutoFish.java77
2 files changed, 78 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/BoSCoVicino.java b/src/main/java/ftbsc/bscv/BoSCoVicino.java
index 5f2bc6b..4603d3f 100644
--- a/src/main/java/ftbsc/bscv/BoSCoVicino.java
+++ b/src/main/java/ftbsc/bscv/BoSCoVicino.java
@@ -64,6 +64,7 @@ public class BoSCoVicino implements ICommons {
BoSCoVicino.mods.add(new EntityList(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new Fullbright(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new AntiHunger(cfg, dp).done(cfg));
+ BoSCoVicino.mods.add(new AutoFish(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new Freecam(cfg, dp).done(cfg));
BoSCoVicino.spec = cfg.build();
diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoFish.java b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java
new file mode 100644
index 0000000..78bed18
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/modules/self/AutoFish.java
@@ -0,0 +1,77 @@
+package ftbsc.bscv.modules.self;
+
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.BoolArgumentType;
+import com.mojang.brigadier.arguments.LongArgumentType;
+
+import ftbsc.bscv.ICommons;
+import ftbsc.bscv.events.PacketEvent;
+import ftbsc.bscv.modules.Module;
+import net.minecraft.client.Minecraft;
+import net.minecraft.command.CommandSource;
+import net.minecraft.network.play.server.SPlaySoundEffectPacket;
+import net.minecraft.util.Hand;
+import net.minecraft.util.SoundEvents;
+import net.minecraftforge.common.ForgeConfigSpec;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+
+public class AutoFish extends Module implements ICommons {
+
+ public final ForgeConfigSpec.ConfigValue<Boolean> recast;
+ public final ForgeConfigSpec.ConfigValue<Long> delay;
+ // public final ForgeConfigSpec.ConfigValue<Long> reaction;
+
+ public AutoFish(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
+ super("AutoFish", Group.SELF, builder, dispatcher);
+
+ this.recast = this.option(
+ "recast", "automatically recast hook after fishing", false,
+ BoolArgumentType.bool(), Boolean.class,
+ builder, dispatcher
+ );
+
+ this.delay = this.option(
+ "delay", "how long in ms to wait before recasting hook", 2500L,
+ LongArgumentType.longArg(0), Long.class,
+ builder, dispatcher
+ );
+
+ // this.reaction = this.option(
+ // "reaction", "time in ms to react to fish biting", 0L,
+ // LongArgumentType.longArg(0), Long.class,
+ // builder, dispatcher
+ // );
+ }
+
+ @SubscribeEvent
+ public void onPacket(PacketEvent event) {
+ if (event.outgoing) return;
+
+ if (event.packet instanceof SPlaySoundEffectPacket) {
+ SPlaySoundEffectPacket packet = (SPlaySoundEffectPacket) event.packet;
+ if (packet.getSound().equals(SoundEvents.FISHING_BOBBER_SPLASH)) {
+ MC.gameMode.useItem(MC.player, MC.level, Hand.MAIN_HAND);
+ if (this.recast.get()) {
+ new RecastThread(MC, this.delay.get()).start();
+ }
+ }
+ }
+ }
+
+ private class RecastThread extends Thread {
+ private long delay;
+ private Minecraft mc;
+ public RecastThread(Minecraft mc, long delay) {
+ this.mc = mc;
+ this.delay = delay;
+ this.setDaemon(true);
+ }
+
+ public void run() {
+ try {
+ Thread.sleep(this.delay);
+ } catch (InterruptedException e) {} // ignore
+ this.mc.gameMode.useItem(this.mc.player, this.mc.level, Hand.MAIN_HAND);
+ }
+ }
+}