9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

fix: array cast [ci skip]

This commit is contained in:
hayanesuru
2025-08-28 17:14:34 +09:00
parent 5cc4388005
commit 6945a581d5

View File

@@ -2,13 +2,13 @@ package org.dreeam.leaf.util;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
public class FastBitRadixSort { public final class FastBitRadixSort {
private static final int SMALL_ARRAY_THRESHOLD = 6; private static final int SMALL_ARRAY_THRESHOLD = 6;
private static final long[] LONGS = new long[0]; private static final long[] LONGS = new long[0];
private long[] bitsBuffer = LONGS; private long[] bitsBuffer = LONGS;
public <T extends Entity> void sort(T[] entities, int size, net.minecraft.core.Position target) { public void sort(Object[] entities, int size, net.minecraft.core.Position target) {
if (size <= 1) { if (size <= 1) {
return; return;
} }
@@ -20,15 +20,14 @@ public class FastBitRadixSort {
double ty = target.y(); double ty = target.y();
double tz = target.z(); double tz = target.z();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
T e = entities[i]; this.bitsBuffer[i] = Double.doubleToRawLongBits(((Entity) entities[i]).distanceToSqr(tx, ty, tz));
this.bitsBuffer[i] = Double.doubleToRawLongBits(e.distanceToSqr(tx, ty, tz));
} }
fastRadixSort(entities, this.bitsBuffer, 0, size - 1, 62); fastRadixSort(entities, this.bitsBuffer, 0, size - 1, 62);
} }
private static void fastRadixSort( private static void fastRadixSort(
Entity[] ents, Object[] ents,
long[] bits, long[] bits,
int low, int low,
int high, int high,
@@ -68,14 +67,14 @@ public class FastBitRadixSort {
} }
private static void insertionSort( private static void insertionSort(
Entity[] ents, Object[] ents,
long[] bits, long[] bits,
int low, int low,
int high int high
) { ) {
for (int i = low + 1; i <= high; i++) { for (int i = low + 1; i <= high; i++) {
int j = i; int j = i;
Entity currentEntity = ents[j]; Object currentEntity = ents[j];
long currentBits = bits[j]; long currentBits = bits[j];
while (j > low && bits[j - 1] > currentBits) { while (j > low && bits[j - 1] > currentBits) {
@@ -88,8 +87,8 @@ public class FastBitRadixSort {
} }
} }
private static void swap(Entity[] ents, long[] bits, int a, int b) { private static void swap(Object[] ents, long[] bits, int a, int b) {
Entity tempEntity = ents[a]; Object tempEntity = ents[a];
ents[a] = ents[b]; ents[a] = ents[b];
ents[b] = tempEntity; ents[b] = tempEntity;