Posted November 18, 20186 yr I'm writing some entity AI, which searches for blocks in a certain range and moves to them if it finds them. It works good, but the problem that I'm facing now is that the entity also moves to the block, even if it's in a position that it can never reach (completely encased behind walls). To try exclude these positions from valid ones, I added a check that calls entity.getNavigator().getPathToPos(pos) and checks if the path is null (because I thought it would be null if there was no available path). Sadly, that doesn't work. The entity now just walks against the wall and stays there until I remove it. Is there a way of checking if valid path to a position can be made before walking to it?
November 18, 20186 yr Look at PathNavigateGround#isDirectPathBetweenPoints, I think that one is a direct check of whether the entity can actually navigate to the point. That said if you keep giving the entity an invalid path every time it asks for one then it will keep getting stuck. You need to check whtether the block is reachable before accepting it as a valid pathing target.
November 18, 20186 yr Author 57 minutes ago, V0idWa1k3r said: Look at PathNavigateGround#isDirectPathBetweenPoints, I think that one is a direct check of whether the entity can actually navigate to the point. That said if you keep giving the entity an invalid path every time it asks for one then it will keep getting stuck. You need to check whtether the block is reachable before accepting it as a valid pathing target. isDirectPathBetweenPoints is protected, but I'll try reflecting it and see if it doesn't impact performance too much. My plan is of course to only make the entity walk to the position, if it is actually reachable.
November 18, 20186 yr Author Not sure... it always seems to return false for some reason, even if a path is available: boolean result = (boolean) isDirectPathBetweenPoints.invoke(nav, new Vec3d(start.getX(), start.getY(), start.getZ()), new Vec3d(end.getX(), end.getY(), end.getZ()), (int)entity.width, (int)entity.height, (int)entity.width);
November 18, 20186 yr You might want to use a method handle to reduce the overhead of reflection. Example About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
November 18, 20186 yr Author 2 minutes ago, Cadiboo said: You might want to use a method handle to reduce the overhead of reflection. Example Good idea, but the way I have it right now it still always returns false. I'm suspecting it has something to do with the sizeX, sizeY and sizeZ parameters. What exactly to they do, and what should their values be in my example?
November 18, 20186 yr I’m pretty sure that casting your entity size (float) to an int won’t be helping whatever your problem is. I’m not sure what they do, but you could look in the method at what happens to them. About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
November 19, 20186 yr Author I'm not sure what's wrong. I give the method the same parameters as vanilla does when moving entities, the entity height and width... The method always returns false at one of the isSafeToStandAt in isDirectPathBetweenPoints. I should probably also mention that the position where the entity should walk is a block of water, that might be why it's failing. Is there any other way than isDirectPathBetweenPoints? Edited November 19, 20186 yr by Tschipp
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.