Fix pig pathing speed

This commit is contained in:
fullwall 2012-07-22 15:44:40 +08:00
parent ec3182cc01
commit 6f30ed3496
5 changed files with 23 additions and 19 deletions

View File

@ -127,6 +127,7 @@ public class CitizensNavigator implements Navigator {
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 SPEED_FIELD; private static Field SPEED_FIELD;
static { static {
MOVEMENT_SPEEDS.put(EntityType.IRON_GOLEM, 0.15F); MOVEMENT_SPEEDS.put(EntityType.IRON_GOLEM, 0.15F);
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);
@ -134,6 +135,7 @@ public class CitizensNavigator implements Navigator {
MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F); MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 0.3F);
MOVEMENT_SPEEDS.put(EntityType.SNOWMAN, 0.25F); 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.PIG, 0.25F);
try { try {
SPEED_FIELD = EntityLiving.class.getDeclaredField("bb"); SPEED_FIELD = EntityLiving.class.getDeclaredField("bb");
SPEED_FIELD.setAccessible(true); SPEED_FIELD.setAccessible(true);

View File

@ -73,10 +73,14 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
getControllerMove().c(); getControllerMove().c();
getControllerLook().a(); getControllerLook().a();
getControllerJump().b(); getControllerJump().b();
// taken from EntityLiving
if (aZ) { if (aZ) {
if (aT()) { boolean inLiquid = aT() || aU();
if (inLiquid) {
motY += 0.04; motY += 0.04;
} else if (onGround && q == 0) { } else if (onGround && q == 0) {
// ac(); - this doesn't jump high enough
motY = 0.6; motY = 0.6;
q = 10; q = 10;
} }
@ -86,6 +90,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
aX *= 0.98F; aX *= 0.98F;
a(aW, aX); a(aW, aX);
X = yaw; // TODO: this looks jerky X = yaw;
} }
} }

View File

@ -3,7 +3,7 @@ package net.citizensnpcs.trait.waypoint;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import net.citizensnpcs.api.ai.Goal; import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.editor.Editor; import net.citizensnpcs.editor.Editor;
@ -24,6 +24,7 @@ import com.google.common.collect.Lists;
public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoint> { public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoint> {
private WaypointGoal currentGoal; private WaypointGoal currentGoal;
private final List<Waypoint> waypoints = Lists.newArrayList(); private final List<Waypoint> waypoints = Lists.newArrayList();
private NPC npc;
@Override @Override
public Editor createEditor(final Player player) { public Editor createEditor(final Player player) {
@ -72,6 +73,12 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
currentGoal.onProviderChanged(); currentGoal.onProviderChanged();
} }
@EventHandler
public void onNPCDespawn(NPCDespawnEvent event) {
if (event.getNPC().equals(npc))
end();
}
@EventHandler @EventHandler
public void onPlayerItemHeldChange(PlayerItemHeldEvent event) { public void onPlayerItemHeldChange(PlayerItemHeldEvent event) {
if (!event.getPlayer().equals(player) || waypoints.size() == 0) if (!event.getPlayer().equals(player) || waypoints.size() == 0)
@ -101,10 +108,11 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
} }
@Override @Override
public Goal getGoal(NPC npc) { public void onSpawn(NPC npc) {
this.npc = npc;
if (currentGoal == null) if (currentGoal == null)
currentGoal = new WaypointGoal(this, npc.getNavigator()); currentGoal = new WaypointGoal(this, npc.getNavigator());
return currentGoal; npc.getDefaultGoalController().addGoal(currentGoal, 1);
} }
@Override @Override

View File

@ -1,6 +1,5 @@
package net.citizensnpcs.trait.waypoint; package net.citizensnpcs.trait.waypoint;
import net.citizensnpcs.api.ai.Goal;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.editor.Editor; import net.citizensnpcs.editor.Editor;
@ -18,14 +17,6 @@ public interface WaypointProvider {
*/ */
public Editor createEditor(Player player); public Editor createEditor(Player player);
/**
*
* @param npc
* The attached {@link NPC} the goal is for.
* @return The {@link Goal} to attach to the NPC.
*/
public Goal getGoal(NPC npc);
/** /**
* Loads from the specified {@link DataKey}. * Loads from the specified {@link DataKey}.
* *
@ -41,4 +32,6 @@ public interface WaypointProvider {
* The key to save to * The key to save to
*/ */
public void save(DataKey key); public void save(DataKey key);
public void onSpawn(NPC npc);
} }

View File

@ -4,7 +4,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.citizensnpcs.api.ai.Goal;
import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.api.util.DataKey;
@ -51,10 +50,8 @@ public class Waypoints extends Trait {
@Override @Override
public void onSpawn() { public void onSpawn() {
if (provider != null) { if (provider != null)
Goal goal = provider.getGoal(getNPC()); provider.onSpawn(getNPC());
getNPC().getDefaultGoalController().addGoal(goal, 1);
}
} }
@Override @Override