-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use reflection to make the plugin compatible with 2.4.x and recent 2.…
…5.0 snapshots. (#41)
- Loading branch information
Showing
5 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/de/lemaik/chunky/denoiser/ChunkyCompatHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.lemaik.chunky.denoiser; | ||
|
||
import se.llbit.chunky.world.Material; | ||
import se.llbit.math.Ray; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
public class ChunkyCompatHelper { | ||
|
||
private static Class<?> getClass(String... classNameCandidates) { | ||
for (String name : classNameCandidates) { | ||
try { | ||
return Class.forName(name); | ||
} catch (ClassNotFoundException ignored) { | ||
} | ||
} | ||
throw new RuntimeException("No class found for " + String.join(" or ", classNameCandidates)); | ||
} | ||
|
||
private static Method getMethod(Class<?> className, String methodName, Class<?>... parameterTypes) { | ||
try { | ||
return className.getDeclaredMethod(methodName, parameterTypes); | ||
} catch (NoSuchMethodException e) { | ||
throw new RuntimeException("Could not invoke " + methodName + " on class " + className.getName(), e); | ||
} | ||
} | ||
|
||
public static class Air { | ||
public static final Material INSTANCE; | ||
|
||
static { | ||
try { | ||
INSTANCE = (Material) ChunkyCompatHelper.getClass("se.llbit.chunky.block.Air", "se.llbit.chunky.block.minecraft.Air").getDeclaredField("INSTANCE").get(null); | ||
} catch (IllegalAccessException | NoSuchFieldException e) { | ||
throw new RuntimeException("Could not get Air.INSTANCE", e); | ||
} | ||
} | ||
} | ||
|
||
public static class Water { | ||
public static final Material INSTANCE; | ||
|
||
static { | ||
try { | ||
INSTANCE = (Material) ChunkyCompatHelper.getClass("se.llbit.chunky.block.Water", "se.llbit.chunky.block.minecraft.Water").getDeclaredField("INSTANCE").get(null); | ||
} catch (IllegalAccessException | NoSuchFieldException e) { | ||
throw new RuntimeException("Could not get Water.INSTANCE", e); | ||
} | ||
} | ||
|
||
private static Class<?> water = ChunkyCompatHelper.getClass( | ||
"se.llbit.chunky.model.WaterModel", | ||
"se.llbit.chunky.model.minecraft.WaterModel" | ||
); | ||
|
||
private static Method doWaterDisplacementImpl = getMethod(water, "doWaterDisplacement", Ray.class); | ||
|
||
public static void doWaterDisplacement(Ray ray) { | ||
try { | ||
doWaterDisplacementImpl.invoke(null, ray); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
throw new RuntimeException("Could not invoke doWaterDisplacement", e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters