diff --git a/build.gradle.kts b/build.gradle.kts index 7664ec4..adcc189 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -116,6 +116,7 @@ dependencies { includeProject("forgeconfigapiport") includeProject("extras-utils") includeProject("kubejs-bridge") + includeProject("jei-bridge") // Misc modImplementation("curse.maven:mcpitanlibarch-682213:4723157") diff --git a/jei-bridge/build.gradle.kts b/jei-bridge/build.gradle.kts new file mode 100644 index 0000000..9eaf508 --- /dev/null +++ b/jei-bridge/build.gradle.kts @@ -0,0 +1,32 @@ +plugins { + id("dev.architectury.loom") +} + +val versionMc: String by rootProject +val versionForge: String by rootProject + +loom { + forge { + mixinConfig("mixins.jeibridge.json") + } + mixin { + defaultRefmapName.set("refmap.jeibridge.json") + } +} + +repositories { + maven { + name = "Jared's maven" + url = uri("https://maven.blamejared.com/") + } +} + +dependencies { + mappings(loom.officialMojangMappings()) + forge("net.minecraftforge:forge:$versionMc-$versionForge") + + modImplementation(group = "dev.su5ed.sinytra", name = "fabric-loader", version = "2.3.4+0.14.21+1.20.1") + modImplementation(group = "dev.su5ed.sinytra.fabric-api", name = "fabric-transfer-api-v1", version = "3.3.1+6acac45477") + + modImplementation(group = "mezz.jei", name = "jei-$versionMc-forge", version = "15.2.0.27") +} diff --git a/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/JEIBridge.java b/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/JEIBridge.java new file mode 100644 index 0000000..20b02dd --- /dev/null +++ b/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/JEIBridge.java @@ -0,0 +1,11 @@ +package dev.su5ed.sinytra.connectorextras.jeibridge; + +import com.mojang.logging.LogUtils; +import net.minecraftforge.fml.common.Mod; +import org.slf4j.Logger; + +@Mod("connectorextras_jei_bridge") +public class JEIBridge { + private static final Logger LOGGER = LogUtils.getLogger(); + public static final String JEI_MODID = "jei"; +} diff --git a/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/JEIBridgeMixinPlugin.java b/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/JEIBridgeMixinPlugin.java new file mode 100644 index 0000000..3714320 --- /dev/null +++ b/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/JEIBridgeMixinPlugin.java @@ -0,0 +1,42 @@ +package dev.su5ed.sinytra.connectorextras.jeibridge; + +import com.google.common.base.Suppliers; +import net.minecraftforge.fml.loading.LoadingModList; +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.Set; +import java.util.function.Supplier; + +public class JEIBridgeMixinPlugin implements IMixinConfigPlugin { + private static final Supplier JEI_LOADED = Suppliers.memoize(() -> LoadingModList.get().getModFileById(JEIBridge.JEI_MODID) != null); + + @Override + public void onLoad(String mixinPackage) {} + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return JEI_LOADED.get(); + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) {} + + @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/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/mixin/ForgePluginFinderMixin.java b/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/mixin/ForgePluginFinderMixin.java new file mode 100644 index 0000000..f0904a4 --- /dev/null +++ b/jei-bridge/src/main/java/dev/su5ed/sinytra/connectorextras/jeibridge/mixin/ForgePluginFinderMixin.java @@ -0,0 +1,30 @@ +package dev.su5ed.sinytra.connectorextras.jeibridge.mixin; + +import mezz.jei.api.IModPlugin; +import mezz.jei.forge.startup.ForgePluginFinder; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.entrypoint.EntrypointContainer; +import org.spongepowered.asm.mixin.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.ArrayList; +import java.util.List; + +@Mixin(ForgePluginFinder.class) +public abstract class ForgePluginFinderMixin { + @Inject(method = "getModPlugins", at = @At("RETURN"), remap = false, cancellable = true) + private static void connectorextras_jei_bridge$addFabricPlugins(CallbackInfoReturnable> cir) { + List forgePlugins = cir.getReturnValue(); + List fabricPlugins = FabricLoader.getInstance() + .getEntrypointContainers("jei_mod_plugin", IModPlugin.class) + .stream() + .map(EntrypointContainer::getEntrypoint) + .toList(); + List merged = new ArrayList<>(); + merged.addAll(forgePlugins); + merged.addAll(fabricPlugins); + cir.setReturnValue(merged); + } +} diff --git a/jei-bridge/src/main/java/mezz/jei/api/fabric/constants/FabricTypes.java b/jei-bridge/src/main/java/mezz/jei/api/fabric/constants/FabricTypes.java new file mode 100644 index 0000000..d47c97b --- /dev/null +++ b/jei-bridge/src/main/java/mezz/jei/api/fabric/constants/FabricTypes.java @@ -0,0 +1,58 @@ +/* + * This file is licensed under the MIT License, part of Just Enough Items. + * Copyright (c) 2014-2015 mezz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package mezz.jei.api.fabric.constants; + +import mezz.jei.api.ingredients.IIngredientType; +import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes; +import mezz.jei.api.fabric.ingredients.fluids.IJeiFluidIngredient; +import net.minecraft.world.level.material.Fluid; + +/** + * Built-in {@link IIngredientType} for Fabric Minecraft. + * + * @since 10.1.0 + */ +public final class FabricTypes { + /** + * @since 10.1.0 + */ + public static final IIngredientTypeWithSubtypes FLUID_STACK = new IIngredientTypeWithSubtypes<>() { + @Override + public Class getIngredientClass() { + return IJeiFluidIngredient.class; + } + + @Override + public Class getIngredientBaseClass() { + return Fluid.class; + } + + @Override + public Fluid getBase(IJeiFluidIngredient ingredient) { + return ingredient.getFluid(); + } + }; + + private FabricTypes() {} +} diff --git a/jei-bridge/src/main/java/mezz/jei/api/fabric/ingredients/fluids/IJeiFluidIngredient.java b/jei-bridge/src/main/java/mezz/jei/api/fabric/ingredients/fluids/IJeiFluidIngredient.java new file mode 100644 index 0000000..0ce81dd --- /dev/null +++ b/jei-bridge/src/main/java/mezz/jei/api/fabric/ingredients/fluids/IJeiFluidIngredient.java @@ -0,0 +1,57 @@ +/* + * This file is licensed under the MIT License, part of Just Enough Items. + * Copyright (c) 2014-2015 mezz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package mezz.jei.api.fabric.ingredients.fluids; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.material.Fluid; + +import java.util.Optional; + +/** + * Built-in ingredient for representing Fluids in Fabric Minecraft. + * + * @since 10.1.0 + */ +public interface IJeiFluidIngredient { + /** + * @return the fluid represented by this ingredient. + * + * @since 10.1.0 + */ + Fluid getFluid(); + + /** + * @return the amount of fluid. + * + * @since 10.1.0 + */ + long getAmount(); + + /** + * @return optionally any {@link CompoundTag} extra data for this fluid ingredient. + * + * @since 10.1.0 + */ + Optional getTag(); +} diff --git a/jei-bridge/src/main/resources/META-INF/mods.toml b/jei-bridge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..d8b21e9 --- /dev/null +++ b/jei-bridge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,27 @@ +modLoader="javafml" +loaderVersion="[47,)" +license="MIT" +issueTrackerURL="https://github.com/Sinytra/ConnectorExtras/issues" + +[[mods]] +modId="connectorextras_jei_bridge" +version="${file.jarVersion}" +displayName="Connector Extras JEI Bridge" +authors="Su5eD" +displayURL="https://github.com/Sinytra/ConnectorExtras" +description=''' +Loads JEI plugins of Fabric mods on Forge. +''' +displayTest = 'IGNORE_ALL_VERSION' +[[dependencies.connectorextras_jei_bridge]] + modId="forge" + mandatory=true + versionRange="[47,)" + ordering="NONE" + side="BOTH" +[[dependencies.connectorextras_jei_bridge]] + modId="minecraft" + mandatory=true + versionRange="[1.20.1,1.21)" + ordering="NONE" + side="BOTH" diff --git a/jei-bridge/src/main/resources/mixins.jeibridge.json b/jei-bridge/src/main/resources/mixins.jeibridge.json new file mode 100644 index 0000000..46bfbb3 --- /dev/null +++ b/jei-bridge/src/main/resources/mixins.jeibridge.json @@ -0,0 +1,10 @@ +{ + "minVersion": "0.8", + "compatibilityLevel": "JAVA_16", + "required": true, + "package": "dev.su5ed.sinytra.connectorextras.jeibridge.mixin", + "plugin": "dev.su5ed.sinytra.connectorextras.jeibridge.JEIBridgeMixinPlugin", + "mixins": [ + "ForgePluginFinderMixin" + ] +} diff --git a/jei-bridge/src/main/resources/pack.mcmeta b/jei-bridge/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..7f62fa1 --- /dev/null +++ b/jei-bridge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "The default data for jeibridge", + "pack_format": 15 + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 581d927..357895d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -43,5 +43,6 @@ include( "amecs-api", "forgeconfigapiport", "extras-utils", - "kubejs-bridge" + "kubejs-bridge", + "jei-bridge" )