Search code examples
javaplotbukkit

Turn this idea into a Java formula


I am making a plot assignment program (for a Bukkit plugin).

There is a world with sandstone slabs placed along every multiple of 200 (x and z axis). I then assign a plot to a player, and get the location of the plot ID with this code:

double zCorner = (Math.floor(plotID / 200)) * 200;
double xCorner = (plotID % 200) * 200;

I would like to do this backwards, i.e. recover the plot ID from the zCorner and xCorner.


Solution

    • xCorner / 200 holds the remainder of plotId divided by 200.
    • yCorner / 200 holds the quotient of plotId divided by 200.

    You could then write the following:

    double recoveredPlotID = (zCorner / 200) * 200 + xCorner / 200;
    

    to get the plotID from the two corners.