|
1 | 1 | package com.neofastftl.infinitypattern; |
2 | 2 |
|
| 3 | +import com.neofastftl.infinitypattern.registries.ModItems; |
| 4 | +import com.neofastftl.infinitypattern.registries.ModCreativeTabs; |
| 5 | +import com.neofastftl.infinitypattern.guidebook.IFPATGuide; |
3 | 6 | import org.slf4j.Logger; |
4 | 7 |
|
5 | 8 | import com.mojang.logging.LogUtils; |
6 | 9 |
|
7 | | -import net.minecraft.client.Minecraft; |
8 | | -import net.minecraft.core.registries.BuiltInRegistries; |
9 | 10 | import net.minecraft.core.registries.Registries; |
10 | 11 | import net.minecraft.network.chat.Component; |
11 | 12 | import net.minecraft.world.item.CreativeModeTab; |
12 | 13 | import net.minecraft.world.item.CreativeModeTabs; |
13 | 14 | import net.minecraft.world.item.Item; |
14 | | -import net.minecraft.world.level.block.Blocks; |
15 | | -import net.neoforged.api.distmarker.Dist; |
16 | 15 | import net.neoforged.bus.api.IEventBus; |
17 | | -import net.neoforged.bus.api.SubscribeEvent; |
18 | | -import net.neoforged.fml.ModContainer; |
19 | | -import net.neoforged.fml.common.EventBusSubscriber; |
20 | 16 | import net.neoforged.fml.common.Mod; |
21 | | -import net.neoforged.fml.config.ModConfig; |
22 | | -import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; |
23 | | -import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; |
24 | | -import net.neoforged.neoforge.common.NeoForge; |
25 | | -import net.neoforged.neoforge.event.server.ServerStartingEvent; |
26 | 17 | import net.neoforged.neoforge.registries.DeferredHolder; |
27 | 18 | import net.neoforged.neoforge.registries.DeferredItem; |
28 | 19 | import net.neoforged.neoforge.registries.DeferredRegister; |
29 | 20 |
|
30 | | -import static net.minecraft.world.item.Items.registerItem; |
31 | | - |
32 | | -// The value here should match an entry in the META-INF/neoforge.mods.toml file |
33 | 21 | @Mod(InfinityPattern.MODID) |
34 | | -public class InfinityPattern |
35 | | -{ |
36 | | - // Define mod id in a common place for everything to reference |
| 22 | +public class InfinityPattern { |
37 | 23 | public static final String MODID = "infinitypattern"; |
38 | | - // Directly reference a slf4j logger |
39 | | - public static final Logger LOGGER = LogUtils.getLogger(); |
40 | | - // Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace |
41 | | - public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(InfinityPattern.MODID); |
42 | | - // Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace |
43 | | - public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); |
44 | | - |
45 | | - // Creates a new food item with the id "examplemod:example_id", nutrition 1 and saturation 2 |
46 | | - public static final DeferredItem<Item> ITEM_INFINITE_EMPTY_PATTERN = ITEMS.register("infinite_empty_pattern", |
47 | | - () -> new Item(new Item.Properties().stacksTo(1))); |
48 | | - |
49 | | - // Creates a creative tab with the id "examplemod:example_tab" for the example item, that is placed after the combat tab |
50 | | - public static final DeferredHolder<CreativeModeTab, CreativeModeTab> INFINITY_PATTERN = CREATIVE_MODE_TABS.register("infinitypattern", () -> CreativeModeTab.builder() |
51 | | - .title(Component.translatable("itemGroup.infinitypattern")) //The language key for the title of your CreativeModeTab |
52 | | - .withTabsBefore(CreativeModeTabs.COMBAT) |
53 | | - .icon(() -> ITEM_INFINITE_EMPTY_PATTERN.get().getDefaultInstance()) |
54 | | - .displayItems((parameters, output) -> { |
55 | | - output.accept(ITEM_INFINITE_EMPTY_PATTERN.get()); // Add the example item to the tab. For your own tabs, this method is preferred over the event |
56 | | - }).build()); |
57 | | - |
58 | | - // The constructor for the mod class is the first code that is run when your mod is loaded. |
59 | | - // FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically. |
60 | | - public InfinityPattern(IEventBus modEventBus, ModContainer modContainer) |
61 | | - { |
62 | | - // Register the commonSetup method for modloading |
63 | | - modEventBus.addListener(this::commonSetup); |
64 | | - |
65 | | - // Register the Deferred Register to the mod event bus so items get registered |
66 | | - ITEMS.register(modEventBus); |
67 | | - // Register the Deferred Register to the mod event bus so tabs get registered |
68 | | - CREATIVE_MODE_TABS.register(modEventBus); |
69 | | - |
70 | | - // Register ourselves for server and other game events we are interested in. |
71 | | - // Note that this is necessary if and only if we want *this* class (ExampleMod) to respond directly to events. |
72 | | - // Do not add this line if there are no @SubscribeEvent-annotated functions in this class, like onServerStarting() below. |
73 | | - NeoForge.EVENT_BUS.register(this); |
74 | | - |
75 | | - // Register our mod's ModConfigSpec so that FML can create and load the config file for us |
76 | | - modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC); |
77 | | - } |
78 | | - |
79 | | - private void commonSetup(final FMLCommonSetupEvent event) |
80 | | - { |
81 | | - // Some common setup code |
82 | | - LOGGER.info("HELLO FROM COMMON SETUP"); |
83 | | - |
84 | | - if (Config.logDirtBlock) |
85 | | - LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT)); |
86 | | - |
87 | | - LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber); |
88 | | - |
89 | | - Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString())); |
90 | | - } |
91 | | - |
92 | | - // You can use SubscribeEvent and let the Event Bus discover methods to call |
93 | | - @SubscribeEvent |
94 | | - public void onServerStarting(ServerStartingEvent event) |
95 | | - { |
96 | | - // Do something when the server starts |
97 | | - LOGGER.info("HELLO from server starting"); |
98 | | - } |
99 | 24 |
|
100 | | - // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent |
101 | | - @EventBusSubscriber(modid = MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) |
102 | | - public static class ClientModEvents |
103 | | - { |
104 | | - @SubscribeEvent |
105 | | - public static void onClientSetup(FMLClientSetupEvent event) |
106 | | - { |
107 | | - // Some client setup code |
108 | | - LOGGER.info("HELLO FROM CLIENT SETUP"); |
109 | | - LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName()); |
110 | | - } |
| 25 | + public InfinityPattern(IEventBus modEventBus) { |
| 26 | + ModItems.ITEMS.register(modEventBus); |
| 27 | + ModCreativeTabs.CREATIVE_MODE_TABS.register(modEventBus); |
| 28 | + IFPATGuide.init(); |
111 | 29 | } |
112 | 30 | } |
0 commit comments