|
4 | 4 | import band.kessokuteatime.nightautoconfig.config.base.ConfigType; |
5 | 5 | import me.shedaniel.autoconfig.AutoConfig; |
6 | 6 | import me.shedaniel.autoconfig.ConfigHolder; |
7 | | -import net.fabricmc.api.ClientModInitializer; |
8 | | -import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; |
9 | | -import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents; |
10 | | -import net.fabricmc.loader.api.FabricLoader; |
11 | 7 | import band.kessokuteatime.splasher.config.SplasherConfig; |
12 | 8 | import net.minecraft.client.MinecraftClient; |
| 9 | +import net.minecraft.client.gui.screen.Screen; |
13 | 10 | import net.minecraft.client.gui.screen.TitleScreen; |
14 | 11 | import net.minecraft.client.sound.PositionedSoundInstance; |
15 | 12 | import net.minecraft.sound.SoundEvents; |
16 | 13 | import net.minecraft.text.MutableText; |
17 | 14 | import net.minecraft.text.Text; |
18 | 15 | import net.minecraft.util.Formatting; |
| 16 | +import net.neoforged.fml.ModList; |
| 17 | +import net.neoforged.fml.ModLoadingContext; |
| 18 | +import net.neoforged.fml.common.Mod; |
| 19 | +import net.neoforged.neoforge.client.event.ScreenEvent; |
| 20 | +import net.neoforged.neoforge.client.gui.IConfigScreenFactory; |
| 21 | +import net.neoforged.neoforge.common.NeoForge; |
19 | 22 | import org.slf4j.Logger; |
20 | 23 | import org.slf4j.LoggerFactory; |
21 | 24 |
|
22 | 25 | import java.util.ArrayList; |
23 | 26 | import java.util.Objects; |
24 | 27 | import java.util.concurrent.atomic.AtomicBoolean; |
25 | 28 |
|
26 | | -public class Splasher implements ClientModInitializer { |
| 29 | +@Mod(Splasher.ID) |
| 30 | +public class Splasher { |
27 | 31 | public static final String NAME = "Splasher", ID = "splasher"; |
28 | 32 | public static final Logger LOGGER = LoggerFactory.getLogger(ID); |
29 | 33 | public static final ConfigHolder<SplasherConfig> CONFIG; |
@@ -79,25 +83,33 @@ public static boolean shouldSplash() { |
79 | 83 | private static float height = 0, width = 0; |
80 | 84 | public static boolean initialized = false; |
81 | 85 |
|
82 | | - @Override |
83 | | - public void onInitializeClient() { |
84 | | - boolean isBouncedLoaded = FabricLoader.getInstance().isModLoaded("bounced"); |
85 | | - |
86 | | - ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> { |
87 | | - if (screen instanceof TitleScreen) { |
88 | | - ScreenMouseEvents.beforeMouseClick(screen) |
89 | | - .register((currentScreen, mouseX, mouseY, button) -> { |
90 | | - // Linkage with Bounced |
91 | | - if (isBouncedLoaded) |
92 | | - mouseY -= Bounced.primaryPos(); |
93 | | - |
94 | | - if (isMouseHovering(scaledWidth, mouseX, mouseY) && CONFIG.get().texts.randomRate.onClick()) { |
95 | | - push(); |
96 | | - playClickingSound(); |
97 | | - } |
98 | | - }); |
99 | | - } |
100 | | - }); |
| 86 | + public Splasher() { |
| 87 | + ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> (modContainer, screen) -> { |
| 88 | + CONFIG.load(); |
| 89 | + return AutoConfig.getConfigScreen(SplasherConfig.class, screen).get(); |
| 90 | + }); |
| 91 | + |
| 92 | + boolean isBouncedLoaded = ModList.get().isLoaded("bounced"); |
| 93 | + |
| 94 | + NeoForge.EVENT_BUS.addListener(ScreenEvent.Init.Post.class, screenInitEvent -> { |
| 95 | + Screen screen = screenInitEvent.getScreen(); |
| 96 | + if (screen instanceof TitleScreen) { |
| 97 | + NeoForge.EVENT_BUS.addListener(ScreenEvent.MouseButtonPressed.Post.class, screenMousePressedEvent -> { |
| 98 | + double mouseX = screenMousePressedEvent.getMouseX(); |
| 99 | + double mouseY = screenMousePressedEvent.getMouseY(); |
| 100 | + double scaledWidth = screen.width; |
| 101 | + |
| 102 | + // Linkage with Bounced |
| 103 | + if (isBouncedLoaded) |
| 104 | + mouseY -= Bounced.primaryPos(); |
| 105 | + |
| 106 | + if (isMouseHovering(scaledWidth, mouseX, mouseY) && CONFIG.get().texts.randomRate.onClick()) { |
| 107 | + push(); |
| 108 | + playClickingSound(); |
| 109 | + } |
| 110 | + }); |
| 111 | + } |
| 112 | + }); |
101 | 113 | } |
102 | 114 |
|
103 | 115 | public static void playClickingSound() { |
|
0 commit comments