Possible fix and optimisation for PlayerEntitySenses

This commit is contained in:
fullwall 2013-08-12 17:32:16 +08:00
parent 0ce5eaeafe
commit ef503120fa
4 changed files with 19 additions and 13 deletions

View File

@ -56,6 +56,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
private final CitizensNPC npc; private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0); private final Location packetLocationCache = new Location(null, 0, 0, 0);
private int packetUpdateCount; private int packetUpdateCount;
private int sensesUpdateCount = 0;
private int useListName = -1; private int useListName = -1;
public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string, public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string,
@ -136,8 +137,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
// swallow // swallow
} }
Y = 1F; // stepHeight - must not stay as the default 0 (breaks steps). NMS.setStepHeight(this, 1);// stepHeight - must not stay as the default
// Check the EntityPlayer constructor for the new name. // 0 (breaks steps).
try { try {
socket.close(); socket.close();
@ -234,7 +235,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
} }
public void updateAI() { public void updateAI() {
entitySenses.a(); if (++sensesUpdateCount == 5) {
sensesUpdateCount = 0;
entitySenses.a();
}
controllerMove.c(); controllerMove.c();
controllerLook.a(); controllerLook.a();
controllerJump.b(); controllerJump.b();
@ -320,6 +324,5 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
} }
private static final float EPSILON = 0.005F; private static final float EPSILON = 0.005F;
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0); private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
} }

View File

@ -70,6 +70,7 @@ public class HorseController extends MobEntityController {
if (npc == null) { if (npc == null) {
super.c(); super.c();
} else { } else {
NMS.setStepHeight(this, 1);
updateAIWithMovement(); updateAIWithMovement();
npc.update(); npc.update();
} }

View File

@ -319,6 +319,10 @@ public class NMS {
} }
} }
public static void setStepHeight(EntityLiving entity, float height) {
entity.Y = height;
}
public static boolean shouldJump(net.minecraft.server.v1_6_R2.Entity entity) { public static boolean shouldJump(net.minecraft.server.v1_6_R2.Entity entity) {
if (JUMP_FIELD == null || !(entity instanceof EntityLiving)) if (JUMP_FIELD == null || !(entity instanceof EntityLiving))
return false; return false;
@ -432,15 +436,13 @@ public class NMS {
} }
private static final float DEFAULT_SPEED = 1F; private static final float DEFAULT_SPEED = 1F;
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT; private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;
private static final Map<Class<?>, Constructor<?>> ENTITY_CONSTRUCTOR_CACHE = new WeakHashMap<Class<?>, Constructor<?>>(); private static final Map<Class<?>, Constructor<?>> ENTITY_CONSTRUCTOR_CACHE = new WeakHashMap<Class<?>, Constructor<?>>();
private static Map<Integer, Class<?>> ENTITY_INT_TO_CLASS; private static Map<Integer, Class<?>> ENTITY_INT_TO_CLASS;
private static Map<Class<?>, Integer> MC_ENTITY_CLASS_TO_INT = null;
private static Map<Integer, Class<?>> MC_ENTITY_INT_TO_CLASS = null;
private static Field GOAL_FIELD = getField(PathfinderGoalSelector.class, "a"); private static Field GOAL_FIELD = getField(PathfinderGoalSelector.class, "a");
private static final Field JUMP_FIELD = getField(EntityLiving.class, "bd"); private static final Field JUMP_FIELD = getField(EntityLiving.class, "bd");
private static Map<Class<?>, Integer> MC_ENTITY_CLASS_TO_INT = null;
private static Map<Integer, Class<?>> MC_ENTITY_INT_TO_CLASS = null;
private static Field NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b"); 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 final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
private static Field PATHFINDING_RANGE = getField(Navigation.class, "e"); private static Field PATHFINDING_RANGE = getField(Navigation.class, "e");

View File

@ -1,15 +1,15 @@
package net.citizensnpcs.util.nms; package net.citizensnpcs.util.nms;
import java.util.ArrayList; import java.util.HashSet;
import java.util.List; import java.util.Set;
import net.minecraft.server.v1_6_R2.Entity; import net.minecraft.server.v1_6_R2.Entity;
import net.minecraft.server.v1_6_R2.EntityLiving; import net.minecraft.server.v1_6_R2.EntityLiving;
public class PlayerEntitySenses { public class PlayerEntitySenses {
EntityLiving entity; private final EntityLiving entity;
List<Entity> seenEntities = new ArrayList<Entity>(); private final Set<Entity> seenEntities = new HashSet<Entity>();
List<Entity> unseenEntities = new ArrayList<Entity>(); private final Set<Entity> unseenEntities = new HashSet<Entity>();
public PlayerEntitySenses(EntityLiving entityinsentient) { public PlayerEntitySenses(EntityLiving entityinsentient) {
this.entity = entityinsentient; this.entity = entityinsentient;