Skip to content

Commit

Permalink
RocketMan - Improved stability after rocket-acceleration patch
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed Dec 29, 2024
1 parent 402799e commit d954917
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/stardust/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private Vec3d spoofYMovement(Vec3d velocity) {
RocketMan rm = modules.get(RocketMan.class);
if (!rm.isActive() || !rm.shouldLockYLevel()) return velocity;
if (!this.getUuid().equals(rm.getClientInstance().player.getUuid())) return velocity;
if (!rm.getClientInstance().player.isFallFlying() || !rm.hasActiveRocket) return velocity;
if (!rm.getClientInstance().player.isFallFlying() || !rm.hasActiveRocket()) return velocity;

Vec3d spoofVec;
if (rm.getClientInstance().player.input.jumping) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,10 @@ private void createTrackedRocketEntity(CallbackInfo ci) {
if (rm.currentRocket != null) {
if (rm.currentRocket.getId() != ((FireworkRocketEntity)(Object)this).getId()) {
rm.discardCurrentRocket("overwrite current");

rm.hasActiveRocket = true;
rm.currentRocket = (FireworkRocketEntity)(Object)this;
rm.extensionStartPos = new BlockPos(player.getBlockX(), 0, player.getBlockZ());
}
} else {
rm.hasActiveRocket = true;
rm.currentRocket = (FireworkRocketEntity)(Object)this;
rm.extensionStartPos = new BlockPos(player.getBlockX(), 0, player.getBlockZ());
if (rm.debug.get()) player.sendMessage(Text.literal("§7Created tracked rocket entity!"));
Expand All @@ -86,7 +83,7 @@ private void spoofRotationVector(CallbackInfo ci, @Local(ordinal = 0) LocalRef<V
rm = modules.get(RocketMan.class);
}
if (!rm.isActive() || !rm.shouldLockYLevel()) return;
if (!rm.getClientInstance().player.isFallFlying() || !rm.hasActiveRocket) return;
if (!rm.getClientInstance().player.isFallFlying() || !rm.hasActiveRocket()) return;

float g = -rm.getClientInstance().player.getYaw() * ((float)Math.PI / 180);
float h = MathHelper.cos(g);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/stardust/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void spoofPitchForSpeedCalcs(CallbackInfo ci, @Local(ordinal = 0) LocalF

if (!rm.isActive() || !rm.shouldLockYLevel()) return;
if (!this.getUuid().equals(rm.getClientInstance().player.getUuid())) return;
if (!rm.getClientInstance().player.isFallFlying() || !rm.hasActiveRocket) return;
if (!rm.getClientInstance().player.isFallFlying() || !rm.hasActiveRocket()) return;

if (rm.getClientInstance().player.input.jumping && rm.verticalSpeed.get() > 0) {
f.set(-45);
Expand Down
75 changes: 47 additions & 28 deletions src/main/java/dev/stardust/modules/RocketMan.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import javax.annotation.Nullable;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import dev.stardust.util.StardustUtil;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.entity.EquipmentSlot;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.client.MinecraftClient;
import meteordevelopment.orbit.EventPriority;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import meteordevelopment.meteorclient.settings.*;
import net.minecraft.component.DataComponentTypes;
import meteordevelopment.meteorclient.utils.Utils;
Expand Down Expand Up @@ -166,11 +169,11 @@ public enum RocketMode {OnKey, Static, Dynamic, Speed }
.build()
);

private final Setting<Integer> extendedDuration = sgBoosts.add(
new IntSetting.Builder()
private final Setting<Double> extendedDuration = sgBoosts.add(
new DoubleSetting.Builder()
.name("max-duration")
.description("Maximum amount in seconds to extend your firework's boost duration by.")
.range(1, 420).sliderRange(1, 69).defaultValue(1)
.range(0.01, 420).sliderRange(0.1, 69.0).defaultValue(0.90)
.visible(extendRockets::get)
.build()
);
Expand Down Expand Up @@ -484,7 +487,6 @@ public enum RocketMode {OnKey, Static, Dynamic, Speed }
public boolean isHovering = false;
public boolean wasHovering = false;
private boolean firstRocket = false;
public boolean hasActiveRocket = false;
public boolean durationBoosted = false;
private String rcc = StardustUtil.rCC();
public @Nullable Long extensionStartTime = null;
Expand All @@ -510,7 +512,7 @@ private void useFireworkRocket(String caller) {

if (foundRocket) {
timer = 0;
hasActiveRocket = true;
justUsed = true;
mc.interactionManager.interactItem(mc.player, Hand.MAIN_HAND);
InvUtils.swapBack();
}else {
Expand All @@ -528,7 +530,7 @@ private void useFireworkRocket(String caller) {

if (foundRocket) {
timer = 0;
hasActiveRocket = true;
justUsed = true;
mc.interactionManager.interactItem(mc.player, Hand.MAIN_HAND);
//noinspection ConstantConditions
if (movedSlot != -1) {
Expand All @@ -551,9 +553,7 @@ public void discardCurrentRocket(String source) {
if (firstRocket) firstRocket = false;
if (currentRocket != null && durationBoosted) {
((FireworkRocketEntityAccessor) currentRocket).invokeExplodeAndRemove();
currentRocket = null;
}
hasActiveRocket = false;
durationBoosted = false;
extensionStartPos = null;
extensionStartTime = null;
Expand All @@ -566,6 +566,15 @@ public void discardCurrentRocket(String source) {
}
}

public boolean hasActiveRocket() {
for (Entity e : mc.world.getEntities()) {
if (e instanceof FireworkRocketEntity r && r.getOwner() != null && r.getOwner() != null && r.getOwner().equals(mc.player)) {
return true;
}
}
return false;
}

private boolean replaceElytra() {
if (mc.player == null) return false;
for (int n = 0; n < mc.player.getInventory().main.size(); n++) {
Expand Down Expand Up @@ -804,8 +813,17 @@ private void onTick(TickEvent.Pre event) {
return;
}

if (hasActiveRocket() && currentRocket == null) {
for (Entity e : mc.world.getEntities()) {
if (e instanceof FireworkRocketEntity r && r.getOwner() != null && r.getOwner().equals(mc.player)) {
currentRocket = r;
break;
}
}
}

try {
if (extendRockets.get() && hasActiveRocket && extensionStartTime != null && extensionStartPos != null) {
if (extendRockets.get() && hasActiveRocket() && extensionStartTime != null && extensionStartPos != null) {
BlockPos playerPos = new BlockPos(mc.player.getBlockX(), 0, mc.player.getBlockZ());
long elapsed = System.currentTimeMillis() - extensionStartTime;

Expand All @@ -820,7 +838,7 @@ private void onTick(TickEvent.Pre event) {

if (pongQueue.size() >= 1900) {
discardCurrentRocket("max packet queue size reached");
} else if (elapsed >= extendedDuration.get() * 1000) {
} else if (elapsed >= extendedDuration.get() * 1000.0) {
discardCurrentRocket("max duration reached");
} else if (!playerPos.isWithinDistance(extensionStartPos, extensionRange.get())) {
extensionStartPos = null;
Expand Down Expand Up @@ -860,7 +878,7 @@ private void onTick(TickEvent.Pre event) {

ItemStack activeItem = mc.player.getActiveItem();
if ((activeItem.contains(DataComponentTypes.FOOD) || Utils.isThrowable(activeItem.getItem())) && mc.player.getItemUseTime() > 0) {
if (!isHovering || (isHovering && hasActiveRocket)) {
if (!isHovering || (isHovering && hasActiveRocket())) {
++ticksBusy;
return;
}
Expand Down Expand Up @@ -905,9 +923,9 @@ private void onTick(TickEvent.Pre event) {
firstRocket = true;
++rocketStockTicks;
++durabilityCheckTicks;
if (hoverTimer == 2 && (!hasActiveRocket || durationBoosted)) {
if (hoverTimer == 2 && (!hasActiveRocket() || durationBoosted)) {
useFireworkRocket("hover initiate");
} else if (!hasActiveRocket && forceRocketUsage.get()) useFireworkRocket("hover maintain");
} else if (!hasActiveRocket() && forceRocketUsage.get()) useFireworkRocket("hover maintain");
return;
} else hoverTimer = 0;

Expand All @@ -919,8 +937,7 @@ private void onTick(TickEvent.Pre event) {
switch (usageMode.get()) {
case Speed -> {
double blocksPerSecond = Utils.getPlayerSpeed().length();
if (blocksPerSecond <= usageSpeed.get() && !justUsed && !hasActiveRocket) {
justUsed = true;
if (blocksPerSecond <= usageSpeed.get() && !justUsed && !hasActiveRocket()) {
useFireworkRocket("speed threshold usage");
}
}
Expand All @@ -931,18 +948,17 @@ private void onTick(TickEvent.Pre event) {
}
}
case Dynamic -> {
if (!hasActiveRocket) useFireworkRocket("dynamic usage");
if (!hasActiveRocket() && !justUsed) useFireworkRocket("dynamic usage");
}
case OnKey -> {
if (usageKey.get().isPressed() && !justUsed) {
justUsed = true;
useFireworkRocket("forward key usage");
}
}
}
if (justUsed) {
++ticksSinceUsed;
if (ticksSinceUsed >= usageCooldown.get()) {
if (ticksSinceUsed >= usageCooldown.get() || (usageMode.get().equals(RocketMode.Dynamic) && ticksSinceUsed >= 10)) {
justUsed = false;
ticksSinceUsed = 0;
}
Expand All @@ -969,7 +985,7 @@ private void onSendPacket(PacketEvent.Send event) {
} else ((PlayerMoveC2SPacketAccessor) packet).setPitch(0);
}

@EventHandler
@EventHandler(priority = EventPriority.HIGHEST)
private void onReceivePacket(PacketEvent.Receive event) {
if (mc.player == null || !mc.player.isFallFlying()) return;
if (event.packet instanceof PlayerPositionLookS2CPacket) {
Expand All @@ -984,19 +1000,22 @@ private void onReceivePacket(PacketEvent.Receive event) {
if (durationBoosted) {
discardCurrentRocket("lagback reset");
}
}else if (currentRocket != null && event.packet instanceof EntitiesDestroyS2CPacket packet) {
}else if (extendRockets.get() && currentRocket != null && event.packet instanceof EntitiesDestroyS2CPacket packet) {
boolean cancelled = false;
IntList entityIds = new IntArrayList();
for (int id : packet.getEntityIds()) {
if (id == currentRocket.getId()) {
if (extendRockets.get()) {
event.cancel();
durationBoosted = true;
extensionStartTime = System.currentTimeMillis();
} else {
discardCurrentRocket("default duration discard");
}
return;
event.cancel();
cancelled = true;
durationBoosted = true;
extensionStartTime = System.currentTimeMillis();
} else {
entityIds.add(id);
}
}
if (cancelled && !entityIds.isEmpty()) {
mc.getNetworkHandler().onEntitiesDestroy(new EntitiesDestroyS2CPacket(entityIds));
}
}

if (!(event.packet instanceof PlaySoundS2CPacket packet)) return;
Expand Down

0 comments on commit d954917

Please sign in to comment.