Skip to content

Commit

Permalink
Enable new target location mapping API and disable /npc gravity when …
Browse files Browse the repository at this point in the history
…navigating
  • Loading branch information
fullwall committed Nov 24, 2015
1 parent 5f63b3f commit 7a23f78
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
16 changes: 15 additions & 1 deletion src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ public void setPath() {
}

private void setStrategy() {
Location location = target.getBukkitEntity().getLocation(TARGET_LOCATION);
Location location = parameters.entityTargetLocationMapper().apply(target.getBukkitEntity());
if (location == null) {
throw new IllegalStateException("mapper should not return null");
}
strategy = npc.isFlyable() ? new FlyingAStarNavigationStrategy(npc, location, parameters)
: new AStarNavigationStrategy(npc, location, parameters);
}
Expand All @@ -183,7 +186,18 @@ private NavigationFieldWrapper(NavigationAbstract navigation) {

@Override
public void setPath() {
Location location = parameters.entityTargetLocationMapper().apply(target.getBukkitEntity());
if (location == null) {
throw new IllegalStateException("mapper should not return null");
}
double oldX = target.locX, oldY = target.locY, oldZ = target.locZ;
target.locX = location.getX();
target.locY = location.getY();
target.locZ = location.getZ();
navigation.a(target, parameters.speed());
target.locX = oldX;
target.locY = oldY;
target.locZ = oldZ;
}

@Override
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/net/citizensnpcs/npc/entity/BatController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package net.citizensnpcs.npc.entity;

import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftBat;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.Bat;
import org.bukkit.util.Vector;

import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC;
Expand All @@ -11,13 +18,6 @@
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.World;

import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftBat;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.Bat;
import org.bukkit.util.Vector;

public class BatController extends MobEntityController {
public BatController() {
super(EntityBatNPC.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public EntityRabbitNPC(World world, NPC npc) {
this.npc = (CitizensNPC) npc;
if (npc != null) {
NMS.clearGoals(goalSelector, targetSelector);
// this.g = new ControllerJump(this);
// this.moveController = new ControllerMove(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/citizensnpcs/trait/Gravity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void run() {
((PlayerNPC) npc.getEntity()).setGravityEnabled(!enabled);
return;
}
if (!enabled)
if (!enabled || npc.getNavigator().isNavigating())
return;
Vector vector = npc.getEntity().getVelocity();
vector.setY(Math.max(0, vector.getY()));
Expand Down

0 comments on commit 7a23f78

Please sign in to comment.