lightsource randomiser hash will be same even when x < 0

This commit is contained in:
minjaesong
2020-02-24 14:46:37 +09:00
parent 0d8d6ca9fa
commit ad903952cc
4 changed files with 16 additions and 8 deletions

View File

@@ -10,9 +10,11 @@ import net.torvald.terrarum.gameworld.fmod
* Created by minjaesong on 2016-03-27.
*/
object LandUtil {
fun getBlockAddr(world: GameWorld, x: Int, y: Int): BlockAddress =
// coercing and fmod-ing follows ROUNDWORLD rule. See: GameWorld.coerceXY()
(world.width * y.coerceIn(0, world.height - 1)).toLong() + x.fmod(world.width)
fun getBlockAddr(world: GameWorld, x: Int, y: Int): BlockAddress {
// coercing and fmod-ing follows ROUNDWORLD rule. See: GameWorld.coerceXY()
val (x, y) = world.coerceXY(x, y)
return (world.width.toLong() * y) + x
}
fun resolveBlockAddr(world: GameWorld, t: BlockAddress): Pair<Int, Int> =
Pair((t % world.width).toInt(), (t / world.width).toInt())