use of net.minecraft.server.v1_16_R3.ControllerMoveFlying in project Citizens2 by CitizensDev.
the class NMSImpl method setNoGravity.
@Override
public void setNoGravity(org.bukkit.entity.Entity entity, boolean enabled) {
Entity handle = getHandle(entity);
handle.setNoGravity(enabled);
if (!(handle instanceof EntityInsentient) || !(entity instanceof NPCHolder))
return;
EntityInsentient mob = (EntityInsentient) handle;
NPC npc = ((NPCHolder) entity).getNPC();
if (!(mob.getControllerMove() instanceof ControllerMoveFlying) || npc.data().has("flying-nogravity-float"))
return;
try {
if (enabled) {
boolean old = (boolean) FLYING_MOVECONTROL_FLOAT_GETTER.invoke(mob.getControllerMove());
FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), true);
npc.data().set("flying-nogravity-float", old);
} else if (npc.data().has("flying-nogravity-float")) {
FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), npc.data().get("flying-nogravity-float"));
npc.data().remove("flying-nogravity-float");
}
} catch (Throwable t) {
t.printStackTrace();
}
}
use of net.minecraft.server.v1_16_R3.ControllerMoveFlying in project Citizens2 by CitizensDev.
the class NMSImpl method setNoGravity.
@Override
public void setNoGravity(org.bukkit.entity.Entity entity, boolean enabled) {
Entity handle = getHandle(entity);
handle.setNoGravity(enabled);
if (!(handle instanceof EntityInsentient) || !(entity instanceof NPCHolder))
return;
EntityInsentient mob = (EntityInsentient) handle;
NPC npc = ((NPCHolder) entity).getNPC();
if (!(mob.getControllerMove() instanceof ControllerMoveFlying) || npc.data().has("flying-nogravity-float"))
return;
try {
if (enabled) {
boolean old = (boolean) FLYING_MOVECONTROL_FLOAT_GETTER.invoke(mob.getControllerMove());
FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), true);
npc.data().set("flying-nogravity-float", old);
} else if (npc.data().has("flying-nogravity-float")) {
FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), npc.data().get("flying-nogravity-float"));
npc.data().remove("flying-nogravity-float");
}
} catch (Throwable t) {
t.printStackTrace();
}
}
Aggregations