Skip to content

Commit e56eeb8

Browse files
committed
2 parents dacdcf6 + ea904f7 commit e56eeb8

File tree

3 files changed

+122
-60
lines changed

3 files changed

+122
-60
lines changed

src/main/java/dev/journey/PathSeeker/modules/automation/AFKVanillaFly.java

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import dev.journey.PathSeeker.PathSeeker;
44
import dev.journey.PathSeeker.modules.exploration.TrailFollower;
5+
import dev.journey.PathSeeker.modules.utility.Firework;
6+
import meteordevelopment.meteorclient.systems.modules.Modules;
57
import meteordevelopment.meteorclient.events.world.TickEvent;
68
import meteordevelopment.meteorclient.settings.*;
79
import meteordevelopment.meteorclient.systems.modules.Module;
@@ -13,6 +15,18 @@
1315
import net.minecraft.util.Hand;
1416

1517
public class AFKVanillaFly extends Module {
18+
private long lastRocketUse = 0;
19+
private boolean launched = false;
20+
private boolean manuallyEnabled = false;
21+
private double yTarget = -1;
22+
private float targetPitch = 0;
23+
24+
public AFKVanillaFly() {
25+
super(PathSeeker.Automation, "AFKVanillaFly", "Maintains a level Y-flight with fireworks and smooth pitch control.");
26+
}
27+
28+
private final SettingGroup sgGeneral = settings.getDefaultGroup();
29+
1630
private final SettingGroup sgGeneral = settings.getDefaultGroup();
1731
private final Setting<AutoFireworkMode> fireworkMode = sgGeneral.add(new EnumSetting.Builder<AutoFireworkMode>()
1832
.name("Auto Firework Mode")
@@ -46,14 +60,25 @@ public AFKVanillaFly() {
4660

4761
@Override
4862
public void onActivate() {
63+
manuallyEnabled = true; // Track manual activation
4964
launched = false;
5065
yTarget = -1;
5166

67+
Firework firework = Modules.get().get(Firework.class);
68+
if (!firework.isActive()) firework.toggle();
69+
5270
if (mc.player == null || !mc.player.isFallFlying()) {
5371
info("You must be flying before enabling AFKVanillaFly.");
5472
}
5573
}
5674

75+
@Override
76+
public void onDeactivate() {
77+
manuallyEnabled = false; // Reset manual flag
78+
Firework firework = Modules.get().get(Firework.class);
79+
if (firework.isActive()) firework.toggle();
80+
}
81+
5782
public void tickFlyLogic() {
5883
if (mc.player == null) return;
5984

@@ -83,19 +108,15 @@ public void tickFlyLogic() {
83108
targetPitch = 0f;
84109
}
85110

111+
// pitch fix
112+
targetPitch = Math.max(-30f, Math.min(30f, targetPitch));
113+
86114
float currentPitch = mc.player.getPitch();
87115
mc.player.setPitch(currentPitch + (targetPitch - currentPitch) * 0.1f);
88116

89-
if (fireworkMode.get() == AutoFireworkMode.TIMED_DELAY) {
90-
if (System.currentTimeMillis() - lastRocketUse > fireworkDelay.get()) {
91-
tryUseFirework();
92-
}
93-
} else if (fireworkMode.get() == AutoFireworkMode.VELOCITY) {
94-
double speed = Math.sqrt(Math.pow(mc.player.getVelocity().x, 2) + Math.pow(mc.player.getVelocity().z, 2));
95-
if (speed < velocityThreshold.get()) {
96-
tryUseFirework();
97-
}
98-
}
117+
Firework firework = Modules.get().get(Firework.class);
118+
if (!firework.isActive()) firework.toggle();
119+
99120
} else {
100121
// Just jumped or crashed out of flight
101122
TrailFollower trailFollower = Modules.get().get(TrailFollower.class);
@@ -106,54 +127,31 @@ public void tickFlyLogic() {
106127
if (!launched) {
107128
mc.player.jump();
108129
launched = true;
109-
} else if (System.currentTimeMillis() - lastRocketUse > 1000) {
110-
tryUseFirework();
111130
}
112131
yTarget = -1;
113132
}
114133
}
115134

116135
@EventHandler
117136
private void onTick(TickEvent.Pre event) {
118-
tickFlyLogic();
119-
}
120-
121-
public void resetYLock() {
122-
yTarget = -1;
123-
launched = false;
124-
}
125-
126-
private void tryUseFirework() {
127-
FindItemResult hotbar = InvUtils.findInHotbar(Items.FIREWORK_ROCKET);
128-
if (!hotbar.found()) {
129-
FindItemResult inv = InvUtils.find(Items.FIREWORK_ROCKET);
130-
if (inv.found()) {
131-
int hotbarSlot = findEmptyHotbarSlot();
132-
if (hotbarSlot != -1) {
133-
InvUtils.move().from(inv.slot()).to(hotbarSlot);
134-
} else {
135-
info("No empty hotbar slot available.");
136-
return;
137-
}
138-
} else {
139-
info("No fireworks in inventory.");
140-
return;
141-
}
137+
TrailFollower trailFollower = Modules.get().get(TrailFollower.class);
138+
Firework firework = Modules.get().get(Firework.class);
139+
140+
boolean shouldAutoEnable = trailFollower.isActive()
141+
&& trailFollower.flightMode.get() == TrailFollower.FlightMode.VANILLA
142+
&& mc.world != null
143+
&& mc.world.getRegistryKey().getValue().getPath().equals("overworld");
144+
if (shouldAutoEnable && !this.isActive() && !manuallyEnabled) {
145+
this.toggle(); // Auto enable
146+
if (!firework.isActive()) firework.toggle();
142147
}
143-
144-
// Use false so elytra isn't required
145-
dev.journey.PathSeeker.utils.PathSeekerUtil.firework(mc, false);
146-
mc.player.swingHand(Hand.MAIN_HAND);
147-
lastRocketUse = System.currentTimeMillis();
148-
}
149-
150-
private int findEmptyHotbarSlot() {
151-
for (int i = 0; i < 9; i++) {
152-
if (mc.player.getInventory().getStack(i).isEmpty()) return i;
148+
if (!shouldAutoEnable && !manuallyEnabled && this.isActive()) {
149+
this.toggle(); // Auto disable
150+
if (firework.isActive()) firework.toggle();
153151
}
154-
return -1;
152+
if (this.isActive()) tickFlyLogic();
155153
}
156-
154+
}
157155
public enum AutoFireworkMode {
158156
VELOCITY,
159157
TIMED_DELAY

src/main/java/dev/journey/PathSeeker/modules/automation/AutoPortal.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,27 @@ public void onActivate() {
9898
BlockPos base = mc.player.getBlockPos()
9999
.offset(forward, 2)
100100
.offset(right, -1);
101+
// duplicate check
102+
int obsidianCheck = 0;
103+
104+
List<BlockPos> checkPositions = List.of(
105+
base.offset(right, 1), base.offset(right, 2),
106+
base.offset(right, 0).up(1), base.offset(right, 0).up(2), base.offset(right, 0).up(3),
107+
base.offset(right, 3).up(1), base.offset(right, 3).up(2), base.offset(right, 3).up(3),
108+
base.offset(right, 1).up(4), base.offset(right, 2).up(4)
109+
);
110+
111+
for (BlockPos checkPos : checkPositions) {
112+
if (mc.world.getBlockState(checkPos).getBlock().asItem() == Items.OBSIDIAN) {
113+
obsidianCheck++;
114+
}
115+
}
116+
117+
if (obsidianCheck >= checkPositions.size()) {
118+
error("A portal already exists here!");
119+
toggle();
120+
return;
121+
}
101122

102123
portalBlocks.add(base.offset(right, 1));
103124
portalBlocks.add(base.offset(right, 2));
@@ -141,14 +162,29 @@ private void onTick(TickEvent.Post event) {
141162

142163
delay++;
143164
if (delay < placeDelay.get()) return;
144-
// loop to place multiple blocks per tick
145165
for (int i = 0; i < blocksPerTick.get() && index < portalBlocks.size(); i++, index++) {
146166
BlockPos pos = portalBlocks.get(index);
167+
// prevent faulty portal placements
168+
if (!mc.world.getBlockState(pos).isReplaceable()) {
169+
// stop mining obby
170+
if (mc.world.getBlockState(pos).getBlock().asItem() == Items.OBSIDIAN) continue;
171+
172+
if (mc.interactionManager != null) {
173+
mc.interactionManager.attackBlock(pos, Direction.UP);
174+
mc.player.swingHand(Hand.MAIN_HAND);
175+
}
176+
return;
177+
}
178+
179+
147180
BlockHitResult bhr = new BlockHitResult(Vec3d.ofCenter(pos), Direction.UP, pos, false);
148181

149-
mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
150-
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.OFF_HAND, bhr, mc.player.currentScreenHandler.getRevision() + 2));
151-
mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
182+
mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(
183+
PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
184+
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(
185+
Hand.OFF_HAND, bhr, mc.player.currentScreenHandler.getRevision() + 2));
186+
mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(
187+
PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
152188
mc.player.swingHand(Hand.MAIN_HAND);
153189
}
154190
delay = 0;

src/main/java/dev/journey/PathSeeker/modules/utility/Firework.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package dev.journey.PathSeeker.modules.utility;
22

33
import dev.journey.PathSeeker.PathSeeker;
4+
import dev.journey.PathSeeker.modules.automation.AFKVanillaFly;
45
import meteordevelopment.meteorclient.events.world.TickEvent;
56
import meteordevelopment.meteorclient.settings.BoolSetting;
67
import meteordevelopment.meteorclient.settings.DoubleSetting;
78
import meteordevelopment.meteorclient.settings.Setting;
89
import meteordevelopment.meteorclient.settings.SettingGroup;
910
import meteordevelopment.meteorclient.systems.modules.Module;
11+
import meteordevelopment.meteorclient.systems.modules.Modules;
1012
import meteordevelopment.orbit.EventHandler;
1113
import net.minecraft.item.Items;
1214
import net.minecraft.util.Hand;
@@ -38,15 +40,15 @@ public class Firework extends Module {
3840
private final Setting<Double> useDelay = sgGeneral.add(new DoubleSetting.Builder()
3941
.name("use-delay")
4042
.description("Delay in seconds between using rockets.")
41-
.defaultValue(1.0)
43+
.defaultValue(.1)
4244
.min(0.1)
4345
.sliderMax(5.0)
4446
.build()
4547
);
4648
private final Setting<Double> minSpeed = sgVelocity.add(new DoubleSetting.Builder()
4749
.name("minimum-speed")
4850
.description("Minimum speed threshold before using rockets.")
49-
.defaultValue(0.6)
51+
.defaultValue(1.35)
5052
.min(0.1)
5153
.sliderMax(2.0)
5254
.build()
@@ -88,22 +90,48 @@ private void onTick(TickEvent.Post event) {
8890
Vec3d lookVec = getLookVector(yaw, pitch);
8991

9092
double forwardSpeed = velocity.dotProduct(lookVec);
91-
9293
int delayTicks = (int) (useDelay.get() * 20);
9394

9495
if (!isBoostActive && forwardSpeed < minSpeed.get() && ticksSinceLastUse >= delayTicks) {
95-
// Check if player is holding a rocket
9696
boolean holdingRocket = mc.player.getMainHandStack().getItem() == Items.FIREWORK_ROCKET ||
9797
mc.player.getOffHandStack().getItem() == Items.FIREWORK_ROCKET;
9898

99-
if (onlyWhenHoldingRocket.get() && !holdingRocket) return;
100-
99+
if (!holdingRocket) {
100+
int slot = -1;
101+
for (int i = 0; i < 9; i++) {
102+
if (mc.player.getInventory().getStack(i).getItem() == Items.FIREWORK_ROCKET) {
103+
slot = i;
104+
break;
105+
}
106+
}
107+
if (slot == -1) {
108+
for (int i = 9; i < mc.player.getInventory().size(); i++) {
109+
if (mc.player.getInventory().getStack(i).getItem() == Items.FIREWORK_ROCKET) {
110+
for (int j = 0; j < 9; j++) {
111+
if (mc.player.getInventory().getStack(j).isEmpty()) {
112+
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, i + 36, j,
113+
net.minecraft.screen.slot.SlotActionType.SWAP, mc.player);
114+
slot = j;
115+
break;
116+
}
117+
}
118+
break;
119+
}
120+
}
121+
}
122+
123+
holdingRocket = mc.player.getMainHandStack().getItem() == Items.FIREWORK_ROCKET ||
124+
mc.player.getOffHandStack().getItem() == Items.FIREWORK_ROCKET;
125+
if (!holdingRocket && onlyWhenHoldingRocket.get()) return;
126+
}
101127
if (checkCooldown.get() && mc.player.getItemCooldownManager().isCoolingDown(Items.FIREWORK_ROCKET)) return;
102128

103-
Hand hand = mc.player.getMainHandStack().getItem() == Items.FIREWORK_ROCKET ?
104-
Hand.MAIN_HAND : Hand.OFF_HAND;
129+
Hand hand = mc.player.getMainHandStack().getItem() == Items.FIREWORK_ROCKET
130+
? Hand.MAIN_HAND
131+
: Hand.OFF_HAND;
105132

106133
mc.interactionManager.interactItem(mc.player, hand);
134+
mc.player.swingHand(hand);
107135
isBoostActive = true;
108136
boostTicks = 0;
109137
ticksSinceLastUse = 0;

0 commit comments

Comments
 (0)