blob: 95e86857fc14b38340291e59fcd9deae8bf9fea3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package moe.nea.ultranotifier.commands
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import moe.nea.ultranotifier.UltraNotifier
import moe.nea.ultranotifier.event.CommandRegistrationEvent
import moe.nea.ultranotifier.event.SubscriptionTarget
import moe.nea.ultranotifier.event.UltraNotifierEvents
import moe.nea.ultranotifier.event.UltraSubscribe
import net.minecraft.text.Text
interface CustomSource {
fun sendFeedback(text: Text)
}
typealias UltraCommandSource =
//#if FORGE
//$$ CustomSource
//#else
net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
//#endif
fun translatableText(key: String, vararg args: String) =
//#if MC > 11400
Text.translatable(key, *args)
//#else
//$$ net.minecraft.util.ChatComponentTranslation(key, *args)
//#endif
fun literalText(string: String): Text =
//#if MC > 11400
Text.literal(string)
//#else
//$$ net.minecraft.util.ChatComponentText(string)
//#endif
object Commands : SubscriptionTarget {
@UltraSubscribe
fun registerTestCommand(event: CommandRegistrationEvent) {
event.dispatcher.register(LiteralArgumentBuilder.literal<UltraCommandSource>("hello")
.executes {
it.source.sendFeedback(literalText("Hello World"))
0
})
}
override fun init() {
//#if FORGE
//$$ UltraNotifierEvents.register(BrigadierPatchbay)
//#else
net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback.EVENT.register { dispatcher, registryAccess ->
UltraNotifierEvents.post(CommandRegistrationEvent(dispatcher))
}
//#endif
UltraNotifier.logger.info("Initialized command subsystem")
}
}
|