Search in sources :

Example 1 with FlyingMoveControl

use of net.minecraft.world.entity.ai.control.FlyingMoveControl 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 Mob) || !(entity instanceof NPCHolder))
        return;
    Mob mob = (Mob) handle;
    NPC npc = ((NPCHolder) entity).getNPC();
    if (!(mob.getMoveControl() instanceof FlyingMoveControl) || npc.data().has("flying-nogravity-float"))
        return;
    try {
        if (enabled) {
            boolean old = (boolean) FLYING_MOVECONTROL_FLOAT_GETTER.invoke(mob.getMoveControl());
            FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getMoveControl(), true);
            npc.data().set("flying-nogravity-float", old);
        } else if (npc.data().has("flying-nogravity-float")) {
            FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getMoveControl(), npc.data().get("flying-nogravity-float"));
            npc.data().remove("flying-nogravity-float");
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) EntityHumanNPC(net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) TrackedEntity(net.minecraft.server.level.ChunkMap.TrackedEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.world.entity.Entity) LivingEntity(net.minecraft.world.entity.LivingEntity) Mob(net.minecraft.world.entity.Mob) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) FlyingMoveControl(net.minecraft.world.entity.ai.control.FlyingMoveControl)

Example 2 with FlyingMoveControl

use of net.minecraft.world.entity.ai.control.FlyingMoveControl 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 Mob) || !(entity instanceof NPCHolder))
        return;
    Mob mob = (Mob) handle;
    NPC npc = ((NPCHolder) entity).getNPC();
    if (!(mob.getMoveControl() instanceof FlyingMoveControl) || npc.data().has("flying-nogravity-float"))
        return;
    try {
        if (enabled) {
            boolean old = (boolean) FLYING_MOVECONTROL_FLOAT_GETTER.invoke(mob.getMoveControl());
            FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getMoveControl(), true);
            npc.data().set("flying-nogravity-float", old);
        } else if (npc.data().has("flying-nogravity-float")) {
            FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getMoveControl(), npc.data().get("flying-nogravity-float"));
            npc.data().remove("flying-nogravity-float");
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) EntityHumanNPC(net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC) TrackedEntity(net.minecraft.server.level.ChunkMap.TrackedEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) Mob(net.minecraft.world.entity.Mob) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) FlyingMoveControl(net.minecraft.world.entity.ai.control.FlyingMoveControl)

Aggregations

NPC (net.citizensnpcs.api.npc.NPC)2 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)2 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)2 TrackedEntity (net.minecraft.server.level.ChunkMap.TrackedEntity)2 Entity (net.minecraft.world.entity.Entity)2 LivingEntity (net.minecraft.world.entity.LivingEntity)2 Mob (net.minecraft.world.entity.Mob)2 FlyingMoveControl (net.minecraft.world.entity.ai.control.FlyingMoveControl)2 EntityHumanNPC (net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC)1 EntityHumanNPC (net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC)1 FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)1 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)1 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)1