geforkt von Mirrors/Paper
[Bleeding] Implement EntityShootBowEvent. Thanks Zeerix.
Dieser Commit ist enthalten in:
Ursprung
edbb7358fc
Commit
bcf6440bc4
@ -1,6 +1,8 @@
|
|||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||||
|
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||||
import org.bukkit.event.entity.EntityCombustEvent;
|
import org.bukkit.event.entity.EntityCombustEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
@ -76,10 +78,22 @@ public class EntitySkeleton extends EntityMonster {
|
|||||||
double d2 = entity.locY + (double) entity.y() - 0.699999988079071D - entityarrow.locY;
|
double d2 = entity.locY + (double) entity.y() - 0.699999988079071D - entityarrow.locY;
|
||||||
float f1 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 0.2F;
|
float f1 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 0.2F;
|
||||||
|
|
||||||
this.world.makeSound(this, "random.bow", 1.0F, 1.0F / (this.random.nextFloat() * 0.4F + 0.8F));
|
this.world.makeSound(this, "random.bow", 1.0F, 1.0F / (this.random.nextFloat() * 0.4F + 0.8F)); // CraftBukkit - moved down
|
||||||
this.world.addEntity(entityarrow);
|
// this.world.addEntity(entityarrow); // CraftBukkit - moved down
|
||||||
entityarrow.shoot(d0, d2 + (double) f1, d1, 1.6F, 12.0F);
|
entityarrow.shoot(d0, d2 + (double) f1, d1, 1.6F, 12.0F);
|
||||||
this.attackTicks = 60;
|
this.attackTicks = 60;
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(this, null, entityarrow, 0.5F);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
if (event.getProjectile() != null) {
|
||||||
|
event.getProjectile().remove();
|
||||||
|
}
|
||||||
|
} else if (event.getProjectile() == entityarrow.getBukkitEntity()) {
|
||||||
|
world.addEntity(entityarrow);
|
||||||
|
}
|
||||||
|
this.world.makeSound(this, "random.bow", 1.0F, 1.0F / (this.random.nextFloat() * 0.4F + 0.8F));
|
||||||
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
|
|
||||||
this.yaw = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
|
this.yaw = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
|
||||||
|
99
src/main/java/net/minecraft/server/ItemBow.java
Normale Datei
99
src/main/java/net/minecraft/server/ItemBow.java
Normale Datei
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import net.minecraft.server.ChunkCoordinates;
|
import net.minecraft.server.ChunkCoordinates;
|
||||||
import net.minecraft.server.Entity;
|
import net.minecraft.server.Entity;
|
||||||
|
import net.minecraft.server.EntityArrow;
|
||||||
import net.minecraft.server.EntityBlaze;
|
import net.minecraft.server.EntityBlaze;
|
||||||
import net.minecraft.server.EntityCaveSpider;
|
import net.minecraft.server.EntityCaveSpider;
|
||||||
import net.minecraft.server.EntityChicken;
|
import net.minecraft.server.EntityChicken;
|
||||||
@ -51,7 +52,9 @@ import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
|||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.AnimalTamer;
|
import org.bukkit.entity.AnimalTamer;
|
||||||
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.entity.CreatureType;
|
import org.bukkit.entity.CreatureType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event.Type;
|
import org.bukkit.event.Event.Type;
|
||||||
import org.bukkit.event.block.*;
|
import org.bukkit.event.block.*;
|
||||||
@ -182,6 +185,24 @@ public class CraftEventFactory {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EntityShootBowEvent
|
||||||
|
*/
|
||||||
|
public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack itemstack, EntityArrow entityArrow, float force) {
|
||||||
|
LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
|
||||||
|
CraftItemStack itemInHand = new CraftItemStack(itemstack);
|
||||||
|
Arrow arrow = (Arrow) entityArrow.getBukkitEntity();
|
||||||
|
|
||||||
|
if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
|
||||||
|
itemInHand = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BlockDamageEvent
|
* BlockDamageEvent
|
||||||
*/
|
*/
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren