Add experimental PacketFly
All checks were successful
/ Build BaseBand (push) Successful in 2m32s

This commit is contained in:
Daniella / Tove 2024-10-05 05:36:59 +02:00
parent ab2c00cb0c
commit f8ad1c48eb
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
2 changed files with 163 additions and 0 deletions

View file

@ -71,6 +71,7 @@ public class Setup {
new NoSlowDown(), new NoSlowDown(),
new Notifier(), new Notifier(),
new PacketCounter(), new PacketCounter(),
new PacketFly(),
new Ping(), new Ping(),
new PlayerLog(), new PlayerLog(),
new PlayerSelector(), new PlayerSelector(),

View file

@ -0,0 +1,162 @@
package de.com.baseband.client.feature.modules.movement;
import de.com.baseband.client.event.Listen;
import de.com.baseband.client.event.events.MoveEvent;
import de.com.baseband.client.event.events.PacketEvent;
import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.feature.category.Experimental;
import de.com.baseband.client.feature.modules.render.HUD;
import de.com.baseband.client.registry.annotation.Config;
import de.com.baseband.client.registry.annotation.Description;
import de.com.baseband.client.registry.annotation.Range;
import de.com.baseband.client.util.interact.ServerDataManager;
import net.minecraft.network.play.client.CPacketConfirmTeleport;
import net.minecraft.network.play.client.CPacketPlayer;
import net.minecraft.network.play.server.SPacketPlayerPosLook;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec2f;
@Experimental
public class PacketFly extends Feature {
@Config("Speed")
@Description("How fast to move. Actual speed is determined by the packet fly constant multiplied with this value.")
@Range("0.05..1")
public float speed = 0.5f;
@Config("Delay")
@Description("How often to move, in ticks")
@Range("0..10")
public int delay = 2;
@Config("Predict")
@Description("Predict server-side movement. Sacrifices reliability for speed and independence of ping.")
public boolean predict = true;
@Config("Anti fly-kick")
@Description("Tries to avoid the automatic flight kick mechanism in vanilla.")
public boolean noFlyKick = true;
private int ticksElapsed = 0;
private int trackingTPPacket = 0;
private boolean moving = false;
private SPacketPlayerPosLook lastPacket = null;
private long time = 0;
public void onDisable() {
moving = false;
trackingTPPacket = 0;
}
@Override
public void onTick() {
meta = "";
if(moving)
meta += " Moving";
if(trackingTPPacket != 0)
meta += " Tracking";
meta = meta.trim();
if(meta.isEmpty())
meta = null;
time++;
ticksElapsed++;
}
@Listen
public void move(MoveEvent e) {
e.setCancelled(true);
if(ticksElapsed < delay)
return;
if(trackingTPPacket == 0 && moving && ticksElapsed < 10) {
return;
}
if(mc.getRenderViewEntity() == mc.player) {
Vec2f movementVec = mc.player.movementInput.getMoveVector();
float f1 = MathHelper.sin(mc.player.rotationYaw * 0.017453292F);
float f2 = MathHelper.cos(mc.player.rotationYaw * 0.017453292F);
double x = movementVec.x * f2 - movementVec.y * f1;
double y = (mc.player.movementInput.jump ? 1 : 0) + (mc.player.movementInput.sneak ? -1 : 0);
double z = movementVec.y * f2 + movementVec.x * f1;
float d = (float) Math.sqrt(x * x + y * y + z * z) / (0.249f * speed);
if(d == 0) {
if(moving) {
sendPosition(0);
sendForce();
trackingTPPacket = 0;
lastPacket = null;
moving = false;
}
return;
}
x /= d;
y /= d;
z /= d;
mc.player.posX += x;
mc.player.posY += y;
mc.player.posZ += z;
double yOffset = (time % 30 == 0 ? -0.05 : 0);
sendPosition(yOffset);
sendForce();
if(predict) {
if (trackingTPPacket == 0) {
HUD.notify("Synchronizing PacketFly.", 1000);
} else {
mc.player.connection.sendPacket(new CPacketConfirmTeleport(++trackingTPPacket));
sendPosition(yOffset);
}
}
else {
trackingTPPacket = 0;
}
moving = true;
ticksElapsed = 0;
}
}
private void sendPosition(double yOffset) {
mc.player.connection.sendPacket(new CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY + yOffset, mc.player.posZ, mc.player.rotationYaw, mc.player.rotationPitch, mc.player.onGround));
}
private void sendForce() {
mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX, mc.player.posY - 1000, mc.player.posZ, mc.player.onGround));
}
@Listen
public void onPacket(PacketEvent.Receive event) {
if(event.getPacket() instanceof SPacketPlayerPosLook) {
if(!predict) {
trackingTPPacket = -1;
return;
}
SPacketPlayerPosLook pppl = ((SPacketPlayerPosLook) event.getPacket());
if(lastPacket != null && !(pppl.getX() != lastPacket.getX() || pppl.getY() != lastPacket.getY() || pppl.getZ() != lastPacket.getZ())) {
ticksElapsed = -ServerDataManager.timeToSurelyTicked();
moving = false;
trackingTPPacket = 0;
return;
}
lastPacket = pppl;
if(trackingTPPacket == 0 || trackingTPPacket < pppl.getTeleportId()) {
trackingTPPacket = pppl.getTeleportId();
}
else if(moving) {
event.setCancelled(true);
}
}
}
@Override
public String toString() {
return "PacketFly";
}
}