adepierre / Botcraft

Botcraft is a cross-platform C++ library to create bots that connect and interact with Minecraft servers with (optional) integrated OpenGL renderer
GNU General Public License v3.0
405 stars 43 forks source link

Pathfinding X and Z axis off by +1 when coordinates are negative in Example 2 #103

Closed AnthonyvW closed 1 year ago

AnthonyvW commented 1 year ago

In example 2 pathfinding to a location results in pathfinding to the block next to it when the respective coordinate is negative. When the coordinates are positive pathfinding works just fine.

Steps to Reproduce

  1. Create 1.19.3 vanilla server and join it
  2. Run Example 2 Chat Command Example to join server
  3. Go to a place where the X and Z coordinates are negative
  4. Get coordinates from F3 and tell it to pathfind to them
  5. See that it path finds to the block X+1 and Z+1 relative to the block you told it to go to

It will always pathfind to the block's coordinates +1 on the X and Z axis when those coordinates are negative.

AnthonyvW commented 1 year ago

This appears to be due to the center of blocks being offset by 0.5. Line 720 in PathfindingTask.cpp compensates for this when the coordinates are positive, but that compensation causes the destination to be wrong when the coordinates are negative.

AnthonyvW commented 1 year ago

Overall this seems to be more of an issue with how intuitive the input is. Since the coordinates gotten from F3 don't seem to make a difference if you specify the center of the block or the corner the user won't know to compensate for the 0.5 being added to the coordinate by subtracting one from the X and Z coordinates.

adepierre commented 1 year ago

Thanks for the report and the detailed repro steps 👍

Will look into it today, it should not be too hard to fix

adepierre commented 1 year ago

I can't seem to reproduce the issue on my side.

If I use BCChatCommand goto -15 1 -9 the bot ends up at -14.5 1 -8.5 i.e. at the center of the block with coordinates -15 1 -9.

The whole pathfinding system is block based and the bot will always go from the center of one block to the center of the next. So I feel it's more natural to have the input as block coordinates and then add the 0.5 rather than ask user to always make sure they specify .5 coordinates to make sure it's the center of a block.

Let me know if there is something I misunderstood.