Skip to content

Commit

Permalink
RocketMan - Added speed threshold usage mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed Nov 7, 2024
1 parent fbd81e1 commit 606db4f
Showing 1 changed file with 59 additions and 33 deletions.
92 changes: 59 additions & 33 deletions src/main/java/dev/stardust/modules/RocketMan.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public RocketMan() {

public enum KeyModifiers { Alt, Ctrl, Shift, None }
public enum HoverMode { Off, Hold, Toggle, Creative }
public enum RocketMode { OnForwardKey, Static, Dynamic }
public enum RocketMode { OnForwardKey, Static, Dynamic, Speed }

private final SettingGroup sgRockets = settings.createGroup("Rocket Usage");
private final SettingGroup sgBoosts = settings.createGroup("Rocket Boosts");
Expand All @@ -69,20 +69,38 @@ public enum RocketMode { OnForwardKey, Static, Dynamic }
new IntSetting.Builder()
.name("Rocket Usage Cooldown")
.description("How often (in ticks) to allow using firework rockets.")
.range(1, 1200).sliderRange(2, 100).defaultValue(50)
.visible(() -> usageMode.get().equals(RocketMode.OnForwardKey))
.range(1, 10000).sliderRange(2, 100).defaultValue(40)
.visible(() -> usageMode.get().equals(RocketMode.OnForwardKey) || usageMode.get().equals(RocketMode.Speed))
.build()
);

private final Setting<Double> usageSpeed = sgRockets.add(
new DoubleSetting.Builder()
.name("Minimum Speed Threshold (b/s)")
.description("Will use a rocket when your speed falls below this threshold.")
.range(1, 1000).sliderRange(2, 100).defaultValue(37)
.visible(() -> usageMode.get().equals(RocketMode.Speed))
.build()
);

private final Setting<Integer> usageTickRate = sgRockets.add(
new IntSetting.Builder()
.name("Rocket Usage-Rate")
.description("How often (in ticks) to use firework rockets.")
.range(1, 1200).sliderRange(2, 420).defaultValue(100)
.range(1, 10000).sliderRange(2, 420).defaultValue(100)
.visible(() -> usageMode.get().equals(RocketMode.Static))
.build()
);

public final Setting<Boolean> yLevelLock = sgRockets.add(
new BoolSetting.Builder()
.name("Y Level Lock")
.description("Lock Your Y level while flying (requires Dynamic mode.)")
.defaultValue(false)
.visible(() -> usageMode.get().equals(RocketMode.Dynamic))
.build()
);

private final Setting<Boolean> combatAssist = sgRockets.add(
new BoolSetting.Builder()
.name("Combat Assist")
Expand Down Expand Up @@ -230,15 +248,6 @@ public enum RocketMode { OnForwardKey, Static, Dynamic }
.build()
);

public final Setting<Boolean> yLevelLock = sgControl.add(
new BoolSetting.Builder()
.name("Y Level Lock")
.description("Lock Your Y level while flying (requires Dynamic mode.)")
.defaultValue(false)
.visible(() -> keyboardControl.get() && usageMode.get() == RocketMode.Dynamic)
.build()
);

public final Setting<Double> verticalSpeed = sgHover.add(
new DoubleSetting.Builder()
.name("Vertical Speed")
Expand Down Expand Up @@ -467,7 +476,7 @@ public enum RocketMode { OnForwardKey, Static, Dynamic }
private void useFireworkRocket(String caller) {
if (mc.player == null) return;
if (mc.interactionManager == null) return;
if (debug.get()) mc.player.sendMessage(Text.literal("§7Caller: "+StardustUtil.rCC()+caller));
if (debug.get() && chatFeedback) mc.player.sendMessage(Text.literal("§7Caller: "+StardustUtil.rCC()+caller));

boolean foundRocket = false;
for (int n = 0; n < 9; n++) {
Expand Down Expand Up @@ -511,7 +520,7 @@ private void useFireworkRocket(String caller) {
}

public void discardCurrentRocket(String source) {
if (!source.trim().isEmpty() && debug.get()) {
if (!source.trim().isEmpty() && debug.get() && chatFeedback) {
mc.player.sendMessage(
Text.literal("§7Discarding current rocket! Why: "
+StardustUtil.rCC()+source+" §7| Packets: "
Expand Down Expand Up @@ -630,13 +639,13 @@ public boolean isHoverKeyPressed() {

// See EntityMixin.java && LivingEntityMixin.java && PlayerEntityMixin.java
public boolean shouldLockYLevel() {
return yLevelLock.isVisible() && yLevelLock.get();
return usageMode.get().equals(RocketMode.Dynamic) && yLevelLock.get();
}

// See PlayerEntityMixin.java
public void setIsHovering(boolean hovering) {
isHovering = hovering;
if (hoverModeFeedback.get()) {
if (hoverModeFeedback.get() && chatFeedback) {
((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
Text.of("§8<"+ StardustUtil.rCC()+"§o✨§r§8> "+"§7Hover Mode "+ (hovering ? "§2§oEnabled§7§o." : "§4§oDisabled§7.")),
"hover mode feedback".hashCode()
Expand Down Expand Up @@ -737,6 +746,7 @@ public void onActivate() {
);
}
} else if (takeoff.get() && mc.player.isFallFlying()) {
justUsed = true;
takingOff = true;
useFireworkRocket("on activate");
}
Expand Down Expand Up @@ -769,7 +779,7 @@ private void onTick(TickEvent.Pre event) {
String formatted = duration.substring(0, Math.min(5, duration.length()));
if (formatted.length() <= 4) formatted = formatted+"0";

if (debug.get() || durationFeedback.get()) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
if (debug.get() || durationFeedback.get() && chatFeedback) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
Text.literal("§7Duration Boost: §e§o"+formatted+" §7§oseconds."),
"rocketDurationUpdate".hashCode()
);
Expand All @@ -784,13 +794,13 @@ private void onTick(TickEvent.Pre event) {
}
}
} catch (Exception err) {
Stardust.LOG.error("extensionStartPos should not have been null, but it was! Why:\n"+err);
Stardust.LOG.error("[RocketMan] extensionStartPos should not have been null, but it was! Why:\n"+err);
}


++setbackTimer;
if (needReset) {
if (antiLagBackFeedback.get() || debug.get()) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
if (antiLagBackFeedback.get() || debug.get() && chatFeedback) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
Text.literal("§8§o["+rcc+"§oAntiLagBack...§8§o]"),
"LagBackReset".hashCode()
);
Expand Down Expand Up @@ -845,6 +855,7 @@ private void onTick(TickEvent.Pre event) {
if (!hoverMode.get().equals(HoverMode.Toggle)) isHovering = false;
return;
}else if (!takingOff && takeoff.get() && mc.player.isFallFlying()) {
justUsed = true;
takingOff = true;
useFireworkRocket("takeoff assist");
return;
Expand All @@ -870,16 +881,31 @@ private void onTick(TickEvent.Pre event) {
++rocketStockTicks;
++durabilityCheckTicks;
if (ticksFlying > 10) firstRocket = false;
if (usageMode.get().equals(RocketMode.Dynamic) && !hasActiveRocket) useFireworkRocket("dynamic usage");
else if (usageMode.get().equals(RocketMode.Static)) {
if (timer >= usageTickRate.get()) {
timer = 0;
useFireworkRocket("static usage");
switch (usageMode.get()) {
case Speed -> {
double blocksPerSecond = Utils.getPlayerSpeed().length();
if (blocksPerSecond <= usageSpeed.get() && !justUsed && !hasActiveRocket) {
justUsed = true;
useFireworkRocket("speed threshold usage");
}
}
}else if (usageMode.get().equals(RocketMode.OnForwardKey) && mc.player.input.pressingForward && !justUsed) {
justUsed = true;
useFireworkRocket("forward key usage");
} else if (justUsed) {
case Static -> {
if (timer >= usageTickRate.get()) {
timer = 0;
useFireworkRocket("static usage");
}
}
case Dynamic -> {
if (!hasActiveRocket) useFireworkRocket("dynamic usage");
}
case OnForwardKey -> {
if (mc.player.input.pressingForward && !justUsed) {
justUsed = true;
useFireworkRocket("forward key usage");
}
}
}
if (justUsed) {
++ticksSinceUsed;
if (ticksSinceUsed >= usageCooldown.get()) {
justUsed = false;
Expand Down Expand Up @@ -957,7 +983,7 @@ private void onScrollWheel(MouseScrollEvent event) {
double speed = verticalSpeed.get();
double newSpeed = speed + (event.value * verticalScrollSensitivity.get());
verticalSpeed.set(newSpeed);
if (scrollSpeedFeedback.get()) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
if (scrollSpeedFeedback.get() && chatFeedback) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
Text.literal("§8<§5§o✨§r§8> §7Vertical Speed: §3"+String.valueOf(newSpeed).substring(0, Math.min(5, String.valueOf(newSpeed).length()))),
"verticalSpeedScroll".hashCode()
);
Expand All @@ -967,7 +993,7 @@ private void onScrollWheel(MouseScrollEvent event) {
double speed = speedSetting.get();
double newSpeed = speed + (event.value * maxSpeedScrollSensitivity.get());
speedSetting.set(newSpeed);
if (scrollSpeedFeedback.get()) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
if (scrollSpeedFeedback.get() && chatFeedback) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
Text.literal("§8<§5§o✨§r§8> §7Max Speed: §3"+String.valueOf(newSpeed).substring(0, Math.min(5, String.valueOf(newSpeed).length()))),
"maxSpeedScroll".hashCode()
);
Expand All @@ -979,7 +1005,7 @@ private void onScrollWheel(MouseScrollEvent event) {
double speed = horizontalSpeed.get();
double newSpeed = speed + (event.value * horizontalScrollSensitivity.get());
horizontalSpeed.set(newSpeed);
if (scrollSpeedFeedback.get()) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
if (scrollSpeedFeedback.get() && chatFeedback) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
Text.literal("§8<§3§o✨§r§8> §7Horizontal Speed: §5"+String.valueOf(newSpeed).substring(0, Math.min(5, String.valueOf(newSpeed).length()))),
"horizontalSpeedScroll".hashCode()
);
Expand All @@ -989,7 +1015,7 @@ private void onScrollWheel(MouseScrollEvent event) {
double speed = accelerationSetting.get();
double newSpeed = speed + (event.value * accelerationScrollSensitivity.get());
accelerationSetting.set(newSpeed);
if (scrollSpeedFeedback.get()) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
if (scrollSpeedFeedback.get() && chatFeedback) ((IChatHud) mc.inGameHud.getChatHud()).meteor$add(
Text.literal("§8<§3§o✨§r§8> §7Acceleration: §5"+String.valueOf(newSpeed).substring(0, Math.min(5, String.valueOf(newSpeed).length()))),
"accelerationScroll".hashCode()
);
Expand Down

0 comments on commit 606db4f

Please sign in to comment.