Java Code Examples for cn.nukkit.entity.EntityLiving

The following examples show how to use cn.nukkit.entity.EntityLiving. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Nukkit   Source File: EntityMinecartEmpty.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onUpdate(int currentTick) {
    boolean update = super.onUpdate(currentTick);

    if (this.passengers.isEmpty()) {
        for (Entity entity : this.level.getCollidingEntities(this.boundingBox.grow(0.20000000298023224, 0.0D, 0.20000000298023224), this)) {
            if (entity.riding != null || !(entity instanceof EntityLiving) || entity instanceof Player || entity instanceof EntityWaterAnimal) {
                continue;
            }

            this.mountEntity(entity);
            update = true;
            break;
        }
    }

    return update;
}
 
Example 2
@Override
protected int computeRedstoneStrength() {
    AxisAlignedBB bb = getCollisionBoundingBox();

    for (Entity entity : this.level.getCollidingEntities(bb)) {
        if (entity instanceof EntityLiving && entity.doesTriggerPressurePlate()) {
            return 15;
        }
    }

    return 0;
}
 
Example 3
Source Project: Jupiter   Source File: Potion.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void applyPotion(Entity entity, double health) {
    if (!(entity instanceof EntityLiving)) {
        return;
    }

    Effect applyEffect = getEffect(this.getId(), this.isSplash());

    if (applyEffect == null) {
        return;
    }

    if (entity instanceof Player) {
        if (!((Player) entity).isSurvival() && applyEffect.isBad()) {
            return;
        }
    }

    PotionApplyEvent event = new PotionApplyEvent(this, entity);

    entity.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    switch (this.getId()) {
        case INSTANT_HEALTH:
        case INSTANT_HEALTH_II:
            entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_EATING));
            break;
        case HARMING:
        case HARMING_II:
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1)))));
            break;
        default:
            int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5);
            applyEffect.setDuration(duration);
            entity.addEffect(applyEffect);
    }
}
 
Example 4
@Override
protected int computeRedstoneStrength() {
    AxisAlignedBB bb = getCollisionBoundingBox();

    for (Entity entity : this.level.getCollidingEntities(bb)) {
        if (entity instanceof EntityLiving && entity.doesTriggerPressurePlate()) {
            return 15;
        }
    }

    return 0;
}
 
Example 5
@Override
protected int computeRedstoneStrength() {
    AxisAlignedBB bb = getCollisionBoundingBox();

    for (Entity entity : this.level.getCollidingEntities(bb)) {
        if (entity instanceof EntityLiving && entity.doesTriggerPressurePlate()) {
            return 15;
        }
    }

    return 0;
}
 
Example 6
@Override
public void applyEntityCollision(Entity entity) {
    if (entity != riding) {
        if (entity instanceof EntityLiving
                && !(entity instanceof EntityHuman)
                && motionX * motionX + motionZ * motionZ > 0.01D
                && linkedEntity == null
                && entity.riding == null
                && blockInside == null) {
            if (riding == null && devs) {
                mountEntity(entity);// TODO: rewrite (weird riding)
            }
        }

        double motiveX = entity.x - x;
        double motiveZ = entity.z - z;
        double square = motiveX * motiveX + motiveZ * motiveZ;

        if (square >= 9.999999747378752E-5D) {
            square = Math.sqrt(square);
            motiveX /= square;
            motiveZ /= square;
            double next = 1 / square;

            if (next > 1) {
                next = 1;
            }

            motiveX *= next;
            motiveZ *= next;
            motiveX *= 0.10000000149011612D;
            motiveZ *= 0.10000000149011612D;
            motiveX *= 1 + entityCollisionReduction;
            motiveZ *= 1 + entityCollisionReduction;
            motiveX *= 0.5D;
            motiveZ *= 0.5D;
            if (entity instanceof EntityMinecartAbstract) {
                EntityMinecartAbstract mine = (EntityMinecartAbstract) entity;
                double desinityX = mine.x - x;
                double desinityZ = mine.z - z;
                Vector3 vector = new Vector3(desinityX, 0, desinityZ).normalize();
                Vector3 vec = new Vector3((double) MathHelper.cos((float) yaw * 0.017453292F), 0, (double) MathHelper.sin((float) yaw * 0.017453292F)).normalize();
                double desinityXZ = Math.abs(vector.dot(vec));

                if (desinityXZ < 0.800000011920929D) {
                    return;
                }

                double motX = mine.motionX + motionX;
                double motZ = mine.motionZ + motionZ;

                if (mine.getType().getId() == 2 && getType().getId() != 2) {
                    motionX *= 0.20000000298023224D;
                    motionZ *= 0.20000000298023224D;
                    motionX += mine.motionX - motiveX;
                    motionZ += mine.motionZ - motiveZ;
                    mine.motionX *= 0.949999988079071D;
                    mine.motionZ *= 0.949999988079071D;
                } else if (mine.getType().getId() != 2 && getType().getId() == 2) {
                    mine.motionX *= 0.20000000298023224D;
                    mine.motionZ *= 0.20000000298023224D;
                    motionX += mine.motionX - motiveX;
                    motionZ += mine.motionZ - motiveZ;
                    motionX *= 0.949999988079071D;
                    motionZ *= 0.949999988079071D;
                } else {
                    motX /= 2;
                    motZ /= 2;
                    motionX *= 0.20000000298023224D;
                    motionZ *= 0.20000000298023224D;
                    motionX += motX - motiveX;
                    motionZ += motZ - motiveZ;
                    mine.motionX *= 0.20000000298023224D;
                    mine.motionZ *= 0.20000000298023224D;
                    mine.motionX += motX - motiveX;
                    mine.motionZ += motZ - motiveZ;
                }
            } else {
                motionX -= motiveX;
                motionZ -= motiveZ;
            }
        }
    }
}
 
Example 7
Source Project: Jupiter   Source File: EntityProjectile.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canCollideWith(Entity entity) {
    return entity instanceof EntityLiving && !this.onGround;
}
 
Example 8
Source Project: Jupiter   Source File: EntityShootBowEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityShootBowEvent(EntityLiving shooter, Item bow, EntityProjectile projectile, double force) {
    this.entity = shooter;
    this.bow = bow;
    this.projectile = projectile;
    this.force = force;
}
 
Example 9
Source Project: Jupiter   Source File: EntityShootBowEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityLiving getEntity() {
    return (EntityLiving) this.entity;
}
 
Example 10
Source Project: Jupiter   Source File: EntityDeathEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityDeathEvent(EntityLiving entity) {
    this(entity, new Item[0]);
}
 
Example 11
Source Project: Jupiter   Source File: EntityDeathEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityDeathEvent(EntityLiving entity, Item[] drops) {
    this.entity = entity;
    this.drops = drops;
}
 
Example 12
@Override
public void applyEntityCollision(cn.nukkit.entity.Entity entity) {
    if (entity != riding && !(entity instanceof Player && ((Player) entity).getGamemode() == Player.SPECTATOR)) {
        if (entity instanceof EntityLiving
                && !(entity instanceof EntityHuman)
                && motionX * motionX + motionZ * motionZ > 0.01D
                && passengers.isEmpty()
                && entity.riding == null
                && blockInside == null) {
            if (riding == null && devs) {
                mountEntity(entity);// TODO: rewrite (weird riding)
            }
        }

        double motiveX = entity.x - x;
        double motiveZ = entity.z - z;
        double square = motiveX * motiveX + motiveZ * motiveZ;

        if (square >= 9.999999747378752E-5D) {
            square = Math.sqrt(square);
            motiveX /= square;
            motiveZ /= square;
            double next = 1 / square;

            if (next > 1) {
                next = 1;
            }

            motiveX *= next;
            motiveZ *= next;
            motiveX *= 0.10000000149011612D;
            motiveZ *= 0.10000000149011612D;
            motiveX *= 1 + entityCollisionReduction;
            motiveZ *= 1 + entityCollisionReduction;
            motiveX *= 0.5D;
            motiveZ *= 0.5D;
            if (entity instanceof EntityMinecartAbstract) {
                EntityMinecartAbstract mine = (EntityMinecartAbstract) entity;
                double desinityX = mine.x - x;
                double desinityZ = mine.z - z;
                Vector3 vector = new Vector3(desinityX, 0, desinityZ).normalize();
                Vector3 vec = new Vector3((double) MathHelper.cos((float) yaw * 0.017453292F), 0, (double) MathHelper.sin((float) yaw * 0.017453292F)).normalize();
                double desinityXZ = Math.abs(vector.dot(vec));

                if (desinityXZ < 0.800000011920929D) {
                    return;
                }

                double motX = mine.motionX + motionX;
                double motZ = mine.motionZ + motionZ;

                if (mine.getType().getId() == 2 && getType().getId() != 2) {
                    motionX *= 0.20000000298023224D;
                    motionZ *= 0.20000000298023224D;
                    motionX += mine.motionX - motiveX;
                    motionZ += mine.motionZ - motiveZ;
                    mine.motionX *= 0.949999988079071D;
                    mine.motionZ *= 0.949999988079071D;
                } else if (mine.getType().getId() != 2 && getType().getId() == 2) {
                    mine.motionX *= 0.20000000298023224D;
                    mine.motionZ *= 0.20000000298023224D;
                    motionX += mine.motionX + motiveX;
                    motionZ += mine.motionZ + motiveZ;
                    motionX *= 0.949999988079071D;
                    motionZ *= 0.949999988079071D;
                } else {
                    motX /= 2;
                    motZ /= 2;
                    motionX *= 0.20000000298023224D;
                    motionZ *= 0.20000000298023224D;
                    motionX += motX - motiveX;
                    motionZ += motZ - motiveZ;
                    mine.motionX *= 0.20000000298023224D;
                    mine.motionZ *= 0.20000000298023224D;
                    mine.motionX += motX + motiveX;
                    mine.motionZ += motZ + motiveZ;
                }
            } else {
                motionX -= motiveX;
                motionZ -= motiveZ;
            }
        }
    }
}
 
Example 13
Source Project: Nukkit   Source File: EntityBoat.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
    public boolean onUpdate(int currentTick) {
        if (this.closed) {
            return false;
        }

        int tickDiff = currentTick - this.lastUpdate;

        if (tickDiff <= 0 && !this.justCreated) {
            return true;
        }

        this.lastUpdate = currentTick;

        boolean hasUpdate = this.entityBaseTick(tickDiff);

        if (this.isAlive()) {
            super.onUpdate(currentTick);

            double waterDiff = getWaterLevel();
            if (!hasControllingPassenger()) {

                if (waterDiff > SINKING_DEPTH && !sinking) {
                    sinking = true;
                } else if (waterDiff < -SINKING_DEPTH && sinking) {
                    sinking = false;
                }

                if (waterDiff < -SINKING_DEPTH) {
                    this.motionY = Math.min(0.05, this.motionY + 0.005);
                } else if (waterDiff < 0 || !sinking) {
                    this.motionY = this.motionY > SINKING_MAX_SPEED ? Math.max(this.motionY - 0.02, SINKING_MAX_SPEED) : this.motionY + SINKING_SPEED;
//                    this.motionY = this.motionY + SINKING_SPEED > SINKING_MAX_SPEED ? this.motionY - SINKING_SPEED : this.motionY + SINKING_SPEED;
                }
            }

            if (this.checkObstruction(this.x, this.y, this.z)) {
                hasUpdate = true;
            }

            this.move(this.motionX, this.motionY, this.motionZ);

            double friction = 1 - this.getDrag();

            if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) {
                friction *= this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor();
            }

            this.motionX *= friction;

            if (!hasControllingPassenger()) {
                if (waterDiff > SINKING_DEPTH || sinking) {
                    this.motionY = waterDiff > 0.5 ? this.motionY - this.getGravity() : (this.motionY - SINKING_SPEED < -SINKING_MAX_SPEED ? this.motionY : this.motionY - SINKING_SPEED);
                }
            }

            this.motionZ *= friction;

            Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level);
            Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level);

            this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this));

            if (!from.equals(to)) {
                this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to));
            }

            //TODO: lily pad collision
            this.updateMovement();

            if (this.passengers.size() < 2) {
                for (Entity entity : this.level.getCollidingEntities(this.boundingBox.grow(0.20000000298023224, 0.0D, 0.20000000298023224), this)) {
                    if (entity.riding != null || !(entity instanceof EntityLiving) || entity instanceof Player || entity instanceof EntityWaterAnimal || isPassenger(entity)) {
                        continue;
                    }

                    this.mountEntity(entity);

                    if (this.passengers.size() >= 2) {
                        break;
                    }
                }
            }
        }

        return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001;
    }
 
Example 14
Source Project: Nukkit   Source File: EntityProjectile.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canCollideWith(Entity entity) {
    return (entity instanceof EntityLiving || entity instanceof EntityEndCrystal) && !this.onGround;
}
 
Example 15
Source Project: Nukkit   Source File: EntityShootBowEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityShootBowEvent(EntityLiving shooter, Item bow, EntityProjectile projectile, double force) {
    this.entity = shooter;
    this.bow = bow;
    this.projectile = projectile;
    this.force = force;
}
 
Example 16
Source Project: Nukkit   Source File: EntityShootBowEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityLiving getEntity() {
    return (EntityLiving) this.entity;
}
 
Example 17
Source Project: Nukkit   Source File: EntityDeathEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityDeathEvent(EntityLiving entity) {
    this(entity, new Item[0]);
}
 
Example 18
Source Project: Nukkit   Source File: EntityDeathEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityDeathEvent(EntityLiving entity, Item[] drops) {
    this.entity = entity;
    this.drops = drops;
}
 
Example 19
Source Project: Nukkit   Source File: Potion.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void applyPotion(Entity entity, double health) {
    if (!(entity instanceof EntityLiving)) {
        return;
    }

    Effect applyEffect = getEffect(this.getId(), this.isSplash());

    if (applyEffect == null) {
        return;
    }

    if (entity instanceof Player) {
        if (!((Player) entity).isSurvival() && !((Player) entity).isAdventure() && applyEffect.isBad()) {
            return;
        }
    }

    PotionApplyEvent event = new PotionApplyEvent(this, applyEffect, entity);

    entity.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    applyEffect = event.getApplyEffect();

    switch (this.getId()) {
        case INSTANT_HEALTH:
        case INSTANT_HEALTH_II:
            entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_MAGIC));
            break;
        case HARMING:
        case HARMING_II:
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1)))));
            break;
        default:
            int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5);
            applyEffect.setDuration(duration);
            entity.addEffect(applyEffect);
    }
}
 
Example 20
@Override
public boolean isLiving() {
    return entity instanceof EntityLiving;
}
 
Example 21
@Override
public void applyEntityCollision(Entity entity) {
    if (entity != riding) {
        if (entity instanceof EntityLiving
                && !(entity instanceof EntityHuman)
                && motionX * motionX + motionZ * motionZ > 0.01D
                && linkedEntity == null
                && entity.riding == null
                && blockInside == null) {
            if (riding == null && devs) {
                mountEntity(entity);// TODO: rewrite (weird riding)
            }
        }

        double motiveX = entity.x - x;
        double motiveZ = entity.z - z;
        double square = motiveX * motiveX + motiveZ * motiveZ;

        if (square >= 9.999999747378752E-5D) {
            square = Math.sqrt(square);
            motiveX /= square;
            motiveZ /= square;
            double next = 1 / square;

            if (next > 1) {
                next = 1;
            }

            motiveX *= next;
            motiveZ *= next;
            motiveX *= 0.10000000149011612D;
            motiveZ *= 0.10000000149011612D;
            motiveX *= 1 + entityCollisionReduction;
            motiveZ *= 1 + entityCollisionReduction;
            motiveX *= 0.5D;
            motiveZ *= 0.5D;
            if (entity instanceof EntityMinecartAbstract) {
                EntityMinecartAbstract mine = (EntityMinecartAbstract) entity;
                double desinityX = mine.x - x;
                double desinityZ = mine.z - z;
                Vector3 vector = new Vector3(desinityX, 0, desinityZ).normalize();
                Vector3 vec = new Vector3((double) MathHelper.cos((float) yaw * 0.017453292F), 0, (double) MathHelper.sin((float) yaw * 0.017453292F)).normalize();
                double desinityXZ = Math.abs(vector.dot(vec));

                if (desinityXZ < 0.800000011920929D) {
                    return;
                }

                double motX = mine.motionX + motionX;
                double motZ = mine.motionZ + motionZ;

                if (mine.getType().getId() == 2 && getType().getId() != 2) {
                    motionX *= 0.20000000298023224D;
                    motionZ *= 0.20000000298023224D;
                    motionX += mine.motionX - motiveX;
                    motionZ += mine.motionZ - motiveZ;
                    mine.motionX *= 0.949999988079071D;
                    mine.motionZ *= 0.949999988079071D;
                } else if (mine.getType().getId() != 2 && getType().getId() == 2) {
                    mine.motionX *= 0.20000000298023224D;
                    mine.motionZ *= 0.20000000298023224D;
                    motionX += mine.motionX + motiveX;
                    motionZ += mine.motionZ + motiveZ;
                    motionX *= 0.949999988079071D;
                    motionZ *= 0.949999988079071D;
                } else {
                    motX /= 2;
                    motZ /= 2;
                    motionX *= 0.20000000298023224D;
                    motionZ *= 0.20000000298023224D;
                    motionX += motX - motiveX;
                    motionZ += motZ - motiveZ;
                    mine.motionX *= 0.20000000298023224D;
                    mine.motionZ *= 0.20000000298023224D;
                    mine.motionX += motX + motiveX;
                    mine.motionZ += motZ + motiveZ;
                }
            } else {
                motionX -= motiveX;
                motionZ -= motiveZ;
            }                
        }
    }
}
 
Example 22
Source Project: Nukkit   Source File: EntityProjectile.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canCollideWith(Entity entity) {
    return entity instanceof EntityLiving && !this.onGround;
}
 
Example 23
Source Project: Nukkit   Source File: EntityShootBowEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityShootBowEvent(EntityLiving shooter, Item bow, EntityProjectile projectile, double force) {
    this.entity = shooter;
    this.bow = bow;
    this.projectile = projectile;
    this.force = force;
}
 
Example 24
Source Project: Nukkit   Source File: EntityShootBowEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public EntityLiving getEntity() {
    return (EntityLiving) this.entity;
}
 
Example 25
Source Project: Nukkit   Source File: EntityDeathEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityDeathEvent(EntityLiving entity) {
    this(entity, new Item[0]);
}
 
Example 26
Source Project: Nukkit   Source File: EntityDeathEvent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public EntityDeathEvent(EntityLiving entity, Item[] drops) {
    this.entity = entity;
    this.drops = drops;
}
 
Example 27
Source Project: Nukkit   Source File: Potion.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void applyPotion(Entity entity, double health) {
    if (!(entity instanceof EntityLiving)) {
        return;
    }

    Effect applyEffect = getEffect(this.getId(), this.isSplash());

    if (applyEffect == null) {
        return;
    }

    if (entity instanceof Player) {
        if (!((Player) entity).isSurvival() && applyEffect.isBad()) {
            return;
        }
    }

    PotionApplyEvent event = new PotionApplyEvent(this, applyEffect, entity);

    entity.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    applyEffect = event.getApplyEffect();

    switch (this.getId()) {
        case INSTANT_HEALTH:
        case INSTANT_HEALTH_II:
            entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_EATING));
            break;
        case HARMING:
        case HARMING_II:
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1)))));
            break;
        default:
            int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5);
            applyEffect.setDuration(duration);
            entity.addEffect(applyEffect);
    }
}