This commit is contained in:
parent
3d5c5f5a46
commit
6975f720a3
2 changed files with 166 additions and 52 deletions
|
@ -12,6 +12,7 @@ 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 de.com.baseband.client.util.misc.StateMachineUtil;
|
||||
import net.minecraft.network.play.client.CPacketConfirmTeleport;
|
||||
import net.minecraft.network.play.client.CPacketPlayer;
|
||||
import net.minecraft.network.play.server.SPacketPlayerPosLook;
|
||||
|
@ -26,6 +27,24 @@ import java.util.Queue;
|
|||
@Experimental
|
||||
public class PacketFly extends Feature {
|
||||
|
||||
private enum State {
|
||||
Unlocked,
|
||||
DoNotMove,
|
||||
Dip,
|
||||
Rise,
|
||||
DoNotMove2,
|
||||
}
|
||||
|
||||
public enum ForceMode {
|
||||
NegativeK,
|
||||
PositiveK,
|
||||
Random,
|
||||
Twenty,
|
||||
}
|
||||
|
||||
@Config("Force mode")
|
||||
public ForceMode mode = ForceMode.Random;
|
||||
|
||||
@Config("Speed")
|
||||
@Description("How fast to move. Actual speed is determined by the packet fly constant multiplied with this value.")
|
||||
@Range("0.05..1")
|
||||
|
@ -47,15 +66,22 @@ public class PacketFly extends Feature {
|
|||
@Config("Use conservative constant")
|
||||
public boolean conservative = false;
|
||||
|
||||
private int ticksElapsed = 0;
|
||||
private int ticksElapsedSinceLast = 0;
|
||||
private int trackingTPPacket = 0;
|
||||
private boolean moving = false;
|
||||
private int ticksSinceMovement = 0;
|
||||
private long time = 0;
|
||||
private long verticalTimeout = 0;
|
||||
private int ticksSinceMoving = 0;
|
||||
private final Queue<Vec3d> positions = new LinkedList<>();
|
||||
|
||||
// state machine
|
||||
private State state = State.Unlocked;
|
||||
private int ticksToNextState = 0;
|
||||
private long verticalTimeout = 0;
|
||||
private long horizontalTimeout = 0;
|
||||
|
||||
public void onDisable() {
|
||||
state = State.Unlocked;
|
||||
ticksToNextState = 0;
|
||||
verticalTimeout = horizontalTimeout = 0;
|
||||
moving = false;
|
||||
trackingTPPacket = 0;
|
||||
positions.clear();
|
||||
|
@ -63,6 +89,8 @@ public class PacketFly extends Feature {
|
|||
|
||||
@Override
|
||||
public void onTick() {
|
||||
mc.player.motionX = mc.player.motionY = mc.player.motionZ = 0;
|
||||
|
||||
meta = "";
|
||||
if(moving)
|
||||
meta += " Moving";
|
||||
|
@ -72,81 +100,140 @@ public class PacketFly extends Feature {
|
|||
if(meta.isEmpty())
|
||||
meta = null;
|
||||
|
||||
ticksSinceMovement++;
|
||||
// timer for moving flag
|
||||
|
||||
ticksSinceMoving++;
|
||||
if(moving)
|
||||
ticksSinceMovement = 0;
|
||||
ticksSinceMoving = 0;
|
||||
|
||||
ticksElapsed++;
|
||||
// timer for delay
|
||||
|
||||
mc.world.spawnParticle(EnumParticleTypes.FLAME, mc.player.posX, mc.player.posY + 1, mc.player.posZ, 0.1, 0.1, 0.1);
|
||||
ticksElapsedSinceLast++;
|
||||
|
||||
// timers for state machine
|
||||
|
||||
if(ticksToNextState > 0)
|
||||
ticksToNextState--;
|
||||
|
||||
horizontalTimeout--;
|
||||
verticalTimeout--;
|
||||
}
|
||||
|
||||
@Listen
|
||||
public void move(MoveEvent e) {
|
||||
e.setCancelled(true);
|
||||
|
||||
if(ticksElapsed < delay)
|
||||
if(ticksElapsedSinceLast < delay)
|
||||
return;
|
||||
|
||||
if(trackingTPPacket == 0 && moving && ticksElapsed < 10) {
|
||||
if(trackingTPPacket == 0 && moving && ticksElapsedSinceLast < 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean noFlyKick = this.noFlyKick;
|
||||
if(!mc.world.getCollisionBoxes(mc.player, mc.player.getEntityBoundingBox().shrink(0.0625)).isEmpty())
|
||||
noFlyKick = false;
|
||||
boolean noFlyKickBegin = noFlyKick && time % 30 <= 1;
|
||||
boolean willMove = false;
|
||||
if(noFlyKick) {
|
||||
maybeStateTransition();
|
||||
|
||||
time++;
|
||||
switch (state) {
|
||||
case DoNotMove:
|
||||
case DoNotMove2:
|
||||
verticalTimeout = horizontalTimeout = 1;
|
||||
break;
|
||||
case Dip:
|
||||
case Rise:
|
||||
willMove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
state = State.Unlocked;
|
||||
}
|
||||
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
double z = 0;
|
||||
|
||||
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;
|
||||
if(y != 0 || noFlyKickBegin) {
|
||||
verticalTimeout = ServerDataManager.asyncTimeToSurelyTicked();
|
||||
x = movementVec.x * f2 - movementVec.y * f1;
|
||||
y = (mc.player.movementInput.jump ? 1 : 0) + (mc.player.movementInput.sneak ? -1 : 0);
|
||||
z = movementVec.y * f2 + movementVec.x * f1;
|
||||
}
|
||||
|
||||
// lock axes when others are in use
|
||||
if(y != 0) {
|
||||
verticalTimeout = ServerDataManager.asyncTimeToSurelyTicked();
|
||||
}
|
||||
if(verticalTimeout > 0) {
|
||||
x = z = 0;
|
||||
}
|
||||
if(x != 0 || z != 0) {
|
||||
horizontalTimeout = ServerDataManager.asyncTimeToSurelyTicked();
|
||||
}
|
||||
if(horizontalTimeout > 0) {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
float d = (float) Math.sqrt(x * x + y * y + z * z) / ((conservative ? 0.06249f : 0.249f) * speed);
|
||||
|
||||
if (d == 0 && !willMove) {
|
||||
if (verticalTimeout < 0 && horizontalTimeout < 0) {
|
||||
if (moving)
|
||||
moving = false;
|
||||
}
|
||||
if(verticalTimeout-- > 0) {
|
||||
x = z = 0;
|
||||
else {
|
||||
sendPosition();
|
||||
}
|
||||
|
||||
if(!noFlyKickBegin) {
|
||||
float d = (float) Math.sqrt(x * x + y * y + z * z) / ((conservative ? 0.06249f : 0.249f) * speed);
|
||||
|
||||
if (d == 0) {
|
||||
if (moving && verticalTimeout < 0) {
|
||||
moving = false;
|
||||
}
|
||||
if (ticksSinceMovement > 10) {
|
||||
sendPosition();
|
||||
sendForce();
|
||||
trackingTPPacket = 0;
|
||||
positions.clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
x /= d;
|
||||
y /= d;
|
||||
z /= d;
|
||||
if (ticksSinceMoving > 10) {
|
||||
sendPosition();
|
||||
sendForce();
|
||||
trackingTPPacket = 0;
|
||||
positions.clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(d != 0) {
|
||||
x /= d;
|
||||
y /= d;
|
||||
z /= d;
|
||||
}
|
||||
|
||||
if(noFlyKick && time % 30 == 0)
|
||||
y = -0.05;
|
||||
if(noFlyKick && time % 30 == 1)
|
||||
y = 0.05;
|
||||
if (state == State.Dip)
|
||||
y = -0.05;
|
||||
if (state == State.Rise)
|
||||
y = 0.05;
|
||||
|
||||
mc.player.posX += x;
|
||||
mc.player.posY += y;
|
||||
mc.player.posZ += z;
|
||||
mc.player.posX += x;
|
||||
mc.player.posY += y;
|
||||
mc.player.posZ += z;
|
||||
|
||||
sendPositionFull();
|
||||
sendPositionFull();
|
||||
|
||||
moving = true;
|
||||
ticksElapsed = 0;
|
||||
moving = true;
|
||||
ticksElapsedSinceLast = 0;
|
||||
}
|
||||
|
||||
private void maybeStateTransition() {
|
||||
if(ticksToNextState == 0) {
|
||||
state = StateMachineUtil.nextState(state);
|
||||
switch (state) {
|
||||
case Unlocked:
|
||||
ticksToNextState = 30 - mc.player.ticksExisted % 30;
|
||||
break;
|
||||
case DoNotMove:
|
||||
case DoNotMove2:
|
||||
case Rise:
|
||||
case Dip:
|
||||
ticksToNextState = ServerDataManager.asyncTimeToSurelyTicked();
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("BaseBand BUG - Code PFSTIS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,12 +253,31 @@ public class PacketFly extends Feature {
|
|||
}
|
||||
|
||||
private void sendPosition() {
|
||||
mc.player.connection.sendPacket(new CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, mc.player.rotationYaw, mc.player.rotationPitch, false));
|
||||
mc.player.connection.sendPacket(new CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, mc.player.rotationYaw, mc.player.rotationPitch, true));
|
||||
}
|
||||
|
||||
private void sendForce() {
|
||||
positions.add(mc.player.getPositionVector());
|
||||
mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX + 1000, mc.player.posY + 1000, mc.player.posZ + 1000, false));
|
||||
double offset;
|
||||
switch (mode) {
|
||||
case NegativeK:
|
||||
offset = -1000;
|
||||
break;
|
||||
case PositiveK:
|
||||
offset = 1000;
|
||||
break;
|
||||
case Random:
|
||||
offset = BaseBand.RANDOM.nextInt(100 - 22) + 22;
|
||||
if(BaseBand.RANDOM.nextBoolean())
|
||||
offset = -offset;
|
||||
break;
|
||||
case Twenty:
|
||||
offset = 20;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("BaseBand BUG - Code PFSFIM");
|
||||
}
|
||||
mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX, mc.player.posY + offset, mc.player.posZ, true));
|
||||
}
|
||||
|
||||
@Listen
|
||||
|
@ -185,7 +291,7 @@ public class PacketFly extends Feature {
|
|||
if(positions.isEmpty() ||
|
||||
(new Vec3d(pppl.getX(), pppl.getY(), pppl.getZ()))
|
||||
.squareDistanceTo(positions.poll()) > 0.2) {
|
||||
ticksElapsed = -ServerDataManager.timeToSurelyTicked();
|
||||
ticksElapsedSinceLast = -ServerDataManager.timeToSurelyTicked();
|
||||
moving = false;
|
||||
trackingTPPacket = 0;
|
||||
positions.clear();
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package de.com.baseband.client.util.misc;
|
||||
|
||||
public class StateMachineUtil {
|
||||
public static <T extends Enum<T>> T nextState(T currentState) {
|
||||
T[] constants = (T[]) currentState.getClass().getEnumConstants();
|
||||
return constants[(currentState.ordinal() + 1) % constants.length];
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue