mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-28 03:57:35 +01:00
Fix target in navigation
This commit is contained in:
parent
a064a28aab
commit
5b1a73f4d8
@ -11,6 +11,7 @@ import net.citizensnpcs.api.ai.event.CancelReason;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.minecraft.server.v1_6_R1.AttributeInstance;
|
||||
import net.minecraft.server.v1_6_R1.Entity;
|
||||
import net.minecraft.server.v1_6_R1.EntityInsentient;
|
||||
import net.minecraft.server.v1_6_R1.EntityLiving;
|
||||
@ -30,17 +31,17 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
private final EntityLiving handle;
|
||||
private final NPC npc;
|
||||
private final NavigatorParameters parameters;
|
||||
private final TargetNavigator targetNavigator;
|
||||
private final Entity target;
|
||||
private final TargetNavigator targetNavigator;
|
||||
|
||||
public MCTargetStrategy(NPC npc, org.bukkit.entity.Entity target, boolean aggro, NavigatorParameters params) {
|
||||
this.npc = npc;
|
||||
this.parameters = params;
|
||||
this.handle = ((CraftLivingEntity) npc.getBukkitEntity()).getHandle();
|
||||
this.target = ((CraftEntity) target).getHandle();
|
||||
this.targetNavigator = this.handle instanceof EntityInsentient ? new NavigationFieldWrapper(
|
||||
((EntityInsentient) this.handle).getNavigation()) : new AStarTargeter();
|
||||
this.aggro = aggro;
|
||||
this.parameters = params;
|
||||
}
|
||||
|
||||
private boolean canAttack() {
|
||||
@ -163,7 +164,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
this.l = navigation.a();
|
||||
try {
|
||||
if (NAV_E != null)
|
||||
e = NAV_E.getFloat(navigation);
|
||||
e = (float) ((AttributeInstance) NAV_E.get(navigation)).e();
|
||||
if (NAV_J != null)
|
||||
j = NAV_J.getBoolean(navigation);
|
||||
if (NAV_M != null)
|
||||
|
@ -67,11 +67,6 @@ public class BatController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_6_R1.Entity entity) {
|
||||
// this method is called by both the entities involved - cancelling
|
||||
|
@ -56,11 +56,6 @@ public class BlazeController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void bh() {
|
||||
if (npc != null) {
|
||||
|
@ -64,11 +64,6 @@ public class CaveSpiderController extends MobEntityController {
|
||||
npc.update();
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void bh() {
|
||||
if (npc == null)
|
||||
|
@ -56,11 +56,6 @@ public class ChickenController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -57,12 +57,6 @@ public class CowController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -64,11 +64,6 @@ public class CreeperController extends MobEntityController {
|
||||
super.a(entitylightning);
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -56,11 +56,6 @@ public class EnderDragonController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void bh() {
|
||||
if (npc == null) {
|
||||
|
@ -56,11 +56,6 @@ public class EndermanController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -57,11 +57,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
initialise(minecraftServer);
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_6_R1.Entity entity) {
|
||||
// this method is called by both the entities involved - cancelling
|
||||
|
@ -42,11 +42,6 @@ public class GhastController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void bh() {
|
||||
if (npc != null) {
|
||||
|
@ -42,11 +42,6 @@ public class GiantController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void bh() {
|
||||
if (npc == null) {
|
||||
|
@ -42,11 +42,6 @@ public class HorseController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void c() {
|
||||
if (npc == null) {
|
||||
|
@ -42,11 +42,6 @@ public class IronGolemController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -43,11 +43,6 @@ public class MagmaCubeController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -43,11 +43,6 @@ public class MushroomCowController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -43,11 +43,6 @@ public class OcelotController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -49,12 +49,6 @@ public class PigController extends MobEntityController {
|
||||
super.a(entitylightning);
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -43,11 +43,6 @@ public class PigZombieController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -43,11 +43,6 @@ public class SheepController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -43,11 +43,6 @@ public class SilverfishController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -42,11 +42,6 @@ public class SkeletonController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -44,11 +44,6 @@ public class SlimeController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -42,11 +42,6 @@ public class SnowmanController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -42,11 +42,6 @@ public class SpiderController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -42,11 +42,6 @@ public class SquidController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void bh() {
|
||||
if (npc != null) {
|
||||
|
@ -50,11 +50,6 @@ public class VillagerController extends MobEntityController {
|
||||
// trades
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -49,11 +49,6 @@ public class WitchController extends MobEntityController {
|
||||
npc.update();
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_6_R1.Entity entity) {
|
||||
// this method is called by both the entities involved - cancelling
|
||||
|
@ -42,11 +42,6 @@ public class WitherController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -42,11 +42,6 @@ public class WolfController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -42,11 +42,6 @@ public class ZombieController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public float bE() {
|
||||
return NMS.modifiedSpeed(super.bE(), npc);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void be() {
|
||||
super.be();
|
||||
|
@ -35,7 +35,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftLivingEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -43,8 +42,6 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginLoadOrder;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class NMS {
|
||||
private NMS() {
|
||||
@ -144,22 +141,9 @@ public class NMS {
|
||||
}
|
||||
|
||||
public static float getSpeedFor(NPC npc) {
|
||||
EntityType entityType = npc.getBukkitEntity().getType();
|
||||
Float cached = MOVEMENT_SPEEDS.get(entityType);
|
||||
if (cached != null)
|
||||
return cached;
|
||||
if (SPEED_FIELD == null) {
|
||||
MOVEMENT_SPEEDS.put(entityType, DEFAULT_SPEED);
|
||||
if (!npc.isSpawned())
|
||||
return DEFAULT_SPEED;
|
||||
}
|
||||
try {
|
||||
float speed = SPEED_FIELD.getFloat(((CraftEntity) npc.getBukkitEntity()).getHandle());
|
||||
MOVEMENT_SPEEDS.put(entityType, speed);
|
||||
return speed;
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
return DEFAULT_SPEED;
|
||||
}
|
||||
return (float) NMS.getHandle(npc.getBukkitEntity()).a(GenericAttributes.d).b();
|
||||
}
|
||||
|
||||
public static boolean inWater(LivingEntity entity) {
|
||||
@ -280,16 +264,6 @@ public class NMS {
|
||||
handle.aQ = yaw;
|
||||
}
|
||||
|
||||
public static void setLandSpeedModifier(EntityLiving handle, float speed) {
|
||||
if (LAND_SPEED_MODIFIER_FIELD == null)
|
||||
return;
|
||||
try {
|
||||
LAND_SPEED_MODIFIER_FIELD.setFloat(handle, speed);
|
||||
} catch (Exception e) {
|
||||
Messaging.logTr(Messages.ERROR_UPDATING_SPEED, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setShouldJump(LivingEntity entity) {
|
||||
EntityLiving handle = getHandle(entity);
|
||||
if (handle instanceof EntityInsentient) {
|
||||
@ -394,25 +368,19 @@ public class NMS {
|
||||
}
|
||||
|
||||
private static final float DEFAULT_SPEED = 1F;
|
||||
|
||||
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;
|
||||
private static final Map<Class<?>, Constructor<?>> ENTITY_CONSTRUCTOR_CACHE = new WeakHashMap<Class<?>, Constructor<?>>();
|
||||
private static Map<Integer, Class<?>> ENTITY_INT_TO_CLASS;
|
||||
private static Field GOAL_FIELD = getField(PathfinderGoalSelector.class, "a");
|
||||
private static final Field JUMP_FIELD = getField(EntityLiving.class, "bd");
|
||||
private static Field LAND_SPEED_MODIFIER_FIELD = getField(EntityLiving.class, "bs");
|
||||
private static final Map<EntityType, Float> MOVEMENT_SPEEDS = Maps.newEnumMap(EntityType.class);
|
||||
private static Field NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b");
|
||||
private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
|
||||
private static Field PATHFINDING_RANGE = getField(Navigation.class, "d");
|
||||
private static final Random RANDOM = Util.getFastRandom();
|
||||
private static Field SPEED_FIELD = getField(EntityLiving.class, "bI");
|
||||
private static Field THREAD_STOPPER = getField(NetworkManager.class, "n");
|
||||
// true field above false and three synchronised lists
|
||||
|
||||
static {
|
||||
// TODO: speed fields are all wrong - need to use attributes
|
||||
|
||||
try {
|
||||
Field field = getField(EntityTypes.class, "d");
|
||||
ENTITY_INT_TO_CLASS = (Map<Integer, Class<?>>) field.get(null);
|
||||
|
Loading…
Reference in New Issue
Block a user