| /* Copyright 2015-2020 Rivoreo |
| |
| Permission is hereby granted, free of charge, to any person obtaining |
| a copy of this software and associated documentation files (the |
| "Software"), to deal in the Software without restriction, including |
| without limitation the rights to use, copy, modify, merge, publish, |
| distribute, sublicense, and/or sell copies of the Software, and to |
| permit persons to whom the Software is furnished to do so, subject to |
| the following conditions: |
| |
| The above copyright notice and this permission notice shall be |
| included in all copies or substantial portions of the Software. |
| |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
| FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| */ |
| |
| package org.rivoreo.minecraft.toocramming; |
| |
| import org.spongepowered.api.world.Location; |
| |
| public class FuzzyLocation implements Comparable<FuzzyLocation> { |
| public FuzzyLocation(Location location) { |
| x = (int)(location.getX() * 10); |
| y = (int)(location.getY() * 10); |
| z = (int)(location.getZ() * 10); |
| } |
| |
| /* |
| private final int x_major, x_minor; |
| private final int y_major, y_minor; |
| private final int z_major, z_minor; |
| */ |
| private final int x; |
| private final int y; |
| private final int z; |
| |
| public int compareTo(FuzzyLocation another) { |
| //return (x - another.x) + (y - another.y) + (z - another.z); |
| //System.err.println(((x - another.x) << 10) + (y - another.y) + ((z - another.z) << 20)); |
| return ((x - another.x) << 10) + (y - another.y) + ((z - another.z) << 20); |
| } |
| |
| @Override |
| public boolean equals(Object o) { |
| if(!(o instanceof FuzzyLocation)) return false; |
| FuzzyLocation another = (FuzzyLocation)o; |
| return x == another.x && y == another.y && z == another.z; |
| } |
| |
| @Override |
| public int hashCode() { |
| return x ^ (y << 10) ^ (z << 20); |
| } |
| |
| /* |
| public void print_debug_line() { |
| System.err.printf("x = %d, y = %d, z = %d, hash code: %d\n", |
| x, y, z, hashCode()); |
| } |
| */ |
| } |