Search in sources :

Example 31 with Entity

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

the class NMSImpl method tick.

@Override
public boolean tick(org.bukkit.entity.Entity next) {
    Entity entity = NMSImpl.getHandle(next);
    Entity entity1 = entity.bB();
    if (entity1 != null) {
        if ((entity1.dead) || (!entity1.w(entity))) {
            entity.stopRiding();
        }
    } else {
        if (!entity.dead) {
            try {
                entity.world.g(entity);
            } catch (Throwable throwable) {
                CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
                CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
                entity.appendEntityCrashDetails(crashreportsystemdetails);
                throw new ReportedException(crashreport);
            }
        }
        boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
        if (entity.dead) {
            entity.world.removeEntity(entity);
            return true;
        } else if (!removeFromPlayerList) {
            if (!entity.world.players.contains(entity)) {
                entity.world.players.add((EntityHuman) entity);
            }
            return true;
        } else {
            entity.world.players.remove(entity);
        }
    }
    return false;
}
Also used : PathEntity(net.minecraft.server.v1_10_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) Entity(net.minecraft.server.v1_10_R1.Entity) EntityHuman(net.minecraft.server.v1_10_R1.EntityHuman) CrashReportSystemDetails(net.minecraft.server.v1_10_R1.CrashReportSystemDetails) CrashReport(net.minecraft.server.v1_10_R1.CrashReport) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) ReportedException(net.minecraft.server.v1_10_R1.ReportedException)

Example 32 with Entity

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

the class NMSImpl method getTargetNavigator.

private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, final Function<NavigationAbstract, Boolean> function) {
    net.minecraft.server.v1_13_R2.Entity raw = getHandle(entity);
    raw.onGround = true;
    // not sure of a better way around this - if onGround is false, then
    // navigation won't execute, and calling entity.move doesn't
    // entirely fix the problem.
    final NavigationAbstract navigation = NMSImpl.getNavigation(entity);
    final float oldWater = raw instanceof EntityPlayer ? ((EntityHumanNPC) raw).a(PathType.WATER) : ((EntityInsentient) raw).a(PathType.WATER);
    if (params.avoidWater() && oldWater >= 0) {
        if (raw instanceof EntityPlayer) {
            ((EntityHumanNPC) raw).a(PathType.WATER, oldWater + 1F);
        } else {
            ((EntityInsentient) raw).a(PathType.WATER, oldWater + 1F);
        }
    }
    return new MCNavigator() {

        float lastSpeed;

        CancelReason reason;

        @Override
        public CancelReason getCancelReason() {
            return reason;
        }

        @Override
        public Iterable<Vector> getPath() {
            return new NavigationIterable(navigation);
        }

        @Override
        public void stop() {
            if (params.debug() && navigation.m() != null) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.m().d(); i++) {
                        PathPoint pp = navigation.m().a(i);
                        org.bukkit.block.Block block = new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()).getBlock();
                        player.sendBlockChange(block.getLocation(), block.getBlockData());
                    }
                }
            }
            if (oldWater >= 0) {
                if (raw instanceof EntityPlayer) {
                    ((EntityHumanNPC) raw).a(PathType.WATER, oldWater);
                } else {
                    ((EntityInsentient) raw).a(PathType.WATER, oldWater);
                }
            }
            stopNavigation(navigation);
        }

        @Override
        public boolean update() {
            if (params.speed() != lastSpeed) {
                if (Messaging.isDebugging() && lastSpeed > 0) {
                    Messaging.debug("Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change");
                }
                Entity handle = getHandle(entity);
                float oldWidth = handle.width;
                if (handle instanceof EntityHorse) {
                    handle.width = Math.min(0.99f, oldWidth);
                }
                if (!function.apply(navigation)) {
                    reason = CancelReason.STUCK;
                }
                // minecraft requires that an entity fit onto both blocks if width >= 1f,
                handle.width = oldWidth;
                // but we'd prefer to make it just fit on 1 so hack around it a bit.
                lastSpeed = params.speed();
            }
            if (params.debug() && !NMSImpl.isNavigationFinished(navigation)) {
                BlockData data = Material.DANDELION.createBlockData();
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.m().d(); i++) {
                        PathPoint pp = navigation.m().a(i);
                        player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), data);
                    }
                }
            }
            navigation.a(params.speed());
            return NMSImpl.isNavigationFinished(navigation);
        }
    };
}
Also used : PathEntity(net.minecraft.server.v1_13_R2.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) Entity(net.minecraft.server.v1_13_R2.Entity) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_13_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityInsentient(net.minecraft.server.v1_13_R2.EntityInsentient) Entity(net.minecraft.server.v1_13_R2.Entity) NavigationAbstract(net.minecraft.server.v1_13_R2.NavigationAbstract) PathPoint(net.minecraft.server.v1_13_R2.PathPoint) EntityHumanNPC(net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC) PathPoint(net.minecraft.server.v1_13_R2.PathPoint) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) EntityHorse(net.minecraft.server.v1_13_R2.EntityHorse) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) EntityPlayer(net.minecraft.server.v1_13_R2.EntityPlayer) BlockData(org.bukkit.block.data.BlockData) IBlockData(net.minecraft.server.v1_13_R2.IBlockData) Vector(org.bukkit.util.Vector)

Example 33 with Entity

use of net.minecraft.server.v1_13_R2.Entity 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 34 with Entity

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

the class NMSImpl method tick.

@Override
public boolean tick(org.bukkit.entity.Entity next) {
    Entity entity = NMSImpl.getHandle(next);
    Entity entity1 = entity.getVehicle();
    if (entity1 != null) {
        if ((entity1.dead) || (!entity1.w(entity))) {
            entity.stopRiding();
        }
    } else {
        if (!entity.dead) {
            try {
                entity.world.entityJoinedWorld(entity, true);
            } catch (Throwable throwable) {
                CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
                CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
                entity.appendEntityCrashDetails(crashreportsystemdetails);
                throw new ReportedException(crashreport);
            }
        }
        boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
        if (entity.dead) {
            entity.world.removeEntity(entity);
            return true;
        } else if (!removeFromPlayerList) {
            if (!entity.world.players.contains(entity)) {
                entity.world.players.add((EntityHuman) entity);
            }
            return true;
        } else {
            entity.world.players.remove(entity);
        }
    }
    return false;
}
Also used : PathEntity(net.minecraft.server.v1_13_R2.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) Entity(net.minecraft.server.v1_13_R2.Entity) EntityHuman(net.minecraft.server.v1_13_R2.EntityHuman) CrashReportSystemDetails(net.minecraft.server.v1_13_R2.CrashReportSystemDetails) CrashReport(net.minecraft.server.v1_13_R2.CrashReport) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) ReportedException(net.minecraft.server.v1_13_R2.ReportedException)

Example 35 with Entity

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

the class NMSImpl method registerEntityClass.

@Override
public void registerEntityClass(Class<?> clazz) {
    if (ENTITY_REGISTRY == null)
        return;
    Class<?> search = clazz;
    while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
        EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
        MinecraftKey key = ENTITY_REGISTRY.getKey(type);
        if (key == null)
            continue;
        int code = ENTITY_REGISTRY.a(type);
        ENTITY_REGISTRY.put(code, key, type);
        return;
    }
    throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString());
}
Also used : PathEntity(net.minecraft.server.v1_13_R2.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) Entity(net.minecraft.server.v1_13_R2.Entity) MinecraftKey(net.minecraft.server.v1_13_R2.MinecraftKey) PathPoint(net.minecraft.server.v1_13_R2.PathPoint)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)95 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 net.minecraft.world.entity (net.minecraft.world.entity)32 org.bukkit.entity (org.bukkit.entity)32 Entity (com.google.datastore.v1.Entity)31 Location (org.bukkit.Location)30 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21 Entity (net.minecraft.server.v1_12_R1.Entity)20 Entity (net.minecraft.server.v1_16_R3.Entity)19 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 Entity (net.minecraft.server.v1_8_R3.Entity)17 Player (org.bukkit.entity.Player)17 Entity (net.minecraft.server.v1_11_R1.Entity)16 Mob (net.minecraft.world.entity.Mob)16 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)16 org.bukkit.craftbukkit.v1_17_R1.entity (org.bukkit.craftbukkit.v1_17_R1.entity)16 PathEntity (net.minecraft.server.v1_16_R3.PathEntity)13 Entity (net.minecraft.server.v1_15_R1.Entity)12 Entity (net.minecraft.server.v1_13_R2.Entity)11