austinv11 / PeripheralsPlusPlus

A pseudo-port of miscperipherals, with other stuff as well!
GNU General Public License v2.0
25 stars 28 forks source link

Player sensor incorrectly reading distance #173

Closed AppliedEM closed 6 years ago

AppliedEM commented 6 years ago

Description

The player sensor's x reading is 1.3 blocks too high in the x direction, and roughly .3 blocks too high in the y direction. Could not get it to change its reading based on the z direction distance and I expect it is simply not reading any values based on that axis.

Steps to Reproduce

  1. place player sensor to right of computer
  2. call player.getNearbyPlayers(200)
  3. correlate the distance from the nearest player to the distance reported by the block. It is cutting out the contribution from the z axis and using inaccurate values from the x and y axis.

...

Expected behavior: A true cartesian floating point distance from the player to the center of the block

Actual behavior: The cartesian distance from the player's x.y plane, with significant error

Version affected: 1.3.6 forge 1.7.10

Additional Information

something to note is that my tests were conducted in a mystcraft dimension. Not sure if that would have any affect

AppliedEM commented 6 years ago

After looking at the code, the issue is in \src\main\java\com\austinv11\peripheralsplusplus\tiles\TileEntityPlayerSensor.java. The distance was being calculated incorrectly on line 89. I changed the line to map.put(player.getDisplayName(), Math.sqrt(Math.pow(location.getX() - player.posX,2) + Math.pow(location.getY() - player.posY,2) + Math.pow(location.getZ() - player.posZ,2))); And the sensor began working mostly correctly again.

ghost commented 6 years ago

This mod got taken over, please head to https://github.com/rolandoislas/PeripheralsPlusOne for any further questions.