diff options
15 files changed, 142 insertions, 184 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index 91cbf75..5f84c09 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,28 +53,11 @@ val runtimeMod by configurations.creating { isVisible = false } -val downloadOptifine by tasks.creating() { - val outputFile = layout.buildDirectory.file("download/optifine.jar") - outputs.file(outputFile) - doLast { - outputFile.get().asFile.parentFile.mkdirs() - uri("https://optifine.net/download?f=preview_OptiFine_1.8.9_HD_U_M6_pre2.jar") - .toURL() - .openStream().use { input -> - outputFile.get().asFile.outputStream().use { output -> - input.copyTo(output) - } - } - } -} - dependencies { minecraft("com.mojang:minecraft:1.8.9") mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") - compileOnly(project.files(downloadOptifine)) - shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") { isTransitive = false } @@ -85,7 +68,7 @@ dependencies { runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:1.1.0") shadowImpl("moe.nea:libautoupdate:1.2.0") - shadowModImpl("org.notenoughupdates.moulconfig:legacy:3.0.0-beta.1") + shadowModImpl("org.notenoughupdates.moulconfig:legacy:3.0.0-beta.7") modCompileOnly(runtimeMod("com.github.notenoughupdates:notenoughupdates:a1b74ca22:all") { isTransitive = false @@ -100,9 +83,8 @@ loom { // If you don't want mixins, remove these lines property("mixin.debug", "true") property("moulconfig.warn.crash", "false") - property("asmhelper.verbose", "true") arg("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker") - arg("--tweakClass", "io.github.moulberry.moulconfig.tweaker.DevelopmentResourceTweaker") + arg("--tweakClass", "io.github.notenoughupdates.moulconfig.tweaker.DevelopmentResourceTweaker") arg("--mixin", "mixins.neuhax.json") val modFiles = runtimeMod.files arg("--mods", modFiles.joinToString(",") { it.relativeTo(file("run")).path }) diff --git a/src/main/java/moe/nea/sky/config/GuiOptionEditorNeedDependent.kt b/src/main/java/moe/nea/sky/config/GuiOptionEditorNeedDependent.kt new file mode 100644 index 0000000..f9ba392 --- /dev/null +++ b/src/main/java/moe/nea/sky/config/GuiOptionEditorNeedDependent.kt @@ -0,0 +1,52 @@ +package moe.nea.sky.config + +import io.github.notenoughupdates.moulconfig.gui.GuiOptionEditor +import io.github.moulberry.notenoughupdates.core.config.GuiOptionEditorBlocked +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils +import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.Gui +import net.minecraft.client.renderer.GlStateManager + +class GuiOptionEditorNeedDependent(val backing: GuiOptionEditor, val missingMods: List<NeedsMod>) : + GuiOptionEditor(backing.option) { + override fun render(x: Int, y: Int, width: Int) { + backing.render(x, y, width) + val mc = Minecraft.getMinecraft() + Gui.drawRect(x, y, x + width, y + this.height, Int.MIN_VALUE) + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) + mc.textureManager.bindTexture(GuiOptionEditorBlocked.blockedTexture) + val iconWidth = this.height.toFloat() * 96.0f / 64.0f + RenderUtils.drawTexturedRect( + x.toFloat(), y.toFloat(), iconWidth, + this.height.toFloat() + ) + TextRenderUtils.drawStringScaledMaxWidth( + "This option requires you to have the following mods installed:", + x.toFloat() + iconWidth, + y.toFloat() + this.height.toFloat() / 2.0f - mc.fontRendererObj.FONT_HEIGHT.toFloat(), + true, + (width.toFloat() - iconWidth).toInt(), + -48060 + ) + TextRenderUtils.drawStringScaledMaxWidth( + missingMods.joinToString(", ", postfix = ".") { it.modName }, + x.toFloat() + iconWidth, + y.toFloat() + this.height.toFloat() / 2.0f, + true, + (width.toFloat() - iconWidth).toInt(), + -48060 + ) + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) + + } + + override fun mouseInput(x: Int, y: Int, width: Int, mouseX: Int, mouseY: Int): Boolean { + return false + } + + override fun keyboardInput(): Boolean { + return false + } + +} diff --git a/src/main/java/moe/nea/sky/mixin/patches/PatchCustomItemModelCache.java b/src/main/java/moe/nea/sky/mixin/patches/PatchCustomItemModelCache.java deleted file mode 100644 index 8a0bc21..0000000 --- a/src/main/java/moe/nea/sky/mixin/patches/PatchCustomItemModelCache.java +++ /dev/null @@ -1,44 +0,0 @@ -package moe.nea.sky.mixin.patches; - -import moe.nea.sky.features.fopt.CacheResult; -import moe.nea.sky.features.fopt.OptifineCustomItemCache; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.optifine.CustomItemProperties; -import net.optifine.CustomItems; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Pseudo -@Mixin(value = CustomItems.class, remap = false) -public class PatchCustomItemModelCache { - - @Inject(method = "getCustomItemProperties", at = @At("HEAD"), cancellable = true) - private static void overrideCustomItemProperties( - ItemStack itemStack, int type, - CallbackInfoReturnable<CustomItemProperties> cir) { - CacheResult cacheHit = OptifineCustomItemCache.retrieveCacheHit(itemStack, type); - if (cacheHit != null) { - cir.setReturnValue(cacheHit.getCustomItemProperties()); - } - } - - @Inject(method = "getCustomItemProperties", at = @At(value = "RETURN", ordinal = 2), - locals = LocalCapture.CAPTURE_FAILHARD) - private static void storeCustomItemProperties( - ItemStack itemStack, int type, CallbackInfoReturnable<CustomItemProperties> cir, Item item, int itemId, CustomItemProperties[] cips, int i, CustomItemProperties cip) { - OptifineCustomItemCache.storeCacheElement(itemStack, type, new CacheResult(cip)); - } - - @Inject(method = "getCustomItemProperties", at = @At(value = "RETURN", ordinal = 3)) - private static void storeCustomItemProperties( - ItemStack itemStack, int type, CallbackInfoReturnable<CustomItemProperties> cir) { - OptifineCustomItemCache.storeCacheElement(itemStack, type, new CacheResult(null)); - } - - -} 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 |