CitizensAPI setTarget only follows the X and Z direction #989

Open
kinukin opened this Issue Nov 27, 2016 · 14 comments

Projects

None yet

4 participants

@kinukin
kinukin commented Nov 27, 2016 edited

Bug

Location loc = spawnLocation.get(e.getNPC().getName());
e.getNPC().getNavigator().setTarget(loc);

In the Citizens API, the npc does not follow the location coordinates accordingly and only goes to the X and Z coordinates, ignoring the Y coordinate.

For example, if a building was a 2 story house and the npc was spawned on the first level. And the npc moved to the second level and if the location is set back to its original coordinates it would go to the designated coordinates of the original coordinates except it won't go back to the first level. It would be on the second level but in the same position as the first level.

Minecraft Version 1.11, Citizens Version 2.0.21-SNAPSHOT <build 1426>

@fullwall
Member

Can you screenshot your path?

@kinukin
kinukin commented Nov 27, 2016 edited

This is how I'm setting the target

Set location to these coordinates and spawn on these coordinates
spawnlocation



then If a player attacks the NPC, follow the player and attack the player until health is below 15

e.getNPC().getNavigator().setTarget(p, true); // aggressively attack to player

then set location back to original spawn position after attacking player
public static Map<String, Location> spawnLocation = new HashMap<String,Location>();
spawnLocation.put(npc.getName(), npc.getEntity().getLocation()); //put original location into hashmap

//load location from hashmap and set target to original location
Location loc = spawnLocation.get(e.getNPC().getName());
e.getNPC().getNavigator().setTarget(loc);

Location set back to original position (spawnLocation) -

spawnLocation2


The npc is just directly below the original coordinates, when the npc should be on the original coordinates.

When a player attacks the npc the npc follows the player, but when the npc is no longer following the player it's suppose to go to the original position but except it doesn't

pink wool = the original spawn location of the npc.
below = wrong position
2016-11-28_00.32.35


There are stairs that lead up to the second floor of the house

@kinukin
kinukin commented Nov 28, 2016 edited

So basically when you set the target to getStoredLocation(); it breaks

@kinukin
kinukin commented Nov 28, 2016

Is there an issue within the npc.getNavigator().setTarget(npc.getStoredLocation()); code?

@fullwall
Member
fullwall commented Nov 28, 2016 edited

@kinukin getStoredLocation() is updated every tick to the NPC's current location - it's for when the NPC is despawned and you want to know its last known location. The code you gave doesn't mention getStoredLocation(), but it's not the location you spawn the NPC at so you shouldn't use it like that.

@kinukin
kinukin commented Nov 28, 2016 edited

Okay, I'll just stick with saving the original position in a hashmap when the npc is spawned.

By the way, is there a problem if setTarget(location)? The npc doesn't seem to head properly to the location set.

@fullwall
Member

Have you been using the new pathfinder? If so I just pushed a fix for it.

@kinukin
kinukin commented Nov 30, 2016 edited

Ah, yes I'm using the latest build of Citizens. The same problem still occurs.
Citizens-2.0.21-SNAPSHOT.jar

@kinukin
kinukin commented Nov 30, 2016 edited

after checking if the npc was not in the original location after setting its target to the original location, it appears the npc is having a hard time distinguishing the x,y and z coordinates.

The npc knows that it's in the wrong location but it doesn't know how to get there.

@Nutty101
Nutty101 commented Dec 27, 2016 edited

After looking into issues on a couple servers, we are finding that the Y axis isn't respected. So you can set targets and it will say its there, but it will stay on the current level and act like it reached that location when it's in fact still +5 on the y axis. Causing issues with getting NPC's to go where they should go.

This is only on the old pathfinder it seems with the latest build (1464)

@fullwall
Member
fullwall commented Dec 28, 2016 edited

@Nutty101 it seems to be a problem with the Minecraft pathfinder, have been looking through its code today but haven't tracked down the issue yet. It is getting the right destination and everything it just seems to not look for blocks in all directions very well.

The pathfinder is not finding a valid path in my test setup rather than it ignoring the y direction.

@fullwall
Member
fullwall commented Dec 28, 2016 edited

@Nutty101 it may be to do with stairs.

@Nutty101

Ahh, that might make sense. I will setup a non stair version tomorrow. Crashing out for tonight :) Thanks for looking at it.

@File14
File14 commented Jan 6, 2017

I think I have the same issuse: #1038

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment