feat: add distance option to autofish
This commit is contained in:
parent
63cfbaa56c
commit
2893438f64
1 changed files with 14 additions and 1 deletions
|
@ -9,6 +9,7 @@ import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.network.play.server.SPlaySoundEffectPacket;
|
import net.minecraft.network.play.server.SPlaySoundEffectPacket;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.SoundEvents;
|
import net.minecraft.util.SoundEvents;
|
||||||
|
import net.minecraft.util.math.vector.Vector3d;
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
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<Boolean> recast;
|
||||||
public final ForgeConfigSpec.ConfigValue<Integer> delay;
|
public final ForgeConfigSpec.ConfigValue<Integer> delay;
|
||||||
|
public final ForgeConfigSpec.ConfigValue<Double> distance;
|
||||||
// public final ForgeConfigSpec.ConfigValue<Long> reaction;
|
// public final ForgeConfigSpec.ConfigValue<Long> reaction;
|
||||||
|
|
||||||
public AutoFish() {
|
public AutoFish() {
|
||||||
|
@ -33,13 +35,23 @@ public class AutoFish extends AbstractModule {
|
||||||
.name("delay")
|
.name("delay")
|
||||||
.comment("how long in ms to wait before recasting hook")
|
.comment("how long in ms to wait before recasting hook")
|
||||||
.build(this);
|
.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
|
@SubscribeEvent
|
||||||
public void onPacket(PacketEvent.Incoming event) {
|
public void onPacket(PacketEvent.Incoming event) {
|
||||||
if (event.packet instanceof SPlaySoundEffectPacket) {
|
if (event.packet instanceof SPlaySoundEffectPacket) {
|
||||||
SPlaySoundEffectPacket packet = (SPlaySoundEffectPacket) event.packet;
|
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);
|
MC.gameMode.useItem(MC.player, MC.level, Hand.MAIN_HAND);
|
||||||
if (this.recast.get()) {
|
if (this.recast.get()) {
|
||||||
new RecastThread(MC, this.delay.get()).start();
|
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 class RecastThread extends Thread {
|
||||||
private long delay;
|
private long delay;
|
||||||
private Minecraft mc;
|
private Minecraft mc;
|
||||||
|
|
Loading…
Reference in a new issue