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.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)) {
throw new RequirementMissingException("The NPC cannot be the mob type '" + type.getName()
+ "' to use that command.");

View File

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

View File

@ -177,7 +177,7 @@ public class NPCCommands {
// Initialize necessary traits
if (!Setting.SERVER_OWNS_NPCS.asBoolean())
npc.getTrait(Owner.class).setOwner(player.getName());
npc.getTrait(MobType.class).setType(type.toString());
npc.getTrait(MobType.class).setType(type);
npc.spawn(player.getLocation());
@ -241,13 +241,13 @@ public class NPCCommands {
}
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.");
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);
}
}

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 Field PATHFINDING_RANGE;
private static Field SPEED_FIELD;
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.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.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.PLAYER, 1F);
MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F);
try {
SPEED_FIELD = EntityLiving.class.getDeclaredField("bb");
SPEED_FIELD.setAccessible(true);

View File

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

View File

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

View File

@ -76,5 +76,12 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
public NPC getNPC() {
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;
}
@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);
}
@Override
public void d_() {
if (npc == null)
super.d_();
else
npc.update();
}
@Override
public NPC getNPC() {
return npc;

View File

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

View File

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

View File

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