Fix errors in entity instantiation and update entities properly

This commit is contained in:
fullwall 2012-04-20 22:45:09 +08:00
parent 82da2c8beb
commit e60e889775
29 changed files with 97 additions and 76 deletions

View File

@ -280,12 +280,14 @@ public class Citizens extends JavaPlugin {
Messaging.log("Could not find a name for the NPC with ID '" + id + "'.");
continue;
}
EntityType type = EntityType.fromName(key.getString("traits.type"));
String unparsedEntityType = key.getString("traits.type");
EntityType type = EntityType.fromName(unparsedEntityType);
if (type == null) {
try {
type = EntityType.valueOf(key.getString("traits.type"));
type = EntityType.valueOf(unparsedEntityType);
} catch (IllegalArgumentException ex) {
Messaging.log("NPC type not recognized. Did you spell it correctly?");
Messaging.log("NPC type '" + unparsedEntityType
+ "' was not recognized. Did you spell it correctly?");
continue;
}
}

View File

@ -63,7 +63,9 @@ public class CitizensNPCManager implements NPCManager {
private int generateUniqueId() {
int count = 0;
while (getNPC(count++) != null)
;
; // TODO: doesn't respect existing save data that might not have
// been loaded. This causes DBs with NPCs that weren't loaded to
// have conflicting primary keys.
return count - 1;
}

View File

@ -25,9 +25,9 @@ public class CitizensBlazeNPC extends CitizensMobNPC {
public static class EntityBlazeNPC extends EntityBlaze implements NPCHandle {
private final CitizensNPC npc;
public EntityBlazeNPC(World world, CitizensNPC npc) {
public EntityBlazeNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}

View File

@ -25,15 +25,16 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC {
public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHandle {
private final CitizensNPC npc;
public EntityCaveSpiderNPC(World world, CitizensNPC npc) {
public EntityCaveSpiderNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,15 +25,16 @@ public class CitizensChickenNPC extends CitizensMobNPC {
public static class EntityChickenNPC extends EntityChicken implements NPCHandle {
private final CitizensNPC npc;
public EntityChickenNPC(World world, CitizensNPC npc) {
public EntityChickenNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,15 +25,16 @@ public class CitizensCowNPC extends CitizensMobNPC {
public static class EntityCowNPC extends EntityCow implements NPCHandle {
private final CitizensNPC npc;
public EntityCowNPC(World world, CitizensNPC npc) {
public EntityCowNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -26,9 +26,9 @@ public class CitizensCreeperNPC extends CitizensMobNPC {
public static class EntityCreeperNPC extends EntityCreeper implements NPCHandle {
private final CitizensNPC npc;
public EntityCreeperNPC(World world, CitizensNPC npc) {
public EntityCreeperNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@ -38,7 +38,8 @@ public class CitizensCreeperNPC extends CitizensMobNPC {
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,9 +25,9 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC {
public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHandle {
private final CitizensNPC npc;
public EntityEnderDragonNPC(World world, CitizensNPC npc) {
public EntityEnderDragonNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}

View File

@ -63,9 +63,9 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable {
public static class EntityEndermanNPC extends EntityEnderman implements NPCHandle {
private final CitizensNPC npc;
public EntityEndermanNPC(World world, CitizensNPC npc) {
public EntityEndermanNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}

View File

@ -25,9 +25,9 @@ public class CitizensGhastNPC extends CitizensMobNPC {
public static class EntityGhastNPC extends EntityGhast implements NPCHandle {
private final CitizensNPC npc;
public EntityGhastNPC(World world, CitizensNPC npc) {
public EntityGhastNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}

View File

@ -25,9 +25,9 @@ public class CitizensGiantNPC extends CitizensMobNPC {
public static class EntityGiantNPC extends EntityGiantZombie implements NPCHandle {
private final CitizensNPC npc;
public EntityGiantNPC(World world, CitizensNPC npc) {
public EntityGiantNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}

View File

@ -25,15 +25,16 @@ public class CitizensIronGolemNPC extends CitizensMobNPC {
public static class EntityIronGolemNPC extends EntityIronGolem implements NPCHandle {
private final CitizensNPC npc;
public EntityIronGolemNPC(World world, CitizensNPC npc) {
public EntityIronGolemNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,9 +25,9 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC {
public static class EntityMagmaCubeNPC extends EntityMagmaCube implements NPCHandle {
private final CitizensNPC npc;
public EntityMagmaCubeNPC(World world, CitizensNPC npc) {
public EntityMagmaCubeNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
setSize(3);
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();

View File

@ -25,15 +25,16 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC {
public static class EntityMushroomCowNPC extends EntityMushroomCow implements NPCHandle {
private final CitizensNPC npc;
public EntityMushroomCowNPC(World world, CitizensNPC npc) {
public EntityMushroomCowNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,15 +25,16 @@ public class CitizensOcelotNPC extends CitizensMobNPC {
public static class EntityOcelotNPC extends EntityOcelot implements NPCHandle {
private final CitizensNPC npc;
public EntityOcelotNPC(World world, CitizensNPC npc) {
public EntityOcelotNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -52,9 +52,9 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
public static class EntityPigNPC extends EntityPig implements NPCHandle {
private final CitizensNPC npc;
public EntityPigNPC(World world, CitizensNPC npc) {
public EntityPigNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@ -64,7 +64,8 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,9 +25,9 @@ public class CitizensPigZombieNPC extends CitizensMobNPC {
public static class EntityPigZombieNPC extends EntityPigZombie implements NPCHandle {
private final CitizensNPC npc;
public EntityPigZombieNPC(World world, CitizensNPC npc) {
public EntityPigZombieNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}

View File

@ -62,15 +62,16 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
public static class EntitySheepNPC extends EntitySheep implements NPCHandle {
private final CitizensNPC npc;
public EntitySheepNPC(World world, CitizensNPC npc) {
public EntitySheepNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,15 +25,16 @@ public class CitizensSilverfishNPC extends CitizensMobNPC {
public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHandle {
private final CitizensNPC npc;
public EntitySilverfishNPC(World world, CitizensNPC npc) {
public EntitySilverfishNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,15 +25,16 @@ public class CitizensSkeletonNPC extends CitizensMobNPC {
public static class EntitySkeletonNPC extends EntitySkeleton implements NPCHandle {
private final CitizensNPC npc;
public EntitySkeletonNPC(World world, CitizensNPC npc) {
public EntitySkeletonNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,16 +25,17 @@ public class CitizensSlimeNPC extends CitizensMobNPC {
public static class EntitySlimeNPC extends EntitySlime implements NPCHandle {
private final CitizensNPC npc;
public EntitySlimeNPC(World world, CitizensNPC npc) {
public EntitySlimeNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
setSize(3);
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,15 +25,16 @@ public class CitizensSnowmanNPC extends CitizensMobNPC {
public static class EntitySnowmanNPC extends EntitySnowman implements NPCHandle {
private final CitizensNPC npc;
public EntitySnowmanNPC(World world, CitizensNPC npc) {
public EntitySnowmanNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,15 +25,16 @@ public class CitizensSpiderNPC extends CitizensMobNPC {
public static class EntitySpiderNPC extends EntitySpider implements NPCHandle {
private final CitizensNPC npc;
public EntitySpiderNPC(World world, CitizensNPC npc) {
public EntitySpiderNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,9 +25,9 @@ public class CitizensSquidNPC extends CitizensMobNPC {
public static class EntitySquidNPC extends EntitySquid implements NPCHandle {
private final CitizensNPC npc;
public EntitySquidNPC(World world, CitizensNPC npc) {
public EntitySquidNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}

View File

@ -25,15 +25,16 @@ public class CitizensVillagerNPC extends CitizensMobNPC {
public static class EntityVillagerNPC extends EntityVillager implements NPCHandle {
private final CitizensNPC npc;
public EntityVillagerNPC(World world, CitizensNPC npc) {
public EntityVillagerNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,15 +25,16 @@ public class CitizensWolfNPC extends CitizensMobNPC {
public static class EntityWolfNPC extends EntityWolf implements NPCHandle {
private final CitizensNPC npc;
public EntityWolfNPC(World world, CitizensNPC npc) {
public EntityWolfNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}
@Override
public void d_() {
public void z_() {
super.z_();
npc.update();
}

View File

@ -25,9 +25,9 @@ public class CitizensZombieNPC extends CitizensMobNPC {
public static class EntityZombieNPC extends EntityZombie implements NPCHandle {
private final CitizensNPC npc;
public EntityZombieNPC(World world, CitizensNPC npc) {
public EntityZombieNPC(World world, NPC npc) {
super(world);
this.npc = npc;
this.npc = (CitizensNPC) npc;
goalSelector = new PathfinderGoalSelector();
targetSelector = new PathfinderGoalSelector();
}

View File

@ -26,9 +26,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
private CitizensNPC npc;
public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string,
ItemInWorldManager itemInWorldManager, CitizensNPC npc) {
ItemInWorldManager itemInWorldManager, NPC npc) {
super(minecraftServer, world, string, itemInWorldManager);
this.npc = npc;
this.npc = (CitizensNPC) npc;
itemInWorldManager.setGameMode(0);
NPCSocket socket = new NPCSocket();

View File

@ -35,11 +35,12 @@ public class Controllable extends Trait implements Runnable, Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
EntityPlayer handle = ((CraftPlayer) event.getPlayer()).getHandle();
if (event.getAction() == Action.PHYSICAL || !handle.equals(npc.getHandle().passenger))
Action performed = event.getAction();
if (performed == Action.PHYSICAL || !handle.equals(npc.getHandle().passenger))
return;
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
if (performed == Action.LEFT_CLICK_AIR || performed == Action.LEFT_CLICK_BLOCK) {
jump();
} else {
} else if (-170F >= event.getPlayer().getLocation().getPitch()) {
event.getPlayer().leaveVehicle();
}
}
@ -64,5 +65,5 @@ public class Controllable extends Trait implements Runnable, Listener {
public void save(DataKey key) {
}
private static final double JUMP_VELOCITY = 0.4;
private static final double JUMP_VELOCITY = 0.6;
}