他導入plugins
Mutiverse
WorldEdit
現在指定したtargetを自動で追尾するような弓を作ろうとしており
公開されているソースなどから次のように組むことが出来
無事曲がることに成功したのですがバグとして
victimがガードをすると矢が空中で止まる、ガードを離すと矢が動き出しtargetも復活するというようなバグです。
ガードしながら移動をすると矢もついてくるのでcancelされているわけではないと思うのですが。。。
どなたかわかるかたいますかね?
- コード: 全て選択
package com.homing;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class Homingarrow
extends JavaPlugin
implements Listener
{
public void onEnable()
{
getLogger().info("BlingGravity has been loaded.");
getServer().getPluginManager().registerEvents(this, this);
}
public void onDisable()
{
getLogger().info("BlingGravity has been unloaded.");
}
@EventHandler
public void eventArrowFired(EntityShootBowEvent e)
{
if (((e.getEntity() instanceof LivingEntity)) && ((e.getProjectile() instanceof Arrow)))
{
LivingEntity player = e.getEntity();
double minAngle = 6.283185307179586D;
Entity minEntity = null;
for (Entity entity : player.getNearbyEntities(64.0D, 64.0D, 64.0D)) {
if ((player.hasLineOfSight(entity)) && ((entity instanceof LivingEntity)) && (!entity.isDead()))
{
Vector toTarget = entity.getLocation().toVector().clone().subtract(player.getLocation().toVector());
double angle = e.getProjectile().getVelocity().angle(toTarget);
if (angle < minAngle)
{
minAngle = angle;
minEntity = entity;
}
}
}
if (minEntity != null) {
new HomingTask((Arrow)e.getProjectile(), (LivingEntity)minEntity, this);
}
}
}
}
- コード: 全て選択
package com.homing;
import org.bukkit.Effect;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
public class HomingTask
extends BukkitRunnable
{
private static final double MaxRotationAngle = 0.12D;
private static final double TargetSpeed = 1.4D;
Arrow arrow;
LivingEntity target;
public HomingTask(Arrow arrow, LivingEntity target, Plugin plugin)
{
this.arrow = arrow;
this.target = target;
runTaskTimer(plugin, 1L, 1L);
}
public void run()
{
double speed = this.arrow.getVelocity().length();
if ((this.arrow.isOnGround()) || (this.arrow.isDead()) || (this.target.isDead()))
{
cancel();
return;
}
Vector toTarget = this.target.getLocation().clone().add(new Vector(0.0D, 0.5D, 0.0D)).subtract(this.arrow.getLocation()).toVector();
Vector dirVelocity = this.arrow.getVelocity().clone().normalize();
Vector dirToTarget = toTarget.clone().normalize();
double angle = dirVelocity.angle(dirToTarget);
double newSpeed = 0.9D * speed + 0.13999999999999999D;
if (((this.target instanceof Player)) && (this.arrow.getLocation().distance(this.target.getLocation()) < 8.0D))
{
Player player = (Player)this.target;
if (player.isBlocking()) {
newSpeed = speed * 0.6D;
}
}
Vector newVelocity;
if (angle < 0.12D)
{
newVelocity = dirVelocity.clone().multiply(newSpeed);
}
else
{
Vector newDir = dirVelocity.clone().multiply((angle - 0.12D) / angle).add(dirToTarget.clone().multiply(0.12D / angle));
newDir.normalize();
newVelocity = newDir.clone().multiply(newSpeed);
}
this.arrow.setVelocity(newVelocity.add(new Vector(0.0D, 0.03D, 0.0D)));
this.arrow.getWorld().playEffect(this.arrow.getLocation(), Effect.SMOKE, 0);
}
}