diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -1,118 +1,33 @@ -# User-specific stuff -.idea/ +# gradle +.gradle/ +build/ +out/ +classes/ + +# eclipse + +*.launch + +# idea + +.idea/ *.iml *.ipr *.iws -# IntelliJ -out/ -# mpeltonen/sbt-idea plugin -.idea_modules/ +# vscode -# JIRA plugin -atlassian-ide-plugin.xml +.settings/ +.vscode/ +bin/ +.classpath +.project -# Compiled class file -*.class +# macos -# Log file -*.log +*.DS_Store -# BlueJ files -*.ctxt +# fabric -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -.gradle -build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Cache of project -.gradletasknamecache - -**/build/ - -# Common working directory run/ - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,58 @@ plugins { - id 'fabric-loom' version '0.12-SNAPSHOT' - id 'maven-publish' + id "dev.architectury.loom" version "0.12.0-SNAPSHOT" + id "maven-publish" id 'io.github.juuxel.loom-quiltflower' version '1.7.+' } +sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17 + +archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group + +loom { + // use this if you are using the official mojang mappings + // and want loom to stop warning you about their license + //silentMojangMappingsLicense() + + // since loom 0.10, you are **required** to use the + // "forge" block to configure forge-specific features, + // such as the mixinConfigs array or datagen + forge { + // specify the mixin configs used in this mod + // this will be added to the jar manifest as well! + mixinConfigs = [ + "recipebookispain.mixins.json" + ] + + // missing access transformers? + // don't worry, you can still use them! + // note that your AT *MUST* be located at + // src/main/resources/META-INF/accesstransformer.cfg + // to work as there is currently no config option to change this. + // also, any names used in your access transformer will need to be + // in SRG mapped ("func_" / "field_" with MCP class names) to work! + // (both of these things may be subject to change in the future) + + // this will create a data generator configuration + // that you can use to automatically generate assets and data + // using architectury loom. Note that this currently *only* works + // for forge projects made with architectury loom! + dataGen { + mod project.mod_id + } + } + + // This allows you to modify your launch configurations, + // for example to add custom arguments. In this case, we want + // the data generator to check our resources directory for + // existing files. (see Forge's ExistingFileHelper for more info) + launches { + data { + arg "--existing", file("src/main/resources").absolutePath + } + } +} repositories { // Add repositories to retrieve artifacts from in here. @@ -13,51 +60,61 @@ // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - content { - includeGroup "maven.modrinth" - } - } } dependencies { - // To change the versions see the gradle.properties file + // to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modCompileOnly("maven.modrinth:mouse-wheelie:1.8.8+mc1.18-pre5") + // choose what mappings you want to use here + // leave this uncommented if you want to use + // mojang's official mappings, or feel free + // to add your own mappings here (how about + // mojmap layered with parchment, for example?) + //mappings loom.officialMojangMappings() + + // uncomment this if you want to use yarn mappings + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + + // your forge dependency, this is **required** when using Forge Loom in forge mode! + forge "net.minecraftforge:forge:${project.forge_version}" + + // additional dependencies can be specified using loom's regular format + // specifying a "mod" dependency (like modImplementation or modApi) + // will cause loom to remap the file to your specified mappings + + // in this example, we'll be adding JEI as a dependency + // according to their developer example on GitHub + // see: https://github.com/mezz/JustEnoughItems/wiki/Getting-Started + // compile against the JEI API but do not include it at runtime + // don't worry about loom "not finding a forge mod" here, + // JEI's api just doesn't have any class with an @Mod annotation + // modCompileOnly "mezz.jei:jei-1.18.1:${jei_version}:api" + // at runtime, use the full JEI jar + // modRuntimeOnly "mezz.jei:jei-1.18.1:${jei_version}" } processResources { + // define properties that can be used during resource processing inputs.property "version", project.version - filteringCharset "UTF-8" - filesMatching("fabric.mod.json") { + // this will replace the property "${version}" in your mods.toml + // with the version you've defined in your gradle.properties + filesMatching("META-INF/mods.toml") { expand "version": project.version } } -def targetJavaVersion = 17 -tasks.withType(JavaCompile).configureEach { +tasks.withType(JavaCompile) { // ensure that the encoding is set to UTF-8, no matter what the system default is // this fixes some edge cases with special characters not displaying correctly // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html // If Javadoc is generated, this must be specified in that task too. - it.options.encoding = "UTF-8" - if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { - it.options.release = targetJavaVersion - } + options.encoding = "UTF-8" + options.release = 17 } java { - def javaVersion = JavaVersion.toVersion(targetJavaVersion) - if (JavaVersion.current() < javaVersion) { - toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) - } - archivesBaseName = project.archives_base_name // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task // if it is present. // If you remove this line, sources will not be generated. @@ -65,8 +122,17 @@ } jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}" } + // add some additional metadata to the jar manifest + manifest { + attributes([ + "Specification-Title" : project.mod_id, + "Specification-Vendor" : project.mod_author, + "Specification-Version" : "1", + "Implementation-Title" : project.name, + "Implementation-Version" : version, + "Implementation-Vendor" : project.mod_author, + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") + ]) } } @@ -74,7 +140,13 @@ publishing { publications { mavenJava(MavenPublication) { - from components.java + // add all the jars that should be included when publishing to maven + artifact(remapJar) { + builtBy remapJar + } + artifact(sourcesJar) { + builtBy remapSourcesJar + } } } diff --git a/gradle.properties b/gradle.properties --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,23 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.18 -yarn_mappings=1.18+build.1 -loader_version=0.14.8 +org.gradle.jvmargs=-Xmx2G + +# tell architectury loom that this project is a forge project. +# this will enable us to use the "forge" dependency. +# using archloom without this is possible and will give you a +# "standard" loom installation with some extra features. +loom.platform=forge + +# Base properties + # minecraft version + minecraft_version=1.18.2 + # forge version, latest version can be found on https://files.minecraftforge.net/ + forge_version=1.18.2-40.1.54 + # yarn, latest version can be found on https://fabricmc.net/use + yarn_mappings=1.18.2+build.3 + # Mod Properties -mod_version=0.6-1.18 -maven_group=me.melontini -archives_base_name=recipe-book-is-pain + mod_version=0.6-1.18-forge + maven_group=me.melontini + archives_base_name=recipe-book-is-pain + mod_id=recipe-book-is-pain + mod_author=melontini diff --git a/settings.gradle b/settings.gradle --- a/settings.gradle +++ b/settings.gradle @@ -1,9 +1,10 @@ pluginManagement { + // when using additional gradle plugins like shadow, + // add their repositories to this list! repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } + maven { url "https://maven.fabricmc.net/" } + maven { url "https://maven.architectury.dev/" } + maven { url "https://files.minecraftforge.net/maven/" } gradlePluginPortal() } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar --- a/gradle/wrapper/gradle-wrapper.jar +++ b/gradle/wrapper/gradle-wrapper.jar diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json deleted file mode 100644 --- a/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "schemaVersion": 1, - "id": "recipe-book-is-pain", - "version": "${version}", - "name": "Recipe Book Is Pain", - "description": "Makes the recipe book use a little more enums", - "authors": [ - "melontini" - ], - "contact": {}, - "license": "MIT", - "icon": "assets/recipe-book-is-pain/icon.png", - "environment": "client", - "entrypoints": { - "client": [ - "me.melontini.recipebookispain.client.RecipeBookIsPainClient" - ], - "main": [ - "me.melontini.recipebookispain.RecipeBookIsPain" - ] - }, - "mixins": [ - "recipe-book-is-pain.mixins.json" - ], - "depends": { - "fabricloader": "*", - "minecraft": ">=1.18" - } -} diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta new file mode 100644 --- /dev/null +++ b/src/main/resources/pack.mcmeta @@ -0,0 +1,7 @@ +{ + "pack": { + "description": "Resources for rbip", + "pack_format": 8, + "_comment": "pack_format 8 is the current format for Minecraft 1.18.1. Be aware may have changed by the time you use this template!" + } +} diff --git a/src/main/resources/recipe-book-is-pain.mixins.json b/src/main/resources/recipe-book-is-pain.mixins.json deleted file mode 100644 --- a/src/main/resources/recipe-book-is-pain.mixins.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "me.melontini.recipebookispain.mixin", - "compatibilityLevel": "JAVA_17", - "plugin": "me.melontini.recipebookispain.mixin.MixinConfigPlugin", - "mixins": [ - ], - "client": [ - "Accessor", - "ClientRecipeBookMixin", - "MouseWheelieCompatMixin", - "RecipeBookGroupMixin", - "RecipeBookWidgetMixin", - "RecipeGroupButtonMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/src/main/resources/recipebookispain.mixins.json b/src/main/resources/recipebookispain.mixins.json new file mode 100644 --- /dev/null +++ b/src/main/resources/recipebookispain.mixins.json @@ -0,0 +1,18 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "me.melontini.recipebookispain.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "ForgeRecipeBookRegistryMixin", + "ClientRecipeBookMixin", + "RecipeBookGroupMixin", + "RecipeBookWidgetMixin", + "RecipeGroupButtonMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 --- /dev/null +++ b/src/main/resources/META-INF/accesstransformer.cfg diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,54 @@ +# This is an example mods.toml file. +# Any fields that aren't annotated with #optional are *required*! +modLoader = "javafml" +loaderVersion = "[40,)" +license = "MIT" # Want to make your mod open source? Check out https://choosealicense.com/! + +# This is a URL to e.g. your GitHub or CurseForge issues page. +# It will appear in any crash reports this mod is directly involved in. +# issueTrackerURL="https://github.com/invalid/pleasechangeme/issues" #optional +# A list of mods - how many allowed here is determined by the individual mod loader + +[[mods]] +modId = "recipe_book_is_pain" +# The version number of the mod - unlike in the Forge MDK, +# we'll use the processResources task to replace this for us +version = "${version}" +displayName = "Recipe Book Is Pain" +# This URL will be queried by the Forge update checker in order to find the latest version of your mod. +# If an update is found, you'll see a little blinking "emerald" symbol on your Mods button! +# updateJSONURL="https://changeme.dev/updates.json" #optional +# This is your mod's "homepage" and will be displayed on the mod's information screen in the Mods panel. +# displayURL="https://changeme.dev/" #optional +# This will be displayed as your mod's logo in the Mods panel. +# logoFile="icon.png" #optional +# Some more fluff displayed in the Mods panel. Feel free to issue your special thanks here! +# credits="Thanks to Mojang for making this great game" #optional +# Some more fluff displayed in the Mods panel. Plug your stuff here! +authors="melontini" #optional +# A multi-line description for your mod. This has no minimum length, but it *is* required! +description = ''' +Makes the recipe book use a little more enums. +''' + +# An (optional) dependency for your mod. Though technically not required, +# it's always helpful to add these to stop your mod from loading when something is missing +# rather than erroring out later +[[dependencies.recipe_book_is_pain]] +modId = "forge" +mandatory = true # do you **need** this mod to be able to launch? +# A version range using interval notation. +# Brackets mean "inclusive" bounds, while parentheses mean "exclusive". +versionRange = "[40,)" # This essentially means any forge >= 39 +ordering = "NONE" # Use this if you want your mod to be loaded specifically BEFORE or AFTER another mod +side = "CLIENT" # Specify where this mod is required: can be BOTH, CLIENT or SERVER + +# And another dependency, use this if you want to require a certain Minecraft version. +[[dependencies.recipe_book_is_pain]] +modId = "minecraft" +mandatory = true +# See above for how to read this notation, this essentially means any +# version of Minecraft from 1.18.1 (inclusive). +versionRange = "[1.18.2,)" +ordering = "NONE" +side = "BOTH" diff --git a/src/main/java/me/melontini/recipebookispain/RecipeBookIsPain.java b/src/main/java/me/melontini/recipebookispain/RecipeBookIsPain.java --- a/src/main/java/me/melontini/recipebookispain/RecipeBookIsPain.java +++ b/src/main/java/me/melontini/recipebookispain/RecipeBookIsPain.java @@ -1,9 +1,34 @@ package me.melontini.recipebookispain; -import net.fabricmc.api.ModInitializer; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.recipebook.RecipeBookGroup; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.asm.RuntimeEnumExtender; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; -public class RecipeBookIsPain implements ModInitializer { - @Override - public void onInitialize() { +import java.util.*; + +@Mod("recipe_book_is_pain") +public class RecipeBookIsPain { + + public static final Logger LOGGER = LogManager.getLogger("RBIP"); + public static Map ADDED_GROUPS = new HashMap<>(); + public static Map AAAAAAAA = new HashMap<>(); + + public static List CRAFTING_SEARCH_MAP; + + public RecipeBookIsPain() { + IEventBus MOD_BUS = FMLJavaModLoadingContext.get().getModEventBus(); + MOD_BUS.addListener(this::clientSetup); + } + + private void clientSetup(final FMLClientSetupEvent event) { + } } diff --git a/src/main/java/me/melontini/recipebookispain/mixin/Accessor.java b/src/main/java/me/melontini/recipebookispain/mixin/Accessor.java deleted file mode 100644 --- a/src/main/java/me/melontini/recipebookispain/mixin/Accessor.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.melontini.recipebookispain.mixin; - -import net.minecraft.client.recipebook.RecipeBookGroup; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(RecipeBookGroup.class) -public interface Accessor { - @Invoker("") - static RecipeBookGroup newGroup(String internalName, int internalId, ItemStack... stacks) { - throw new AssertionError(); - } -} diff --git a/src/main/java/me/melontini/recipebookispain/mixin/ClientRecipeBookMixin.java b/src/main/java/me/melontini/recipebookispain/mixin/ClientRecipeBookMixin.java --- a/src/main/java/me/melontini/recipebookispain/mixin/ClientRecipeBookMixin.java +++ b/src/main/java/me/melontini/recipebookispain/mixin/ClientRecipeBookMixin.java @@ -1,6 +1,6 @@ package me.melontini.recipebookispain.mixin; -import me.melontini.recipebookispain.client.RecipeBookIsPainClient; +import me.melontini.recipebookispain.RecipeBookIsPain; import net.minecraft.client.recipebook.ClientRecipeBook; import net.minecraft.client.recipebook.RecipeBookGroup; import net.minecraft.item.ItemGroup; @@ -15,7 +15,6 @@ @Mixin(value = ClientRecipeBook.class, priority = 999) public class ClientRecipeBookMixin { static { - //noinspection ResultOfMethodCallIgnored RecipeBookGroup.values(); } @Inject(at = @At("HEAD"), method = "getGroupForRecipe", cancellable = true) @@ -26,10 +25,10 @@ ItemGroup group = itemStack.getItem().getGroup(); if (group != null) { if (group != ItemGroup.HOTBAR && group != ItemGroup.INVENTORY && group != ItemGroup.SEARCH) - if (RecipeBookIsPainClient.ADDED_GROUPS.get("P_CRAFTING_" + group.getIndex()) != null) - cir.setReturnValue(RecipeBookIsPainClient.ADDED_GROUPS.get("P_CRAFTING_" + group.getIndex())); + if (RecipeBookIsPain.ADDED_GROUPS.get("P_CRAFTING_" + group.getIndex()) != null) + cir.setReturnValue(RecipeBookIsPain.ADDED_GROUPS.get("P_CRAFTING_" + group.getIndex())); else - cir.setReturnValue(RecipeBookIsPainClient.ADDED_GROUPS.get("P_CRAFTING_" + ItemGroup.MISC.getIndex())); + cir.setReturnValue(RecipeBookIsPain.ADDED_GROUPS.get("P_CRAFTING_" + ItemGroup.MISC.getIndex())); } } } diff --git a/src/main/java/me/melontini/recipebookispain/mixin/ForgeRecipeBookRegistryMixin.java b/src/main/java/me/melontini/recipebookispain/mixin/ForgeRecipeBookRegistryMixin.java new file mode 100644 --- /dev/null +++ b/src/main/java/me/melontini/recipebookispain/mixin/ForgeRecipeBookRegistryMixin.java @@ -0,0 +1,23 @@ +package me.melontini.recipebookispain.mixin; + +import com.google.common.collect.ImmutableList; +import me.melontini.recipebookispain.RecipeBookIsPain; +import net.minecraft.client.recipebook.RecipeBookGroup; +import net.minecraftforge.client.RecipeBookRegistry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(RecipeBookRegistry.class) //cope +public class ForgeRecipeBookRegistryMixin { + // pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work + @SuppressWarnings("unchecked") + @Redirect(at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList;of(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList;"), remap = false, method = "") + private static ImmutableList listOf(E e1, E e2, E e3, E e4) { + RecipeBookIsPain.LOGGER.info("Redirecting ImmutableList.of() Call"); + if (e1 == RecipeBookGroup.CRAFTING_EQUIPMENT) { + return (ImmutableList) ImmutableList.copyOf(RecipeBookIsPain.CRAFTING_SEARCH_MAP); + } + return ImmutableList.of(e1, e2, e3, e4); + } +} diff --git a/src/main/java/me/melontini/recipebookispain/mixin/MixinConfigPlugin.java b/src/main/java/me/melontini/recipebookispain/mixin/MixinConfigPlugin.java deleted file mode 100644 --- a/src/main/java/me/melontini/recipebookispain/mixin/MixinConfigPlugin.java +++ /dev/null @@ -1,49 +0,0 @@ -package me.melontini.recipebookispain.mixin; - -import net.fabricmc.loader.api.FabricLoader; -import org.objectweb.asm.tree.ClassNode; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import java.util.List; -import java.util.Objects; -import java.util.Set; - -public class MixinConfigPlugin implements IMixinConfigPlugin { - @Override - public void onLoad(String mixinPackage) { - - } - - @Override - public String getRefMapperConfig() { - return null; - } - - @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - if (Objects.equals(mixinClassName, "me.melontini.recipebookispain.mixin.MouseWheelieCompatMixin") && !FabricLoader.getInstance().isModLoaded("mousewheelie")) - return false; - return true; - } - - @Override - public void acceptTargets(Set myTargets, Set otherTargets) { - - } - - @Override - public List getMixins() { - return null; - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } - - @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } -} diff --git a/src/main/java/me/melontini/recipebookispain/mixin/MouseWheelieCompatMixin.java b/src/main/java/me/melontini/recipebookispain/mixin/MouseWheelieCompatMixin.java deleted file mode 100644 --- a/src/main/java/me/melontini/recipebookispain/mixin/MouseWheelieCompatMixin.java +++ /dev/null @@ -1,51 +0,0 @@ -package me.melontini.recipebookispain.mixin; - -import de.siphalor.mousewheelie.client.mixin.gui.other.MixinRecipeBookWidget; -import de.siphalor.mousewheelie.client.util.ScrollAction; -import me.melontini.recipebookispain.access.RecipeBookWidgetAccess; -import me.melontini.recipebookispain.access.RecipeGroupButtonAccess; -import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; -import net.minecraft.client.gui.screen.recipebook.RecipeGroupButtonWidget; -import net.minecraft.util.math.MathHelper; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.*; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.List; - -@Pseudo -@Mixin(value = RecipeBookWidget.class, priority = 1001) -public abstract class MouseWheelieCompatMixin { - @Shadow - @Final - private List tabButtons; - - @Shadow - @Nullable - private RecipeGroupButtonWidget currentTab; - - @Shadow - protected abstract void refreshResults(boolean resetCurrentPage); - - //pain - //pretty funny tho - @SuppressWarnings("ReferenceToMixin") - @Dynamic(mixin = MixinRecipeBookWidget.class) - @Inject(at = @At(value = "INVOKE", target = "net/minecraft/client/gui/screen/recipebook/RecipeGroupButtonWidget.setToggled (Z)V", ordinal = 0, shift = At.Shift.BEFORE), method = "mouseWheelie_scrollRecipeBook", cancellable = true) - private void inject(double mouseX, double mouseY, double scrollAmount, CallbackInfoReturnable cir) { - RecipeBookWidget bookWidget = (RecipeBookWidget) (Object) this; - int index; - index = this.tabButtons.indexOf(this.currentTab); - int newIndex = MathHelper.clamp(index + (int) Math.round(scrollAmount), 0, this.tabButtons.size() - 1); - this.currentTab.setToggled(false); - this.currentTab = this.tabButtons.get(newIndex); - this.currentTab.setToggled(true); - if (((RecipeBookWidgetAccess) bookWidget).getBookPage() != ((RecipeGroupButtonAccess) this.currentTab).getPage()) { - ((RecipeBookWidgetAccess) bookWidget).setBookPage(((RecipeGroupButtonAccess) this.currentTab).getPage()); - } - this.refreshResults(true); - cir.setReturnValue(ScrollAction.SUCCESS); - } -} diff --git a/src/main/java/me/melontini/recipebookispain/mixin/RecipeBookGroupMixin.java b/src/main/java/me/melontini/recipebookispain/mixin/RecipeBookGroupMixin.java --- a/src/main/java/me/melontini/recipebookispain/mixin/RecipeBookGroupMixin.java +++ b/src/main/java/me/melontini/recipebookispain/mixin/RecipeBookGroupMixin.java @@ -1,11 +1,12 @@ package me.melontini.recipebookispain.mixin; import com.google.common.collect.ImmutableList; -import me.melontini.recipebookispain.client.RecipeBookIsPainClient; +import me.melontini.recipebookispain.RecipeBookIsPain; import net.minecraft.client.recipebook.RecipeBookGroup; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.recipe.book.RecipeBookCategory; +import net.minecraftforge.client.RecipeBookRegistry; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; @@ -13,49 +14,36 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.stringtemplate.v4.ST; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -@Mixin(RecipeBookGroup.class) +@Mixin(value = RecipeBookGroup.class, priority = 666) @Unique -public class RecipeBookGroupMixin { - //me when I can't use Fabric ASM - @Shadow - @Final - @Mutable - private static RecipeBookGroup[] field_1805; +public abstract class RecipeBookGroupMixin { - @Unique - private static List CRAFTING_SEARCH_MAP; @Unique private static List CRAFTING_MAP; - // pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work pls work - @SuppressWarnings("unchecked") - @Redirect(at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList;of(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList;"), remap = false, method = "") - private static ImmutableList listOf(E e1, E e2, E e3, E e4) { - if (e1 == RecipeBookGroup.CRAFTING_EQUIPMENT) { - return (ImmutableList) ImmutableList.copyOf(CRAFTING_SEARCH_MAP); - } - return ImmutableList.of(e1, e2, e3, e4); - } - @Inject(at = @At(value = "FIELD", opcode = Opcodes.PUTSTATIC, target = "Lnet/minecraft/client/recipebook/RecipeBookGroup;field_1805:[Lnet/minecraft/client/recipebook/RecipeBookGroup;", shift = At.Shift.AFTER), method = "") private static void recipe_book_is_pain$addCustomGroups(CallbackInfo ci) { - var groups = new ArrayList<>(Arrays.asList(field_1805)); - var last = groups.get(groups.size() - 1); - + //RecipeBookIsPain.LOGGER.info("Adding to RecipeBookGroup enum"); for (ItemGroup group : ItemGroup.GROUPS) { - if (group != ItemGroup.HOTBAR && group != ItemGroup.INVENTORY && group != ItemGroup.SEARCH) { - var group1 = Accessor.newGroup("P_CRAFTING_" + group.getIndex(), last.ordinal() + 1, new ItemStack(group.getIcon().getItem())); + if (group != ItemGroup.HOTBAR && group != ItemGroup.INVENTORY && group != ItemGroup.SEARCH && group != null) { String name = "P_CRAFTING_" + group.getIndex(); - RecipeBookIsPainClient.ADDED_GROUPS.put(name, group1); - RecipeBookIsPainClient.AAAAAAAA.put(name, group); - groups.add(group1); + RecipeBookGroup.create(name, new ItemStack(group.getIcon().getItem())); + var group1 = RecipeBookGroup.valueOf(RecipeBookGroup.class, name); + RecipeBookIsPain.ADDED_GROUPS.put(name, group1); + RecipeBookIsPain.AAAAAAAA.put(name, group); } } + + var groups = new ArrayList<>(Arrays.asList(RecipeBookGroup.values())); + + Arrays.stream(RecipeBookGroup.values()).toList().forEach(group -> + RecipeBookIsPain.LOGGER.info(group.name())); List craftingMap = new ArrayList<>(); List craftingSearchMap = new ArrayList<>(); @@ -66,11 +54,12 @@ craftingSearchMap.add(bookGroup); } } - CRAFTING_SEARCH_MAP = craftingSearchMap; + + RecipeBookIsPain.CRAFTING_SEARCH_MAP = craftingSearchMap; CRAFTING_MAP = craftingMap; - field_1805 = groups.toArray(new RecipeBookGroup[0]); - RecipeBookIsPainClient.LOGGER.info("[RBIP] recipe book init complete"); + RecipeBookRegistry.addCategoriesToType(RecipeBookCategory.CRAFTING, CRAFTING_MAP); + RecipeBookIsPain.LOGGER.info("recipe book init complete"); } @Inject(at = @At("HEAD"), method = "getGroups", cancellable = true) diff --git a/src/main/java/me/melontini/recipebookispain/mixin/RecipeBookWidgetMixin.java b/src/main/java/me/melontini/recipebookispain/mixin/RecipeBookWidgetMixin.java --- a/src/main/java/me/melontini/recipebookispain/mixin/RecipeBookWidgetMixin.java +++ b/src/main/java/me/melontini/recipebookispain/mixin/RecipeBookWidgetMixin.java @@ -1,8 +1,8 @@ package me.melontini.recipebookispain.mixin; +import me.melontini.recipebookispain.RecipeBookIsPain; import me.melontini.recipebookispain.access.RecipeBookWidgetAccess; import me.melontini.recipebookispain.access.RecipeGroupButtonAccess; -import me.melontini.recipebookispain.client.RecipeBookIsPainClient; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; import net.minecraft.client.gui.screen.recipebook.RecipeGroupButtonWidget; @@ -104,8 +104,8 @@ client.currentScreen.renderTooltip(stack, ItemGroup.SEARCH.getDisplayName(), mouseX, mouseY); } else if (widget.hasKnownRecipes(recipeBook)) { widget.checkForNewRecipes(this.client); - if (RecipeBookIsPainClient.AAAAAAAA.get(recipeBookGroup.name()) != null) { - Text text = RecipeBookIsPainClient.AAAAAAAA.get(recipeBookGroup.name()).getDisplayName(); + if (RecipeBookIsPain.AAAAAAAA.get(recipeBookGroup.name()) != null) { + Text text = RecipeBookIsPain.AAAAAAAA.get(recipeBookGroup.name()).getDisplayName(); if (text != null) if (widget.isHovered()) client.currentScreen.renderTooltip(stack, text, mouseX, mouseY); }