-
-
Notifications
You must be signed in to change notification settings - Fork 307
/
Gravity.java
63 lines (53 loc) · 1.47 KB
/
Gravity.java
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
package net.citizensnpcs.trait;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.util.NMS;
/**
* Enable/disable Minecraft's gravity.
*/
@TraitName("gravity")
public class Gravity extends Trait implements Toggleable {
@Persist("enabled")
private boolean nogravity;
public Gravity() {
super("gravity");
}
private void applyImmediately() {
if (nogravity && npc.getEntity() != null) {
npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(0));
NMS.setNoGravity(npc.getEntity(), nogravity);
}
}
/**
* Set whether to disable gravity or not
*
* @param gravitate
* true = disable gravity, false = enable gravity
*/
public void gravitate(boolean gravitate) {
nogravity = gravitate;
}
public boolean hasGravity() {
return !nogravity;
}
@Override
public void onSpawn() {
applyImmediately();
}
@Override
public void run() {
if (!npc.isSpawned())
return;
NMS.setNoGravity(npc.getEntity(), nogravity);
}
public void setEnabled(boolean enabled) {
this.nogravity = enabled;
}
@Override
public boolean toggle() {
nogravity = !nogravity;
applyImmediately();
return nogravity;
}
}