Start migration
This commit is contained in:
parent
6630ce0cab
commit
47ed597358
491 changed files with 12045 additions and 11953 deletions
|
@ -7,16 +7,16 @@ import java.lang.reflect.Method;
|
|||
|
||||
import net.fabricmc.fabric.api.tag.TagRegistry;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tag.BlockTags;
|
||||
import net.minecraft.tag.ItemTags;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.tag.Tag.Identified;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.Tag.Identified;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
|
@ -27,63 +27,65 @@ import ru.betterend.world.features.EndFeature;
|
|||
|
||||
public abstract class ModIntegration {
|
||||
private final String modID;
|
||||
|
||||
public void register() {}
|
||||
|
||||
public void addBiomes() {}
|
||||
|
||||
|
||||
public void register() {
|
||||
}
|
||||
|
||||
public void addBiomes() {
|
||||
}
|
||||
|
||||
public ModIntegration(String modID) {
|
||||
this.modID = modID;
|
||||
}
|
||||
|
||||
public Identifier getID(String name) {
|
||||
return new Identifier(modID, name);
|
||||
|
||||
public ResourceLocation getID(String name) {
|
||||
return new ResourceLocation(modID, name);
|
||||
}
|
||||
|
||||
|
||||
public Block getBlock(String name) {
|
||||
return Registry.BLOCK.get(getID(name));
|
||||
}
|
||||
|
||||
|
||||
public Item getItem(String name) {
|
||||
return Registry.ITEM.get(getID(name));
|
||||
}
|
||||
|
||||
public BlockState getDefaultState(String name) {
|
||||
return getBlock(name).getDefaultState();
|
||||
return getBlock(name).defaultBlockState();
|
||||
}
|
||||
|
||||
|
||||
public RegistryKey<Biome> getKey(String name) {
|
||||
return RegistryKey.of(Registry.BIOME_KEY, getID(name));
|
||||
}
|
||||
|
||||
|
||||
public boolean modIsInstalled() {
|
||||
return FabricLoader.getInstance().isModLoaded(modID);
|
||||
}
|
||||
|
||||
|
||||
public EndFeature getFeature(String featureID, String configuredFeatureID, GenerationStep.Feature featureStep) {
|
||||
Feature<?> feature = Registry.FEATURE.get(getID(featureID));
|
||||
ConfiguredFeature<?, ?> featureConfigured = BuiltinRegistries.CONFIGURED_FEATURE.get(getID(configuredFeatureID));
|
||||
ConfiguredFeature<?, ?> featureConfigured = BuiltinRegistries.CONFIGURED_FEATURE
|
||||
.get(getID(configuredFeatureID));
|
||||
return new EndFeature(feature, featureConfigured, featureStep);
|
||||
}
|
||||
|
||||
|
||||
public EndFeature getFeature(String name, GenerationStep.Feature featureStep) {
|
||||
return getFeature(name, name, featureStep);
|
||||
}
|
||||
|
||||
|
||||
public ConfiguredFeature<?, ?> getConfiguredFeature(String name) {
|
||||
return BuiltinRegistries.CONFIGURED_FEATURE.get(getID(name));
|
||||
}
|
||||
|
||||
|
||||
public Biome getBiome(String name) {
|
||||
return BuiltinRegistries.BIOME.get(getID(name));
|
||||
}
|
||||
|
||||
|
||||
public Class<?> getClass(String path) {
|
||||
Class<?> cl = null;
|
||||
try {
|
||||
cl = Class.forName(path);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
} catch (ClassNotFoundException e) {
|
||||
BetterEnd.LOGGER.error(e.getMessage());
|
||||
if (BetterEnd.isDevEnvironment()) {
|
||||
e.printStackTrace();
|
||||
|
@ -91,7 +93,7 @@ public abstract class ModIntegration {
|
|||
}
|
||||
return cl;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Object> T getStaticFieldValue(Class<?> cl, String name) {
|
||||
if (cl != null) {
|
||||
|
@ -100,14 +102,13 @@ public abstract class ModIntegration {
|
|||
if (field != null) {
|
||||
return (T) field.get(null);
|
||||
}
|
||||
}
|
||||
catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Object getFieldValue(Class<?> cl, String name, Object classInstance) {
|
||||
if (cl != null) {
|
||||
try {
|
||||
|
@ -115,20 +116,18 @@ public abstract class ModIntegration {
|
|||
if (field != null) {
|
||||
return field.get(classInstance);
|
||||
}
|
||||
}
|
||||
catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Method getMethod(Class<?> cl, String functionName, Class<?>... args) {
|
||||
if (cl != null) {
|
||||
try {
|
||||
return cl.getMethod(functionName, args);
|
||||
}
|
||||
catch (NoSuchMethodException | SecurityException e) {
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
BetterEnd.LOGGER.error(e.getMessage());
|
||||
if (BetterEnd.isDevEnvironment()) {
|
||||
e.printStackTrace();
|
||||
|
@ -137,13 +136,12 @@ public abstract class ModIntegration {
|
|||
}
|
||||
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) {
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
BetterEnd.LOGGER.error(e.getMessage());
|
||||
if (BetterEnd.isDevEnvironment()) {
|
||||
e.printStackTrace();
|
||||
|
@ -152,7 +150,7 @@ public abstract class ModIntegration {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Object getAndExecuteStatic(Class<?> cl, String functionName, Object... args) {
|
||||
if (cl != null) {
|
||||
Class<?>[] classes = new Class<?>[args.length];
|
||||
|
@ -164,9 +162,10 @@ public abstract class ModIntegration {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Object> T getAndExecuteRuntime(Class<?> cl, Object instance, String functionName, Object... args) {
|
||||
public <T extends Object> T getAndExecuteRuntime(Class<?> cl, Object instance, String functionName,
|
||||
Object... args) {
|
||||
if (instance != null) {
|
||||
Class<?>[] classes = new Class<?>[args.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
|
@ -177,15 +176,15 @@ public abstract class ModIntegration {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Object newInstance(Class<?> cl, Object... args) {
|
||||
if (cl != null) {
|
||||
for (Constructor<?> constructor: cl.getConstructors()) {
|
||||
for (Constructor<?> constructor : cl.getConstructors()) {
|
||||
if (constructor.getParameterCount() == args.length) {
|
||||
try {
|
||||
return constructor.newInstance(args);
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException e) {
|
||||
BetterEnd.LOGGER.error(e.getMessage());
|
||||
if (BetterEnd.isDevEnvironment()) {
|
||||
e.printStackTrace();
|
||||
|
@ -196,15 +195,15 @@ public abstract class ModIntegration {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Tag.Identified<Item> getItemTag(String name) {
|
||||
Identifier id = getID(name);
|
||||
ResourceLocation id = getID(name);
|
||||
Tag<Item> tag = ItemTags.getTagGroup().getTag(id);
|
||||
return tag == null ? (Identified<Item>) TagRegistry.item(id) : (Identified<Item>) tag;
|
||||
}
|
||||
|
||||
|
||||
public Tag.Identified<Block> getBlockTag(String name) {
|
||||
Identifier id = getID(name);
|
||||
ResourceLocation id = getID(name);
|
||||
Tag<Block> tag = BlockTags.getTagGroup().getTag(id);
|
||||
return tag == null ? (Identified<Block>) TagRegistry.block(id) : (Identified<Block>) tag;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue