下面列出了org.bukkit.Material#TIPPED_ARROW 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Gets the correct ArrowItem type for the NPC based on inventory items (can be null if the NPC needs ammo but has none).
*/
public ItemStack getArrow() {
if (!getNPC().hasTrait(Inventory.class)) {
return sentinel.needsAmmo ? null : new ItemStack(Material.ARROW, 1);
}
Inventory inv = getNPC().getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
for (ItemStack item : items) {
if (item != null) {
Material mat = item.getType();
if (mat == Material.ARROW
|| (SentinelVersionCompat.v1_9 && (mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW))
|| (SentinelVersionCompat.v1_14 && mat == Material.FIREWORK_ROCKET)) {
return item.clone();
}
}
}
return sentinel.needsAmmo ? null : new ItemStack(Material.ARROW, 1);
}
/**
* Takes an arrow from the NPC's inventory.
*/
public void takeArrow() {
if (!getNPC().hasTrait(Inventory.class)) {
return;
}
Inventory inv = getNPC().getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (mat == Material.ARROW
|| (SentinelVersionCompat.v1_9 && (mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW))
|| (SentinelVersionCompat.v1_14 && mat == Material.FIREWORK_ROCKET)) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
items[i] = item;
inv.setContents(items);
return;
}
else {
items[i] = null;
inv.setContents(items);
return;
}
}
}
}
}
/**
* Fires an arrow from the NPC at a target.
*/
public void fireArrow(ItemStack type, Location target, Vector lead) {
Location launchStart;
Vector baseVelocity;
if (SentinelVersionCompat.v1_14 && type.getType() == Material.FIREWORK_ROCKET) {
launchStart = sentinel.getLivingEntity().getEyeLocation();
launchStart = launchStart.clone().add(launchStart.getDirection());
baseVelocity = target.toVector().subtract(launchStart.toVector().add(lead));
if (baseVelocity.lengthSquared() > 0) {
baseVelocity = baseVelocity.normalize();
}
baseVelocity = baseVelocity.multiply(2);
}
else {
HashMap.SimpleEntry<Location, Vector> start = sentinel.getLaunchDetail(target, lead);
if (start == null || start.getKey() == null) {
return;
}
launchStart = start.getKey();
baseVelocity = start.getValue();
}
Vector velocity = sentinel.fixForAcc(baseVelocity);
sentinel.stats_arrowsFired++;
Entity arrow;
if (SentinelVersionCompat.v1_9) {
if (SentinelVersionCompat.v1_14) {
double length = Math.max(1.0, velocity.length());
if (type.getType() == Material.FIREWORK_ROCKET) {
FireworkMeta meta = (FireworkMeta) type.getItemMeta();
meta.setPower(3);
arrow = launchStart.getWorld().spawn(launchStart, EntityType.FIREWORK.getEntityClass(), (e) -> {
((Firework) e).setShotAtAngle(true);
((Firework) e).setFireworkMeta(meta);
e.setVelocity(velocity);
});
}
else {
Class toShoot;
toShoot = type.getType() == Material.SPECTRAL_ARROW ? SpectralArrow.class :
(type.getType() == Material.TIPPED_ARROW ? TippedArrow.class : Arrow.class);
arrow = launchStart.getWorld().spawnArrow(launchStart, velocity.multiply(1.0 / length), (float) length, 0f, toShoot);
((Projectile) arrow).setShooter(getLivingEntity());
((Arrow) arrow).setPickupStatus(Arrow.PickupStatus.DISALLOWED);
if (type.getItemMeta() instanceof PotionMeta) {
PotionData data = ((PotionMeta) type.getItemMeta()).getBasePotionData();
if (data.getType() == null || data.getType() == PotionType.UNCRAFTABLE) {
if (SentinelPlugin.debugMe) {
sentinel.debug("Potion data '" + data + "' for '" + type.toString() + "' is invalid.");
}
}
else {
((Arrow) arrow).setBasePotionData(data);
for (PotionEffect effect : ((PotionMeta) type.getItemMeta()).getCustomEffects()) {
((Arrow) arrow).addCustomEffect(effect, true);
}
}
}
}
}
else {
arrow = launchStart.getWorld().spawnEntity(launchStart,
type.getType() == Material.SPECTRAL_ARROW ? EntityType.SPECTRAL_ARROW :
(type.getType() == Material.TIPPED_ARROW ? TIPPED_ARROW : EntityType.ARROW));
arrow.setVelocity(velocity);
((Projectile) arrow).setShooter(getLivingEntity());
}
}
else {
arrow = launchStart.getWorld().spawnEntity(launchStart, EntityType.ARROW);
((Projectile) arrow).setShooter(getLivingEntity());
arrow.setVelocity(velocity);
}
if (sentinel.itemHelper.getHeldItem().containsEnchantment(Enchantment.ARROW_FIRE)) {
arrow.setFireTicks(10000);
}
sentinel.useItem();
}