Fix some issues with pathing/controllable

This commit is contained in:
fullwall 2012-07-28 16:15:12 +08:00
parent 588d491667
commit b2253db67d
12 changed files with 77 additions and 25 deletions

View File

@ -117,7 +117,7 @@ public class CommandManager {
types = EnumSet.allOf(EntityType.class); types = EnumSet.allOf(EntityType.class);
types.removeAll(Sets.newHashSet(cmdRequirements.excludedTypes())); types.removeAll(Sets.newHashSet(cmdRequirements.excludedTypes()));
EntityType type = EntityType.valueOf(npc.getTrait(MobType.class).getType()); EntityType type = npc.getTrait(MobType.class).getType();
if (!types.contains(type)) { if (!types.contains(type)) {
throw new RequirementMissingException("The NPC cannot be the mob type '" + type.getName() throw new RequirementMissingException("The NPC cannot be the mob type '" + type.getName()
+ "' to use that command."); + "' to use that command.");

View File

@ -23,8 +23,8 @@ public class EditorCommands {
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.edit.equip") permission = "npc.edit.equip")
@Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG, @Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER,
EntityType.SHEEP }) EntityType.PIG, EntityType.SHEEP })
public void equip(CommandContext args, Player player, NPC npc) { public void equip(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, new EquipmentEditor(player, npc)); Editor.enterOrLeave(player, new EquipmentEditor(player, npc));
} }
@ -37,8 +37,8 @@ public class EditorCommands {
min = 1, min = 1,
max = 1, max = 1,
permission = "npc.edit.path") permission = "npc.edit.path")
@Requirements(selected = true, ownership = true, excludedTypes = { EntityType.ENDER_DRAGON, EntityType.SQUID, @Requirements(selected = true, ownership = true, excludedTypes = { EntityType.BLAZE,
EntityType.GHAST, EntityType.BLAZE }) EntityType.ENDER_DRAGON, EntityType.GHAST, EntityType.SQUID })
public void path(CommandContext args, Player player, NPC npc) { public void path(CommandContext args, Player player, NPC npc) {
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player)); Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
} }

View File

@ -177,7 +177,7 @@ public class NPCCommands {
// Initialize necessary traits // Initialize necessary traits
if (!Setting.SERVER_OWNS_NPCS.asBoolean()) if (!Setting.SERVER_OWNS_NPCS.asBoolean())
npc.getTrait(Owner.class).setOwner(player.getName()); npc.getTrait(Owner.class).setOwner(player.getName());
npc.getTrait(MobType.class).setType(type.toString()); npc.getTrait(MobType.class).setType(type);
npc.spawn(player.getLocation()); npc.spawn(player.getLocation());
@ -241,13 +241,13 @@ public class NPCCommands {
} }
if (args.hasValueFlag("type")) { if (args.hasValueFlag("type")) {
String type = args.getFlag("type"); EntityType type = Util.matchEntityType(args.getFlag("type"));
if (EntityType.fromName(type.replace('-', '_')) == null) if (type == null)
throw new CommandException("'" + type + "' is not a valid mob type."); throw new CommandException("'" + type + "' is not a valid mob type.");
for (NPC add : npcRegistry) { for (NPC add : npcRegistry) {
if (!npcs.contains(add) && add.getTrait(MobType.class).getType().equalsIgnoreCase(type)) if (!npcs.contains(add) && add.getTrait(MobType.class).getType() == type)
npcs.add(add); npcs.add(add);
} }
} }

View File

@ -149,21 +149,24 @@ public class CitizensNavigator implements Navigator {
} }
} }
private static final float DEFAULT_SPEED = 0.7F; private static final float DEFAULT_SPEED = 0.4F;
private static final Map<EntityType, Float> MOVEMENT_SPEEDS = Maps.newEnumMap(EntityType.class); private static final Map<EntityType, Float> MOVEMENT_SPEEDS = Maps.newEnumMap(EntityType.class);
private static Field PATHFINDING_RANGE; private static Field PATHFINDING_RANGE;
private static Field SPEED_FIELD; private static Field SPEED_FIELD;
static { static {
MOVEMENT_SPEEDS.put(EntityType.IRON_GOLEM, 0.15F); // constants taken from source code
MOVEMENT_SPEEDS.put(EntityType.CHICKEN, 0.25F); MOVEMENT_SPEEDS.put(EntityType.CHICKEN, 0.25F);
MOVEMENT_SPEEDS.put(EntityType.COW, 0.2F); MOVEMENT_SPEEDS.put(EntityType.COW, 0.2F);
MOVEMENT_SPEEDS.put(EntityType.SHEEP, 0.25F);
MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F);
MOVEMENT_SPEEDS.put(EntityType.SNOWMAN, 0.25F);
MOVEMENT_SPEEDS.put(EntityType.CREEPER, 0.3F); MOVEMENT_SPEEDS.put(EntityType.CREEPER, 0.3F);
MOVEMENT_SPEEDS.put(EntityType.IRON_GOLEM, 0.15F);
MOVEMENT_SPEEDS.put(EntityType.MUSHROOM_COW, 0.2F);
MOVEMENT_SPEEDS.put(EntityType.OCELOT, 0.23F);
MOVEMENT_SPEEDS.put(EntityType.SHEEP, 0.25F);
MOVEMENT_SPEEDS.put(EntityType.SNOWMAN, 0.25F);
MOVEMENT_SPEEDS.put(EntityType.PIG, 0.27F); MOVEMENT_SPEEDS.put(EntityType.PIG, 0.27F);
MOVEMENT_SPEEDS.put(EntityType.PLAYER, 1F); MOVEMENT_SPEEDS.put(EntityType.PLAYER, 1F);
MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F);
try { try {
SPEED_FIELD = EntityLiving.class.getDeclaredField("bb"); SPEED_FIELD = EntityLiving.class.getDeclaredField("bb");
SPEED_FIELD.setAccessible(true); SPEED_FIELD.setAccessible(true);

View File

@ -59,6 +59,14 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC {
Util.callCollisionEvent(npc, entity); Util.callCollisionEvent(npc, entity);
} }
@Override
public void d_() {
if (npc == null)
super.d_();
else
npc.update();
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;

View File

@ -105,13 +105,13 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
public void d_() { public void d_() {
if (npc == null) if (npc == null)
super.d_(); super.d_();
else
npc.update();
} }
@Override @Override
public void e() { public void e() {
if (npc != null) if (npc == null)
npc.update();
else
super.e(); super.e();
} }
@ -120,5 +120,9 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
return npc; return npc;
} }
@Override
public void z_() {
}
} }
} }

View File

@ -76,5 +76,12 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;
} }
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
} }
} }

View File

@ -76,5 +76,11 @@ public class CitizensPigZombieNPC extends CitizensMobNPC {
return npc; return npc;
} }
@Override
public void z_() {
super.z_();
if (npc != null)
npc.update();
}
} }
} }

View File

@ -63,6 +63,14 @@ public class CitizensSilverfishNPC extends CitizensMobNPC {
Util.callCollisionEvent(npc, entity); Util.callCollisionEvent(npc, entity);
} }
@Override
public void d_() {
if (npc == null)
super.d_();
else
npc.update();
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;

View File

@ -64,6 +64,14 @@ public class CitizensSlimeNPC extends CitizensMobNPC {
Util.callCollisionEvent(npc, entity); Util.callCollisionEvent(npc, entity);
} }
@Override
public void d_() {
if (npc == null)
super.d_();
else
npc.update();
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;

View File

@ -14,7 +14,6 @@ import org.bukkit.entity.Spider;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class CitizensSpiderNPC extends CitizensMobNPC { public class CitizensSpiderNPC extends CitizensMobNPC {
public CitizensSpiderNPC(int id, String name) { public CitizensSpiderNPC(int id, String name) {
super(id, name, EntitySpiderNPC.class); super(id, name, EntitySpiderNPC.class);
} }
@ -63,6 +62,14 @@ public class CitizensSpiderNPC extends CitizensMobNPC {
Util.callCollisionEvent(npc, entity); Util.callCollisionEvent(npc, entity);
} }
@Override
public void d_() {
if (npc == null)
super.d_();
else
npc.update();
}
@Override @Override
public NPC getNPC() { public NPC getNPC() {
return npc; return npc;

View File

@ -2,7 +2,6 @@ package net.citizensnpcs.trait;
import net.citizensnpcs.api.event.NPCRightClickEvent; import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.DataKey;
import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityLiving;
@ -18,7 +17,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
public class Controllable extends Trait implements Toggleable { public class Controllable extends Trait implements Toggleable {
private boolean enabled; private boolean enabled;
public Controllable(NPC npc) { public Controllable() {
super("controllable"); super("controllable");
} }
@ -54,13 +53,12 @@ public class Controllable extends Trait implements Toggleable {
@EventHandler @EventHandler
public void onRightClick(NPCRightClickEvent event) { public void onRightClick(NPCRightClickEvent event) {
if (!npc.isSpawned() || !event.getNPC().equals(npc)) if (!enabled || !npc.isSpawned() || !event.getNPC().equals(npc))
return; return;
EntityPlayer handle = ((CraftPlayer) event.getClicker()).getHandle(); EntityPlayer handle = ((CraftPlayer) event.getClicker()).getHandle();
if (getHandle().passenger != null) { if (getHandle().passenger != null) {
if (getHandle().passenger == handle) { if (getHandle().passenger == handle)
event.getClicker().leaveVehicle(); event.getClicker().leaveVehicle();
}
return; return;
} }
handle.setPassengerOf(getHandle()); handle.setPassengerOf(getHandle());
@ -68,7 +66,7 @@ public class Controllable extends Trait implements Toggleable {
@Override @Override
public void run() { public void run() {
if (!npc.isSpawned() || getHandle().passenger == null) if (!enabled || !npc.isSpawned() || getHandle().passenger == null)
return; return;
EntityLiving handle = getHandle(); EntityLiving handle = getHandle();
boolean onGround = handle.onGround; boolean onGround = handle.onGround;
@ -83,7 +81,10 @@ public class Controllable extends Trait implements Toggleable {
@Override @Override
public boolean toggle() { public boolean toggle() {
return (enabled = !enabled); enabled = !enabled;
if (!enabled && getHandle().passenger != null)
getHandle().passenger.getBukkitEntity().leaveVehicle();
return enabled;
} }
private static final double AIR_SPEED = 1.5; private static final double AIR_SPEED = 1.5;