blob: 66c94bec894b4097afb345cc6f9cd35ede6d7ca9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
package ftbsc.bscv.modules.motion;
import com.google.auto.service.AutoService;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.QuickModule;
import ftbsc.bscv.patches.PacketPatch.PacketEvent;
import ftbsc.bscv.tools.Keyboard;
import ftbsc.bscv.tools.Setting;
import net.minecraft.network.play.client.CPlayerPacket;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@AutoService(ILoadable.class)
public class VanillaFlight extends QuickModule {
public enum AntiKickMode {
NONE,
PACKET,
FORCED
}
private static final int MS_PER_TICK = 50;
public final ForgeConfigSpec.ConfigValue<Boolean> force;
public final ForgeConfigSpec.ConfigValue<Boolean> drift;
public final ForgeConfigSpec.ConfigValue<Double> speed;
public final ForgeConfigSpec.ConfigValue<AntiKickMode> antikick;
public final ForgeConfigSpec.ConfigValue<Double> antikickMagnitude;
public final ForgeConfigSpec.ConfigValue<Integer> antikickCycle;
public final ForgeConfigSpec.ConfigValue<Integer> antikickDuration;
private int tick = 0;
public VanillaFlight() {
super();
this.force = Setting.Bool.builder()
.name("force")
.comment("force enable flight on user")
.fallback(true)
.build(this);
this.drift = Setting.Bool.builder()
.name("drift")
.comment("gradually reduce momentum")
.fallback(false)
.build(this);
this.speed = Setting.Decimal.builder()
.min(0.)
.fallback(0.1)
.name("speed")
.comment("flight speed to set")
.build(this);
this.antikick = Setting.Switch.builder(AntiKickMode.class)
.fallback(AntiKickMode.PACKET)
.name("antikick")
.comment("prevent vanilla flight kick by descending")
.build(this);
this.antikickMagnitude = Setting.Decimal.builder()
.min(0.)
.fallback(0.032)
.name("magnitude")
.comment("magnitude of antikick push")
.build(this);
this.antikickCycle = Setting.Number.builder()
.min(1)
.max(80)
.fallback(70)
.name("cycle")
.comment("how often to run antikick routine")
.build(this);
this.antikickDuration = Setting.Number.builder()
.min(1)
.max(80)
.fallback(5)
.name("duration")
.comment("how long to apply antikick (only for PACKET)")
.build(this);
}
private long lastEvent = 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;
if (MC.player == null) return;
MC.player.abilities.mayfly = true;
MC.player.abilities.setFlyingSpeed(this.speed.get().floatValue());
if (this.force.get()) {
MC.player.abilities.flying = true;
}
if (!this.drift.get() && !Keyboard.isMoving()) {
MC.player.setDeltaMovement(Vector3d.ZERO);
}
this.tick = ( this.tick + 1 ) % this.antikickCycle.get();
Vector3d pos = MC.player.position();
if (this.tick == 0 && this.antikick.get() == AntiKickMode.PACKET) {
MC.player.setPos(pos.x, pos.y - this.antikickMagnitude.get(), pos.z);
}
}
@SubscribeEvent
public void onPacketSent(PacketEvent.Outgoing event) {
long now = System.currentTimeMillis();
switch (this.antikickState) {
case COOLDOWN:
if (now - this.lastEvent < this.antikickCycle.get() * MS_PER_TICK) break;
this.lastEvent = now;
this.antikickState = AntikickState.ACTIVE; // don't break and also run ACTIVE
case ACTIVE:
if (now - this.lastEvent > this.antikickDuration.get() * MS_PER_TICK) {
this.antikickState = AntikickState.COOLDOWN;
break;
}
if (
event.packet instanceof CPlayerPacket.PositionPacket ||
event.packet instanceof CPlayerPacket.PositionRotationPacket
) {
CPlayerPacket packet = (CPlayerPacket) event.packet;
packet.y = packet.y - this.antikickMagnitude.get();
}
}
}
@Override
public void enable() {
this.tick = 0;
if (MC.player != null) {
this.couldFlyBefore = MC.player.abilities.mayfly;
this.flyingSpeedBefore = MC.player.abilities.getFlyingSpeed();
}
super.enable();
}
@Override
public void disable() {
if (MC.player != null) {
MC.player.abilities.mayfly = this.couldFlyBefore;
MC.player.abilities.setFlyingSpeed(this.flyingSpeedBefore);
if (this.force.get()) {
MC.player.abilities.flying = false;
}
}
super.disable();
}
}
|