cn.nukkit.entity.projectile.EntityProjectile Java Examples

The following examples show how to use cn.nukkit.entity.projectile.EntityProjectile. 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 File: ProjectileItem.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public boolean onClickAir(Player player, Vector3 directionVector) {
    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", player.x))
                    .add(new DoubleTag("", player.y + player.getEyeHeight()))
                    .add(new DoubleTag("", player.z)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", directionVector.x))
                    .add(new DoubleTag("", directionVector.y))
                    .add(new DoubleTag("", directionVector.z)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", (float) player.yaw))
                    .add(new FloatTag("", (float) player.pitch)));

    this.correctNBT(nbt);
    Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player);
    if (projectile != null) {
        projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce()));
        this.count--;

        if (projectile instanceof EntityProjectile) {
            ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile);

            player.getServer().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                projectile.kill();
            } else {
                projectile.spawnToAll();
                player.getLevel().addSound(new LaunchSound(player), player.getViewers().values());
            }
        } else {
            projectile.spawnToAll();
        }
    } else {
        return false;
    }
    return true;
}
 
Example #2
Source File: EntityShootBowEvent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setProjectile(Entity projectile) {
    if (projectile != this.projectile) {
        if (this.projectile.getViewers().size() == 0) {
            this.projectile.kill();
            this.projectile.close();
        }
        this.projectile = (EntityProjectile) projectile;
    }
}
 
Example #3
Source File: EntityShootBowEvent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void setProjectile(Entity projectile) {
    if (projectile != this.projectile) {
        if (this.projectile.getViewers().size() == 0) {
            this.projectile.kill();
            this.projectile.close();
        }
        this.projectile = (EntityProjectile) projectile;
    }
}
 
Example #4
Source File: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void handleKill(long time, UUID victimUUID, Entity killerEntity) {
    Runnable processor = null;
    if (killerEntity instanceof Player) {
        processor = handlePlayerKill(time, victimUUID, (Player) killerEntity);
    } else if (killerEntity instanceof EntityTameable) {
        processor = handlePetKill(time, victimUUID, (EntityTameable) killerEntity);
    } else if (killerEntity instanceof EntityProjectile) {
        processor = handleProjectileKill(time, victimUUID, (EntityProjectile) killerEntity);
    }
    if (processor != null) {
        processing.submit(processor);
    }
}
 
Example #5
Source File: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Runnable handleProjectileKill(long time, UUID victimUUID, EntityProjectile projectile) {
    Entity source = projectile.shootingEntity;
    if (!(source instanceof Player)) {
        return null;
    }

    Player player = (Player) source;
    String projectileName = new EntityNameFormatter().apply(projectile.getName());

    return victimUUID != null
            ? new PlayerKillProcessor(player.getUniqueId(), time, victimUUID, projectileName)
            : new MobKillProcessor(player.getUniqueId());
}
 
Example #6
Source File: EntityShootBowEvent.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void setProjectile(Entity projectile) {
    if (projectile != this.projectile) {
        if (this.projectile.getViewers().size() == 0) {
            this.projectile.kill();
            this.projectile.close();
        }
        this.projectile = (EntityProjectile) projectile;
    }
}
 
Example #7
Source File: ProjectileItem.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean onClickAir(Player player, Vector3 directionVector) {
    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", player.x))
                    .add(new DoubleTag("", player.y + player.getEyeHeight()))
                    .add(new DoubleTag("", player.z)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", directionVector.x))
                    .add(new DoubleTag("", directionVector.y))
                    .add(new DoubleTag("", directionVector.z)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", (float) player.yaw))
                    .add(new FloatTag("", (float) player.pitch)));

    this.correctNBT(nbt);

    Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player);
    if (projectile != null) {
        projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce()));
        this.count--;

        if (projectile instanceof EntityProjectile) {
            ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile);

            player.getServer().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                projectile.kill();
            } else {
                projectile.spawnToAll();
                player.getLevel().addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values());
            }
        } else {
            projectile.spawnToAll();
        }
    } else {
        return false;
    }
    return true;
}
 
Example #8
Source File: EntityShootBowEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityProjectile getProjectile() {
    return this.projectile;
}
 
Example #9
Source File: EntitySpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isProjectile() {
    return this.entity instanceof EntityProjectile;
}
 
Example #10
Source File: EntitySpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isProjectile() {
    return this.entity instanceof EntityProjectile;
}
 
Example #11
Source File: NukkitEntityType.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isProjectile() {
    return entity instanceof EntityProjectile;
}
 
Example #12
Source File: ItemBow.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean onReleaseUsing(Player player) {
    Item itemArrow = Item.get(Item.ARROW, 0, 1);

    if (player.isSurvival() && !player.getInventory().contains(itemArrow)) {
        player.getInventory().sendContents(player);
        return false;
    }

    double damage = 2;
    boolean flame = false;

    if (this.hasEnchantments()) {
        Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER);

        if (bowDamage != null && bowDamage.getLevel() > 0) {
            damage += 0.25 * (bowDamage.getLevel() + 1);
        }

        Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME);
        flame = flameEnchant != null && flameEnchant.getLevel() > 0;
    }

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", player.x))
                    .add(new DoubleTag("", player.y + player.getEyeHeight()))
                    .add(new DoubleTag("", player.z)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))
                    .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI)))
                    .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw))
                    .add(new FloatTag("", (float) -player.pitch)))
            .putShort("Fire", player.isOnFire() || flame ? 45 * 60 : 0)
            .putDouble("damage", damage);

    int diff = (Server.getInstance().getTick() - player.getStartActionTick());
    double p = (double) diff / 20;

    double f = Math.min((p * p + p * 2) / 3, 1) * 2;
    EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, new EntityArrow(player.chunk, nbt, player, f == 2), f);

    if (f < 0.1 || diff < 5) {
        entityShootBowEvent.setCancelled();
    }

    Server.getInstance().getPluginManager().callEvent(entityShootBowEvent);
    if (entityShootBowEvent.isCancelled()) {
        entityShootBowEvent.getProjectile().kill();
        player.getInventory().sendContents(player);
    } else {
        entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce()));
        if (player.isSurvival()) {
            Enchantment infinity;

            if (!this.hasEnchantments() || (infinity = this.getEnchantment(Enchantment.ID_BOW_INFINITY)) == null || infinity.getLevel() <= 0)
                player.getInventory().removeItem(itemArrow);
            if (!this.isUnbreakable()) {
                Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY);
                if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) {
                    this.setDamage(this.getDamage() + 1);
                    if (this.getDamage() >= 385) {
                        player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0));
                    } else {
                        player.getInventory().setItemInHand(this);
                    }
                }
            }
        }
        if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) {
            ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile());
            Server.getInstance().getPluginManager().callEvent(projectev);
            if (projectev.isCancelled()) {
                entityShootBowEvent.getProjectile().kill();
            } else {
                entityShootBowEvent.getProjectile().spawnToAll();
                player.level.addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values());
            }
        } else {
            entityShootBowEvent.getProjectile().spawnToAll();
        }
    }

    return true;
}
 
Example #13
Source File: ProjectileLaunchEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public ProjectileLaunchEvent(EntityProjectile entity) {
    this.entity = entity;
}
 
Example #14
Source File: ProjectileLaunchEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityProjectile getEntity() {
    return (EntityProjectile) this.entity;
}
 
Example #15
Source File: ProjectileHitEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public ProjectileHitEvent(EntityProjectile entity) {
    this(entity, null);
}
 
Example #16
Source File: ProjectileHitEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public ProjectileHitEvent(EntityProjectile entity, MovingObjectPosition movingObjectPosition) {
    this.entity = entity;
    this.movingObjectPosition = movingObjectPosition;
}
 
Example #17
Source File: EntityDespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean isProjectile() {
    return this.entity instanceof EntityProjectile;
}
 
Example #18
Source File: EntityShootBowEvent.java    From Nukkit with 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 #19
Source File: EntityShootBowEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityProjectile getProjectile() {
    return this.projectile;
}
 
Example #20
Source File: ItemBow.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean onReleaseUsing(Player player) {
    Item itemArrow = Item.get(Item.ARROW, 0, 1);

    if (player.isSurvival() && !player.getInventory().contains(itemArrow)) {
        player.getInventory().sendContents(player);
        return false;
    }

    double damage = 2;
    boolean flame = false;

    if (this.hasEnchantments()) {
        Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER);

        if (bowDamage != null && bowDamage.getLevel() > 0) {
            damage += 0.25 * (bowDamage.getLevel() + 1);
        }

        Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME);
        flame = flameEnchant != null && flameEnchant.getLevel() > 0;
    }

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", player.x))
                    .add(new DoubleTag("", player.y + player.getEyeHeight()))
                    .add(new DoubleTag("", player.z)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))
                    .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI)))
                    .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw))
                    .add(new FloatTag("", (float) -player.pitch)))
            .putShort("Fire", player.isOnFire() || flame ? 45 * 60 : 0)
            .putDouble("damage", damage);

    int diff = (Server.getInstance().getTick() - player.getStartActionTick());
    double p = (double) diff / 20;

    double f = Math.min((p * p + p * 2) / 3, 1) * 2;
    EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, new EntityArrow(player.chunk, nbt, player, f == 2), f);

    if (f < 0.1 || diff < 5) {
        entityShootBowEvent.setCancelled();
    }

    Server.getInstance().getPluginManager().callEvent(entityShootBowEvent);
    if (entityShootBowEvent.isCancelled()) {
        entityShootBowEvent.getProjectile().kill();
        player.getInventory().sendContents(player);
    } else {
        entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce()));
        if (player.isSurvival()) {
            Enchantment infinity;

            if (!this.hasEnchantments() || (infinity = this.getEnchantment(Enchantment.ID_BOW_INFINITY)) == null || infinity.getLevel() <= 0)
                player.getInventory().removeItem(itemArrow);
            if (!this.isUnbreakable()) {
                Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY);
                if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) {
                    this.setDamage(this.getDamage() + 1);
                    if (this.getDamage() >= 385) {
                        player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0));
                    } else {
                        player.getInventory().setItemInHand(this);
                    }
                }
            }
        }
        if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) {
            ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile());
            Server.getInstance().getPluginManager().callEvent(projectev);
            if (projectev.isCancelled()) {
                entityShootBowEvent.getProjectile().kill();
            } else {
                entityShootBowEvent.getProjectile().spawnToAll();
                player.level.addSound(new LaunchSound(player), player.getViewers().values());
            }
        } else {
            entityShootBowEvent.getProjectile().spawnToAll();
        }
    }

    return true;
}
 
Example #21
Source File: ItemBow.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onRelease(Player player, int ticksUsed) {
    Item itemArrow = Item.get(Item.ARROW, 0, 1);

    Inventory inventory = player.getOffhandInventory();

    if (!inventory.contains(itemArrow) && !(inventory = player.getInventory()).contains(itemArrow) && player.isSurvival()) {
        player.getOffhandInventory().sendContents(player);
        inventory.sendContents(player);
        return false;
    }

    double damage = 2;

    Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER);
    if (bowDamage != null && bowDamage.getLevel() > 0) {
        damage += 0.25 * (bowDamage.getLevel() + 1);
    }

    Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME);
    boolean flame = flameEnchant != null && flameEnchant.getLevel() > 0;

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", player.x))
                    .add(new DoubleTag("", player.y + player.getEyeHeight()))
                    .add(new DoubleTag("", player.z)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))
                    .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI)))
                    .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw))
                    .add(new FloatTag("", (float) -player.pitch)))
            .putShort("Fire", flame ? 45 * 60 : 0)
            .putDouble("damage", damage);

    double p = (double) ticksUsed / 20;
    double f = Math.min((p * p + p * 2) / 3, 1) * 2;

    EntityArrow arrow = (EntityArrow) Entity.createEntity("Arrow", player.chunk, nbt, player, f == 2);

    if (arrow == null) {
        return false;
    }

    EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, arrow, f);

    if (f < 0.1 || ticksUsed < 3) {
        entityShootBowEvent.setCancelled();
    }

    Server.getInstance().getPluginManager().callEvent(entityShootBowEvent);
    if (entityShootBowEvent.isCancelled()) {
        entityShootBowEvent.getProjectile().kill();
        player.getInventory().sendContents(player);
        player.getOffhandInventory().sendContents(player);
    } else {
        entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce()));
        Enchantment infinityEnchant = this.getEnchantment(Enchantment.ID_BOW_INFINITY);
        boolean infinity = infinityEnchant != null && infinityEnchant.getLevel() > 0;
        EntityProjectile projectile;
        if (infinity && (projectile = entityShootBowEvent.getProjectile()) instanceof EntityArrow) {
            ((EntityArrow) projectile).setPickupMode(EntityArrow.PICKUP_CREATIVE);
        }
        if (player.isSurvival()) {
            if (!infinity) {
                inventory.removeItem(itemArrow);
            }
            if (!this.isUnbreakable()) {
                Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY);
                if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) {
                    this.setDamage(this.getDamage() + 1);
                    if (this.getDamage() >= getMaxDurability()) {
                        this.count--;
                    }
                    player.getInventory().setItemInHand(this);
                }
            }
        }
        if (entityShootBowEvent.getProjectile() != null) {
            ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile());
            Server.getInstance().getPluginManager().callEvent(projectev);
            if (projectev.isCancelled()) {
                entityShootBowEvent.getProjectile().kill();
            } else {
                entityShootBowEvent.getProjectile().spawnToAll();
                player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_BOW);
            }
        }
    }

    return true;
}
 
Example #22
Source File: ProjectileLaunchEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public ProjectileLaunchEvent(EntityProjectile entity) {
    this.entity = entity;
}
 
Example #23
Source File: ProjectileLaunchEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public EntityProjectile getEntity() {
    return (EntityProjectile) this.entity;
}
 
Example #24
Source File: ProjectileHitEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public ProjectileHitEvent(EntityProjectile entity) {
    this(entity, null);
}
 
Example #25
Source File: ProjectileHitEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public ProjectileHitEvent(EntityProjectile entity, MovingObjectPosition movingObjectPosition) {
    this.entity = entity;
    this.movingObjectPosition = movingObjectPosition;
}
 
Example #26
Source File: EntityDespawnEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean isProjectile() {
    return this.entity instanceof EntityProjectile;
}
 
Example #27
Source File: EntityShootBowEvent.java    From Jupiter with 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 #28
Source File: EntityShootBowEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public EntityProjectile getProjectile() {
    return this.projectile;
}
 
Example #29
Source File: EntitySpawnEvent.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean isProjectile() {
    return this.entity instanceof EntityProjectile;
}
 
Example #30
Source File: EntityShootBowEvent.java    From Nukkit with 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;
}