diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java index 621df9137..4b479fb52 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java @@ -5,6 +5,28 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Creature; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Giant; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.util.Vector; + import net.minecraft.server.v1_8_R3.AxisAlignedBB; import net.minecraft.server.v1_8_R3.EntityBat; import net.minecraft.server.v1_8_R3.EntityCreature; @@ -23,29 +45,6 @@ import net.minecraft.server.v1_8_R3.PathfinderGoalRandomLookaround; import net.minecraft.server.v1_8_R3.PathfinderGoalSelector; import net.minecraft.server.v1_8_R3.WorldServer; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Creature; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.Giant; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.util.Vector; - public class UtilEnt { @@ -259,6 +258,34 @@ public class UtilEnt } } + public static void Rotate(LivingEntity entity, float yaw, float pitch) + { + EntityLiving handle = ((CraftLivingEntity) entity).getHandle(); + + while (yaw < -180.0F) yaw += 360.0F; + while (yaw >= 180.0F) yaw -= 360.0F; + + handle.yaw = yaw; + handle.aK = yaw; + handle.aI = yaw; + handle.aL = yaw; + handle.pitch = pitch; + } + + public static void LookAt(LivingEntity entity, Location location) + { + if (!(entity.getWorld().equals(location.getWorld()))) + return; + + Vector dir = entity.getEyeLocation().toVector().subtract(location.toVector()).normalize(); + Location loc = entity.getEyeLocation().clone(); + + loc.setYaw(180 - (float) Math.toDegrees(Math.atan2(dir.getX(), dir.getZ()))); + loc.setPitch(90 - (float) Math.toDegrees(Math.acos(dir.getY()))); + + Rotate(entity, loc.getYaw(), loc.getPitch()); + } + public static void populate() { if (creatureMap.isEmpty()) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/AttackEnemyObjective.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/AttackEnemyObjective.java index 6f4923546..fa12438cd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/AttackEnemyObjective.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/AttackEnemyObjective.java @@ -127,16 +127,13 @@ public class AttackEnemyObjective extends OrderedObjective return; } - Vector vec = UtilAlg.getTrajectory(shooter.getLocation(), player.getEyeLocation()); - - ((CraftZombie) shooter).getHandle().yaw = UtilAlg.GetYaw(vec); - ((CraftZombie) shooter).getHandle().pitch = UtilAlg.GetPitch(vec); + UtilEnt.LookAt(shooter, player.getEyeLocation()); if (Recharge.Instance.usable(player, "ShotBy" + shooter.getUniqueId().toString())) { Arrow arrow = shooter.shootArrow(); - arrow.setVelocity(UtilAlg.getTrajectory(arrow.getLocation(), player.getLocation()).multiply(1.3)); + arrow.setVelocity(UtilAlg.getTrajectory(arrow.getLocation(), player.getEyeLocation()).multiply(1.6)); Recharge.Instance.use(player, "ShotBy" + shooter.getUniqueId().toString(), 500 + UtilMath.r(2000), false, false); }