diff options
author | Zeerix <zeerix@draig.de> | 2011-12-28 21:36:02 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2012-01-17 19:51:06 +0100 |
commit | bcf6440bc42fcc80c0ec3b08c79f8d501f464749 (patch) | |
tree | e063a3cbaa1522b1b55707349b57cbfec234a4f5 /src/main/java/net/minecraft/server/ItemBow.java | |
parent | edbb7358fc8837218768d584c28f75ea3dedbadc (diff) | |
download | craftbukkit-bcf6440bc42fcc80c0ec3b08c79f8d501f464749.tar craftbukkit-bcf6440bc42fcc80c0ec3b08c79f8d501f464749.tar.gz craftbukkit-bcf6440bc42fcc80c0ec3b08c79f8d501f464749.tar.lz craftbukkit-bcf6440bc42fcc80c0ec3b08c79f8d501f464749.tar.xz craftbukkit-bcf6440bc42fcc80c0ec3b08c79f8d501f464749.zip |
[Bleeding] Implement EntityShootBowEvent. Thanks Zeerix.
Diffstat (limited to 'src/main/java/net/minecraft/server/ItemBow.java')
-rw-r--r-- | src/main/java/net/minecraft/server/ItemBow.java | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/ItemBow.java b/src/main/java/net/minecraft/server/ItemBow.java new file mode 100644 index 00000000..05c013e6 --- /dev/null +++ b/src/main/java/net/minecraft/server/ItemBow.java @@ -0,0 +1,99 @@ +package net.minecraft.server; + +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.EntityShootBowEvent; +// CraftBukkit end + +public class ItemBow extends Item { + + public ItemBow(int i) { + super(i); + this.maxStackSize = 1; + this.setMaxDurability(384); + } + + public void a(ItemStack itemstack, World world, EntityHuman entityhuman, int i) { + boolean flag = entityhuman.abilities.canInstantlyBuild || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, itemstack) > 0; + + if (flag || entityhuman.inventory.c(Item.ARROW.id)) { + int j = this.c(itemstack) - i; + float f = (float) j / 20.0F; + + f = (f * f + f * 2.0F) / 3.0F; + if ((double) f < 0.1D) { + return; + } + + if (f > 1.0F) { + f = 1.0F; + } + + EntityArrow entityarrow = new EntityArrow(world, entityhuman, f * 2.0F); + + if (f == 1.0F) { + entityarrow.d = true; + } + + int k = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, itemstack); + + if (k > 0) { + entityarrow.a(entityarrow.j() + (double) k * 0.5D + 0.5D); + } + + int l = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, itemstack); + + if (l > 0) { + entityarrow.b(l); + } + + if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, itemstack) > 0) { + entityarrow.setOnFire(100); + } + + // CraftBukkit start + EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, entityarrow, f); + if (event.isCancelled()) { + event.getProjectile().remove(); + return; + } + + if (event.getProjectile() == entityarrow.getBukkitEntity()) { + world.addEntity(entityarrow); + } + // CraftBukkit end + + itemstack.damage(1, entityhuman); + world.makeSound(entityhuman, "random.bow", 1.0F, 1.0F / (c.nextFloat() * 0.4F + 1.2F) + f * 0.5F); + if (!flag) { + entityhuman.inventory.b(Item.ARROW.id); + } else { + entityarrow.fromPlayer = false; + } + } + } + + public ItemStack b(ItemStack itemstack, World world, EntityHuman entityhuman) { + return itemstack; + } + + public int c(ItemStack itemstack) { + return 72000; + } + + public EnumAnimation d(ItemStack itemstack) { + return EnumAnimation.e; + } + + public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) { + if (entityhuman.abilities.canInstantlyBuild || entityhuman.inventory.c(Item.ARROW.id)) { + entityhuman.a(itemstack, this.c(itemstack)); + } + + return itemstack; + } + + public int c() { + return 1; + } +} |