feat: better antikick for VanillaFlight

This commit is contained in:
əlemi 2023-03-08 17:25:50 +01:00
parent a9a232838d
commit fbee153272
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,7 +1,6 @@
package ftbsc.bscv.modules.motion;
import com.google.auto.service.AutoService;
import ftbsc.bscv.Boscovicino;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.QuickModule;
@ -22,9 +21,15 @@ public class VanillaFlight extends QuickModule implements ICommons {
return UNBOUND;
}
private enum AntikickMode {
NONE,
PACKET,
FORCED
}
public final ForgeConfigSpec.ConfigValue<Boolean> force;
public final ForgeConfigSpec.ConfigValue<Double> speed;
public final ForgeConfigSpec.ConfigValue<Boolean> antikick;
public final ForgeConfigSpec.ConfigValue<AntikickMode> antikick;
public final ForgeConfigSpec.ConfigValue<Double> antikick_magnitude;
public final ForgeConfigSpec.ConfigValue<Integer> antikick_cycle;
@ -46,23 +51,23 @@ public class VanillaFlight extends QuickModule implements ICommons {
.comment("flight speed to set")
.build(this);
this.antikick = Setting.Bool.builder()
.fallback(false)
this.antikick = Setting.Switch.builder(AntikickMode.class)
.fallback(AntikickMode.NONE)
.name("antikick")
.comment("prevent vanilla flight kick by descending")
.build(this);
this.antikick_magnitude = Setting.Decimal.builder()
.min(0.)
.fallback(1.)
.fallback(0.032)
.name("magnitude")
.comment("magnitude of antikick push")
.build(this);
this.antikick_cycle = Setting.Number.builder()
.min(0)
.max(79)
.fallback(0)
.min(1)
.max(80)
.fallback(70)
.name("cycle")
.comment("how often to run antikick routine")
.build(this);
@ -81,18 +86,23 @@ public class VanillaFlight extends QuickModule implements ICommons {
if (this.force.get()) {
MC.player.abilities.flying = true;
}
if (this.antikick.get() && MC.player.abilities.flying) {
this.tick = ( this.tick + 1 ) % this.antikick_cycle.get();
if (this.tick == 0) {
Vector3d pos = MC.player.position();
Boscovicino.log("[*] antikick");
MC.player.connection.send(
new CPlayerPacket.PositionPacket(pos.x, pos.y - this.antikick_magnitude.get(), pos.z, false)
);
MC.player.setPos(pos.x, pos.y - this.antikick_magnitude.get(), pos.z);
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)
);
break;
case FORCED:
MC.player.setPos(pos.x, pos.y - this.antikick_magnitude.get(), pos.z);
break;
case NONE:
break;
}
} else {
this.tick = 0; // reset antikick counter
}
}