Search in sources :

Example 1 with EntityBird

use of net.minecraft.server.v1_13_R2.EntityBird in project Citizens2 by CitizensDev.

the class NMSImpl method flyingMoveLogic.

public static void flyingMoveLogic(EntityLiving entity, float f, float f1, float f2) {
    if ((entity.cP()) || (entity.bT())) {
        double d0 = 0.08D;
        if ((entity.motY <= 0.0D) && (entity.hasEffect(MobEffects.SLOW_FALLING))) {
            d0 = 0.01D;
            entity.fallDistance = 0.0F;
        }
        if ((entity.isInWater()) && ((!(entity instanceof EntityHuman)) || (!((EntityHuman) entity).abilities.isFlying))) {
            double d2 = entity.locY;
            float f5 = entity instanceof EntityPolarBear ? 0.98F : 0.8F;
            float f4 = 0.02F;
            float f3 = EnchantmentManager.e(entity);
            if (f3 > 3.0F) {
                f3 = 3.0F;
            }
            if (!entity.onGround) {
                f3 *= 0.5F;
            }
            if (f3 > 0.0F) {
                f5 += (0.54600006F - f5) * f3 / 3.0F;
                f4 += (entity.cK() - f4) * f3 / 3.0F;
            }
            if (entity.hasEffect(MobEffects.DOLPHINS_GRACE)) {
                f5 = 0.96F;
            }
            entity.a(f, f1, f2, f4);
            entity.move(EnumMoveType.SELF, entity.motX, entity.motY, entity.motZ);
            entity.motX *= f5;
            entity.motY *= 0.800000011920929D;
            entity.motZ *= f5;
            if ((!entity.isNoGravity()) && (!entity.isSprinting())) {
                if ((entity.motY <= 0.0D) && (Math.abs(entity.motY - 0.005D) >= 0.003D) && (Math.abs(entity.motY - d0 / 16.0D) < 0.003D)) {
                    entity.motY = -0.003D;
                } else {
                    entity.motY -= d0 / 16.0D;
                }
            }
            if ((entity.positionChanged) && (entity.c(entity.motX, entity.motY + 0.6000000238418579D - entity.locY + d2, entity.motZ))) {
                entity.motY = 0.30000001192092896D;
            }
        } else if ((entity.ax()) && ((!(entity instanceof EntityHuman)) || (!((EntityHuman) entity).abilities.isFlying))) {
            double d2 = entity.locY;
            entity.a(f, f1, f2, 0.02F);
            entity.move(EnumMoveType.SELF, entity.motX, entity.motY, entity.motZ);
            entity.motX *= 0.5D;
            entity.motY *= 0.5D;
            entity.motZ *= 0.5D;
            if (!entity.isNoGravity()) {
                entity.motY -= d0 / 4.0D;
            }
            if ((entity.positionChanged) && (entity.c(entity.motX, entity.motY + 0.6000000238418579D - entity.locY + d2, entity.motZ))) {
                entity.motY = 0.30000001192092896D;
            }
        } else if (entity.dc()) {
            if (entity.motY > -0.5D) {
                entity.fallDistance = 1.0F;
            }
            Vec3D vec3d = entity.aN();
            float f6 = entity.pitch * 0.017453292F;
            double d1 = Math.sqrt(vec3d.x * vec3d.x + vec3d.z * vec3d.z);
            double d3 = Math.sqrt(entity.motX * entity.motX + entity.motZ * entity.motZ);
            double d4 = vec3d.b();
            float f7 = MathHelper.cos(f6);
            f7 = (float) (f7 * f7 * Math.min(1.0D, d4 / 0.4D));
            entity.motY += d0 * (-1.0D + f7 * 0.75D);
            if ((entity.motY < 0.0D) && (d1 > 0.0D)) {
                double d5 = entity.motY * -0.1D * f7;
                entity.motY += d5;
                entity.motX += vec3d.x * d5 / d1;
                entity.motZ += vec3d.z * d5 / d1;
            }
            if ((f6 < 0.0F) && (d1 > 0.0D)) {
                double d5 = d3 * -MathHelper.sin(f6) * 0.04D;
                entity.motY += d5 * 3.2D;
                entity.motX -= vec3d.x * d5 / d1;
                entity.motZ -= vec3d.z * d5 / d1;
            }
            if (d1 > 0.0D) {
                entity.motX += (vec3d.x / d1 * d3 - entity.motX) * 0.1D;
                entity.motZ += (vec3d.z / d1 * d3 - entity.motZ) * 0.1D;
            }
            entity.motX *= 0.9900000095367432D;
            entity.motY *= 0.9800000190734863D;
            entity.motZ *= 0.9900000095367432D;
            entity.move(EnumMoveType.SELF, entity.motX, entity.motY, entity.motZ);
            if ((entity.positionChanged) && (!entity.world.isClientSide)) {
                double d5 = Math.sqrt(entity.motX * entity.motX + entity.motZ * entity.motZ);
                double d6 = d3 - d5;
                float f8 = (float) (d6 * 10.0D - 3.0D);
                if (f8 > 0.0F) {
                    entity.a(f8 > 4 ? SoundEffects.ENTITY_GENERIC_BIG_FALL : SoundEffects.ENTITY_GENERIC_SMALL_FALL, 1.0F, 1.0F);
                    entity.damageEntity(DamageSource.FLY_INTO_WALL, f8);
                }
            }
            if ((entity.onGround) && (!entity.world.isClientSide) && (entity.getFlag(7)) && (!CraftEventFactory.callToggleGlideEvent(entity, false).isCancelled())) {
                entity.setFlag(7, false);
            }
        } else {
            float f9 = 0.91F;
            BoundingBox bb = NMSBoundingBox.wrap(entity.getBoundingBox());
            BlockPosition.PooledBlockPosition blockposition_b = BlockPosition.PooledBlockPosition.d(entity.locX, bb.minY - 1.0D, entity.locZ);
            Throwable throwable = null;
            float f4;
            float f3;
            try {
                if (entity.onGround) {
                    f9 = entity.world.getType(blockposition_b).getBlock().n() * 0.91F;
                }
                f4 = 0.16277137F / (f9 * f9 * f9);
                if (entity.onGround) {
                    f3 = entity.cK() * f4;
                } else {
                    f3 = entity.aU;
                }
                entity.a(f, f1, f2, f3);
                f9 = 0.91F;
                if (entity.onGround) {
                    f9 = entity.world.getType(getBlockPositionBE(blockposition_b, entity.locX, bb.minY - 1.0D, entity.locZ)).getBlock().n() * 0.91F;
                }
                if (entity.z_()) {
                    entity.motX = MathHelper.a(entity.motX, -0.15000000596046448D, 0.15000000596046448D);
                    entity.motZ = MathHelper.a(entity.motZ, -0.15000000596046448D, 0.15000000596046448D);
                    entity.fallDistance = 0.0F;
                    if (entity.motY < -0.15D) {
                        entity.motY = -0.15D;
                    }
                    boolean flag = (entity.isSneaking()) && ((entity instanceof EntityHuman));
                    if ((flag) && (entity.motY < 0.0D)) {
                        entity.motY = 0.0D;
                    }
                }
                entity.move(EnumMoveType.SELF, entity.motX, entity.motY, entity.motZ);
                if ((entity.positionChanged) && (entity.z_())) {
                    entity.motY = 0.2D;
                }
                if (entity.hasEffect(MobEffects.LEVITATION)) {
                    entity.motY += (0.05D * (entity.getEffect(MobEffects.LEVITATION).getAmplifier() + 1) - entity.motY) * 0.2D;
                    entity.fallDistance = 0.0F;
                } else {
                    getBlockPositionBE(blockposition_b, entity.locX, 0.0D, entity.locZ);
                    if ((entity.world.isClientSide) && ((!entity.world.isLoaded(blockposition_b)) || (!entity.world.getChunkAtWorldCoords(blockposition_b).y()))) {
                        if (entity.locY > 0.0D) {
                            entity.motY = -0.1D;
                        } else {
                            entity.motY = 0.0D;
                        }
                    } else if (!entity.isNoGravity()) {
                        entity.motY -= d0;
                    }
                }
                entity.motY *= 0.9800000190734863D;
                entity.motX *= f9;
                entity.motZ *= f9;
            } catch (Throwable throwable1) {
                throwable = throwable1;
                throw throwable1;
            } finally {
                if (blockposition_b != null) {
                    if (throwable != null) {
                        try {
                            blockposition_b.close();
                        } catch (Throwable throwable2) {
                            throwable.addSuppressed(throwable2);
                        }
                    } else {
                        blockposition_b.close();
                    }
                }
            }
        }
    }
    entity.aI = entity.aJ;
    double d0 = entity.locX - entity.lastX;
    double d2 = entity.locZ - entity.lastZ;
    double d1 = (entity instanceof EntityBird) ? entity.locY - entity.lastY : 0.0D;
    float f3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 4.0F;
    if (f3 > 1.0F) {
        f3 = 1.0F;
    }
    entity.aJ += (f3 - entity.aJ) * 0.4F;
    entity.aK += entity.aJ;
}
Also used : EntityHuman(net.minecraft.server.v1_13_R2.EntityHuman) BoundingBox(net.citizensnpcs.api.util.BoundingBox) BlockPosition(net.minecraft.server.v1_13_R2.BlockPosition) EntityBird(net.minecraft.server.v1_13_R2.EntityBird) EntityPolarBear(net.minecraft.server.v1_13_R2.EntityPolarBear) Vec3D(net.minecraft.server.v1_13_R2.Vec3D)

Example 2 with EntityBird

use of net.minecraft.server.v1_13_R2.EntityBird in project Citizens2 by CitizensDev.

the class NMSImpl method flyingMoveLogic.

public static void flyingMoveLogic(EntityLiving entity, float f, float f1, float f2) {
    if ((entity.cC()) || (entity.bI())) {
        if ((entity.isInWater())) {
            double d2 = entity.locY;
            float f4 = entity instanceof EntityPolarBear ? 0.98F : 0.8F;
            float f3 = 0.02F;
            float f5 = EnchantmentManager.e(entity);
            if (f5 > 3.0F) {
                f5 = 3.0F;
            }
            if (!entity.onGround) {
                f5 *= 0.5F;
            }
            if (f5 > 0.0F) {
                f4 += (0.54600006F - f4) * f5 / 3.0F;
                f3 += (entity.cy() - f3) * f5 / 3.0F;
            }
            entity.b(f, f1, f2, f3);
            entity.move(EnumMoveType.SELF, entity.motX, entity.motY, entity.motZ);
            entity.motX *= f4;
            entity.motY *= 0.800000011920929D;
            entity.motZ *= f4;
            if (!entity.isNoGravity()) {
                entity.motY -= 0.02D;
            }
            if ((entity.positionChanged) && (entity.c(entity.motX, entity.motY + 0.6000000238418579D - entity.locY + d2, entity.motZ))) {
                entity.motY = 0.30000001192092896D;
            }
        } else if (entity.au()) {
            double d2 = entity.locY;
            entity.b(f, f1, f2, 0.02F);
            entity.move(EnumMoveType.SELF, entity.motX, entity.motY, entity.motZ);
            entity.motX *= 0.5D;
            entity.motY *= 0.5D;
            entity.motZ *= 0.5D;
            if (!entity.isNoGravity()) {
                entity.motY -= 0.02D;
            }
            if ((entity.positionChanged) && (entity.c(entity.motX, entity.motY + 0.6000000238418579D - entity.locY + d2, entity.motZ))) {
                entity.motY = 0.30000001192092896D;
            }
        } else if (entity.cP()) {
            if (entity.motY > -0.5D) {
                entity.fallDistance = 1.0F;
            }
            Vec3D vec3d = entity.aJ();
            float f6 = entity.pitch * 0.017453292F;
            double d0 = Math.sqrt(vec3d.x * vec3d.x + vec3d.z * vec3d.z);
            double d1 = Math.sqrt(entity.motX * entity.motX + entity.motZ * entity.motZ);
            double d3 = vec3d.b();
            float f7 = MathHelper.cos(f6);
            f7 = (float) (f7 * f7 * Math.min(1.0D, d3 / 0.4D));
            entity.motY += -0.08D + f7 * 0.06D;
            if ((entity.motY < 0.0D) && (d0 > 0.0D)) {
                double d4 = entity.motY * -0.1D * f7;
                entity.motY += d4;
                entity.motX += vec3d.x * d4 / d0;
                entity.motZ += vec3d.z * d4 / d0;
            }
            if (f6 < 0.0F) {
                double d4 = d1 * -MathHelper.sin(f6) * 0.04D;
                entity.motY += d4 * 3.2D;
                entity.motX -= vec3d.x * d4 / d0;
                entity.motZ -= vec3d.z * d4 / d0;
            }
            if (d0 > 0.0D) {
                entity.motX += (vec3d.x / d0 * d1 - entity.motX) * 0.1D;
                entity.motZ += (vec3d.z / d0 * d1 - entity.motZ) * 0.1D;
            }
            entity.motX *= 0.9900000095367432D;
            entity.motY *= 0.9800000190734863D;
            entity.motZ *= 0.9900000095367432D;
            entity.move(EnumMoveType.SELF, entity.motX, entity.motY, entity.motZ);
            if ((entity.positionChanged) && (!entity.world.isClientSide)) {
                double d4 = Math.sqrt(entity.motX * entity.motX + entity.motZ * entity.motZ);
                double d5 = d1 - d4;
                float f8 = (float) (d5 * 10.0D - 3.0D);
                if (f8 > 0.0F) {
                    entity.a(f8 > 4 ? SoundEffects.bQ : SoundEffects.bY, 1.0F, 1.0F);
                    entity.damageEntity(DamageSource.FLY_INTO_WALL, f8);
                }
            }
            if ((entity.onGround) && (!entity.world.isClientSide) && (entity.getFlag(7)) && (!CraftEventFactory.callToggleGlideEvent(entity, false).isCancelled())) {
                entity.setFlag(7, false);
            }
        } else {
            float f9 = 0.91F;
            BlockPosition.PooledBlockPosition blockposition_pooledblockposition = BlockPosition.PooledBlockPosition.d(entity.locX, entity.getBoundingBox().b - 1.0D, entity.locZ);
            if (entity.onGround) {
                f9 = entity.world.getType(blockposition_pooledblockposition).getBlock().frictionFactor * 0.91F;
            }
            float f4 = 0.16277136F / (f9 * f9 * f9);
            float f3;
            if (entity.onGround) {
                f3 = entity.cy() * f4;
            } else {
                f3 = entity.aR;
            }
            entity.b(f, f1, f2, f3);
            f9 = 0.91F;
            if (entity.onGround) {
                f9 = entity.world.getType(blockposition_pooledblockposition.e(entity.locX, entity.getBoundingBox().b - 1.0D, entity.locZ)).getBlock().frictionFactor * 0.91F;
            }
            if (entity.m_()) {
                entity.motX = MathHelper.a(entity.motX, -0.15000000596046448D, 0.15000000596046448D);
                entity.motZ = MathHelper.a(entity.motZ, -0.15000000596046448D, 0.15000000596046448D);
                entity.fallDistance = 0.0F;
                if (entity.motY < -0.15D) {
                    entity.motY = -0.15D;
                }
                boolean flag = (entity.isSneaking());
                if ((flag) && (entity.motY < 0.0D)) {
                    entity.motY = 0.0D;
                }
            }
            entity.move(EnumMoveType.SELF, entity.motX, entity.motY, entity.motZ);
            if ((entity.positionChanged) && (entity.m_())) {
                entity.motY = 0.2D;
            }
            if (entity.hasEffect(MobEffects.LEVITATION)) {
                entity.motY += (0.05D * (entity.getEffect(MobEffects.LEVITATION).getAmplifier() + 1) - entity.motY) * 0.2D;
            } else {
                blockposition_pooledblockposition.e(entity.locX, 0.0D, entity.locZ);
                if ((entity.world.isClientSide) && ((!entity.world.isLoaded(blockposition_pooledblockposition)) || (!entity.world.getChunkAtWorldCoords(blockposition_pooledblockposition).p()))) {
                    if (entity.locY > 0.0D) {
                        entity.motY = -0.1D;
                    } else {
                        entity.motY = 0.0D;
                    }
                } else if (!entity.isNoGravity()) {
                    entity.motY -= 0.08D;
                }
            }
            entity.motY *= 0.9800000190734863D;
            entity.motX *= f9;
            entity.motZ *= f9;
            blockposition_pooledblockposition.t();
        }
    }
    entity.aF = entity.aG;
    double d2 = entity.locX - entity.lastX;
    double d0 = entity.locZ - entity.lastZ;
    double d1 = (entity instanceof EntityBird) ? entity.locY - entity.lastY : 0.0D;
    float f10 = MathHelper.sqrt(d2 * d2 + d1 * d1 + d0 * d0) * 4.0F;
    if (f10 > 1.0F) {
        f10 = 1.0F;
    }
    entity.aG += (f10 - entity.aG) * 0.4F;
    entity.aH += entity.aG;
}
Also used : BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) EntityBird(net.minecraft.server.v1_12_R1.EntityBird) EntityPolarBear(net.minecraft.server.v1_12_R1.EntityPolarBear) Vec3D(net.minecraft.server.v1_12_R1.Vec3D)

Example 3 with EntityBird

use of net.minecraft.server.v1_13_R2.EntityBird in project Citizens2 by CitizensDev.

the class NMSImpl method flyingMoveLogic.

public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) {
    if (entity.doAITick() || entity.cs()) {
        double d0 = 0.08D;
        boolean flag = ((entity.getMot()).y <= 0.0D);
        if (flag && entity.hasEffect(MobEffects.SLOW_FALLING)) {
            d0 = 0.01D;
            entity.fallDistance = 0.0F;
        }
        Fluid fluid = entity.world.getFluid(entity.getChunkCoordinates());
        if (entity.isInWater() && /*&& entity.cT() */
        !entity.a(fluid.getType())) {
            double d1 = entity.locY();
            float f = entity.isSprinting() ? 0.9F : 0.8F;
            float f1 = 0.02F;
            float f2 = EnchantmentManager.e(entity);
            if (f2 > 3.0F)
                f2 = 3.0F;
            if (!entity.isOnGround())
                f2 *= 0.5F;
            if (f2 > 0.0F) {
                f += (0.54600006F - f) * f2 / 3.0F;
                f1 += (entity.dN() - f1) * f2 / 3.0F;
            }
            if (entity.hasEffect(MobEffects.DOLPHINS_GRACE))
                f = 0.96F;
            entity.a(f1, vec3d);
            entity.move(EnumMoveType.SELF, entity.getMot());
            Vec3D vec3d1 = entity.getMot();
            if (entity.positionChanged && entity.isClimbing())
                vec3d1 = new Vec3D(vec3d1.x, 0.2D, vec3d1.z);
            entity.setMot(vec3d1.d(f, 0.800000011920929D, f));
            Vec3D vec3d2 = entity.a(d0, flag, entity.getMot());
            entity.setMot(vec3d2);
            if (entity.positionChanged && entity.e(vec3d2.x, vec3d2.y + 0.6D - entity.locY() + d1, vec3d2.z))
                entity.setMot(vec3d2.x, 0.30000001192092896D, vec3d2.z);
        } else if (entity.aQ() && /*&& entity.cT()*/
        !entity.a(fluid.getType())) {
            double d1 = entity.locY();
            entity.a(0.02F, vec3d);
            entity.move(EnumMoveType.SELF, entity.getMot());
            if (entity.b(TagsFluid.LAVA) <= entity.cx()) {
                entity.setMot(entity.getMot().d(0.5D, 0.8D, 0.5D));
                Vec3D vec3D = entity.a(d0, flag, entity.getMot());
                entity.setMot(vec3D);
            } else {
                entity.setMot(entity.getMot().a(0.5D));
            }
            if (!entity.isNoGravity())
                entity.setMot(entity.getMot().add(0.0D, -d0 / 4.0D, 0.0D));
            Vec3D vec3d3 = entity.getMot();
            if (entity.positionChanged && entity.e(vec3d3.x, vec3d3.y + 0.6D - entity.locY() + d1, vec3d3.z))
                entity.setMot(vec3d3.x, 0.3D, vec3d3.z);
        } else if (entity.isGliding()) {
            Vec3D vec3d4 = entity.getMot();
            if (vec3d4.y > -0.5D)
                entity.fallDistance = 1.0F;
            Vec3D vec3d5 = entity.getLookDirection();
            float f = entity.pitch * 0.017453292F;
            double d2 = Math.sqrt(vec3d5.x * vec3d5.x + vec3d5.z * vec3d5.z);
            double d3 = Math.sqrt(entity.c(vec3d4));
            double d4 = vec3d5.f();
            float f3 = MathHelper.cos(f);
            f3 = (float) (f3 * f3 * Math.min(1.0D, d4 / 0.4D));
            vec3d4 = entity.getMot().add(0.0D, d0 * (-1.0D + f3 * 0.75D), 0.0D);
            if (vec3d4.y < 0.0D && d2 > 0.0D) {
                double d5 = vec3d4.y * -0.1D * f3;
                vec3d4 = vec3d4.add(vec3d5.x * d5 / d2, d5, vec3d5.z * d5 / d2);
            }
            if (f < 0.0F && d2 > 0.0D) {
                double d5 = d3 * -MathHelper.sin(f) * 0.04D;
                vec3d4 = vec3d4.add(-vec3d5.x * d5 / d2, d5 * 3.2D, -vec3d5.z * d5 / d2);
            }
            if (d2 > 0.0D)
                vec3d4 = vec3d4.add((vec3d5.x / d2 * d3 - vec3d4.x) * 0.1D, 0.0D, (vec3d5.z / d2 * d3 - vec3d4.z) * 0.1D);
            entity.setMot(vec3d4.d(0.9900000095367432D, 0.9800000190734863D, 0.9900000095367432D));
            entity.move(EnumMoveType.SELF, entity.getMot());
            if (entity.positionChanged && !entity.world.isClientSide) {
                double d5 = Math.sqrt(entity.c(entity.getMot()));
                double d6 = d3 - d5;
                float f4 = (float) (d6 * 10.0D - 3.0D);
                if (f4 > 0.0F) {
                    try {
                        entity.playSound((SoundEffect) ENTITY_GET_SOUND_FALL.invoke(entity, (int) f4), 1.0F, 1.0F);
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                    entity.damageEntity(DamageSource.FLY_INTO_WALL, f4);
                }
            }
            if (entity.isOnGround() && !entity.world.isClientSide && entity.getFlag(7) && !CraftEventFactory.callToggleGlideEvent(entity, false).isCancelled())
                entity.setFlag(7, false);
        } else {
            BlockPosition blockposition = new BlockPosition(entity.locX(), (entity.getBoundingBox()).minY - 0.5000001D, // entity.ar();
            entity.locZ());
            float f5 = entity.world.getType(blockposition).getBlock().getFrictionFactor();
            float f = entity.isOnGround() ? (f5 * 0.91F) : 0.91F;
            Vec3D vec3d6 = entity.a(vec3d, f5);
            double d7 = vec3d6.y;
            if (entity.hasEffect(MobEffects.LEVITATION)) {
                d7 += (0.05D * (entity.getEffect(MobEffects.LEVITATION).getAmplifier() + 1) - vec3d6.y) * 0.2D;
                entity.fallDistance = 0.0F;
            } else if (entity.world.isClientSide && !entity.world.isLoaded(blockposition)) {
                if (entity.locY() > 0.0D) {
                    d7 = -0.1D;
                } else {
                    d7 = 0.0D;
                }
            } else if (!entity.isNoGravity()) {
                d7 -= d0;
            }
            entity.setMot(vec3d6.x * f, d7 * 0.9800000190734863D, vec3d6.z * f);
        }
    }
    entity.a(entity, entity instanceof EntityBird);
}
Also used : Fluid(net.minecraft.server.v1_16_R3.Fluid) TagsFluid(net.minecraft.server.v1_16_R3.TagsFluid) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) EntityBird(net.minecraft.server.v1_16_R3.EntityBird) Vec3D(net.minecraft.server.v1_16_R3.Vec3D)

Example 4 with EntityBird

use of net.minecraft.server.v1_13_R2.EntityBird in project Citizens2 by CitizensDev.

the class NMSImpl method flyingMoveLogic.

public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) {
    double d0;
    float f;
    if (entity.df() || entity.ca()) {
        d0 = 0.08D;
        boolean flag = entity.getMot().y <= 0.0D;
        if (flag && entity.hasEffect(MobEffects.SLOW_FALLING)) {
            d0 = 0.01D;
            entity.fallDistance = 0.0F;
        }
        double d1;
        float f1;
        double d2;
        Vec3D vec3d5;
        Vec3D vec3d2;
        if (!entity.isInWater() || entity instanceof EntityHuman && ((EntityHuman) entity).abilities.isFlying) {
            Vec3D vec3d4;
            if (entity.aD() && (!(entity instanceof EntityHuman) || !((EntityHuman) entity).abilities.isFlying)) {
                d1 = entity.locY;
                entity.a(0.02F, vec3d);
                entity.move(EnumMoveType.SELF, entity.getMot());
                entity.setMot(entity.getMot().a(0.5D));
                if (!entity.isNoGravity()) {
                    entity.setMot(entity.getMot().add(0.0D, -d0 / 4.0D, 0.0D));
                }
                vec3d4 = entity.getMot();
                if (entity.positionChanged && entity.d(vec3d4.x, vec3d4.y + 0.6000000238418579D - entity.locY + d1, vec3d4.z)) {
                    entity.setMot(vec3d4.x, 0.30000001192092896D, vec3d4.z);
                }
            } else if (entity.isGliding()) {
                vec3d4 = entity.getMot();
                if (vec3d4.y > -0.5D) {
                    entity.fallDistance = 1.0F;
                }
                vec3d5 = entity.getLookDirection();
                f1 = entity.pitch * 0.017453292F;
                double d3 = Math.sqrt(vec3d5.x * vec3d5.x + vec3d5.z * vec3d5.z);
                double d4 = Math.sqrt(Entity.b(vec3d4));
                d2 = vec3d5.f();
                float f3 = MathHelper.cos(f1);
                f3 = (float) ((double) f3 * (double) f3 * Math.min(1.0D, d2 / 0.4D));
                vec3d4 = entity.getMot().add(0.0D, d0 * (-1.0D + f3 * 0.75D), 0.0D);
                double d5;
                if (vec3d4.y < 0.0D && d3 > 0.0D) {
                    d5 = vec3d4.y * -0.1D * f3;
                    vec3d4 = vec3d4.add(vec3d5.x * d5 / d3, d5, vec3d5.z * d5 / d3);
                }
                if (f1 < 0.0F && d3 > 0.0D) {
                    d5 = d4 * (-MathHelper.sin(f1)) * 0.04D;
                    vec3d4 = vec3d4.add(-vec3d5.x * d5 / d3, d5 * 3.2D, -vec3d5.z * d5 / d3);
                }
                if (d3 > 0.0D) {
                    vec3d4 = vec3d4.add((vec3d5.x / d3 * d4 - vec3d4.x) * 0.1D, 0.0D, (vec3d5.z / d3 * d4 - vec3d4.z) * 0.1D);
                }
                entity.setMot(vec3d4.d(0.9900000095367432D, 0.9800000190734863D, 0.9900000095367432D));
                entity.move(EnumMoveType.SELF, entity.getMot());
                if (entity.positionChanged && !entity.world.isClientSide) {
                    d5 = Math.sqrt(Entity.b(entity.getMot()));
                    double d6 = d4 - d5;
                    float f4 = (float) (d6 * 10.0D - 3.0D);
                    if (f4 > 0.0F) {
                        try {
                            entity.a((SoundEffect) ENTITY_GET_SOUND_FALL.invoke(entity, (int) f4), 1.0F, 1.0F);
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                        entity.damageEntity(DamageSource.FLY_INTO_WALL, f4);
                    }
                }
                if (entity.onGround && !entity.world.isClientSide && entity.getFlag(7) && !CraftEventFactory.callToggleGlideEvent(entity, false).isCancelled()) {
                    entity.setFlag(7, false);
                }
            } else {
                BlockPosition blockposition = new BlockPosition(entity.locX, entity.getBoundingBox().minY - 1.0D, entity.locZ);
                float f5 = entity.world.getType(blockposition).getBlock().m();
                f1 = entity.onGround ? f5 * 0.91F : 0.91F;
                try {
                    entity.a((float) ENTITY_R.invoke(entity, f5), vec3d);
                    entity.setMot((Vec3D) ISCLIMBING_METHOD.invoke(entity, entity.getMot()));
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                entity.move(EnumMoveType.SELF, entity.getMot());
                vec3d2 = entity.getMot();
                try {
                    if ((entity.positionChanged || (boolean) JUMP_FIELD.invoke(entity)) && entity.isClimbing()) {
                        vec3d2 = new Vec3D(vec3d2.x, 0.2D, vec3d2.z);
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                double d7 = vec3d2.y;
                if (entity.hasEffect(MobEffects.LEVITATION)) {
                    d7 += (0.05D * (entity.getEffect(MobEffects.LEVITATION).getAmplifier() + 1) - vec3d2.y) * 0.2D;
                    entity.fallDistance = 0.0F;
                } else if (entity.world.isClientSide && !entity.world.isLoaded(blockposition)) {
                    if (entity.locY > 0.0D) {
                        d7 = -0.1D;
                    } else {
                        d7 = 0.0D;
                    }
                } else if (!entity.isNoGravity()) {
                    d7 -= d0;
                }
                entity.setMot(vec3d2.x * f1, d7 * 0.9800000190734863D, vec3d2.z * f1);
            }
        } else {
            d1 = entity.locY;
            f1 = entity.isSprinting() ? 0.9F : entity instanceof EntityPolarBear ? 0.98F : 0.8F;
            f = 0.02F;
            float f2 = EnchantmentManager.e(entity);
            if (f2 > 3.0F) {
                f2 = 3.0F;
            }
            if (!entity.onGround) {
                f2 *= 0.5F;
            }
            if (f2 > 0.0F) {
                f1 += (0.54600006F - f1) * f2 / 3.0F;
                f += (entity.db() - f) * f2 / 3.0F;
            }
            if (entity.hasEffect(MobEffects.DOLPHINS_GRACE)) {
                f1 = 0.96F;
            }
            entity.a(f, vec3d);
            entity.move(EnumMoveType.SELF, entity.getMot());
            vec3d5 = entity.getMot();
            if (entity.positionChanged && entity.isClimbing()) {
                vec3d5 = new Vec3D(vec3d5.x, 0.2D, vec3d5.z);
            }
            entity.setMot(vec3d5.d(f1, 0.800000011920929D, f1));
            if (!entity.isNoGravity() && !entity.isSprinting()) {
                vec3d2 = entity.getMot();
                if (flag && Math.abs(vec3d2.y - 0.005D) >= 0.003D && Math.abs(vec3d2.y - d0 / 16.0D) < 0.003D) {
                    d2 = -0.003D;
                } else {
                    d2 = vec3d2.y - d0 / 16.0D;
                }
                entity.setMot(vec3d2.x, d2, vec3d2.z);
            }
            vec3d2 = entity.getMot();
            if (entity.positionChanged && entity.d(vec3d2.x, vec3d2.y + 0.6000000238418579D - entity.locY + d1, vec3d2.z)) {
                entity.setMot(vec3d2.x, 0.30000001192092896D, vec3d2.z);
            }
        }
    }
    entity.aE = entity.aF;
    d0 = entity.locX - entity.lastX;
    double d8 = entity.locZ - entity.lastZ;
    double d9 = entity instanceof EntityBird ? entity.locY - entity.lastY : 0.0D;
    f = MathHelper.sqrt(d0 * d0 + d9 * d9 + d8 * d8) * 4.0F;
    if (f > 1.0F) {
        f = 1.0F;
    }
    entity.aF += (f - entity.aF) * 0.4F;
    entity.aG += entity.aF;
}
Also used : SoundEffect(net.minecraft.server.v1_14_R1.SoundEffect) EntityHuman(net.minecraft.server.v1_14_R1.EntityHuman) BlockPosition(net.minecraft.server.v1_14_R1.BlockPosition) EntityBird(net.minecraft.server.v1_14_R1.EntityBird) EntityPolarBear(net.minecraft.server.v1_14_R1.EntityPolarBear) Vec3D(net.minecraft.server.v1_14_R1.Vec3D)

Example 5 with EntityBird

use of net.minecraft.server.v1_13_R2.EntityBird in project Citizens2 by CitizensDev.

the class NMSImpl method flyingMoveLogic.

public static void flyingMoveLogic(EntityLiving entity, Vec3D vec3d) {
    double d0;
    float f;
    if (entity.doAITick() || entity.cj()) {
        d0 = 0.08D;
        boolean flag = entity.getMot().y <= 0.0D;
        if (flag && entity.hasEffect(MobEffects.SLOW_FALLING)) {
            d0 = 0.01D;
            entity.fallDistance = 0.0F;
        }
        double d1;
        float f1;
        double d2;
        Vec3D vec3d5;
        Vec3D vec3d2;
        if (!entity.isInWater() || entity instanceof EntityHuman && ((EntityHuman) entity).abilities.isFlying) {
            Vec3D vec3d4;
            if (entity.aH() && (!(entity instanceof EntityHuman) || !((EntityHuman) entity).abilities.isFlying)) {
                d1 = entity.locY();
                entity.a(0.02F, vec3d);
                entity.move(EnumMoveType.SELF, entity.getMot());
                entity.setMot(entity.getMot().a(0.5D));
                if (!entity.isNoGravity()) {
                    entity.setMot(entity.getMot().add(0.0D, -d0 / 4.0D, 0.0D));
                }
                vec3d4 = entity.getMot();
                if (entity.positionChanged && entity.e(vec3d4.x, vec3d4.y + 0.6000000238418579D - entity.locY() + d1, vec3d4.z)) {
                    entity.setMot(vec3d4.x, 0.30000001192092896D, vec3d4.z);
                }
            } else if (entity.isGliding()) {
                vec3d4 = entity.getMot();
                if (vec3d4.y > -0.5D) {
                    entity.fallDistance = 1.0F;
                }
                vec3d5 = entity.getLookDirection();
                f1 = entity.pitch * 0.017453292F;
                double d3 = Math.sqrt(vec3d5.x * vec3d5.x + vec3d5.z * vec3d5.z);
                double d4 = Math.sqrt(Entity.b(vec3d4));
                d2 = vec3d5.f();
                float f3 = MathHelper.cos(f1);
                f3 = (float) ((double) f3 * (double) f3 * Math.min(1.0D, d2 / 0.4D));
                vec3d4 = entity.getMot().add(0.0D, d0 * (-1.0D + f3 * 0.75D), 0.0D);
                double d5;
                if (vec3d4.y < 0.0D && d3 > 0.0D) {
                    d5 = vec3d4.y * -0.1D * f3;
                    vec3d4 = vec3d4.add(vec3d5.x * d5 / d3, d5, vec3d5.z * d5 / d3);
                }
                if (f1 < 0.0F && d3 > 0.0D) {
                    d5 = d4 * (-MathHelper.sin(f1)) * 0.04D;
                    vec3d4 = vec3d4.add(-vec3d5.x * d5 / d3, d5 * 3.2D, -vec3d5.z * d5 / d3);
                }
                if (d3 > 0.0D) {
                    vec3d4 = vec3d4.add((vec3d5.x / d3 * d4 - vec3d4.x) * 0.1D, 0.0D, (vec3d5.z / d3 * d4 - vec3d4.z) * 0.1D);
                }
                entity.setMot(vec3d4.d(0.9900000095367432D, 0.9800000190734863D, 0.9900000095367432D));
                entity.move(EnumMoveType.SELF, entity.getMot());
                if (entity.positionChanged && !entity.world.isClientSide) {
                    d5 = Math.sqrt(Entity.b(entity.getMot()));
                    double d6 = d4 - d5;
                    float f4 = (float) (d6 * 10.0D - 3.0D);
                    if (f4 > 0.0F) {
                        try {
                            entity.a((SoundEffect) ENTITY_GET_SOUND_FALL.invoke(entity, (int) f4), 1.0F, 1.0F);
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                        entity.damageEntity(DamageSource.FLY_INTO_WALL, f4);
                    }
                }
                if (entity.onGround && !entity.world.isClientSide && entity.getFlag(7) && !CraftEventFactory.callToggleGlideEvent(entity, false).isCancelled()) {
                    entity.setFlag(7, false);
                }
            } else {
                BlockPosition blockposition = new BlockPosition(entity.locX(), entity.getBoundingBox().minY - 0.5D, entity.locZ());
                float f5 = entity.world.getType(blockposition).getBlock().l();
                f1 = entity.onGround ? f5 * 0.91F : 0.91F;
                try {
                    entity.a((float) ENTITY_R.invoke(entity, f5), vec3d);
                    entity.setMot((Vec3D) ISCLIMBING_METHOD.invoke(entity, entity.getMot()));
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                entity.move(EnumMoveType.SELF, entity.getMot());
                vec3d2 = entity.getMot();
                try {
                    if ((entity.positionChanged || ((boolean) JUMP_FIELD.invoke(entity))) && entity.isClimbing()) {
                        vec3d2 = new Vec3D(vec3d2.x, 0.2D, vec3d2.z);
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                double d7 = vec3d2.y;
                if (entity.hasEffect(MobEffects.LEVITATION)) {
                    d7 += (0.05D * (entity.getEffect(MobEffects.LEVITATION).getAmplifier() + 1) - vec3d2.y) * 0.2D;
                    entity.fallDistance = 0.0F;
                } else if (entity.world.isClientSide && !entity.world.isLoaded(blockposition)) {
                    if (entity.locY() > 0.0D) {
                        d7 = -0.1D;
                    } else {
                        d7 = 0.0D;
                    }
                } else if (!entity.isNoGravity()) {
                    d7 -= d0;
                }
                entity.setMot(vec3d2.x * f1, d7 * 0.9800000190734863D, vec3d2.z * f1);
            }
        } else {
            d1 = entity.locY();
            f1 = entity.isSprinting() ? 0.9F : 0.8F;
            f = 0.02F;
            float f2 = EnchantmentManager.e(entity);
            if (f2 > 3.0F) {
                f2 = 3.0F;
            }
            if (!entity.onGround) {
                f2 *= 0.5F;
            }
            if (f2 > 0.0F) {
                f1 += (0.54600006F - f1) * f2 / 3.0F;
                f += (entity.dt() - f) * f2 / 3.0F;
            }
            if (entity.hasEffect(MobEffects.DOLPHINS_GRACE)) {
                f1 = 0.96F;
            }
            entity.a(f, vec3d);
            entity.move(EnumMoveType.SELF, entity.getMot());
            vec3d5 = entity.getMot();
            if (entity.positionChanged && entity.isClimbing()) {
                vec3d5 = new Vec3D(vec3d5.x, 0.2D, vec3d5.z);
            }
            entity.setMot(vec3d5.d(f1, 0.800000011920929D, f1));
            if (!entity.isNoGravity() && !entity.isSprinting()) {
                vec3d2 = entity.getMot();
                if (flag && Math.abs(vec3d2.y - 0.005D) >= 0.003D && Math.abs(vec3d2.y - d0 / 16.0D) < 0.003D) {
                    d2 = -0.003D;
                } else {
                    d2 = vec3d2.y - d0 / 16.0D;
                }
                entity.setMot(vec3d2.x, d2, vec3d2.z);
            }
            vec3d2 = entity.getMot();
            if (entity.positionChanged && entity.e(vec3d2.x, vec3d2.y + 0.6000000238418579D - entity.locY() + d1, vec3d2.z)) {
                entity.setMot(vec3d2.x, 0.30000001192092896D, vec3d2.z);
            }
        }
    }
    entity.aC = entity.aD;
    d0 = entity.locX() - entity.lastX;
    double d8 = entity.locZ() - entity.lastZ;
    double d9 = entity instanceof EntityBird ? entity.locY() - entity.lastY : 0.0D;
    f = MathHelper.sqrt(d0 * d0 + d9 * d9 + d8 * d8) * 4.0F;
    if (f > 1.0F) {
        f = 1.0F;
    }
    entity.aD += (f - entity.aD) * 0.4F;
    entity.aE += entity.aD;
}
Also used : SoundEffect(net.minecraft.server.v1_15_R1.SoundEffect) EntityHuman(net.minecraft.server.v1_15_R1.EntityHuman) BlockPosition(net.minecraft.server.v1_15_R1.BlockPosition) EntityBird(net.minecraft.server.v1_15_R1.EntityBird) Vec3D(net.minecraft.server.v1_15_R1.Vec3D)

Aggregations

BoundingBox (net.citizensnpcs.api.util.BoundingBox)1 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)1 EntityBird (net.minecraft.server.v1_12_R1.EntityBird)1 EntityPolarBear (net.minecraft.server.v1_12_R1.EntityPolarBear)1 Vec3D (net.minecraft.server.v1_12_R1.Vec3D)1 BlockPosition (net.minecraft.server.v1_13_R2.BlockPosition)1 EntityBird (net.minecraft.server.v1_13_R2.EntityBird)1 EntityHuman (net.minecraft.server.v1_13_R2.EntityHuman)1 EntityPolarBear (net.minecraft.server.v1_13_R2.EntityPolarBear)1 Vec3D (net.minecraft.server.v1_13_R2.Vec3D)1 BlockPosition (net.minecraft.server.v1_14_R1.BlockPosition)1 EntityBird (net.minecraft.server.v1_14_R1.EntityBird)1 EntityHuman (net.minecraft.server.v1_14_R1.EntityHuman)1 EntityPolarBear (net.minecraft.server.v1_14_R1.EntityPolarBear)1 SoundEffect (net.minecraft.server.v1_14_R1.SoundEffect)1 Vec3D (net.minecraft.server.v1_14_R1.Vec3D)1 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)1 EntityBird (net.minecraft.server.v1_15_R1.EntityBird)1 EntityHuman (net.minecraft.server.v1_15_R1.EntityHuman)1 SoundEffect (net.minecraft.server.v1_15_R1.SoundEffect)1