AutoReferee

AutoReferee

9.1k Downloads

Simplified player-in-zone detection

eric-wieser opened this issue ยท 1 comments

commented

You could remove the need for the complex sneak detection:

if (player.isSneaking() && d < SNEAK_DISTANCE && fallspeed < FREEFALL_THRESHOLD);

By implementing a better region class.

A simple min - (0.3, 0, 0.3) <= pos < max + (0.3, 0, 0.3) works correctly for detecting whether a player is over the edge or just sneaking. I tested it in all four directions, and it seems to work every time.

The problems with the worldedit class are:

  • It works on integer coordinates, so adding 0.3 to the size silently fails
  • size = max - min +(1, 1, 1), which can lead to off by one errors
  • The bounds are inclusive at both ends, which is probably not how sneaking is implemented internally. (Making a guess here)
commented

This actually handles some issues with floating point errors.

Experiment time: sneak out over the edge of a cliff as far as you can go, then stop moving. You'll still (most likely) be within 0.3 of the region. Now look around a bit -- just move the mouse, not your player. Your position will update a bit, until, lo' and behold, your distance from the region, thanks to floating point errors, will be greater than 0.3. This handles such a case.