|
| 1 | +package tcfplayz.chemicals; |
| 2 | + |
| 3 | +import net.fabricmc.api.ModInitializer; |
| 4 | +import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; |
| 5 | +import net.fabricmc.fabric.api.item.v1.FabricItemSettings; |
| 6 | + |
| 7 | +import net.minecraft.item.*; |
| 8 | +import net.minecraft.util.Identifier; |
| 9 | +import net.minecraft.util.registry.Registry; |
| 10 | + |
| 11 | +import org.reflections.Reflections; |
| 12 | + |
| 13 | +import tcfplayz.chemicals.blocks.*; |
| 14 | +import tcfplayz.chemicals.elements.*; |
| 15 | +import tcfplayz.chemicals.items.salt.Salt; |
| 16 | +import tcfplayz.misc.utils.blocks.Blocks; |
| 17 | +import tcfplayz.misc.utils.items.*; |
| 18 | + |
| 19 | +import java.lang.reflect.InvocationTargetException; |
| 20 | +import java.util.Set; |
| 21 | + |
| 22 | +public class ChemicalsInit implements ModInitializer { |
| 23 | + |
| 24 | + public static final String modid = "chemicals"; |
| 25 | + |
| 26 | + public static final ItemGroup chemical = FabricItemGroupBuilder.build( |
| 27 | + new Identifier(modid, "chemicals"), |
| 28 | + () -> new ItemStack(new Hydrogen())); |
| 29 | + public static final ItemGroup chemistryitems = FabricItemGroupBuilder.build( |
| 30 | + new Identifier(modid, "chemistryitems"), |
| 31 | + () -> new ItemStack(new AtomCollider())); |
| 32 | + public static final ItemGroup others = FabricItemGroupBuilder.build( |
| 33 | + new Identifier(modid, "otheritems"), |
| 34 | + () -> new ItemStack(new Salt())); |
| 35 | + |
| 36 | + @Override |
| 37 | + public void onInitialize() { |
| 38 | + Reflections reflections = new Reflections("tcfplayz.chemicals"); |
| 39 | + Set<Class<? extends Elements>> classelement = reflections.getSubTypesOf(Elements.class); |
| 40 | + for (Class<? extends Elements> clazz : classelement) { |
| 41 | + try { |
| 42 | + Registry.register(Registry.ITEM, new Identifier(modid, clazz.getDeclaredConstructor().newInstance().getID()), clazz.getDeclaredConstructor().newInstance()); |
| 43 | + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { |
| 44 | + e.printStackTrace(); |
| 45 | + } |
| 46 | + } |
| 47 | + Set<Class<? extends Blocks>> classblock = reflections.getSubTypesOf(Blocks.class); |
| 48 | + for (Class<? extends Blocks> clazz : classblock) { |
| 49 | + try { |
| 50 | + Blocks blocks = clazz.getDeclaredConstructor().newInstance(); |
| 51 | + Identifier id = new Identifier(modid, blocks.getID()); |
| 52 | + Registry.register(Registry.BLOCK, id, blocks); |
| 53 | + Registry.register(Registry.ITEM, id, new BlockItem(blocks, new FabricItemSettings().group(ChemicalsInit.chemistryitems))); |
| 54 | + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { |
| 55 | + e.printStackTrace(); |
| 56 | + } |
| 57 | + } |
| 58 | + /* Set<Class<? extends BossCreator>> classblock2 = reflections.getSubTypesOf(BossCreator.class); |
| 59 | + for (Class<? extends BossCreator> clazz : classblock2) { |
| 60 | + try { |
| 61 | + Constructor<? extends BossCreator> entity = clazz.getDeclaredConstructor(); |
| 62 | + BossCreator e = clazz.getDeclaredConstructor().newInstance(); |
| 63 | + final EntityType<BossCreator> CUBE = Registry.register( |
| 64 | + Registry.ENTITY_TYPE, |
| 65 | + new Identifier("entitytesting", "cube"), |
| 66 | + FabricEntityTypeBuilder.create(SpawnGroup.CREATURE, e).dimensions(EntityDimensions.fixed(0.75f, 0.75f)).build() |
| 67 | + ); |
| 68 | + Identifier id = new Identifier(modid, blocks.getID()); |
| 69 | +
|
| 70 | + System.out.println("registered " + blocks.getID()); |
| 71 | + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { |
| 72 | + e.printStackTrace(); |
| 73 | + } |
| 74 | + } */ |
| 75 | + Set<Class<? extends Solutions>> solution = reflections.getSubTypesOf(Solutions.class); |
| 76 | + for (Class<? extends Solutions> clazz : solution) { |
| 77 | + try { |
| 78 | + Registry.register(Registry.ITEM, new Identifier(modid, clazz.getDeclaredConstructor().newInstance().getID()), clazz.getDeclaredConstructor().newInstance()); |
| 79 | + System.out.println("registered " + clazz.getDeclaredConstructor().newInstance().getID()); |
| 80 | + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { |
| 81 | + e.printStackTrace(); |
| 82 | + } |
| 83 | + } |
| 84 | + Set<Class<? extends OtherItems>> items = reflections.getSubTypesOf(OtherItems.class); |
| 85 | + for (Class<? extends OtherItems> clazz : items) { |
| 86 | + try { |
| 87 | + Registry.register(Registry.ITEM, new Identifier(modid, clazz.getDeclaredConstructor().newInstance().getID()), clazz.getDeclaredConstructor().newInstance()); |
| 88 | + System.out.println("registered " + clazz.getDeclaredConstructor().newInstance().getID()); |
| 89 | + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { |
| 90 | + e.printStackTrace(); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments