cn.nukkit.entity.projectile.EntityArrow Java Examples
The following examples show how to use
cn.nukkit.entity.projectile.EntityArrow.
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: BlockFire.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public void onEntityCollide(Entity entity) { if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1)); } EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8); if (entity instanceof EntityArrow) { ev.setCancelled(); } Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled() && entity instanceof Player && !((Player) entity).isCreative()) { entity.setOnFire(ev.getDuration()); } }
Example #2
Source File: BlockFire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void onEntityCollide(Entity entity) { if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1)); } EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8); if (entity instanceof EntityArrow) { ev.setCancelled(); } Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled() && entity.isAlive() && entity.noDamageTicks == 0) { entity.setOnFire(ev.getDuration()); } }
Example #3
Source File: BlockFire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void onEntityCollide(Entity entity) { if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1)); } EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8); if (entity instanceof EntityArrow) { ev.setCancelled(); } Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled() && entity instanceof Player && !((Player) entity).isCreative()) { entity.setOnFire(ev.getDuration()); } }
Example #4
Source File: ItemBow.java From Jupiter with GNU General Public License v3.0 | 4 votes |
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 #5
Source File: Server.java From Jupiter with GNU General Public License v3.0 | 4 votes |
private void registerEntities() { //mob Entity.registerEntity("Blaze", EntityBlaze.class); Entity.registerEntity("CaveSpider", EntityCaveSpider.class); Entity.registerEntity("Creeper", EntityCreeper.class); Entity.registerEntity("Enderman", EntityEnderman.class); Entity.registerEntity("Endermite", EntityEndermite.class); Entity.registerEntity("Evoker", EntityEvoker.class); Entity.registerEntity("Ghast", EntityGhast.class); Entity.registerEntity("Guardian", EntityGuardian.class); Entity.registerEntity("Hask", EntityHask.class); Entity.registerEntity("MagmaCube", EntityMagmaCube.class); Entity.registerEntity("Shulker", EntityShulker.class); Entity.registerEntity("Silverfish", EntitySilverfish.class); Entity.registerEntity("Skeleton", EntitySkeleton.class); Entity.registerEntity("Slime", EntitySlime.class); Entity.registerEntity("Spider", EntitySpider.class); Entity.registerEntity("Stray", EntityStray.class); Entity.registerEntity("Vex", EntityVex.class); Entity.registerEntity("Vindicator", EntityVindicator.class); Entity.registerEntity("Witch", EntityWitch.class); Entity.registerEntity("WitherSkeleton", EntityWitherSkeleton.class); Entity.registerEntity("Zombie", EntityZombie.class); Entity.registerEntity("ZombiePigman", EntityZombiePigman.class); Entity.registerEntity("ZombieVillager", EntityZombieVillager.class); //passive Entity.registerEntity("Bat", EntityBat.class); Entity.registerEntity("Chicken", EntityChicken.class); Entity.registerEntity("Cow", EntityCow.class); Entity.registerEntity("Donkey", EntityDonkey.class); Entity.registerEntity("Horse", EntityHorse.class); Entity.registerEntity("IronGolem", EntityIronGolem.class); Entity.registerEntity("Llama", EntityLlama.class); Entity.registerEntity("Mooshroom", EntityMooshroom.class); Entity.registerEntity("Mule", EntityMule.class); Entity.registerEntity("Ocelot", EntityOcelot.class); Entity.registerEntity("Parrot", EntityParrot.class); Entity.registerEntity("Pig", EntityPig.class); Entity.registerEntity("PolarBear", EntityPolarBear.class); Entity.registerEntity("Rabbit", EntityRabbit.class); Entity.registerEntity("Sheep", EntitySheep.class); Entity.registerEntity("SkeletonHorse", EntitySkeletonHorse.class); Entity.registerEntity("SnowGolem", EntitySnowGolem.class); Entity.registerEntity("Squid", EntitySquid.class); Entity.registerEntity("Villager", EntityVillager.class); Entity.registerEntity("Wolf", EntityWolf.class); Entity.registerEntity("ZombieHorse", EntityZombieHorse.class); //Bosses Entity.registerEntity("ElderGuardian", EntityElderGuardian.class); Entity.registerEntity("EnderDragon", EntityEnderDragon.class); Entity.registerEntity("EnderWither", EntityWither.class); //item Entity.registerEntity("ArmorStand", EntityArmorStand.class); Entity.registerEntity("EnderCrystal", EntityEnderCrystal.class); Entity.registerEntity("FallingSand", EntityFallingBlock.class); Entity.registerEntity("PrimedTnt", EntityPrimedTNT.class); Entity.registerEntity("Painting", EntityPainting.class); Entity.registerEntity("XpOrb", EntityXPOrb.class); Entity.registerEntity("MinecartRideable", EntityMinecartEmpty.class); Entity.registerEntity("MinecartChest", EntityMinecartChest.class); Entity.registerEntity("MinecartHopper", EntityMinecartHopper.class); Entity.registerEntity("MinecartTnt", EntityMinecartTNT.class); Entity.registerEntity("Boat", EntityBoat.class); //projectile Entity.registerEntity("Arrow", EntityArrow.class); Entity.registerEntity("DragonFireball", EntityDragonFireball.class); Entity.registerEntity("Egg", EntityEgg.class); Entity.registerEntity("EnderPearl", EntityEnderPearl.class); Entity.registerEntity("ThrownExpBottle", EntityExpBottle.class); Entity.registerEntity("Fireball", EntityFireball.class); Entity.registerEntity("FireworkRocket", EntityFireworkRocket.class); Entity.registerEntity("FishingHook", EntityFishingHook.class); Entity.registerEntity("ThrownPotion", EntityPotion.class); Entity.registerEntity("ThrownLingeringPotion", EntityPotionLingering.class); Entity.registerEntity("ShulkerBullet", EntityShulkerBullet.class); Entity.registerEntity("Snowball", EntitySnowball.class); //weather Entity.registerEntity("Lightning", EntityLightning.class); //other Entity.registerEntity("Human", EntityHuman.class, true); }
Example #6
Source File: InventoryPickupArrowEvent.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public InventoryPickupArrowEvent(Inventory inventory, EntityArrow arrow) { super(inventory); this.arrow = arrow; }
Example #7
Source File: InventoryPickupArrowEvent.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public EntityArrow getArrow() { return arrow; }
Example #8
Source File: ItemBow.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@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 #9
Source File: InventoryPickupArrowEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public InventoryPickupArrowEvent(Inventory inventory, EntityArrow arrow) { super(inventory); this.arrow = arrow; }
Example #10
Source File: InventoryPickupArrowEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public EntityArrow getArrow() { return arrow; }
Example #11
Source File: ItemBow.java From Nukkit with GNU General Public License v3.0 | 4 votes |
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 #12
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private void registerEntities() { Entity.registerEntity("Arrow", EntityArrow.class); Entity.registerEntity("Item", EntityItem.class); Entity.registerEntity("FallingSand", EntityFallingBlock.class); Entity.registerEntity("PrimedTnt", EntityPrimedTNT.class); Entity.registerEntity("Snowball", EntitySnowball.class); Entity.registerEntity("EnderPearl", EntityEnderPearl.class); Entity.registerEntity("Painting", EntityPainting.class); //Monsters Entity.registerEntity("Creeper", EntityCreeper.class); Entity.registerEntity("Blaze", EntityBlaze.class); Entity.registerEntity("CaveSpider", EntityCaveSpider.class); Entity.registerEntity("ElderGuardian", EntityElderGuardian.class); Entity.registerEntity("EnderDragon", EntityEnderDragon.class); Entity.registerEntity("Enderman", EntityEnderman.class); Entity.registerEntity("Endermite", EntityEndermite.class); Entity.registerEntity("Evoker", EntityEvoker.class); Entity.registerEntity("Ghast", EntityGhast.class); Entity.registerEntity("Guardian", EntityGuardian.class); Entity.registerEntity("Husk", EntityHusk.class); Entity.registerEntity("MagmaCube", EntityMagmaCube.class); Entity.registerEntity("Shulker", EntityShulker.class); Entity.registerEntity("Silverfish", EntitySilverfish.class); Entity.registerEntity("Skeleton", EntitySkeleton.class); Entity.registerEntity("SkeletonHorse", EntitySkeletonHorse.class); Entity.registerEntity("Slime", EntitySlime.class); Entity.registerEntity("Spider", EntitySpider.class); Entity.registerEntity("Stray", EntityStray.class); Entity.registerEntity("Vindicator", EntityVindicator.class); Entity.registerEntity("Vex", EntityVex.class); Entity.registerEntity("WitherSkeleton", EntityWitherSkeleton.class); Entity.registerEntity("Wither", EntityWither.class); Entity.registerEntity("Witch", EntityWitch.class); Entity.registerEntity("ZombiePigman", EntityZombiePigman.class); Entity.registerEntity("ZombieVillager", EntityZombieVillager.class); Entity.registerEntity("Zombie", EntityZombie.class); //Passive Entity.registerEntity("Bat", EntityBat.class); Entity.registerEntity("Chicken", EntityChicken.class); Entity.registerEntity("Cow", EntityCow.class); Entity.registerEntity("Donkey", EntityDonkey.class); Entity.registerEntity("Horse", EntityHorse.class); Entity.registerEntity("Llama", EntityLlama.class); Entity.registerEntity("Mooshroom", EntityMooshroom.class); Entity.registerEntity("Mule", EntityMule.class); Entity.registerEntity("PolarBear", EntityPolarBear.class); Entity.registerEntity("Pig", EntityPig.class); Entity.registerEntity("Rabbit", EntityRabbit.class); Entity.registerEntity("Sheep", EntitySheep.class); Entity.registerEntity("Squid", EntitySquid.class); Entity.registerEntity("Wolf", EntityWolf.class); Entity.registerEntity("Ocelot", EntityOcelot.class); Entity.registerEntity("Villager", EntityVillager.class); Entity.registerEntity("ThrownExpBottle", EntityExpBottle.class); Entity.registerEntity("XpOrb", EntityXPOrb.class); Entity.registerEntity("ThrownPotion", EntityPotion.class); Entity.registerEntity("Egg", EntityEgg.class); Entity.registerEntity("Human", EntityHuman.class, true); Entity.registerEntity("MinecartRideable", EntityMinecartEmpty.class); // TODO: 2016/1/30 all finds of minecart Entity.registerEntity("Boat", EntityBoat.class); //Entity.registerEntity("Lightning", EntityLightning.class); lightning shouldn't be saved as entity }
Example #13
Source File: InventoryPickupArrowEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public InventoryPickupArrowEvent(Inventory inventory, EntityArrow arrow) { super(inventory); this.arrow = arrow; }
Example #14
Source File: InventoryPickupArrowEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public EntityArrow getArrow() { return arrow; }