From 69d386214f5d3471a3ef1e5533037cdc32648c57 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 28 Feb 2021 02:07:47 +0800 Subject: Port to Architectury Multiloader Signed-off-by: shedaniel --- api/build.gradle | 18 ++- .../me/shedaniel/rei/api/gui/widgets/Tooltip.java | 4 +- api/src/main/resources/fabric.mod.json | 20 --- api/src/main/resources/icon.png | Bin 27270 -> 0 bytes build.gradle | 150 ++++++++------------- default-plugin/build.gradle | 19 ++- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 53 ++++---- default-plugin/src/main/resources/fabric.mod.json | 29 ---- default-plugin/src/main/resources/icon.png | Bin 27270 -> 0 bytes ...roughlyenoughitems-default-plugin.accessWidener | 21 --- fabric/build.gradle | 39 ++++++ .../shedaniel/rei/fabric/PluginDetectorImpl.java | 52 +++++++ .../rei/fabric/RoughlyEnoughItemsFabric.java | 31 +++++ fabric/src/main/resources/fabric.mod.json | 51 +++++++ fabric/src/main/resources/icon.png | Bin 0 -> 27270 bytes .../resources/roughlyenoughitems.accessWidener | 33 +++++ forge/build.gradle | 26 ++++ forge/gradle.properties | 1 + .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 21 +++ .../rei/forge/RoughlyEnoughItemsForge.java | 17 +++ .../main/resources/META-INF/accesstransformer.cfg | 23 ++++ forge/src/main/resources/META-INF/mods.toml | 20 +++ forge/src/main/resources/icon.png | Bin 0 -> 27270 bytes forge/src/main/resources/pack.mcmeta | 6 + gradle.properties | 3 +- runtime/build.gradle | 25 +++- .../main/java/me/shedaniel/rei/PluginDetector.java | 18 +++ .../me/shedaniel/rei/REIModMenuEntryPoint.java | 4 +- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 46 +------ .../rei/RoughlyEnoughItemsInitializer.java | 57 ++++---- .../shedaniel/rei/RoughlyEnoughItemsNetwork.java | 7 +- .../me/shedaniel/rei/RoughlyEnoughItemsState.java | 8 +- .../shedaniel/rei/gui/credits/CreditsScreen.java | 6 +- .../rei/gui/plugin/DefaultRuntimePlugin.java | 3 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 30 +++-- .../me/shedaniel/rei/gui/widget/QueuedTooltip.java | 14 +- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 17 ++- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 3 +- .../java/me/shedaniel/rei/impl/ErrorDisplayer.java | 4 +- .../java/me/shedaniel/rei/impl/IssuesDetector.java | 31 +---- .../java/me/shedaniel/rei/impl/ScreenHelper.java | 4 +- runtime/src/main/resources/fabric.mod.json | 50 ------- runtime/src/main/resources/icon.png | Bin 27270 -> 0 bytes .../roughlyenoughitems-runtime.accessWidener | 23 ---- settings.gradle | 2 + src/main/resources/fabric.mod.json | 21 --- src/main/resources/icon.png | Bin 27270 -> 0 bytes 47 files changed, 570 insertions(+), 440 deletions(-) delete mode 100644 api/src/main/resources/fabric.mod.json delete mode 100644 api/src/main/resources/icon.png delete mode 100644 default-plugin/src/main/resources/fabric.mod.json delete mode 100644 default-plugin/src/main/resources/icon.png delete mode 100644 default-plugin/src/main/resources/roughlyenoughitems-default-plugin.accessWidener create mode 100644 fabric/build.gradle create mode 100644 fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java create mode 100644 fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsFabric.java create mode 100644 fabric/src/main/resources/fabric.mod.json create mode 100644 fabric/src/main/resources/icon.png create mode 100644 fabric/src/main/resources/roughlyenoughitems.accessWidener create mode 100644 forge/build.gradle create mode 100644 forge/gradle.properties create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsForge.java create mode 100644 forge/src/main/resources/META-INF/accesstransformer.cfg create mode 100644 forge/src/main/resources/META-INF/mods.toml create mode 100644 forge/src/main/resources/icon.png create mode 100644 forge/src/main/resources/pack.mcmeta create mode 100644 runtime/src/main/java/me/shedaniel/rei/PluginDetector.java delete mode 100644 runtime/src/main/resources/fabric.mod.json delete mode 100644 runtime/src/main/resources/icon.png delete mode 100644 runtime/src/main/resources/roughlyenoughitems-runtime.accessWidener delete mode 100755 src/main/resources/fabric.mod.json delete mode 100644 src/main/resources/icon.png diff --git a/api/build.gradle b/api/build.gradle index 598a85f5a..925fed277 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -1 +1,17 @@ -archivesBaseName = "api" \ No newline at end of file +archivesBaseName = "api" + +dependencies { + modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}") + modCompileOnly("me.shedaniel.cloth:cloth-config:${cloth_config_version}") + modCompileOnly("me.shedaniel:architectury:${architectury_version}") +} + +architectury { + common() +} + +remapJar { + afterEvaluate { + remapAccessWidener.set(false) + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Tooltip.java index 075e57580..972df5a43 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Tooltip.java @@ -23,8 +23,8 @@ package me.shedaniel.rei.api.gui.widgets; +import me.shedaniel.architectury.utils.EnvExecutor; import me.shedaniel.math.Point; -import me.shedaniel.math.api.Executor; import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.impl.Internals; import net.fabricmc.api.EnvType; @@ -64,6 +64,6 @@ public interface Tooltip { List getText(); default void queue() { - Executor.runIfEnv(EnvType.CLIENT, () -> () -> REIHelper.getInstance().queueTooltip(this)); + EnvExecutor.runInEnv(EnvType.CLIENT, () -> () -> REIHelper.getInstance().queueTooltip(this)); } } diff --git a/api/src/main/resources/fabric.mod.json b/api/src/main/resources/fabric.mod.json deleted file mode 100644 index 29784abf1..000000000 --- a/api/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "schemaVersion": 1, - "id": "roughlyenoughitems-api", - "name": "REI (API)", - "description": "The api facing part of Roughly Enough Items.", - "version": "${version}", - "authors": [ - "shedaniel" - ], - "contact": { - "homepage": "https://www.curseforge.com/minecraft/mc-mods/roughly-enough-items", - "sources": "https://github.com/shedaniel/RoughlyEnoughItems", - "issues": "https://github.com/shedaniel/RoughlyEnoughItems/issues" - }, - "license": "MIT", - "icon": "icon.png", - "custom": { - "modmenu:parent": "roughlyenoughitems" - } -} diff --git a/api/src/main/resources/icon.png b/api/src/main/resources/icon.png deleted file mode 100644 index b7a48aef0..000000000 Binary files a/api/src/main/resources/icon.png and /dev/null differ diff --git a/build.gradle b/build.gradle index b534499d6..5c5d0c67c 100755 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,12 @@ plugins { - id("forgified-fabric-loom") version("0.6.66") apply false - id("maven-publish") - id("java") - id("java-library") - id("net.minecrell.licenser") version("0.4.1") + id("architectury-plugin") version("3.0.89") + id("forgified-fabric-loom") version("0.6.71") apply false + id("org.cadixdev.licenser") version("0.5.0") id("com.matthewprenger.cursegradle") version("1.4.0") + id("java") + id("maven-publish") } -import net.fabricmc.loom.task.RemapJarTask - import java.text.SimpleDateFormat archivesBaseName = "RoughlyEnoughItems" @@ -18,111 +16,77 @@ version = rootProject.base_version + "." + runNumber group = "me.shedaniel" -allprojects { - apply plugin: 'maven-publish' - apply plugin: 'forgified-fabric-loom' - apply plugin: 'net.minecrell.licenser' - - sourceCompatibility = targetCompatibility = 1.8 +subprojects { + apply plugin: "forgified-fabric-loom" loom { silentMojangMappingsLicense() -// shareCaches = true } + dependencies { + minecraft("com.mojang:minecraft:${rootProject.minecraft_version}") + mappings(loom.officialMojangMappings()) + } +} + +allprojects { + apply plugin: "maven-publish" + apply plugin: "architectury-plugin" + apply plugin: "org.cadixdev.licenser" + + sourceCompatibility = targetCompatibility = 1.8 + repositories { + mavenLocal() maven { url "https://maven.shedaniel.me" } maven { url "https://maven.terraformersmc.com/releases" } } - - processResources { - filesMatching('fabric.mod.json') { - expand 'version': project.version - } - inputs.property "version", project.version + + architectury { + transformerVersion = "2.1.9999" } license { - header rootProject.file('HEADER') - include '**/*.java' + header rootProject.file("HEADER") + include "**/*.java" } jar { from rootProject.file("LICENSE") } - dependencies { - minecraft("com.mojang:minecraft:${project.minecraft_version}") - mappings(loom.officialMojangMappings()) - modApi("net.fabricmc:fabric-loader:${project.fabricloader_version}") -// modApi(fabricApi.module("fabric-api-base", project.fabric_api)) -// modApi(fabricApi.module("fabric-resource-loader-v0", project.fabric_api)) -// modApi(fabricApi.module("fabric-networking-api-v1", project.fabric_api)) -// modApi(fabricApi.module("fabric-lifecycle-events-v1", project.fabric_api)) -// modApi(fabricApi.module("fabric-rendering-fluids-v1", project.fabric_api)) - modApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") { - exclude(module: "fabric-api") - } - modApi("org.jetbrains:annotations:19.0.0") - modRuntime("com.terraformersmc:modmenu:${modmenu_version}") { - transitive(false) - } - modRuntime("me.shedaniel:SmoothScrollingEverywhere:3.0.3-unstable") { - transitive(false) - } - modCompileOnly("me.shedaniel:architectury:${architectury_version}") { - exclude(module: "fabric-api") - } - modRuntime("me.shedaniel:architectury-fabric:${architectury_version}") - modRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_api}") - } - tasks.withType(JavaCompile) { options.encoding = "UTF-8" - } - task sourcesJar(type: Jar, dependsOn: classes) { - classifier("sources") - from sourceSets.main.allSource + def targetVersion = 8 + if (JavaVersion.current().isJava9Compatible()) { + options.release = targetVersion + } } } subprojects { +// apply plugin: "forgified-fabric-loom" + group = rootProject.group version = rootProject.version - task remapMavenJar(type: Copy, dependsOn: remapJar) { - afterEvaluate { - from("${project.buildDir}/libs/$archivesBaseName-${version}.jar") - into("${project.buildDir}/libs/") - rename { String fn -> "$archivesBaseName-${version}-maven.jar" } - } - } - - configurations { - dev - remapped - } +// loom { +// silentMojangMappingsLicense() +// } - jar { - classifier("dev") - } - - remapJar { - classifier(null) - } - - artifacts { - dev file: file("${project.buildDir}/libs/$archivesBaseName-${version}-dev.jar"), type: "jar", builtBy: jar - remapped file: file("${project.buildDir}/libs/$archivesBaseName-${version}.jar"), type: "jar", builtBy: remapJar + dependencies { +// minecraft("com.mojang:minecraft:${project.minecraft_version}") +// mappings(loom.officialMojangMappings()) +// modApi("net.fabricmc:fabric-loader:${project.fabricloader_version}") } - publishing { + /*publishing { publications { create("${archivesBaseName}_mavenJava", MavenPublication) { afterEvaluate { - artifact(file("${project.buildDir}/libs/$archivesBaseName-${version}-maven.jar")) { - builtBy remapMavenJar + artifact(jar) { + builtBy mavenJar } artifact(sourcesJar) { builtBy remapSourcesJar @@ -142,25 +106,19 @@ subprojects { } } } - } + }*/ } task licenseFormatAll subprojects { licenseFormatAll.dependsOn("${path}:licenseFormat") } -subprojects { rootProject.remapJar.dependsOn("${path}:remapJar") } +//subprojects { rootProject.remapJar.dependsOn("${path}:remapJar") } -task remapMavenJar(type: RemapJarTask, dependsOn: jar) { - input.set(file("${project.buildDir}/libs/${archivesBaseName}-${project.version}-dev.jar")) - archiveFileName = "${archivesBaseName}-${project.version}-maven.jar" - addNestedDependencies.set(false) -} - -dependencies { - subprojects.each { - compile project(path: ":${it.name}", configuration: "dev") - include project(path: ":${it.name}", configuration: "remapped") - } -} +//dependencies { +// subprojects.each { +// compile project(path: ":${it.name}", configuration: "dev") +// include project(path: ":${it.name}", configuration: "remapped") +// } +//} def releaseChangelog = "No changelog" @@ -193,7 +151,7 @@ task releaseOnCf { dependsOn tasks.getByName("curseforge") } -curseforge { +/*curseforge { if (project.hasProperty('danielshe_curse_api_key') || System.getenv('danielshe_curse_api_key') != null) { apiKey = project.hasProperty('danielshe_curse_api_key') ? project.property('danielshe_curse_api_key') : System.getenv('danielshe_curse_api_key') project { @@ -232,8 +190,8 @@ curseforge { publishing { publications { mavenJava(MavenPublication) { - artifact(file("${project.buildDir}/libs/$archivesBaseName-${version}-maven.jar")) { - builtBy remapMavenJar + artifact(jar) { + builtBy remapJar } artifact(sourcesJar) { builtBy remapSourcesJar @@ -262,4 +220,4 @@ publishing { } } } -} +}*/ diff --git a/default-plugin/build.gradle b/default-plugin/build.gradle index 159cda85d..4f7fbee58 100644 --- a/default-plugin/build.gradle +++ b/default-plugin/build.gradle @@ -1,9 +1,22 @@ archivesBaseName = "default-plugin" loom { - accessWidener = file("src/main/resources/roughlyenoughitems-default-plugin.accessWidener") + accessWidener = gradle.rootProject.project("fabric").file("src/main/resources/roughlyenoughitems.accessWidener") } dependencies { - compile project(path: ":api", configuration: "dev") -} \ No newline at end of file + modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}") + modCompileOnly("me.shedaniel.cloth:cloth-config:${cloth_config_version}") + modCompileOnly("me.shedaniel:architectury:${architectury_version}") + compileOnly(project(path: ":api")) +} + +architectury { + common() +} + +remapJar { + afterEvaluate { + remapAccessWidener.set(false) + } +} diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index edd91e2ba..289ba480b 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -30,6 +30,7 @@ import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import it.unimi.dsi.fastutil.objects.ReferenceSet; import me.shedaniel.architectury.hooks.FluidStackHooks; +import me.shedaniel.architectury.platform.Platform; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.*; import me.shedaniel.rei.api.ingredient.EntryIngredient; @@ -344,32 +345,34 @@ public class DefaultPlugin implements REIPlugin, BuiltinPlugin { }); registry.registerDisplay(new DefaultBeaconBaseDisplay(CollectionUtils.map(Lists.newArrayList(BlockTags.BEACON_BASE_BLOCKS.getValues()), ItemStack::new))); registry.registerDisplay(new DefaultBeaconPaymentDisplay(CollectionUtils.map(Lists.newArrayList(ItemTags.BEACON_PAYMENT_ITEMS.getValues()), ItemStack::new))); - Set potions = Sets.newLinkedHashSet(); - for (Ingredient container : PotionBrewing.ALLOWED_CONTAINERS) { - for (PotionBrewing.Mix mix : PotionBrewing.POTION_MIXES) { - Potion from = mix.from; - Ingredient ingredient = mix.ingredient; - Potion to = mix.to; - Ingredient base = Ingredient.of(Arrays.stream(container.getItems()) - .map(ItemStack::copy) - .map(stack -> PotionUtils.setPotion(stack, from))); - ItemStack output = Arrays.stream(container.getItems()) - .map(ItemStack::copy) - .map(stack -> PotionUtils.setPotion(stack, to)) - .findFirst().orElse(ItemStack.EMPTY); - registerBrewingRecipe(base, ingredient, output); - potions.add(from); - potions.add(to); + if (Platform.isFabric()) { + Set potions = Sets.newLinkedHashSet(); + for (Ingredient container : PotionBrewing.ALLOWED_CONTAINERS) { + for (PotionBrewing.Mix mix : PotionBrewing.POTION_MIXES) { + Potion from = mix.from; + Ingredient ingredient = mix.ingredient; + Potion to = mix.to; + Ingredient base = Ingredient.of(Arrays.stream(container.getItems()) + .map(ItemStack::copy) + .map(stack -> PotionUtils.setPotion(stack, from))); + ItemStack output = Arrays.stream(container.getItems()) + .map(ItemStack::copy) + .map(stack -> PotionUtils.setPotion(stack, to)) + .findFirst().orElse(ItemStack.EMPTY); + registerBrewingRecipe(base, ingredient, output); + potions.add(from); + potions.add(to); + } } - } - for (Potion potion : potions) { - for (PotionBrewing.Mix mix : PotionBrewing.CONTAINER_MIXES) { - Item from = mix.from; - Ingredient ingredient = mix.ingredient; - Item to = mix.to; - Ingredient base = Ingredient.of(PotionUtils.setPotion(new ItemStack(from), potion)); - ItemStack output = PotionUtils.setPotion(new ItemStack(to), potion); - registerBrewingRecipe(base, ingredient, output); + for (Potion potion : potions) { + for (PotionBrewing.Mix mix : PotionBrewing.CONTAINER_MIXES) { + Item from = mix.from; + Ingredient ingredient = mix.ingredient; + Item to = mix.to; + Ingredient base = Ingredient.of(PotionUtils.setPotion(new ItemStack(from), potion)); + ItemStack output = PotionUtils.setPotion(new ItemStack(to), potion); + registerBrewingRecipe(base, ingredient, output); + } } } } diff --git a/default-plugin/src/main/resources/fabric.mod.json b/default-plugin/src/main/resources/fabric.mod.json deleted file mode 100644 index c6b67960d..000000000 --- a/default-plugin/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "schemaVersion": 1, - "id": "roughlyenoughitems-default-plugin", - "name": "REI (Default Plugin)", - "description": "The default implementation of handling vanilla features.", - "version": "${version}", - "authors": [ - "shedaniel" - ], - "contact": { - "homepage": "https://www.curseforge.com/minecraft/mc-mods/roughly-enough-items", - "sources": "https://github.com/shedaniel/RoughlyEnoughItems", - "issues": "https://github.com/shedaniel/RoughlyEnoughItems/issues" - }, - "license": "MIT", - "icon": "icon.png", - "entrypoints": { - "rei_plugins": [ - "me.shedaniel.rei.plugin.DefaultPlugin" - ], - "rei_containers": [ - "me.shedaniel.rei.plugin.DefaultServerContainerPlugin" - ] - }, - "accessWidener": "roughlyenoughitems-default-plugin.accessWidener", - "custom": { - "modmenu:parent": "roughlyenoughitems" - } -} diff --git a/default-plugin/src/main/resources/icon.png b/default-plugin/src/main/resources/icon.png deleted file mode 100644 index b7a48aef0..000000000 Binary files a/default-plugin/src/main/resources/icon.png and /dev/null differ diff --git a/default-plugin/src/main/resources/roughlyenoughitems-default-plugin.accessWidener b/default-plugin/src/main/resources/roughlyenoughitems-default-plugin.accessWidener deleted file mode 100644 index 7a3f5ba99..000000000 --- a/default-plugin/src/main/resources/roughlyenoughitems-default-plugin.accessWidener +++ /dev/null @@ -1,21 +0,0 @@ -accessWidener v1 named -accessible field net/minecraft/world/item/BucketItem content Lnet/minecraft/world/level/material/Fluid; -accessible field net/minecraft/client/gui/screens/inventory/EffectRenderingInventoryScreen doRenderEffects Z -accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent ghostRecipe Lnet/minecraft/client/gui/screens/recipebook/GhostRecipe; -accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent searchBox Lnet/minecraft/client/gui/components/EditBox; -accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent tabButtons Ljava/util/List; -accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen leftPos I -accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen topPos I -accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen imageWidth I -accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen imageHeight I -accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen hoveredSlot Lnet/minecraft/world/inventory/Slot; -accessible method net/minecraft/client/gui/GuiComponent innerBlit (Lcom/mojang/math/Matrix4f;IIIIIFFFF)V -accessible field net/minecraft/world/item/crafting/UpgradeRecipe base Lnet/minecraft/world/item/crafting/Ingredient; -accessible field net/minecraft/world/item/crafting/UpgradeRecipe addition Lnet/minecraft/world/item/crafting/Ingredient; -accessible field net/minecraft/world/item/alchemy/PotionBrewing ALLOWED_CONTAINERS Ljava/util/List; -accessible field net/minecraft/world/item/alchemy/PotionBrewing POTION_MIXES Ljava/util/List; -accessible field net/minecraft/world/item/alchemy/PotionBrewing CONTAINER_MIXES Ljava/util/List; -accessible class net/minecraft/world/item/alchemy/PotionBrewing$Mix -accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix from Ljava/lang/Object; -accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix to Ljava/lang/Object; -accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix ingredient Lnet/minecraft/world/item/crafting/Ingredient; diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 000000000..be813394e --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,39 @@ +archivesBaseName = "fabric" + +architectury { + platformSetupLoomIde() + fabric() +} + +processResources { + filesMatching("fabric.mod.json") { + expand "version": project.version + } + inputs.property "version", project.version +} + +loom { + accessWidener = file("src/main/resources/roughlyenoughitems.accessWidener") +} + +dependencies { + modApi("net.fabricmc:fabric-loader:${project.fabricloader_version}") + modRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_api}") + modApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") { + exclude(module: "fabric-api") + } + modRuntime("com.terraformersmc:modmenu:${modmenu_version}") { + transitive(false) + } + modRuntime("me.shedaniel:SmoothScrollingEverywhere:3.0.3-unstable") { + transitive(false) + } + modApi("me.shedaniel:architectury-fabric:${architectury_version}") + + implementation(project(path: ":api")) { transitive = false } + implementation(project(path: ":default-plugin")) { transitive = false } + implementation(project(path: ":runtime")) { transitive = false } + developmentFabric(project(path: ":api")) { transitive = false } + developmentFabric(project(path: ":default-plugin")) { transitive = false } + developmentFabric(project(path: ":runtime")) { transitive = false } +} diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java new file mode 100644 index 000000000..b8f10ba4e --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java @@ -0,0 +1,52 @@ +package me.shedaniel.rei.fabric; + +import com.google.common.collect.Iterables; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.plugins.REIPlugin; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; + +import static me.shedaniel.rei.RoughlyEnoughItemsCore.registerPlugin; + +public class PluginDetectorImpl { + public static void detectServerPlugins() { + FabricLoader.getInstance().getEntrypoints("rei_containers", Runnable.class).forEach(Runnable::run); + } + + @Environment(EnvType.CLIENT) + public static void detectClientPlugins() { + for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) { + if (modContainer.getMetadata().containsCustomElement("roughlyenoughitems:plugins")) + RoughlyEnoughItemsCore.LOGGER.error("REI plugin from " + modContainer.getMetadata().getId() + " is not loaded because it is too old!"); + } + + for (REIPlugin plugin : Iterables.concat( + FabricLoader.getInstance().getEntrypoints("rei_plugins", REIPlugin.class), + FabricLoader.getInstance().getEntrypoints("rei", REIPlugin.class) + )) { + try { + registerPlugin(plugin); + } catch (Exception e) { + e.printStackTrace(); + RoughlyEnoughItemsCore.LOGGER.error("Can't load REI plugins from %s: %s", plugin.getClass(), e.getLocalizedMessage()); + } + } + for (REIPlugin reiPlugin : FabricLoader.getInstance().getEntrypoints("rei_plugins_v0", REIPlugin.class)) { + try { + registerPlugin(reiPlugin); + } catch (Exception e) { + e.printStackTrace(); + RoughlyEnoughItemsCore.LOGGER.error("Can't load REI plugins from %s: %s", reiPlugin.getClass(), e.getLocalizedMessage()); + } + } + if (FabricLoader.getInstance().isModLoaded("libblockattributes-fluids")) { + try { + registerPlugin((REIPlugin) Class.forName("me.shedaniel.rei.compat.LBASupportPlugin").getConstructor().newInstance()); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } + } +} diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsFabric.java b/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsFabric.java new file mode 100644 index 000000000..7172ec864 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsFabric.java @@ -0,0 +1,31 @@ +package me.shedaniel.rei.fabric; + +import me.shedaniel.rei.impl.IssuesDetector; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; +import org.apache.logging.log4j.Logger; + +import java.lang.reflect.Field; +import java.util.Locale; + +public class RoughlyEnoughItemsFabric implements ModInitializer { + @Override + public void onInitialize() { + IssuesDetector.register(() -> { + try { + FabricLoader instance = FabricLoader.getInstance(); + for (Field field : instance.getClass().getDeclaredFields()) { + if (Logger.class.isAssignableFrom(field.getType())) { + field.setAccessible(true); + Logger logger = (Logger) field.get(instance); + if (logger.getName().toLowerCase(Locale.ROOT).contains("subsystem")) + return true; + } + } + } catch (Throwable ignored) { + } + return false; + }, ".ignoresubsystem", "Subsystem is detected (probably though Aristois), please contact support from them if anything happens."); + + } +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..0bfe4cb2d --- /dev/null +++ b/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,51 @@ +{ + "schemaVersion": 1, + "id": "roughlyenoughitems", + "name": "Roughly Enough Items", + "description": "Clean and Customizable.", + "version": "${version}", + "authors": [ + "shedaniel" + ], + "contact": { + "homepage": "https://www.curseforge.com/minecraft/mc-mods/roughly-enough-items", + "sources": "https://github.com/shedaniel/RoughlyEnoughItems", + "issues": "https://github.com/shedaniel/RoughlyEnoughItems/issues" + }, + "license": "MIT", + "icon": "icon.png", + "entrypoints": { + "main": [ + "me.shedaniel.rei.RoughlyEnoughItemsInitializer::onInitialize" + ], + "client": [ + "me.shedaniel.rei.fabric.RoughlyEnoughItemsFabric", + "me.shedaniel.rei.RoughlyEnoughItemsInitializer::onInitializeClient" + ], + "rei": [ + "me.shedaniel.rei.plugin.DefaultPlugin", + "me.shedaniel.rei.gui.plugin.DefaultRuntimePlugin" + ] + }, + "accessWidener": "roughlyenoughitems.accessWidener", + "custom": { + "rei:translators": { + "English": ["shedaniel"], + "Japanese": ["swordglowsblue", "hinataaki"], + "Chinese Simplified": ["XuyuEre", "shedaniel", "SciUniv_Moring", "Takakura-Anri", "liushuyu", "lkxian17084", "MynameisTT", "detiam", "Snapshot_light", "JerryHan", "WarrenWN", "Lograthmic"], + "Chinese Traditional": ["hugoalh", "gxy17886", "shedaniel", "961111ray"], + "French": ["Yanis48", "Koockies", "dagdar", "samnamstyle123"], + "German": ["MelanX", "guntram7", "tabmeier12", "Siphalor", "M-S-72", "SirClaver", "bugginggg", "wohlhabend", "Eiim", "valoeghese", "luro02"], + "Estonian": ["Madis0"], + "Portuguese": ["thiagokenis", "KewaiiGamer"], + "Portuguese Brazilian": ["thiagokenis", "joaoh1", "yuriob262", "Pinkstyles", "felipemk67", "Stevolaff", "stann0x"], + "LOLCAT": ["shedaniel", "RaxedMC", "lkxian17084"], + "Upside Down English": ["shedaniel", "magnusk28", "scarzdz"], + "Bulgarian": ["geniiii", "Dremski"], + "Russian": ["MrYonter", "kwmika1girl", "LimyChitou", "Great_Manalal", "s3rbug", "TheByKotik", "ebogish", "xqr.", "scarzdz", "JCat", "map788", "kyrtion", "CanslerW", "MinerChAI", "nef1k"], + "Polish": ["mikolajkazmierczak", "Piteriuz", "BeetMacol"], + "Norwegian": ["CanslerW"], + "Turkish": ["NOYB"] + } + } +} diff --git a/fabric/src/main/resources/icon.png b/fabric/src/main/resources/icon.png new file mode 100644 index 000000000..b7a48aef0 Binary files /dev/null and b/fabric/src/main/resources/icon.png differ diff --git a/fabric/src/main/resources/roughlyenoughitems.accessWidener b/fabric/src/main/resources/roughlyenoughitems.accessWidener new file mode 100644 index 000000000..4a5503b87 --- /dev/null +++ b/fabric/src/main/resources/roughlyenoughitems.accessWidener @@ -0,0 +1,33 @@ +accessWidener v1 named +accessible class net/minecraft/client/gui/Font$StringRenderOutput +accessible class net/minecraft/world/item/alchemy/PotionBrewing$Mix +accessible field net/minecraft/client/gui/components/ImageButton resourceLocation Lnet/minecraft/resources/ResourceLocation; +accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen hoveredSlot Lnet/minecraft/world/inventory/Slot; +accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen imageHeight I +accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen imageWidth I +accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen isQuickCrafting Z +accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen leftPos I +accessible field net/minecraft/client/gui/screens/inventory/AbstractContainerScreen topPos I +accessible field net/minecraft/client/gui/screens/inventory/EffectRenderingInventoryScreen doRenderEffects Z +accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent ghostRecipe Lnet/minecraft/client/gui/screens/recipebook/GhostRecipe; +accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent searchBox Lnet/minecraft/client/gui/components/EditBox; +accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent tabButtons Ljava/util/List; +accessible field net/minecraft/client/StringSplitter widthProvider Lnet/minecraft/client/StringSplitter$WidthProvider; +accessible field net/minecraft/world/entity/player/Inventory compartments Ljava/util/List; +accessible field net/minecraft/world/item/alchemy/PotionBrewing ALLOWED_CONTAINERS Ljava/util/List; +accessible field net/minecraft/world/item/alchemy/PotionBrewing CONTAINER_MIXES Ljava/util/List; +accessible field net/minecraft/world/item/alchemy/PotionBrewing POTION_MIXES Ljava/util/List; +accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix from Ljava/lang/Object; +accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix ingredient Lnet/minecraft/world/item/crafting/Ingredient; +accessible field net/minecraft/world/item/alchemy/PotionBrewing$Mix to Ljava/lang/Object; +accessible field net/minecraft/world/item/BucketItem content Lnet/minecraft/world/level/material/Fluid; +accessible field net/minecraft/world/item/crafting/UpgradeRecipe addition Lnet/minecraft/world/item/crafting/Ingredient; +accessible field net/minecraft/world/item/crafting/UpgradeRecipe base Lnet/minecraft/world/item/crafting/Ingredient; +accessible field net/minecraft/world/item/CreativeModeTab langId Ljava/lang/String; +accessible method net/minecraft/client/gui/GuiComponent innerBlit (Lcom/mojang/math/Matrix4f;IIIIIFFFF)V +accessible method net/minecraft/client/gui/screens/Screen addButton (Lnet/minecraft/client/gui/components/AbstractWidget;)Lnet/minecraft/client/gui/components/AbstractWidget; +accessible method net/minecraft/client/gui/screens/Screen addWidget (Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener; +accessible method net/minecraft/client/gui/screens/Screen init ()V +accessible method net/minecraft/client/gui/screens/Screen insertText (Ljava/lang/String;Z)V +accessible method net/minecraft/client/gui/screens/Screen isValidCharacterForName (Ljava/lang/String;CI)Z +accessible method net/minecraft/tags/TagContainer get (Lnet/minecraft/resources/ResourceKey;)Lnet/minecraft/tags/TagCollection; diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 000000000..d81a635c2 --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,26 @@ +archivesBaseName = "forge" + +architectury { + platformSetupLoomIde() + forge() +} + +processResources { + filesMatching("META-INF/mods.toml") { + expand "version": project.version + } + inputs.property "version", project.version +} + +dependencies { + forge("net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}") + modApi("me.shedaniel.cloth:cloth-config-forge:${cloth_config_version}") + modApi("me.shedaniel:architectury-forge:${architectury_version}") + + implementation(project(path: ":api")) { transitive = false } + implementation(project(path: ":default-plugin")) { transitive = false } + implementation(project(path: ":runtime")) { transitive = false } + developmentForge(project(path: ":api")) { transitive = false } + developmentForge(project(path: ":default-plugin")) { transitive = false } + developmentForge(project(path: ":runtime")) { transitive = false } +} diff --git a/forge/gradle.properties b/forge/gradle.properties new file mode 100644 index 000000000..3507db2d4 --- /dev/null +++ b/forge/gradle.properties @@ -0,0 +1 @@ +loom.forge=true diff --git a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java new file mode 100644 index 000000000..044bfd081 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java @@ -0,0 +1,21 @@ +package me.shedaniel.rei.forge; + +import me.shedaniel.rei.gui.plugin.DefaultRuntimePlugin; +import me.shedaniel.rei.plugin.DefaultPlugin; +import me.shedaniel.rei.plugin.DefaultServerContainerPlugin; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +import static me.shedaniel.rei.RoughlyEnoughItemsCore.registerPlugin; + +public class PluginDetectorImpl { + public static void detectServerPlugins() { + new DefaultServerContainerPlugin().run(); + } + + @OnlyIn(Dist.CLIENT) + public static void detectClientPlugins() { + registerPlugin(new DefaultPlugin()); + registerPlugin(new DefaultRuntimePlugin()); + } +} diff --git a/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsForge.java b/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsForge.java new file mode 100644 index 000000000..9147eb8f2 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsForge.java @@ -0,0 +1,17 @@ +package me.shedaniel.rei.forge; + +import me.shedaniel.architectury.platform.forge.EventBuses; +import me.shedaniel.rei.RoughlyEnoughItemsInitializer; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; + +@Mod("roughlyenoughitems") +public class RoughlyEnoughItemsForge { + public RoughlyEnoughItemsForge() { + EventBuses.registerModEventBus("roughlyenoughitems", FMLJavaModLoadingContext.get().getModEventBus()); + RoughlyEnoughItemsInitializer.onInitialize(); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> RoughlyEnoughItemsInitializer::onInitializeClient); + } +} diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 000000000..f4a298c9e --- /dev/null +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1,23 @@ +public net.minecraft.client.gui.recipebook.RecipeBookGui field_191915_z #ghostRecipe +public net.minecraft.client.gui.AbstractGui func_238461_a_(Lnet/minecraft/util/math/vector/Matrix4f;IIIIIFFFF)V #innerBlit +public net.minecraft.client.gui.screen.Screen field_230710_m_ #buttons +public net.minecraft.entity.player.PlayerInventory field_184440_g #compartments +public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147007_t #isQuickCrafting +public net.minecraft.client.gui.widget.button.ImageButton field_191750_o #resourceLocation +public net.minecraft.item.ItemGroup field_78034_o #langId +public net.minecraft.item.crafting.SmithingRecipe field_234837_a_ #base +public net.minecraft.item.crafting.SmithingRecipe field_234838_b_ #addition +public net.minecraft.client.gui.DisplayEffectsScreen field_147045_u #doRenderEffects +public net.minecraft.client.gui.recipebook.RecipeBookGui field_193018_j #tabButtons +public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147006_u #hoveredSlot +public net.minecraft.client.renderer.RenderState field_228520_l_ #SMOOTH_SHADE +public net.minecraft.client.renderer.RenderState field_228528_t_ #LIGHTMAP +public net.minecraft.client.renderer.RenderState field_228515_g_ #TRANSLUCENT_TRANSPARENCY +public net.minecraft.potion.PotionBrewing field_185213_a #POTION_MIXES +public net.minecraft.potion.PotionBrewing field_185214_b #CONTAINER_MIXES +public net.minecraft.potion.PotionBrewing field_185215_c #ALLOWED_CONTAINERS +public net.minecraft.util.text.CharacterManager field_238347_a_ #widthProvider +public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147003_i # leftPos +public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147009_r # topPos +public net.minecraft.client.gui.screen.inventory.ContainerScreen field_146999_f # imageWidth +public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147000_g # imageHeight \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 000000000..aa62f0797 --- /dev/null +++ b/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,20 @@ +modLoader = "javafml" +loaderVersion = "[36,)" +issueTrackerURL = "https://github.com/shedaniel/RoughlyEnoughItems/issues" +logoFile = "icon.png" +authors = "shedaniel" +license = "MIT" +[[mods]] +modId = "roughlyenoughitems" +version = "${version}" +displayName = "Roughly Enough Items" +description = ''' +To allow players to view items and recipes. +''' + +[[dependencies.roughlyenoughitems]] +modId = "cloth-config" +mandatory = true +versionRange = "[4.0.1,)" +ordering = "NONE" +side = "CLIENT" \ No newline at end of file diff --git a/forge/src/main/resources/icon.png b/forge/src/main/resources/icon.png new file mode 100644 index 000000000..b7a48aef0 Binary files /dev/null and b/forge/src/main/resources/icon.png differ diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta new file mode 100644 index 000000000..5cfd55687 --- /dev/null +++ b/forge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "Roughly Enough Items", + "pack_format": 6 + } +} diff --git a/gradle.properties b/gradle.properties index 4f4c7f534..1c7b0a93a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,9 @@ base_version=6.0.0 unstable=true supported_version=1.16.2/3/4/5 minecraft_version=1.16.5 +forge_version=36.0.43 fabricloader_version=0.11.1 -cloth_config_version=4.10.12 +cloth_config_version=4.11.14 modmenu_version=1.16.7 fabric_api=0.30.0+1.16 architectury_version=1.8.126 diff --git a/runtime/build.gradle b/runtime/build.gradle index d7264220b..5d6c24c49 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -1,14 +1,33 @@ archivesBaseName = "runtime" +architectury { + common() +} + repositories { maven { url "https://mod-buildcraft.com/maven" } } loom { - accessWidener = file("src/main/resources/roughlyenoughitems-runtime.accessWidener") + accessWidener = gradle.rootProject.project("fabric").file("src/main/resources/roughlyenoughitems.accessWidener") +} + +sourceSets { + main { + resources.srcDirs += rootProject.file("src/main/resources") + } } dependencies { - compile project(path: ":api", configuration: "dev") + modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}") + modCompileOnly("me.shedaniel.cloth:cloth-config:${cloth_config_version}") + modCompileOnly("me.shedaniel:architectury:${architectury_version}") + compileOnly(project(path: ":api")) modCompileOnly("alexiil.mc.lib:libblockattributes-fluids:0.8.3-pre.3") -} \ No newline at end of file +} + +remapJar { + afterEvaluate { + remapAccessWidener.set(false) + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java b/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java new file mode 100644 index 000000000..5e6de2399 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java @@ -0,0 +1,18 @@ +package me.shedaniel.rei; + +import me.shedaniel.architectury.annotations.ExpectPlatform; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +public class PluginDetector { + @ExpectPlatform + public static void detectServerPlugins() { + throw new AssertionError(); + } + + @Environment(EnvType.CLIENT) + @ExpectPlatform + public static void detectClientPlugins() { + throw new AssertionError(); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java b/runtime/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java index df51d9d03..1375c2f14 100644 --- a/runtime/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java +++ b/runtime/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java @@ -25,10 +25,8 @@ package me.shedaniel.rei; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.rei.api.ConfigManager; -import net.fabricmc.api.ClientModInitializer; -public class REIModMenuEntryPoint implements ClientModInitializer { - @Override +public class REIModMenuEntryPoint { public void onInitializeClient() { Platform.getMod("roughlyenoughitems").registerConfigurationScreen(ConfigManager.getInstance()::getConfigScreen); } diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 052cd903c..f0cfe81b5 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -23,7 +23,6 @@ package me.shedaniel.rei; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -61,11 +60,8 @@ import me.shedaniel.rei.impl.entry.EntryIngredientImpl; import me.shedaniel.rei.impl.view.ViewsImpl; import me.shedaniel.rei.impl.widgets.*; import me.shedaniel.rei.tests.plugin.REITestPlugin; -import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -110,7 +106,7 @@ import static me.shedaniel.rei.impl.Internals.attachInstance; @ApiStatus.Internal @Environment(EnvType.CLIENT) -public class RoughlyEnoughItemsCore implements ClientModInitializer { +public class RoughlyEnoughItemsCore { @ApiStatus.Internal public static final Logger LOGGER = LogManager.getFormatterLogger("REI"); private static final List PLUGINS = new ArrayList<>(); private static final ExecutorService SYNC_RECIPES = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "REI-SyncRecipes")); @@ -396,15 +392,11 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } @SuppressWarnings("deprecation") - @Override public void onInitializeClient() { IssuesDetector.detect(); registerClothEvents(); - discoverPluginEntries(); - for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) { - if (modContainer.getMetadata().containsCustomElement("roughlyenoughitems:plugins")) - RoughlyEnoughItemsCore.LOGGER.error("REI plugin from " + modContainer.getMetadata().getId() + " is not loaded because it is too old!"); - } + PluginDetector.detectClientPlugins(); + loadTestPlugins(); Minecraft client = Minecraft.getInstance(); NetworkManager.registerReceiver(NetworkManager.s2c(), RoughlyEnoughItemsNetwork.CREATE_ITEMS_MESSAGE_PACKET, (buf, context) -> { @@ -445,42 +437,10 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { }); } - private void discoverPluginEntries() { - for (REIPlugin plugin : Iterables.concat( - FabricLoader.getInstance().getEntrypoints("rei_plugins", REIPlugin.class), - FabricLoader.getInstance().getEntrypoints("rei", REIPlugin.class) - )) { - try { - registerPlugin(plugin); - } catch (Exception e) { - e.printStackTrace(); - RoughlyEnoughItemsCore.LOGGER.error("Can't load REI plugins from %s: %s", plugin.getClass(), e.getLocalizedMessage()); - } - } - for (REIPlugin reiPlugin : FabricLoader.getInstance().getEntrypoints("rei_plugins_v0", REIPlugin.class)) { - try { - registerPlugin(reiPlugin); - } catch (Exception e) { - e.printStackTrace(); - RoughlyEnoughItemsCore.LOGGER.error("Can't load REI plugins from %s: %s", reiPlugin.getClass(), e.getLocalizedMessage()); - } - } - - // Test Only - loadTestPlugins(); - } - private void loadTestPlugins() { if (isDebugModeEnabled()) { registerPlugin(new REITestPlugin()); } - if (FabricLoader.getInstance().isModLoaded("libblockattributes-fluids")) { - try { - registerPlugin((REIPlugin) Class.forName("me.shedaniel.rei.compat.LBASupportPlugin").getConstructor().newInstance()); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - } } private boolean shouldReturn(Screen screen) { diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java index 4e933ac7a..7308fbb38 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java @@ -24,20 +24,18 @@ package me.shedaniel.rei; import com.google.common.collect.ImmutableSet; -import net.fabricmc.api.ClientModInitializer; +import me.shedaniel.architectury.platform.Platform; import net.fabricmc.api.EnvType; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.SemanticVersion; -import net.fabricmc.loader.api.VersionParsingException; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; -public class RoughlyEnoughItemsInitializer implements ModInitializer, ClientModInitializer { - @Override - public void onInitialize() { - checkRequiredFabricModules(); - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { +public class RoughlyEnoughItemsInitializer { + public static void onInitialize() { + if (Platform.isFabric()) { + checkRequiredFabricModules(); + } + if (Platform.getEnv() == EnvType.CLIENT) { checkClothConfig(); } @@ -46,8 +44,7 @@ public class RoughlyEnoughItemsInitializer implements ModInitializer, ClientModI } } - @Override - public void onInitializeClient() { + public static void onInitializeClient() { if (RoughlyEnoughItemsState.getErrors().isEmpty()) { initializeEntryPoint("me.shedaniel.rei.RoughlyEnoughItemsCore"); initializeEntryPoint("me.shedaniel.rei.REIModMenuEntryPoint"); @@ -58,13 +55,25 @@ public class RoughlyEnoughItemsInitializer implements ModInitializer, ClientModI initializeEntryPoint("me.shedaniel.rei.impl.ErrorDisplayer"); } - public void initializeEntryPoint(String className) { + public static void initializeEntryPoint(String className) { try { - Object instance = Class.forName(className).getConstructor().newInstance(); - if (instance instanceof ModInitializer) { - ((ModInitializer) instance).onInitialize(); - } else if (instance instanceof ClientModInitializer) { - ((ClientModInitializer) instance).onInitializeClient(); + Class name = Class.forName(className); + Object instance = name.getConstructor().newInstance(); + Method method = null; + try { + method = name.getDeclaredMethod("onInitialize"); + } catch (NoSuchMethodException ignored) { + } + if (method != null) { + method.invoke(instance); + } else if (Platform.getEnv() == EnvType.CLIENT) { + try { + method = name.getDeclaredMethod("onInitializeClient"); + } catch (NoSuchMethodException ignored) { + } + if (method != null) { + method.invoke(instance); + } } } catch (InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) { throw new RuntimeException(e); @@ -72,7 +81,7 @@ public class RoughlyEnoughItemsInitializer implements ModInitializer, ClientModI } public static void checkRequiredFabricModules() { - ImmutableSet requiredModules = FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT ? + ImmutableSet requiredModules = Platform.getEnv() == EnvType.CLIENT ? ImmutableSet.builder() .add("fabric-api-base") .add("fabric-resource-loader-v0") @@ -87,7 +96,7 @@ public class RoughlyEnoughItemsInitializer implements ModInitializer, ClientModI .add("fabric-lifecycle-events-v1") .build(); for (String module : requiredModules) { - boolean moduleLoaded = FabricLoader.getInstance().isModLoaded(module); + boolean moduleLoaded = Platform.isModLoaded(module); if (!moduleLoaded) { RoughlyEnoughItemsState.error("Fabric API is not installed!", "https://www.curseforge.com/minecraft/mc-mods/fabric-api/files/all"); break; @@ -96,15 +105,15 @@ public class RoughlyEnoughItemsInitializer implements ModInitializer, ClientModI } public static void checkClothConfig() { - try { - if (!FabricLoader.getInstance().isModLoaded("cloth-config2")) { + /*try { + if (!Platform.isModLoaded("cloth-config2")) { RoughlyEnoughItemsState.error("Cloth Config is not installed!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all"); - } else if (SemanticVersion.parse(FabricLoader.getInstance().getModContainer("cloth-config2").get().getMetadata().getVersion().getFriendlyString()).compareTo(SemanticVersion.parse("4.10.9")) < 0) { + } else if (SemanticVersion.parse(Platform.getMod("cloth-config2").getVersion()).compareTo(SemanticVersion.parse("4.10.9")) < 0) { RoughlyEnoughItemsState.error("Your Cloth Config version is too old!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all"); } } catch (VersionParsingException e) { RoughlyEnoughItemsState.error("Failed to parse Cloth Config version: " + e.getMessage()); e.printStackTrace(); - } + }*/ } } \ No newline at end of file diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 24310961e..4013f6210 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -27,8 +27,6 @@ import com.google.common.collect.Lists; import io.netty.buffer.Unpooled; import me.shedaniel.architectury.networking.NetworkManager; import me.shedaniel.rei.api.server.InputSlotCrafter; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.core.NonNullList; @@ -45,7 +43,7 @@ import net.minecraft.world.item.ItemStack; import java.util.List; -public class RoughlyEnoughItemsNetwork implements ModInitializer { +public class RoughlyEnoughItemsNetwork { public static final ResourceLocation DELETE_ITEMS_PACKET = new ResourceLocation("roughlyenoughitems", "delete_item"); public static final ResourceLocation CREATE_ITEMS_PACKET = new ResourceLocation("roughlyenoughitems", "create_item"); public static final ResourceLocation CREATE_ITEMS_GRAB_PACKET = new ResourceLocation("roughlyenoughitems", "create_item_grab"); @@ -53,9 +51,8 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { public static final ResourceLocation MOVE_ITEMS_PACKET = new ResourceLocation("roughlyenoughitems", "move_items"); public static final ResourceLocation NOT_ENOUGH_ITEMS_PACKET = new ResourceLocation("roughlyenoughitems", "og_not_enough"); - @Override public void onInitialize() { - FabricLoader.getInstance().getEntrypoints("rei_containers", Runnable.class).forEach(Runnable::run); + PluginDetector.detectServerPlugins(); NetworkManager.registerReceiver(NetworkManager.c2s(), DELETE_ITEMS_PACKET, (buf, context) -> { ServerPlayer player = (ServerPlayer) context.getPlayer(); if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) { diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java index cd5b8c1e2..4f8c42bec 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java @@ -23,9 +23,9 @@ package me.shedaniel.rei; -import com.google.common.collect.ImmutableSet; +import me.shedaniel.architectury.platform.Platform; +import me.shedaniel.architectury.utils.Env; import net.fabricmc.api.EnvType; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.util.Tuple; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -49,7 +49,7 @@ public class RoughlyEnoughItemsState { private static List continueCallbacks = new ArrayList<>(); public static void error(String reason) { - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER || FabricLoader.getInstance().isDevelopmentEnvironment()) + if (Platform.getEnvironment() == Env.SERVER || Platform.isDevelopmentEnvironment()) throw new RuntimeException(reason); if (RoughlyEnoughItemsState.errorSet.add(reason + " " + null)) { RoughlyEnoughItemsState.errors.add(new Tuple<>(reason, null)); @@ -58,7 +58,7 @@ public class RoughlyEnoughItemsState { } public static void error(String reason, String link) { - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER || FabricLoader.getInstance().isDevelopmentEnvironment()) + if (Platform.getEnvironment() == Env.SERVER || Platform.isDevelopmentEnvironment()) throw new RuntimeException(reason + " " + link); if (RoughlyEnoughItemsState.errorSet.add(reason + " " + link)) { RoughlyEnoughItemsState.errors.add(new Tuple<>(reason, link)); diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java index d90fb8140..1e676e405 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java @@ -32,7 +32,6 @@ import me.shedaniel.rei.gui.TransformingScreen; import me.shedaniel.rei.gui.credits.CreditsEntryListWidget.TextCreditsItem; import me.shedaniel.rei.gui.credits.CreditsEntryListWidget.TranslationCreditsItem; import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.metadata.CustomValue; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; @@ -47,7 +46,6 @@ import net.minecraft.util.Tuple; import org.apache.commons.lang3.mutable.MutableLong; import org.jetbrains.annotations.ApiStatus; -import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.stream.Collectors; @@ -79,7 +77,7 @@ public class CreditsScreen extends Screen { entryListWidget.creditsClearEntries(); List> translators = Lists.newArrayList(); Exception[] exception = {null}; - FabricLoader.getInstance().getModContainer("roughlyenoughitems-runtime").ifPresent(rei -> { + /*FabricLoader.getInstance().getModContainer("roughlyenoughitems").ifPresent(rei -> { try { if (rei.getMetadata().containsCustomValue("rei:translators")) { CustomValue.CvObject jsonObject = rei.getMetadata().getCustomValue("rei:translators").getAsObject(); @@ -94,7 +92,7 @@ public class CreditsScreen extends Screen { exception[0] = e; e.printStackTrace(); } - }); + });*/ List> translatorsMapped = translators.stream().map(pair -> { return new Tuple<>( " " + (I18n.exists("language.roughlyenoughitems." + pair.getA().toLowerCase(Locale.ROOT).replace(' ', '_')) ? I18n.get("language.roughlyenoughitems." + pair.getA().toLowerCase(Locale.ROOT).replace(' ', '_')) : pair.getA()), diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java index 390f40f69..2942991e4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java @@ -86,6 +86,7 @@ public class DefaultRuntimePlugin implements REIPlugin { public void registerEntryTypes(EntryTypeRegistry registry) { registry.register(VanillaEntryTypes.ITEM, new ItemEntryDefinition()); registry.register(VanillaEntryTypes.FLUID, new FluidEntryDefinition()); + registry.registerBridge(VanillaEntryTypes.ITEM, VanillaEntryTypes.FLUID, input -> { Optional>> stream = FluidSupportProvider.getInstance().itemToFluids(input); if (!stream.isPresent()) { @@