mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 23:37:14 -04:00
fix: compilation.
This commit is contained in:
parent
83dbeddb12
commit
1df5b0c629
@ -9,16 +9,21 @@ import java.util.function.Supplier;
|
||||
import javafx.event.Event;
|
||||
import javafx.event.EventHandler;
|
||||
|
||||
public interface FunctionHelper {
|
||||
public final class FunctionHelper {
|
||||
private FunctionHelper() {
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> void always(Consumer<T> consumer, T... ts) {
|
||||
Arrays.asList(ts).forEach(consumer);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <A, B> void alwaysA(BiConsumer<A, B> consumer, A a, B... bs) {
|
||||
Arrays.asList(bs).forEach(b -> consumer.accept(a, b));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <A, B> void alwaysB(BiConsumer<A, B> consumer, B b, A... as) {
|
||||
Arrays.asList(as).forEach(a -> consumer.accept(a, b));
|
||||
}
|
||||
@ -27,6 +32,7 @@ public interface FunctionHelper {
|
||||
return (b, a) -> consumer.accept(a, b);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Consumer<T> link(Consumer<T>... consumers) {
|
||||
return t -> {
|
||||
for (Consumer<T> consumer : consumers)
|
||||
@ -34,6 +40,7 @@ public interface FunctionHelper {
|
||||
};
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T extends Event> EventHandler<T> link(EventHandler<T>... handlers) {
|
||||
return t -> {
|
||||
for (EventHandler<T> handler : handlers)
|
||||
|
@ -4,6 +4,7 @@ import javafx.scene.image.Image;
|
||||
import javafx.scene.shape.Mesh;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.TriangleMesh;
|
||||
import org.jackhuang.hmcl.util.ArrayUtils;
|
||||
|
||||
public class SkinCube extends MeshView {
|
||||
|
||||
@ -76,7 +77,7 @@ public class SkinCube extends MeshView {
|
||||
3, 5, 6, 2, 7, 1 //P3,T2, P6,T5, P7,T6
|
||||
};
|
||||
|
||||
int copy[] = ArrayUtils.clone(faces);
|
||||
int[] copy = faces.clone();
|
||||
ArrayUtils.reverse(copy);
|
||||
for (int i = 0; i < copy.length; i += 2) {
|
||||
int tmp = copy[i];
|
||||
|
@ -0,0 +1,38 @@
|
||||
package moe.mickey.minecraft.skin.fx.test;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import moe.mickey.minecraft.skin.fx.FunctionHelper;
|
||||
import moe.mickey.minecraft.skin.fx.SkinCanvas;
|
||||
import moe.mickey.minecraft.skin.fx.SkinCanvasSupport;
|
||||
import moe.mickey.minecraft.skin.fx.animation.SkinAniRunning;
|
||||
import moe.mickey.minecraft.skin.fx.animation.SkinAniWavingArms;
|
||||
|
||||
public class Test extends Application {
|
||||
|
||||
public static final String TITLE = "FX - Minecraft skin preview";
|
||||
|
||||
public static SkinCanvas createSkinCanvas() {
|
||||
SkinCanvas canvas = new SkinCanvas(SkinCanvas.CHOCOLATE, 400, 400, true);
|
||||
canvas.getAnimationplayer().addSkinAnimation(new SkinAniWavingArms(100, 2000, 7.5, canvas), new SkinAniRunning(100, 100, 30, canvas));
|
||||
FunctionHelper.alwaysB(Consumer<SkinCanvas>::accept, canvas, new SkinCanvasSupport.Mouse(.5), new SkinCanvasSupport.Drag(TITLE));
|
||||
return canvas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
stage.setTitle(TITLE);
|
||||
Scene scene = new Scene(createSkinCanvas());
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
}
|
@ -14,13 +14,4 @@ dependencies {
|
||||
api group: 'com.nqzero', name: 'permit-reflect', version: '0.3'
|
||||
api group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1'
|
||||
compileOnlyApi group: 'org.jetbrains', name: 'annotations', version: '16.0.3'
|
||||
|
||||
// compileOnlyApi group: 'org.openjfx', name: 'javafx-base', version: '15', classifier: 'win'
|
||||
// compileOnlyApi group: 'org.openjfx', name: 'javafx-controls', version: '15', classifier: 'win'
|
||||
// compileOnlyApi group: 'org.openjfx', name: 'javafx-fxml', version: '15', classifier: 'win'
|
||||
// compileOnlyApi group: 'org.openjfx', name: 'javafx-graphics', version: '15', classifier: 'win'
|
||||
// compileOnlyApi group: 'org.openjfx', name: 'javafx-media', version: '15', classifier: 'win'
|
||||
// compileOnlyApi group: 'org.openjfx', name: 'javafx-swing', version: '15', classifier: 'win'
|
||||
// compileOnlyApi group: 'org.openjfx', name: 'javafx-web', version: '15', classifier: 'win'
|
||||
|
||||
}
|
||||
|
434
HMCLCore/src/main/java/org/jackhuang/hmcl/util/ArrayUtils.java
Normal file
434
HMCLCore/src/main/java/org/jackhuang/hmcl/util/ArrayUtils.java
Normal file
@ -0,0 +1,434 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher
|
||||
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.jackhuang.hmcl.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
/**
|
||||
* Commons-lang ArrayUtils
|
||||
*/
|
||||
public final class ArrayUtils {
|
||||
private ArrayUtils() {
|
||||
}
|
||||
|
||||
public static boolean[] addAll(boolean[] array1, boolean... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
} else {
|
||||
boolean[] joinedArray = new boolean[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] addAll(byte[] array1, byte... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
} else {
|
||||
byte[] joinedArray = new byte[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static char[] addAll(char[] array1, char... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
} else {
|
||||
char[] joinedArray = new char[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static double[] addAll(double[] array1, double... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
} else {
|
||||
double[] joinedArray = new double[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static float[] addAll(float[] array1, float... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
} else {
|
||||
float[] joinedArray = new float[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] addAll(int[] array1, int... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
} else {
|
||||
int[] joinedArray = new int[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static long[] addAll(long[] array1, long... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
} else {
|
||||
long[] joinedArray = new long[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
}
|
||||
}
|
||||
|
||||
public static short[] addAll(short[] array1, short... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
} else {
|
||||
short[] joinedArray = new short[array1.length + array2.length];
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
return joinedArray;
|
||||
}
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> T[] addAll(final T[] array1, final T... array2) {
|
||||
if (array1 == null) {
|
||||
return clone(array2);
|
||||
} else if (array2 == null) {
|
||||
return clone(array1);
|
||||
}
|
||||
final Class<?> type1 = array1.getClass().getComponentType();
|
||||
@SuppressWarnings("unchecked") // OK, because array is of type T
|
||||
final T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + array2.length);
|
||||
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
|
||||
try {
|
||||
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
|
||||
} catch (final ArrayStoreException ase) {
|
||||
// Check if problem was due to incompatible types
|
||||
/*
|
||||
* We do this here, rather than before the copy because:
|
||||
* - it would be a wasted check most of the time
|
||||
* - safer, in case check turns out to be too strict
|
||||
*/
|
||||
final Class<?> type2 = array2.getClass().getComponentType();
|
||||
if (!type1.isAssignableFrom(type2)) {
|
||||
throw new IllegalArgumentException("Cannot store " + type2.getName() + " in an array of "
|
||||
+ type1.getName(), ase);
|
||||
}
|
||||
throw ase; // No, so rethrow original
|
||||
}
|
||||
return joinedArray;
|
||||
}
|
||||
|
||||
public static boolean[] clone(final boolean[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static byte[] clone(final byte[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static char[] clone(final char[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static double[] clone(final double[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static float[] clone(final float[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static int[] clone(final int[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static long[] clone(final long[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static short[] clone(final short[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static <T> T[] clone(final T[] array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
public static void reverse(final boolean[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final byte[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final char[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final double[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final float[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final int[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final long[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final short[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final Object[] array) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
reverse(array, 0, array.length);
|
||||
}
|
||||
|
||||
public static void reverse(final boolean[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
boolean tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reverse(final byte[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
byte tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reverse(final char[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
char tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reverse(final double[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
double tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reverse(final float[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
float tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reverse(final int[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
int tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reverse(final long[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
long tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reverse(final short[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
short tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reverse(final Object[] array, final int startIndexInclusive, final int endIndexExclusive) {
|
||||
if (array == null) {
|
||||
return;
|
||||
}
|
||||
int i = Math.max(startIndexInclusive, 0);
|
||||
int j = Math.min(array.length, endIndexExclusive) - 1;
|
||||
Object tmp;
|
||||
while (j > i) {
|
||||
tmp = array[j];
|
||||
array[j] = array[i];
|
||||
array[i] = tmp;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,6 +316,16 @@ public final class Lang {
|
||||
};
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Consumer<T> compose(Consumer<T>... consumers) {
|
||||
return t -> {
|
||||
for (Consumer<T> consumer : consumers) {
|
||||
consumer.accept(t);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
public static <T> Stream<T> toStream(Optional<T> optional) {
|
||||
return optional.map(Stream::of).orElseGet(Stream::empty);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user