feat: better packet antikick for vanillaflight

This commit is contained in:
əlemi 2023-03-18 22:09:40 +01:00
parent fa10646d8f
commit a1d538f299
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 47 additions and 18 deletions

View file

@ -4,6 +4,7 @@ import com.google.auto.service.AutoService;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.QuickModule;
import ftbsc.bscv.patches.PacketPatch.PacketEvent;
import ftbsc.bscv.tools.Setting;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.network.play.client.CPlayerPacket;
@ -14,12 +15,7 @@ import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@AutoService(ILoadable.class)
public class VanillaFlight extends QuickModule implements ICommons {
@Override
protected int getDefaultKey() {
return UNBOUND;
}
public class VanillaFlight extends QuickModule {
private enum AntikickMode {
NONE,
@ -27,11 +23,14 @@ public class VanillaFlight extends QuickModule implements ICommons {
FORCED
}
private static final int MS_PER_TICK = 50;
public final ForgeConfigSpec.ConfigValue<Boolean> force;
public final ForgeConfigSpec.ConfigValue<Double> speed;
public final ForgeConfigSpec.ConfigValue<AntikickMode> antikick;
public final ForgeConfigSpec.ConfigValue<Double> antikick_magnitude;
public final ForgeConfigSpec.ConfigValue<Integer> antikick_cycle;
public final ForgeConfigSpec.ConfigValue<Integer> antikick_duration;
private int tick = 0;
@ -71,11 +70,28 @@ public class VanillaFlight extends QuickModule implements ICommons {
.name("cycle")
.comment("how often to run antikick routine")
.build(this);
this.antikick_duration = Setting.Number.builder()
.min(1)
.max(80)
.fallback(5)
.name("duration")
.comment("how long to apply antikick (only for PACKET)")
.build(this);
}
private long last_event = 0;
private boolean couldFlyBefore = false;
private float flyingSpeedBefore = 0.05f;
private AntikickState antikickState = AntikickState.COOLDOWN;
private enum AntikickState {
COOLDOWN,
ACTIVE
}
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if (event.phase == Phase.END) return;
@ -90,19 +106,31 @@ public class VanillaFlight extends QuickModule implements ICommons {
this.tick = ( this.tick + 1 ) % this.antikick_cycle.get();
Vector3d pos = MC.player.position();
if (this.tick == 0) {
switch (this.antikick.get()) {
case PACKET:
MC.player.connection.send(
new CPlayerPacket.PositionPacket(pos.x, pos.y - this.antikick_magnitude.get(), pos.z, false)
);
if (this.tick == 0 && this.antikick.get() == AntikickMode.PACKET) {
MC.player.setPos(pos.x, pos.y - this.antikick_magnitude.get(), pos.z);
}
}
@SubscribeEvent
public void onPacketSent(PacketEvent.Outgoing event) {
long now = System.currentTimeMillis();
switch (this.antikickState) {
case COOLDOWN:
if (now - this.last_event < this.antikick_cycle.get() * MS_PER_TICK) break;
this.last_event = now;
this.antikickState = AntikickState.ACTIVE; // don't break and also run ACTIVE
case ACTIVE:
if (now - this.last_event > this.antikick_duration.get() * MS_PER_TICK) {
this.antikickState = AntikickState.COOLDOWN;
break;
case FORCED:
MC.player.setPos(pos.x, pos.y - this.antikick_magnitude.get(), pos.z);
break;
case NONE:
break;
}
}
if (
event.packet instanceof CPlayerPacket.PositionPacket ||
event.packet instanceof CPlayerPacket.PositionRotationPacket
) {
CPlayerPacket packet = (CPlayerPacket) event.packet;
packet.y = packet.y - this.antikick_magnitude.get();
}
}
}

View file

@ -2,5 +2,6 @@ public net.minecraft.client.gui.screen.Screen field_230710_m_ # buttons
public net.minecraft.client.gui.screen.Screen field_230705_e_ # children
public net.minecraft.client.network.play.NetworkPlayerInfo field_178866_b # gameMode
public net.minecraft.network.play.client.CPlayerPacket field_149474_g # onGround
public net.minecraft.network.play.client.CPlayerPacket field_149477_b # y
public net.minecraft.client.multiplayer.PlayerController func_78750_j()V # ensureHasSentCarriedItem()
public net.minecraft.client.Minecraft field_71467_ac # rightClickDelay