diff options
author | makamys <makamys@outlook.com> | 2023-12-02 22:11:32 +0100 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2023-12-03 00:38:41 +0100 |
commit | 5db6a3d12652e4d01beb5c13b91247f1ab36d4f1 (patch) | |
tree | b95760f3b6c55d3d099fedea5265ae799a12fe36 | |
parent | 1fb7166ab4ad724368b67f8fed81c2e2fb2a66f9 (diff) | |
download | Neodymium-5db6a3d12652e4d01beb5c13b91247f1ab36d4f1.tar.gz Neodymium-5db6a3d12652e4d01beb5c13b91247f1ab36d4f1.tar.bz2 Neodymium-5db6a3d12652e4d01beb5c13b91247f1ab36d4f1.zip |
Move comparators to Comparators class
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/Comparators.java | 96 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/NeoRenderer.java | 92 |
2 files changed, 98 insertions, 90 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/Comparators.java b/src/main/java/makamys/neodymium/renderer/Comparators.java new file mode 100644 index 0000000..61dc1bc --- /dev/null +++ b/src/main/java/makamys/neodymium/renderer/Comparators.java @@ -0,0 +1,96 @@ +package makamys.neodymium.renderer; + +import java.util.Comparator; + +import net.minecraft.entity.Entity; +import net.minecraft.world.ChunkCoordIntPair; + +public class Comparators { + public static final MeshDistanceComparator MESH_DISTANCE_COMPARATOR = new MeshDistanceComparator(); + + public static class NeoChunkComparator implements Comparator<NeoChunk> { + Entity player; + + public NeoChunkComparator(Entity player) { + this.player = player; + } + + @Override + public int compare(NeoChunk p1, NeoChunk p2) { + int distSq1 = distSq(p1); + int distSq2 = distSq(p2); + return distSq1 < distSq2 ? -1 : distSq1 > distSq2 ? 1 : 0; + } + + int distSq(NeoChunk p) { + return (int)( + Math.pow(((p.x * 16) - player.chunkCoordX), 2) + + Math.pow(((p.z * 16) - player.chunkCoordZ), 2) + ); + } + } + + public static class ChunkCoordDistanceComparator implements Comparator<ChunkCoordIntPair> { + double x, y, z; + + public ChunkCoordDistanceComparator(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public int compare(ChunkCoordIntPair p1, ChunkCoordIntPair p2) { + int distSq1 = distSq(p1); + int distSq2 = distSq(p2); + return distSq1 < distSq2 ? -1 : distSq1 > distSq2 ? 1 : 0; + } + + int distSq(ChunkCoordIntPair p) { + return (int)( + Math.pow(((p.chunkXPos * 16) - x), 2) + + Math.pow(((p.chunkZPos * 16) - z), 2) + ); + } + } + + public static class MeshDistanceComparator implements Comparator<Mesh> { + double x, y, z; + boolean inverted; + + public Comparator<? super Mesh> setInverted(boolean inverted) { + this.inverted = inverted; + return this; + } + + public MeshDistanceComparator setOrigin(double x, double y, double z) { + this.x = x / 16.0; + this.y = y / 16.0; + this.z = z / 16.0; + return this; + } + + @Override + public int compare(Mesh a, Mesh b) { + if(a.pass < b.pass) { + return -1; + } else if(a.pass > b.pass) { + return 1; + } else { + double distSqA = a.distSq(x, y, z); + double distSqB = b.distSq(x, y, z); + + int mult = inverted ? -1 : 1; + + if(distSqA > distSqB) { + return 1 * mult; + } else if(distSqA < distSqB) { + return -1 * mult; + } else { + return 0; + } + } + } + + } +} diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index 3c5dfd6..1caf301 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -49,8 +49,6 @@ import net.minecraft.world.World; /** The main renderer class. */ public class NeoRenderer { - private static final MeshDistanceComparator DISTANCE_COMPARATOR = new MeshDistanceComparator(); - public boolean hasInited = false; public boolean destroyPending; public boolean reloadPending; @@ -184,10 +182,10 @@ public class NeoRenderer { private void sort(boolean pass0, boolean pass1) { if(pass0) { - sentMeshes[0].sort(DISTANCE_COMPARATOR.setOrigin(eyePosX, eyePosY, eyePosZ).setInverted(false)); + sentMeshes[0].sort(Comparators.MESH_DISTANCE_COMPARATOR.setOrigin(eyePosX, eyePosY, eyePosZ).setInverted(false)); } if(pass1) { - sentMeshes[1].sort(DISTANCE_COMPARATOR.setOrigin(eyePosX, eyePosY, eyePosZ).setInverted(true)); + sentMeshes[1].sort(Comparators.MESH_DISTANCE_COMPARATOR.setOrigin(eyePosX, eyePosY, eyePosZ).setInverted(true)); } } @@ -668,92 +666,6 @@ public class NeoRenderer { return Config.wireframe && CheatHelper.canCheat(); } - public static class NeoChunkComparator implements Comparator<NeoChunk> { - Entity player; - - public NeoChunkComparator(Entity player) { - this.player = player; - } - - @Override - public int compare(NeoChunk p1, NeoChunk p2) { - int distSq1 = distSq(p1); - int distSq2 = distSq(p2); - return distSq1 < distSq2 ? -1 : distSq1 > distSq2 ? 1 : 0; - } - - int distSq(NeoChunk p) { - return (int)( - Math.pow(((p.x * 16) - player.chunkCoordX), 2) + - Math.pow(((p.z * 16) - player.chunkCoordZ), 2) - ); - } - } - - public static class ChunkCoordDistanceComparator implements Comparator<ChunkCoordIntPair> { - double x, y, z; - - public ChunkCoordDistanceComparator(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public int compare(ChunkCoordIntPair p1, ChunkCoordIntPair p2) { - int distSq1 = distSq(p1); - int distSq2 = distSq(p2); - return distSq1 < distSq2 ? -1 : distSq1 > distSq2 ? 1 : 0; - } - - int distSq(ChunkCoordIntPair p) { - return (int)( - Math.pow(((p.chunkXPos * 16) - x), 2) + - Math.pow(((p.chunkZPos * 16) - z), 2) - ); - } - } - - public static class MeshDistanceComparator implements Comparator<Mesh> { - double x, y, z; - boolean inverted; - - public Comparator<? super Mesh> setInverted(boolean inverted) { - this.inverted = inverted; - return this; - } - - public MeshDistanceComparator setOrigin(double x, double y, double z) { - this.x = x / 16.0; - this.y = y / 16.0; - this.z = z / 16.0; - return this; - } - - @Override - public int compare(Mesh a, Mesh b) { - if(a.pass < b.pass) { - return -1; - } else if(a.pass > b.pass) { - return 1; - } else { - double distSqA = a.distSq(x, y, z); - double distSqB = b.distSq(x, y, z); - - int mult = inverted ? -1 : 1; - - if(distSqA > distSqB) { - return 1 * mult; - } else if(distSqA < distSqB) { - return -1 * mult; - } else { - return 0; - } - } - } - - } - public static enum WorldRendererChange { VISIBLE, INVISIBLE, DELETED } |