mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-12 18:31:40 +01:00
NPC stairclimbing: still not working
This commit is contained in:
parent
d00a19d8fc
commit
cb578bd677
@ -2,6 +2,8 @@ package net.citizensnpcs.npc;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import net.citizensnpcs.EventListen;
|
import net.citizensnpcs.EventListen;
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
import net.citizensnpcs.api.ai.Navigator;
|
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.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
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;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
public abstract class CitizensNPC extends AbstractNPC {
|
public abstract class CitizensNPC extends AbstractNPC {
|
||||||
@ -83,10 +88,19 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
return getHandle() != null;
|
return getHandle() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load(DataKey root) {
|
public void load(final DataKey root) {
|
||||||
metadata.loadFrom(root.getRelative("metadata"));
|
metadata.loadFrom(root.getRelative("metadata"));
|
||||||
// Load traits
|
// 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"))
|
if (traitKey.keyExists("enabled") && !traitKey.getBoolean("enabled"))
|
||||||
continue;
|
continue;
|
||||||
Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(traitKey.name());
|
Class<? extends Trait> clazz = CitizensAPI.getTraitFactory().getTraitClass(traitKey.name());
|
||||||
@ -141,11 +155,16 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
navigator.save(root.getRelative("navigator"));
|
navigator.save(root.getRelative("navigator"));
|
||||||
|
|
||||||
// Save all existing traits
|
// Save all existing traits
|
||||||
|
StringBuilder traitNames = new StringBuilder();
|
||||||
for (Trait trait : traits.values()) {
|
for (Trait trait : traits.values()) {
|
||||||
DataKey traitKey = root.getRelative("traits." + trait.getName());
|
DataKey traitKey = root.getRelative("traits." + trait.getName());
|
||||||
trait.save(traitKey);
|
trait.save(traitKey);
|
||||||
PersistenceLoader.save(trait, traitKey);
|
PersistenceLoader.save(trait, traitKey);
|
||||||
removedTraits.remove(trait.getName());
|
removedTraits.remove(trait.getName());
|
||||||
|
traitNames.append(trait.getName() + ",");
|
||||||
|
}
|
||||||
|
if (traitNames.length() > 0) {
|
||||||
|
root.setString("traitnames", traitNames.substring(0, traitNames.length() - 1));
|
||||||
}
|
}
|
||||||
removeTraitData(root);
|
removeTraitData(root);
|
||||||
}
|
}
|
||||||
|
@ -140,11 +140,9 @@ public class CitizensHumanNPC extends CitizensNPC implements Equipable {
|
|||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
if (isSpawned() && getBukkitEntity().getLocation().getChunk().isLoaded()) {
|
if (isSpawned() && getBukkitEntity().getLocation().getChunk().isLoaded()) {
|
||||||
if (NMS.inWater(mcEntity)) {
|
if (!getNavigator().isNavigating() && !NMS.inWater(mcEntity))
|
||||||
mcEntity.motY += 0.08F;
|
|
||||||
} else if (!getNavigator().isNavigating())
|
|
||||||
mcEntity.move(0, -0.2, 0);
|
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)
|
// (onGround is normally updated by the client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
navigation.e();
|
navigation.e();
|
||||||
moveOnCurrentHeading();
|
moveOnCurrentHeading();
|
||||||
} else if (motX != 0 || motZ != 0 || motY != 0)
|
} else if (motX != 0 || motZ != 0 || motY != 0)
|
||||||
e(0, 0); // is this necessary? it does gravity/controllable but
|
e(0, 0); // is this necessary? it does controllable but sometimes
|
||||||
// sometimes players sink into the ground
|
// players sink into the ground
|
||||||
|
|
||||||
if (noDamageTicks > 0)
|
if (noDamageTicks > 0)
|
||||||
--noDamageTicks;
|
--noDamageTicks;
|
||||||
@ -136,17 +136,15 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
getControllerMove().c();
|
getControllerMove().c();
|
||||||
getControllerLook().a();
|
getControllerLook().a();
|
||||||
getControllerJump().b();
|
getControllerJump().b();
|
||||||
e(npc.getNavigator().getDefaultParameters().speed());
|
|
||||||
|
|
||||||
// taken from EntityLiving update method
|
// taken from EntityLiving update method
|
||||||
if (bG) {
|
if (bG) {
|
||||||
/* boolean inLiquid = H() || J();
|
/* boolean inLiquid = H() || J();
|
||||||
if (inLiquid) {
|
if (inLiquid) {
|
||||||
motY += 0.04;
|
motY += 0.04;
|
||||||
} else (handled elsewhere)*/
|
} else //(handled elsewhere)*/
|
||||||
if (onGround && bW == 0) {
|
if (onGround && bW == 0) {
|
||||||
// this.aZ(); - this doesn't jump high enough
|
bf(); // jump
|
||||||
motY = 0.6;
|
|
||||||
bW = 10;
|
bW = 10;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -155,9 +153,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
bD *= 0.98F;
|
bD *= 0.98F;
|
||||||
bE *= 0.98F;
|
bE *= 0.98F;
|
||||||
bF *= 0.9F;
|
bF *= 0.9F;
|
||||||
|
float speed = npc.getNavigator().getDefaultParameters().speed();
|
||||||
|
e(speed);
|
||||||
float prev = aM;
|
float prev = aM;
|
||||||
aM *= by() * npc.getNavigator().getDefaultParameters().speed();
|
aM *= by() * speed;
|
||||||
e(bD, bE); // movement method
|
e(bD, bE); // movement method
|
||||||
aM = prev;
|
aM = prev;
|
||||||
NMS.setHeadYaw(this, yaw);
|
NMS.setHeadYaw(this, yaw);
|
||||||
|
Loading…
Reference in New Issue
Block a user