NPC stairclimbing: still not working

This commit is contained in:
fullwall 2012-10-29 22:45:03 +08:00
parent 5f15f0146d
commit e43a233ade
3 changed files with 30 additions and 14 deletions

View File

@ -2,6 +2,8 @@ package net.citizensnpcs.npc;
import java.util.List;
import javax.annotation.Nullable;
import net.citizensnpcs.EventListen;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.ai.Navigator;
@ -27,6 +29,9 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.metadata.FixedMetadataValue;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public abstract class CitizensNPC extends AbstractNPC {
@ -83,10 +88,19 @@ public abstract class CitizensNPC extends AbstractNPC {
return getHandle() != null;
}
public void load(DataKey root) {
public void load(final DataKey root) {
metadata.loadFrom(root.getRelative("metadata"));
// Load traits
for (DataKey traitKey : root.getRelative("traits").getSubKeys()) {
String traitNames = root.getString("traitnames");
Iterable<DataKey> keys = traitNames.isEmpty() ? root.getRelative("traits").getSubKeys() : Iterables
.transform(Splitter.on(',').split(traitNames), new Function<String, DataKey>() {
@Override
public DataKey apply(@Nullable String input) {
return root.getRelative("traits." + input);
}
});
for (DataKey traitKey : keys) {
if (traitKey.keyExists("enabled") && !traitKey.getBoolean("enabled"))
continue;
Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(traitKey.name());
@ -141,11 +155,16 @@ public abstract class CitizensNPC extends AbstractNPC {
navigator.save(root.getRelative("navigator"));
// Save all existing traits
StringBuilder traitNames = new StringBuilder();
for (Trait trait : traits.values()) {
DataKey traitKey = root.getRelative("traits." + trait.getName());
trait.save(traitKey);
PersistenceLoader.save(trait, traitKey);
removedTraits.remove(trait.getName());
traitNames.append(trait.getName() + ",");
}
if (traitNames.length() > 0) {
root.setString("traitnames", traitNames.substring(0, traitNames.length() - 1));
}
removeTraitData(root);
}

View File

@ -140,11 +140,9 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
public void update() {
super.update();
if (isSpawned() && getBukkitEntity().getLocation().getChunk().isLoaded()) {
if (NMS.inWater(mcEntity)) {
mcEntity.motY += 0.08F;
} else if (!getNavigator().isNavigating())
if (!getNavigator().isNavigating() && !NMS.inWater(mcEntity))
mcEntity.move(0, -0.2, 0);
// gravity! also works around an entity.onGround not updating issue
// gravity. also works around an entity.onGround not updating issue
// (onGround is normally updated by the client)
}
}

View File

@ -124,8 +124,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
navigation.e();
moveOnCurrentHeading();
} else if (motX != 0 || motZ != 0 || motY != 0)
e(0, 0); // is this necessary? it does gravity/controllable but
// sometimes players sink into the ground
e(0, 0); // is this necessary? it does controllable but sometimes
// players sink into the ground
if (noDamageTicks > 0)
--noDamageTicks;
@ -136,17 +136,15 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
getControllerMove().c();
getControllerLook().a();
getControllerJump().b();
e(npc.getNavigator().getDefaultParameters().speed());
// taken from EntityLiving update method
if (bG) {
/* boolean inLiquid = H() || J();
if (inLiquid) {
motY += 0.04;
} else (handled elsewhere)*/
} else //(handled elsewhere)*/
if (onGround && bW == 0) {
// this.aZ(); - this doesn't jump high enough
motY = 0.6;
bf(); // jump
bW = 10;
}
} else
@ -155,9 +153,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
bD *= 0.98F;
bE *= 0.98F;
bF *= 0.9F;
float speed = npc.getNavigator().getDefaultParameters().speed();
e(speed);
float prev = aM;
aM *= by() * npc.getNavigator().getDefaultParameters().speed();
aM *= by() * speed;
e(bD, bE); // movement method
aM = prev;
NMS.setHeadYaw(this, yaw);