Adorn integration (WIP)
This commit is contained in:
parent
64167386f9
commit
8833906cc9
4 changed files with 136 additions and 1 deletions
|
@ -8,7 +8,7 @@
|
||||||
loader_version=0.10.8
|
loader_version=0.10.8
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.8.5-beta
|
mod_version = 0.8.6-beta
|
||||||
maven_group = ru.betterend
|
maven_group = ru.betterend
|
||||||
archives_base_name = better-end
|
archives_base_name = better-end
|
||||||
|
|
||||||
|
|
27
src/main/java/ru/betterend/integration/AdornIntegration.java
Normal file
27
src/main/java/ru/betterend/integration/AdornIntegration.java
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package ru.betterend.integration;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import ru.betterend.BetterEnd;
|
||||||
|
|
||||||
|
public class AdornIntegration extends ModIntegration {
|
||||||
|
public AdornIntegration() {
|
||||||
|
super("adorn");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register() {
|
||||||
|
Class<?> adornBlockBuilder = getClass("juuxel.adorn.api.block.AdornBlockBuilder");
|
||||||
|
Class<?> blockVariantWood = getClass("juuxel.adorn.api.block.BlockVariant$Wood");
|
||||||
|
Class<?> blockVariant = getClass("juuxel.adorn.api.block.BlockVariant");
|
||||||
|
|
||||||
|
Object testVariant = newInstance(blockVariantWood, BetterEnd.MOD_ID + "/mossy_glowshroom");
|
||||||
|
Method create = getMethod(adornBlockBuilder, "create", blockVariant);
|
||||||
|
Object builder = executeMethod(adornBlockBuilder, create, testVariant);
|
||||||
|
getAndExecuteRuntime(builder, "withEverything");
|
||||||
|
getAndExecuteRuntime(builder, "registerIn", "adorn");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBiomes() {}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import ru.betterend.integration.byg.BYGIntegration;
|
||||||
public class Integrations {
|
public class Integrations {
|
||||||
public static final List<ModIntegration> INTEGRATIONS = Lists.newArrayList();
|
public static final List<ModIntegration> INTEGRATIONS = Lists.newArrayList();
|
||||||
public static final ModIntegration BYG = register(new BYGIntegration());
|
public static final ModIntegration BYG = register(new BYGIntegration());
|
||||||
|
public static final ModIntegration ADORN = register(new AdornIntegration());
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
INTEGRATIONS.forEach((integration) -> {
|
INTEGRATIONS.forEach((integration) -> {
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package ru.betterend.integration;
|
package ru.betterend.integration;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
@ -11,6 +15,7 @@ import net.minecraft.world.biome.Biome;
|
||||||
import net.minecraft.world.gen.GenerationStep;
|
import net.minecraft.world.gen.GenerationStep;
|
||||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||||
import net.minecraft.world.gen.feature.Feature;
|
import net.minecraft.world.gen.feature.Feature;
|
||||||
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.world.features.EndFeature;
|
import ru.betterend.world.features.EndFeature;
|
||||||
|
|
||||||
public abstract class ModIntegration {
|
public abstract class ModIntegration {
|
||||||
|
@ -61,4 +66,106 @@ public abstract class ModIntegration {
|
||||||
public Biome getBiome(String name) {
|
public Biome getBiome(String name) {
|
||||||
return BuiltinRegistries.BIOME.get(getID(name));
|
return BuiltinRegistries.BIOME.get(getID(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Class<?> getClass(String path) {
|
||||||
|
Class<?> cl = null;
|
||||||
|
try {
|
||||||
|
cl = Class.forName(path);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
|
BetterEnd.LOGGER.error(e.getMessage());
|
||||||
|
if (BetterEnd.isDevEnvironment()) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Method getMethod(Class<?> cl, String functionName, Class<?>... args) {
|
||||||
|
if (cl != null) {
|
||||||
|
try {
|
||||||
|
return cl.getMethod(functionName, args);
|
||||||
|
}
|
||||||
|
catch (NoSuchMethodException | SecurityException e) {
|
||||||
|
BetterEnd.LOGGER.error(e.getMessage());
|
||||||
|
if (BetterEnd.isDevEnvironment()) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Method getInstanceMethod(Object instance, String functionName, Class<?>... args) {
|
||||||
|
if (instance != null) {
|
||||||
|
try {
|
||||||
|
return instance.getClass().getDeclaredMethod(functionName, args);
|
||||||
|
}
|
||||||
|
catch (NoSuchMethodException | SecurityException e) {
|
||||||
|
BetterEnd.LOGGER.error(e.getMessage());
|
||||||
|
if (BetterEnd.isDevEnvironment()) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object executeMethod(Object instance, Method method, Object... args) {
|
||||||
|
if (method != null) {
|
||||||
|
try {
|
||||||
|
return method.invoke(instance, args);
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||||
|
BetterEnd.LOGGER.error(e.getMessage());
|
||||||
|
if (BetterEnd.isDevEnvironment()) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getAndExecuteStatic(Class<?> cl, String functionName, Object... args) {
|
||||||
|
if (cl != null) {
|
||||||
|
Class<?>[] classes = new Class<?>[args.length];
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
classes[i] = args[i].getClass();
|
||||||
|
}
|
||||||
|
Method method = getMethod(cl, functionName, classes);
|
||||||
|
return executeMethod(null, method, args);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getAndExecuteRuntime(Object instance, String functionName, Object... args) {
|
||||||
|
if (instance != null) {
|
||||||
|
Class<?>[] classes = new Class<?>[args.length];
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
classes[i] = args[i].getClass();
|
||||||
|
}
|
||||||
|
Method method = getInstanceMethod(instance, functionName, classes);
|
||||||
|
return executeMethod(instance, method, args);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object newInstance(Class<?> cl, Object... args) {
|
||||||
|
if (cl != null) {
|
||||||
|
for (Constructor<?> constructor: cl.getConstructors()) {
|
||||||
|
if (constructor.getParameterCount() == args.length) {
|
||||||
|
try {
|
||||||
|
return constructor.newInstance(args);
|
||||||
|
}
|
||||||
|
catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||||
|
BetterEnd.LOGGER.error(e.getMessage());
|
||||||
|
if (BetterEnd.isDevEnvironment()) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue