Search in sources :

Example 1 with EntityHuman

use of cn.nukkit.entity.EntityHuman in project Nukkit by Nukkit.

the class EntityMinecartAbstract method applyEntityCollision.

@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) {
                // TODO: rewrite (weird riding)
                mountEntity(entity);
            }
        }
        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;
            }
        }
    }
}
Also used : EntityHuman(cn.nukkit.entity.EntityHuman) EntityLiving(cn.nukkit.entity.EntityLiving) Vector3(cn.nukkit.math.Vector3)

Example 2 with EntityHuman

use of cn.nukkit.entity.EntityHuman in project Nukkit by Nukkit.

the class PlayerInventory method onSlotChange.

@Override
public void onSlotChange(int index, Item before, boolean send) {
    EntityHuman holder = this.getHolder();
    if (holder instanceof Player && !((Player) holder).spawned) {
        return;
    }
    if (index >= this.getSize()) {
        this.sendArmorSlot(index, this.getViewers());
        this.sendArmorSlot(index, this.getHolder().getViewers().values());
    } else {
        super.onSlotChange(index, before, send);
    }
}
Also used : EntityHuman(cn.nukkit.entity.EntityHuman) Player(cn.nukkit.Player)

Aggregations

EntityHuman (cn.nukkit.entity.EntityHuman)2 Player (cn.nukkit.Player)1 EntityLiving (cn.nukkit.entity.EntityLiving)1 Vector3 (cn.nukkit.math.Vector3)1