|
1 | 1 | package yalter.mousetweaks.forge; |
2 | 2 |
|
| 3 | +import net.minecraftforge.api.distmarker.Dist; |
3 | 4 | import net.minecraftforge.client.event.ScreenEvent.MouseButtonPressed; |
4 | 5 | import net.minecraftforge.client.event.ScreenEvent.MouseButtonReleased; |
5 | 6 | import net.minecraftforge.client.event.ScreenEvent.MouseDragged; |
6 | 7 | import net.minecraftforge.client.event.ScreenEvent.MouseScrolled; |
7 | 8 | import net.minecraftforge.common.MinecraftForge; |
8 | 9 | import net.minecraftforge.eventbus.api.bus.BusGroup; |
| 10 | +import net.minecraftforge.eventbus.api.bus.EventBus; |
9 | 11 | import net.minecraftforge.eventbus.api.listener.SubscribeEvent; |
10 | 12 | import net.minecraftforge.fml.common.Mod; |
| 13 | +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; |
| 14 | +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; |
| 15 | +import net.minecraftforge.fml.loading.FMLEnvironment; |
11 | 16 | import yalter.mousetweaks.*; |
12 | 17 |
|
13 | 18 | import java.lang.invoke.MethodHandles; |
14 | 19 |
|
15 | 20 | @Mod(Constants.MOD_ID) |
16 | 21 | public class MouseTweaksForge { |
17 | | - public MouseTweaksForge() { |
18 | | - Main.initialize(); |
| 22 | + public MouseTweaksForge(FMLJavaModLoadingContext context) { |
| 23 | + if (FMLEnvironment.dist != Dist.CLIENT) { |
| 24 | + Logger.Log("Disabled because not running on the client."); |
| 25 | + return; |
| 26 | + } |
| 27 | + |
19 | 28 | BusGroup.DEFAULT.register(MethodHandles.lookup(), this); |
20 | 29 |
|
21 | 30 | MinecraftForge.registerConfigScreen(ConfigScreen::new); |
22 | 31 | } |
23 | 32 |
|
| 33 | + @Mod.EventBusSubscriber(modid = Constants.MOD_ID, value = Dist.CLIENT) |
| 34 | + public static class ClientModEvents { |
| 35 | + @SubscribeEvent |
| 36 | + public static void onClientSetup(FMLClientSetupEvent event) { |
| 37 | + // Minecraft.getInstance() is now non-null in this event handler. |
| 38 | + Main.initialize(); |
| 39 | + } |
| 40 | + } |
| 41 | + |
24 | 42 | @SubscribeEvent |
25 | 43 | public boolean onGuiMouseClickedPre(MouseButtonPressed.Pre event) { |
26 | 44 | Logger.DebugLog("onGuiMouseClickedPre button = " + event.getButton()); |
|
0 commit comments