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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
package moe.nea.firmament.commands
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.StringArgumentType.string
import io.ktor.client.statement.bodyAsText
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.minecraft.nbt.NbtOps
import net.minecraft.text.Text
import net.minecraft.text.TextCodecs
import moe.nea.firmament.apis.UrsaManager
import moe.nea.firmament.events.CommandEvent
import moe.nea.firmament.events.FirmamentEventBus
import moe.nea.firmament.features.debug.DebugLogger
import moe.nea.firmament.features.debug.PowerUserTools
import moe.nea.firmament.features.inventory.buttons.InventoryButtons
import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlayScreen
import moe.nea.firmament.features.inventory.storageoverlay.StorageOverviewScreen
import moe.nea.firmament.gui.config.AllConfigsGui
import moe.nea.firmament.gui.config.BooleanHandler
import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.gui.config.ManagedOption
import moe.nea.firmament.init.MixinPlugin
import moe.nea.firmament.repo.HypixelStaticData
import moe.nea.firmament.repo.ItemCache
import moe.nea.firmament.repo.RepoDownloadManager
import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.FirmFormatters
import moe.nea.firmament.util.FirmFormatters.debugPath
import moe.nea.firmament.util.FirmFormatters.formatBool
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SBData
import moe.nea.firmament.util.ScreenUtil
import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.accessors.messages
import moe.nea.firmament.util.collections.InstanceList
import moe.nea.firmament.util.collections.WeakCache
import moe.nea.firmament.util.mc.SNbtFormatter
import moe.nea.firmament.util.tr
import moe.nea.firmament.util.unformattedString
fun firmamentCommand() = literal("firmament") {
thenLiteral("config") {
thenExecute {
AllConfigsGui.showAllGuis()
}
thenLiteral("toggle") {
thenArgument("config", string()) { config ->
suggestsList {
ManagedConfig.allManagedConfigs.getAll().asSequence().map { it.name }.asIterable()
}
thenArgument("property", string()) { property ->
suggestsList {
(ManagedConfig.allManagedConfigs.getAll().find { it.name == this[config] }
?: return@suggestsList listOf())
.allOptions.entries.asSequence().filter { it.value.handler is BooleanHandler }
.map { it.key }
.asIterable()
}
thenExecute {
val config = this[config]
val property = this[property]
val configObj = ManagedConfig.allManagedConfigs.getAll().find { it.name == config }
if (configObj == null) {
source.sendFeedback(
Text.stringifiedTranslatable(
"firmament.command.toggle.no-config-found",
config
)
)
return@thenExecute
}
val propertyObj = configObj.allOptions[property]
if (propertyObj == null) {
source.sendFeedback(
Text.stringifiedTranslatable("firmament.command.toggle.no-property-found", property)
)
return@thenExecute
}
if (propertyObj.handler !is BooleanHandler) {
source.sendFeedback(
Text.stringifiedTranslatable("firmament.command.toggle.not-a-toggle", property)
)
return@thenExecute
}
propertyObj as ManagedOption<Boolean>
propertyObj.value = !propertyObj.value
configObj.save()
source.sendFeedback(
Text.stringifiedTranslatable(
"firmament.command.toggle.toggled", configObj.labelText,
propertyObj.labelText,
Text.translatable("firmament.toggle.${propertyObj.value}")
)
)
}
}
}
}
}
thenLiteral("buttons") {
thenExecute {
InventoryButtons.openEditor()
}
}
thenLiteral("sendcoords") {
thenExecute {
val p = MC.player ?: return@thenExecute
MC.sendServerChat("x: ${p.blockX}, y: ${p.blockY}, z: ${p.blockZ}")
}
thenArgument("rest", RestArgumentType) { rest ->
thenExecute {
val p = MC.player ?: return@thenExecute
MC.sendServerChat("x: ${p.blockX}, y: ${p.blockY}, z: ${p.blockZ} ${this[rest]}")
}
}
}
thenLiteral("storageoverview") {
thenExecute {
ScreenUtil.setScreenLater(StorageOverviewScreen())
MC.player?.networkHandler?.sendChatCommand("storage")
}
}
thenLiteral("storage") {
thenExecute {
ScreenUtil.setScreenLater(StorageOverlayScreen())
MC.player?.networkHandler?.sendChatCommand("storage")
}
}
thenLiteral("repo") {
thenLiteral("reload") {
thenLiteral("fetch") {
thenExecute {
source.sendFeedback(Text.translatable("firmament.repo.reload.network")) // TODO better reporting
RepoManager.launchAsyncUpdate()
}
}
thenExecute {
source.sendFeedback(Text.translatable("firmament.repo.reload.disk"))
RepoManager.reload()
}
}
}
thenLiteral("price") {
thenArgument("item", string()) { item ->
suggestsList { RepoManager.neuRepo.items.items.keys }
thenExecute {
val itemName = SkyblockId(get(item))
source.sendFeedback(Text.stringifiedTranslatable("firmament.price", itemName.neuItem))
val bazaarData = HypixelStaticData.bazaarData[itemName]
if (bazaarData != null) {
source.sendFeedback(Text.translatable("firmament.price.bazaar"))
source.sendFeedback(
Text.stringifiedTranslatable("firmament.price.bazaar.productid", bazaarData.productId.bazaarId)
)
source.sendFeedback(
Text.stringifiedTranslatable(
"firmament.price.bazaar.buy.price",
FirmFormatters.formatCommas(bazaarData.quickStatus.buyPrice, 1)
)
)
source.sendFeedback(
Text.stringifiedTranslatable(
"firmament.price.bazaar.buy.order",
bazaarData.quickStatus.buyOrders
)
)
source.sendFeedback(
Text.stringifiedTranslatable(
"firmament.price.bazaar.sell.price",
FirmFormatters.formatCommas(bazaarData.quickStatus.sellPrice, 1)
)
)
source.sendFeedback(
Text.stringifiedTranslatable(
"firmament.price.bazaar.sell.order",
bazaarData.quickStatus.sellOrders
)
)
}
val lowestBin = HypixelStaticData.lowestBin[itemName]
if (lowestBin != null) {
source.sendFeedback(
Text.stringifiedTranslatable(
"firmament.price.lowestbin",
FirmFormatters.formatCommas(lowestBin, 1)
)
)
}
}
}
}
thenLiteral("dev") {
thenLiteral("simulate") {
thenArgument("message", RestArgumentType) { message ->
thenExecute {
MC.instance.messageHandler.onGameMessage(Text.literal(get(message)), false)
}
}
}
thenLiteral("debuglog") {
thenLiteral("toggle") {
thenArgument("tag", string()) { tag ->
suggestsList { DebugLogger.allInstances.getAll().map { it.tag } + DebugLogger.EnabledLogs.data }
thenExecute {
val tagText = this[tag]
val enabled = DebugLogger.EnabledLogs.data
if (tagText in enabled) {
enabled.remove(tagText)
source.sendFeedback(Text.literal("Disabled $tagText debug logging"))
} else {
enabled.add(tagText)
source.sendFeedback(Text.literal("Enabled $tagText debug logging"))
}
}
}
}
}
thenLiteral("dumpchat") {
thenExecute {
MC.inGameHud.chatHud.messages.forEach {
val nbt = TextCodecs.CODEC.encodeStart(NbtOps.INSTANCE, it.content).orThrow
println(nbt)
}
}
thenArgument("search", string()) { search ->
thenExecute {
MC.inGameHud.chatHud.messages
.filter { this[search] in it.content.unformattedString }
.forEach {
val nbt = TextCodecs.CODEC.encodeStart(NbtOps.INSTANCE, it.content).orThrow
println(SNbtFormatter.prettify(nbt))
}
}
}
}
thenLiteral("sbdata") {
thenExecute {
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.profile", SBData.profileId))
val locrawInfo = SBData.locraw
if (locrawInfo == null) {
source.sendFeedback(Text.translatable("firmament.sbinfo.nolocraw"))
} else {
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.server", locrawInfo.server))
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.gametype", locrawInfo.gametype))
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.mode", locrawInfo.mode))
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.map", locrawInfo.map))
}
}
}
thenLiteral("copyEntities") {
thenExecute {
val player = MC.player ?: return@thenExecute
player.world.getOtherEntities(player, player.boundingBox.expand(12.0))
.forEach(PowerUserTools::showEntity)
}
}
thenLiteral("callUrsa") {
thenArgument("path", string()) { path ->
thenExecute {
source.sendFeedback(Text.translatable("firmament.ursa.debugrequest.start"))
val text = UrsaManager.request(this[path].split("/")).bodyAsText()
source.sendFeedback(Text.stringifiedTranslatable("firmament.ursa.debugrequest.result", text))
}
}
}
thenLiteral("events") {
thenExecute {
source.sendFeedback(tr("firmament.event.start", "Event Bus Readout:"))
FirmamentEventBus.allEventBuses.forEach { eventBus ->
val prefixName = eventBus.eventType.typeName.removePrefix("moe.nea.firmament")
source.sendFeedback(tr(
"firmament.event.bustype",
"- $prefixName:"))
eventBus.handlers.forEach { handler ->
source.sendFeedback(tr(
"firmament.event.handler",
" * ${handler.label}"))
}
}
}
}
thenLiteral("caches") {
thenExecute {
source.sendFeedback(Text.literal("Caches:"))
WeakCache.allInstances.getAll().forEach {
source.sendFeedback(Text.literal(" - ${it.name}: ${it.size}"))
}
source.sendFeedback(Text.translatable("Instance lists:"))
InstanceList.allInstances.getAll().forEach {
source.sendFeedback(Text.literal(" - ${it.name}: ${it.size}"))
}
}
}
thenLiteral("mixins") {
thenExecute {
source.sendFeedback(Text.translatable("firmament.mixins.start"))
MixinPlugin.appliedMixins
.map { it.removePrefix(MixinPlugin.mixinPackage) }
.forEach {
source.sendFeedback(Text.literal(" - ").withColor(0xD020F0)
.append(Text.literal(it).withColor(0xF6BA20)))
}
}
}
thenLiteral("repo") {
thenExecute {
source.sendFeedback(tr("firmament.repo.info.ref", "Repo Upstream: ${RepoManager.getRepoRef()}"))
source.sendFeedback(tr("firmament.repo.info.downloadedref",
"Downloaded ref: ${RepoDownloadManager.latestSavedVersionHash}"))
source.sendFeedback(tr("firmament.repo.info.location",
"Saved location: ${debugPath(RepoDownloadManager.repoSavedLocation)}"))
source.sendFeedback(tr("firmament.repo.info.reloadstatus",
"Incomplete: ${
formatBool(RepoManager.neuRepo.isIncomplete,
trueIsGood = false)
}, Unstable ${formatBool(RepoManager.neuRepo.isUnstable, trueIsGood = false)}"))
source.sendFeedback(tr("firmament.repo.info.items",
"Loaded items: ${RepoManager.neuRepo.items?.items?.size}"))
source.sendFeedback(tr("firmament.repo.info.itemcache",
"ItemCache flawless: ${formatBool(ItemCache.isFlawless)}"))
source.sendFeedback(tr("firmament.repo.info.itemdir",
"Items on disk: ${debugPath(RepoDownloadManager.repoSavedLocation.resolve("items"))}"))
}
}
}
thenExecute {
AllConfigsGui.showAllGuis()
}
CommandEvent.SubCommand.publish(CommandEvent.SubCommand(this@literal))
}
fun registerFirmamentCommand(dispatcher: CommandDispatcher<FabricClientCommandSource>) {
val firmament = dispatcher.register(firmamentCommand())
dispatcher.register(literal("firm") {
redirect(firmament)
})
}
|