mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 20:25:19 +01:00
Add immediate parameter to Util.faceLocation and fix a bug in it
This commit is contained in:
parent
1bd3b7e0e8
commit
cf5beab4c5
@ -156,8 +156,8 @@ public class NMS {
|
|||||||
BRIDGE.look(entity, yaw, pitch);
|
BRIDGE.look(entity, yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly) {
|
public static void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
|
||||||
BRIDGE.look(entity, to, headOnly);
|
BRIDGE.look(entity, to, headOnly, immediate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void look(org.bukkit.entity.Entity bhandle, org.bukkit.entity.Entity btarget) {
|
public static void look(org.bukkit.entity.Entity bhandle, org.bukkit.entity.Entity btarget) {
|
||||||
|
@ -82,7 +82,7 @@ public interface NMSBridge {
|
|||||||
|
|
||||||
public void look(Entity entity, float yaw, float pitch);
|
public void look(Entity entity, float yaw, float pitch);
|
||||||
|
|
||||||
public void look(Entity entity, Location to, boolean headOnly);
|
public void look(Entity entity, Location to, boolean headOnly, boolean immediate);
|
||||||
|
|
||||||
public void mount(Entity entity, Entity passenger);
|
public void mount(Entity entity, Entity passenger);
|
||||||
|
|
||||||
|
@ -66,9 +66,13 @@ public class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void faceLocation(Entity entity, Location to, boolean headOnly) {
|
public static void faceLocation(Entity entity, Location to, boolean headOnly) {
|
||||||
|
faceLocation(entity, to, headOnly, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void faceLocation(Entity entity, Location to, boolean headOnly, boolean immediate) {
|
||||||
if (to == null || entity.getWorld() != to.getWorld())
|
if (to == null || entity.getWorld() != to.getWorld())
|
||||||
return;
|
return;
|
||||||
NMS.look(entity, to, headOnly);
|
NMS.look(entity, to, headOnly, immediate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location getEyeLocation(Entity entity) {
|
public static Location getEyeLocation(Entity entity) {
|
||||||
|
@ -383,7 +383,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setTargetLook(Location target) {
|
public void setTargetLook(Location target) {
|
||||||
controllerLook.a(target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch());
|
controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAI() {
|
public void updateAI() {
|
||||||
|
@ -605,9 +605,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly) {
|
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
|
||||||
Entity handle = NMSImpl.getHandle(entity);
|
Entity handle = NMSImpl.getHandle(entity);
|
||||||
if (headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())
|
if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())
|
||||||
|| (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
|
|| (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
|
||||||
Location fromLocation = entity.getLocation(FROM_LOCATION);
|
Location fromLocation = entity.getLocation(FROM_LOCATION);
|
||||||
double xDiff, yDiff, zDiff;
|
double xDiff, yDiff, zDiff;
|
||||||
@ -635,8 +635,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (handle instanceof EntityInsentient) {
|
if (handle instanceof EntityInsentient) {
|
||||||
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), to.getYaw(),
|
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(),
|
||||||
to.getPitch());
|
((EntityInsentient) handle).cJ(), ((EntityInsentient) handle).N());
|
||||||
while (((EntityInsentient) handle).aQ >= 180F) {
|
while (((EntityInsentient) handle).aQ >= 180F) {
|
||||||
((EntityInsentient) handle).aQ -= 360F;
|
((EntityInsentient) handle).aQ -= 360F;
|
||||||
}
|
}
|
||||||
@ -653,9 +653,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to);
|
Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to);
|
||||||
if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
|
if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
|
||||||
if (to instanceof LivingEntity) {
|
if (to instanceof LivingEntity) {
|
||||||
look(from, ((LivingEntity) to).getEyeLocation(), false);
|
look(from, ((LivingEntity) to).getEyeLocation(), false, true);
|
||||||
} else {
|
} else {
|
||||||
look(from, to.getLocation(), false);
|
look(from, to.getLocation(), false, true);
|
||||||
}
|
}
|
||||||
} else if (handle instanceof EntityInsentient) {
|
} else if (handle instanceof EntityInsentient) {
|
||||||
((EntityInsentient) handle).getControllerLook().a(target, ((EntityInsentient) handle).cJ(),
|
((EntityInsentient) handle).getControllerLook().a(target, ((EntityInsentient) handle).cJ(),
|
||||||
@ -1390,9 +1390,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
navigation.l();
|
navigation.l();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE,
|
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
|
||||||
EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE,
|
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
|
||||||
EntityType.GHAST);
|
EntityType.HORSE, EntityType.GHAST);
|
||||||
|
|
||||||
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
||||||
private static final float DEFAULT_SPEED = 1F;
|
private static final float DEFAULT_SPEED = 1F;
|
||||||
|
@ -394,7 +394,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setTargetLook(Location target) {
|
public void setTargetLook(Location target) {
|
||||||
controllerLook.a(target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch());
|
controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAI() {
|
public void updateAI() {
|
||||||
|
@ -637,9 +637,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly) {
|
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
|
||||||
Entity handle = NMSImpl.getHandle(entity);
|
Entity handle = NMSImpl.getHandle(entity);
|
||||||
if (headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())
|
if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())
|
||||||
|| (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
|
|| (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
|
||||||
Location fromLocation = entity.getLocation(FROM_LOCATION);
|
Location fromLocation = entity.getLocation(FROM_LOCATION);
|
||||||
double xDiff, yDiff, zDiff;
|
double xDiff, yDiff, zDiff;
|
||||||
@ -667,8 +667,8 @@ public class NMSImpl implements NMSBridge {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (handle instanceof EntityInsentient) {
|
if (handle instanceof EntityInsentient) {
|
||||||
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), to.getYaw(),
|
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(),
|
||||||
to.getPitch());
|
((EntityInsentient) handle).cL(), ((EntityInsentient) handle).N());
|
||||||
|
|
||||||
while (((EntityLiving) handle).aP >= 180F) {
|
while (((EntityLiving) handle).aP >= 180F) {
|
||||||
((EntityLiving) handle).aP -= 360F;
|
((EntityLiving) handle).aP -= 360F;
|
||||||
@ -686,9 +686,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to);
|
Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to);
|
||||||
if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
|
if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
|
||||||
if (to instanceof LivingEntity) {
|
if (to instanceof LivingEntity) {
|
||||||
look(from, ((LivingEntity) to).getEyeLocation(), false);
|
look(from, ((LivingEntity) to).getEyeLocation(), false, true);
|
||||||
} else {
|
} else {
|
||||||
look(from, to.getLocation(), false);
|
look(from, to.getLocation(), false, true);
|
||||||
}
|
}
|
||||||
} else if (handle instanceof EntityInsentient) {
|
} else if (handle instanceof EntityInsentient) {
|
||||||
((EntityInsentient) handle).getControllerLook().a(target, ((EntityInsentient) handle).cL(),
|
((EntityInsentient) handle).getControllerLook().a(target, ((EntityInsentient) handle).cL(),
|
||||||
@ -1434,9 +1434,9 @@ public class NMSImpl implements NMSBridge {
|
|||||||
navigation.l();
|
navigation.l();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE,
|
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
|
||||||
EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE,
|
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
|
||||||
EntityType.GHAST);
|
EntityType.HORSE, EntityType.GHAST);
|
||||||
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
|
||||||
private static final float DEFAULT_SPEED = 1F;
|
private static final float DEFAULT_SPEED = 1F;
|
||||||
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
|
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
|
||||||
|
Loading…
Reference in New Issue
Block a user