Skip to content

Commit 731e179

Browse files
committed
Add a command to open config screen
1 parent c16368e commit 731e179

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

‎changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Updated to mc26.1.2
66
- Removed refmap usages
7+
- Added a command to open the config screen
78

89
## 3.0.0
910

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* EffectTimerPlus
3+
* Copyright (C) 2026 TerminalMC
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation, version 3 of the License.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package dev.terminalmc.effecttimerplus.command;
19+
20+
import com.mojang.brigadier.Command;
21+
import com.mojang.brigadier.CommandDispatcher;
22+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
23+
import dev.terminalmc.effecttimerplus.EffectTimerPlus;
24+
import dev.terminalmc.effecttimerplus.gui.screen.ConfigScreenProvider;
25+
import net.minecraft.client.Minecraft;
26+
import net.minecraft.commands.CommandBuildContext;
27+
28+
import static net.minecraft.commands.Commands.literal;
29+
30+
public class Commands {
31+
32+
private Commands() {
33+
throw new UnsupportedOperationException("This class cannot be instantiated.");
34+
}
35+
36+
public static <S> void register(CommandDispatcher<S> dispatcher, CommandBuildContext buildCtx) {
37+
Minecraft mc = Minecraft.getInstance();
38+
//noinspection unchecked
39+
dispatcher.register((LiteralArgumentBuilder<S>) literal(EffectTimerPlus.MOD_ID)
40+
.executes((ctx) -> {
41+
mc.schedule(() -> mc.setScreen(ConfigScreenProvider.getConfigScreen(null)));
42+
return Command.SINGLE_SUCCESS;
43+
})
44+
);
45+
}
46+
}

‎fabric/src/main/java/dev/terminalmc/effecttimerplus/EffectTimerPlusFabric.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717

1818
package dev.terminalmc.effecttimerplus;
1919

20+
import dev.terminalmc.effecttimerplus.command.Commands;
2021
import net.fabricmc.api.ClientModInitializer;
22+
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
2123

2224
@SuppressWarnings("unused")
2325
public class EffectTimerPlusFabric implements ClientModInitializer {
2426

2527
@Override
2628
public void onInitializeClient() {
29+
// Register all commands
30+
ClientCommandRegistrationCallback.EVENT.register(Commands::register);
31+
32+
// Initialize client
2733
EffectTimerPlus.init();
2834
}
2935
}

‎neoforge/src/main/java/dev/terminalmc/effecttimerplus/EffectTimerPlusNeoForge.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
package dev.terminalmc.effecttimerplus;
1919

20+
import dev.terminalmc.effecttimerplus.command.Commands;
2021
import dev.terminalmc.effecttimerplus.gui.screen.ConfigScreenProvider;
2122
import net.neoforged.api.distmarker.Dist;
23+
import net.neoforged.bus.api.SubscribeEvent;
2224
import net.neoforged.fml.ModLoadingContext;
25+
import net.neoforged.fml.common.EventBusSubscriber;
2326
import net.neoforged.fml.common.Mod;
27+
import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
2428
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
2529

2630
@Mod(
@@ -30,11 +34,28 @@
3034
public class EffectTimerPlusNeoForge {
3135

3236
public EffectTimerPlusNeoForge() {
37+
// Register config screen
3338
ModLoadingContext.get().registerExtensionPoint(
3439
IConfigScreenFactory.class,
3540
() -> (mc, parent) -> ConfigScreenProvider.getConfigScreen(parent)
3641
);
3742

43+
// Initialize client
3844
EffectTimerPlus.init();
3945
}
46+
47+
@EventBusSubscriber(
48+
modid = EffectTimerPlus.MOD_ID,
49+
value = Dist.CLIENT
50+
)
51+
static class ClientEventHandler {
52+
53+
/**
54+
* Registers all commands.
55+
*/
56+
@SubscribeEvent
57+
public static void onRegisterClientCommands(RegisterClientCommandsEvent event) {
58+
Commands.register(event.getDispatcher(), event.getBuildContext());
59+
}
60+
}
4061
}

0 commit comments

Comments
 (0)