diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-11 18:03:22 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-11 18:03:27 +0200 |
commit | 658d51d0186aeaa7b23358d8200e157e6d709836 (patch) | |
tree | 6bd406db47d30281a81acfda68ef00f7e4b44f2f /src/main/kotlin | |
parent | 1cc8241032a320b84acab9250bd28b09d44e11fe (diff) | |
download | neuhax-658d51d0186aeaa7b23358d8200e157e6d709836.tar.gz neuhax-658d51d0186aeaa7b23358d8200e157e6d709836.tar.bz2 neuhax-658d51d0186aeaa7b23358d8200e157e6d709836.zip |
Add support for mod requirements
Diffstat (limited to 'src/main/kotlin')
12 files changed, 88 insertions, 120 deletions
diff --git a/src/main/kotlin/moe/nea/sky/NEUHax.kt b/src/main/kotlin/moe/nea/sky/NEUHax.kt index 581aff9..ac1551c 100644 --- a/src/main/kotlin/moe/nea/sky/NEUHax.kt +++ b/src/main/kotlin/moe/nea/sky/NEUHax.kt @@ -10,17 +10,26 @@ package moe.nea.sky -import io.github.moulberry.moulconfig.managed.ManagedConfig import io.github.moulberry.notenoughupdates.util.brigadier.BrigadierRoot +import io.github.notenoughupdates.moulconfig.Config +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption +import io.github.notenoughupdates.moulconfig.gui.GuiOptionEditor +import io.github.notenoughupdates.moulconfig.managed.ManagedDataFile +import io.github.notenoughupdates.moulconfig.processor.BuiltinMoulConfigGuis +import io.github.notenoughupdates.moulconfig.processor.ConfigProcessorDriver +import io.github.notenoughupdates.moulconfig.processor.MoulConfigProcessor +import io.github.notenoughupdates.moulconfig.processor.ProcessedOption import moe.nea.sky.commands.NEUHaxCommand +import moe.nea.sky.config.GuiOptionEditorNeedDependent +import moe.nea.sky.config.NeedsMod import moe.nea.sky.config.NeuHaxConfig -import moe.nea.sky.features.fopt.OptifineCustomItemCache import moe.nea.sky.features.gui.Enchanting import moe.nea.sky.features.gui.Melody import moe.nea.sky.features.meta.AutoUpdate import moe.nea.sky.features.world.AutoFishing import moe.nea.sky.features.world.YawSnapping import moe.nea.sky.util.CommandActionRegistry +import moe.nea.sky.util.MetaAnnotationUtil import net.minecraft.launchwrapper.Launch import net.minecraftforge.client.ClientCommandHandler import net.minecraftforge.common.MinecraftForge @@ -30,6 +39,7 @@ import net.minecraftforge.fml.common.Mod.EventHandler import net.minecraftforge.fml.common.event.FMLInitializationEvent import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import java.io.File +import java.lang.reflect.Field @Mod( @@ -42,7 +52,33 @@ object NEUHax { val version: String by lazy { Loader.instance().indexedModList[MODID]!!.version } - val config by lazy { ManagedConfig.create(File("config/neuhax/config.json"), NeuHaxConfig::class.java) } + val config by lazy { + ManagedDataFile.create(File("config/neuhax/config.json"), NeuHaxConfig::class.java) + } + + class ModLockedProcessor<T : Config>(configBaseObject: T) : MoulConfigProcessor<T>(configBaseObject) { + override fun createOptionGui( + processedOption: ProcessedOption, + field: Field, + option: ConfigOption, + ): GuiOptionEditor? { + val default = super.createOptionGui(processedOption, field, option) ?: return null + val neededMods = MetaAnnotationUtil.getMetaAnnotations(NeedsMod::class.java, field) + val missingMods = neededMods.filter { !Loader.isModLoaded(it.modId) } + if (missingMods.isNotEmpty()) { + return GuiOptionEditorNeedDependent(default, missingMods) + } + return default + } + } + + val configInstance by lazy { + val processor = ModLockedProcessor(config.instance) + BuiltinMoulConfigGuis.addProcessors(processor) + ConfigProcessorDriver(processor).processConfig(config.instance) + return@lazy processor + } + val deobf by lazy { Launch.blackboard["fml.deobfuscatedEnvironment"] == true } @@ -59,7 +95,6 @@ object NEUHax { YawSnapping, AutoUpdate, Melody, - OptifineCustomItemCache, ).forEach { MinecraftForge.EVENT_BUS.register(it) } diff --git a/src/main/kotlin/moe/nea/sky/commands/NEUHaxCommand.kt b/src/main/kotlin/moe/nea/sky/commands/NEUHaxCommand.kt index 8075c8d..a0d87c9 100644 --- a/src/main/kotlin/moe/nea/sky/commands/NEUHaxCommand.kt +++ b/src/main/kotlin/moe/nea/sky/commands/NEUHaxCommand.kt @@ -10,6 +10,8 @@ package moe.nea.sky.commands +import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper +import io.github.notenoughupdates.moulconfig.gui.MoulConfigEditor import io.github.moulberry.notenoughupdates.NotEnoughUpdates import moe.nea.sky.NEUHax import moe.nea.sky.util.showMessage @@ -38,7 +40,7 @@ object NEUHaxCommand : CommandBase() { val verb = args.singleOrNull() when (verb) { "config" -> { - NotEnoughUpdates.INSTANCE.openGui = NEUHax.config.getGui() + NotEnoughUpdates.INSTANCE.openGui = GuiScreenElementWrapper(MoulConfigEditor(NEUHax.configInstance)) } else -> { diff --git a/src/main/kotlin/moe/nea/sky/config/EnchantingConfig.kt b/src/main/kotlin/moe/nea/sky/config/EnchantingConfig.kt index 01212cc..daf5ebc 100644 --- a/src/main/kotlin/moe/nea/sky/config/EnchantingConfig.kt +++ b/src/main/kotlin/moe/nea/sky/config/EnchantingConfig.kt @@ -1,10 +1,10 @@ package moe.nea.sky.config import com.google.gson.annotations.Expose -import io.github.moulberry.moulconfig.annotations.Accordion -import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind -import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider -import io.github.moulberry.moulconfig.annotations.ConfigOption +import io.github.notenoughupdates.moulconfig.annotations.Accordion +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption import org.lwjgl.input.Keyboard diff --git a/src/main/kotlin/moe/nea/sky/config/FishingConfig.kt b/src/main/kotlin/moe/nea/sky/config/FishingConfig.kt index 75bc8b5..267a2e1 100644 --- a/src/main/kotlin/moe/nea/sky/config/FishingConfig.kt +++ b/src/main/kotlin/moe/nea/sky/config/FishingConfig.kt @@ -1,9 +1,9 @@ package moe.nea.sky.config import com.google.gson.annotations.Expose -import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean -import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider -import io.github.moulberry.moulconfig.annotations.ConfigOption +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption class FishingConfig { diff --git a/src/main/kotlin/moe/nea/sky/config/MetaConfig.kt b/src/main/kotlin/moe/nea/sky/config/MetaConfig.kt index 1ab9ad4..041e010 100644 --- a/src/main/kotlin/moe/nea/sky/config/MetaConfig.kt +++ b/src/main/kotlin/moe/nea/sky/config/MetaConfig.kt @@ -1,8 +1,8 @@ package moe.nea.sky.config import com.google.gson.annotations.Expose -import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean -import io.github.moulberry.moulconfig.annotations.ConfigOption +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption class MetaConfig { diff --git a/src/main/kotlin/moe/nea/sky/config/MiscellaneousConfig.kt b/src/main/kotlin/moe/nea/sky/config/MiscellaneousConfig.kt index 440be10..a76f6eb 100644 --- a/src/main/kotlin/moe/nea/sky/config/MiscellaneousConfig.kt +++ b/src/main/kotlin/moe/nea/sky/config/MiscellaneousConfig.kt @@ -1,7 +1,7 @@ package moe.nea.sky.config import com.google.gson.annotations.Expose -import io.github.moulberry.moulconfig.annotations.* +import io.github.notenoughupdates.moulconfig.annotations.* import org.lwjgl.input.Keyboard class MiscellaneousConfig { diff --git a/src/main/kotlin/moe/nea/sky/config/NeedsMod.kt b/src/main/kotlin/moe/nea/sky/config/NeedsMod.kt new file mode 100644 index 0000000..4126571 --- /dev/null +++ b/src/main/kotlin/moe/nea/sky/config/NeedsMod.kt @@ -0,0 +1,13 @@ +package moe.nea.sky.config + +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.ANNOTATION_CLASS) +annotation class NeedsMod( + val modId: String, + val modName: String, +) { + @Retention(AnnotationRetention.RUNTIME) + @Target(AnnotationTarget.FIELD) + @NeedsMod("skyhanni", "SkyHanni") + annotation class SkyHanni +}
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/sky/config/NeuHaxConfig.kt b/src/main/kotlin/moe/nea/sky/config/NeuHaxConfig.kt index 7be11d0..0ed4733 100644 --- a/src/main/kotlin/moe/nea/sky/config/NeuHaxConfig.kt +++ b/src/main/kotlin/moe/nea/sky/config/NeuHaxConfig.kt @@ -1,23 +1,27 @@ package moe.nea.sky.config import com.google.gson.annotations.Expose -import io.github.moulberry.moulconfig.Config -import io.github.moulberry.moulconfig.annotations.Category +import io.github.notenoughupdates.moulconfig.Config +import io.github.notenoughupdates.moulconfig.annotations.Category import moe.nea.sky.NEUHax class NeuHaxConfig : Config() { @Category(name = "Misc", desc = "Misc macros") @Expose val meta = MetaConfig() + @Category(name = "Fishing", desc = "Fishing features") @Expose val fishing = FishingConfig() + @Category(name = "Enchanting", desc = "Enchanting features") @Expose val enchanting = EnchantingConfig() + @Category(name = "Wallhacks", desc = "Misc macros") @Expose val wallhacks = WallhackConfig() + @Category(name = "Misc", desc = "Misc macros") @Expose val miscellaneous = MiscellaneousConfig() diff --git a/src/main/kotlin/moe/nea/sky/config/WallhackConfig.kt b/src/main/kotlin/moe/nea/sky/config/WallhackConfig.kt index 6b2db13..4d68f78 100644 --- a/src/main/kotlin/moe/nea/sky/config/WallhackConfig.kt +++ b/src/main/kotlin/moe/nea/sky/config/WallhackConfig.kt @@ -1,12 +1,13 @@ package moe.nea.sky.config import com.google.gson.annotations.Expose -import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean -import io.github.moulberry.moulconfig.annotations.ConfigOption +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption class WallhackConfig { @Expose @ConfigOption(name = "NEU World Wallhacks", desc = "Wallhacks for the neu world renderer") @ConfigEditorBoolean var neuWorld = false + } diff --git a/src/main/kotlin/moe/nea/sky/features/fopt/OptifineCustomItemCacheKey.kt b/src/main/kotlin/moe/nea/sky/features/fopt/OptifineCustomItemCacheKey.kt deleted file mode 100644 index ce922a3..0000000 --- a/src/main/kotlin/moe/nea/sky/features/fopt/OptifineCustomItemCacheKey.kt +++ /dev/null @@ -1,101 +0,0 @@ -package moe.nea.sky.features.fopt - -import io.github.moulberry.notenoughupdates.deps.com.mojang.brigadier.arguments.IntegerArgumentType -import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent -import io.github.moulberry.notenoughupdates.util.brigadier.get -import io.github.moulberry.notenoughupdates.util.brigadier.thenArgumentExecute -import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute -import io.github.moulberry.notenoughupdates.util.brigadier.withHelp -import moe.nea.sky.util.showMessage -import net.minecraft.command.ICommandSender -import net.minecraft.item.ItemStack -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent -import net.optifine.CustomItemProperties - -class OptifineCustomItemCacheKey(val itemstack: ItemStack, val type: Int) { - override fun equals(other: Any?): Boolean { - if (other !is OptifineCustomItemCacheKey) return false - return itemstack === other.itemstack && type == other.type - } - - override fun hashCode(): Int { - return System.identityHashCode(itemstack) + type * 31 - } -} - -class CacheResult(val customItemProperties: CustomItemProperties?) - -class Histogram<T>(val maxSize: Int) : Iterable<T> { - private val dequeue = ArrayDeque<T>() - fun append(element: T) { - dequeue.addLast(element) - if (dequeue.size > maxSize) { - dequeue.removeFirst() - } - } - - val size get() = dequeue.size - - override fun iterator(): Iterator<T> { - return dequeue.iterator() - } -} - -data class CacheStats(var cacheHits: Int = 0, var cacheMisses: Int = 0, var cacheCount: Int = 0) -object OptifineCustomItemCache { - private val map: MutableMap<OptifineCustomItemCacheKey, CacheResult> = mutableMapOf() - private val histogram = Histogram<CacheStats>(100) - private var cacheStats = CacheStats() - - fun dumpStats(target: ICommandSender, length: Int) { - target.showMessage { - text("Optifine Cache Size:") - histogram.forEachIndexed { index, stats -> - val ago = histogram.size - index - if (ago <= length) - text("§b${ago}§e tick${s(ago)} ago: §a${stats.cacheHits}§e-§c${stats.cacheMisses}§e-§b${stats.cacheCount}") - } - } - } - - @SubscribeEvent - fun onCommands(event: RegisterBrigadierCommandEvent) { - event.command("nhopticache") { - thenExecute { - dumpStats(source, Int.MAX_VALUE) - } - thenArgumentExecute("count", IntegerArgumentType.integer()) { - dumpStats(source, this[it]) - }.withHelp("Show stats about the last count ticks") - }.withHelp("Show stats about the optifine item cache") - } - - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (event.phase == TickEvent.Phase.END) { - cacheStats.cacheCount = map.size - histogram.append(cacheStats) - cacheStats = CacheStats() - map.clear() - } - } - - @JvmStatic - fun retrieveCacheHit(itemstack: ItemStack, type: Int): CacheResult? { - val cacheResult = map[OptifineCustomItemCacheKey(itemstack, type)] - if (cacheResult == null) { - cacheStats.cacheMisses++ - } else { - cacheStats.cacheHits++ - } - return cacheResult - } - - @JvmStatic - fun storeCacheElement(itemstack: ItemStack, type: Int, properties: CacheResult) { - map[OptifineCustomItemCacheKey(itemstack, type)] = properties - } - -}
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt b/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt index a2fbf6a..88aa201 100644 --- a/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt +++ b/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt @@ -48,6 +48,7 @@ object YawSnapping { if (event.getEffectiveKeyCode() == config.yawSnappingKeybinding) { config.yawSnapping = !config.yawSnapping + NEUHax.config.saveToFile() showPlayerMessage { text("Yaw Snapping ${if (isEnabled()) "${GREEN}Enabled" else "${RED}Disabled"}") } diff --git a/src/main/kotlin/moe/nea/sky/util/MetaAnnotationUtil.kt b/src/main/kotlin/moe/nea/sky/util/MetaAnnotationUtil.kt new file mode 100644 index 0000000..611e95f --- /dev/null +++ b/src/main/kotlin/moe/nea/sky/util/MetaAnnotationUtil.kt @@ -0,0 +1,13 @@ +package moe.nea.sky.util + +import java.lang.reflect.AnnotatedElement + +object MetaAnnotationUtil { + fun <T : Annotation> getMetaAnnotations(type: Class<T>, element: AnnotatedElement): List<T> { + val x = element.annotations + .flatMap { + it.annotationClass.annotations.toList() + } + return x.filterIsInstance(type) + } +}
\ No newline at end of file |