Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JEI bridge #22

Merged
merged 2 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ dependencies {
includeProject("forgeconfigapiport")
includeProject("extras-utils")
includeProject("kubejs-bridge")
includeProject("jei-bridge")

// Misc
modImplementation("curse.maven:mcpitanlibarch-682213:4723157")
Expand Down
32 changes: 32 additions & 0 deletions jei-bridge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> 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<String> getMixins() {
return null;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> 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) {}
}
Original file line number Diff line number Diff line change
@@ -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<List<IModPlugin>> cir) {
List<IModPlugin> forgePlugins = cir.getReturnValue();
List<IModPlugin> fabricPlugins = FabricLoader.getInstance()
.getEntrypointContainers("jei_mod_plugin", IModPlugin.class)
.stream()
.map(EntrypointContainer::getEntrypoint)
.toList();
List<IModPlugin> merged = new ArrayList<>();
merged.addAll(forgePlugins);
merged.addAll(fabricPlugins);
cir.setReturnValue(merged);
}
}
Original file line number Diff line number Diff line change
@@ -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, IJeiFluidIngredient> FLUID_STACK = new IIngredientTypeWithSubtypes<>() {
@Override
public Class<? extends IJeiFluidIngredient> getIngredientClass() {
return IJeiFluidIngredient.class;
}

@Override
public Class<? extends Fluid> getIngredientBaseClass() {
return Fluid.class;
}

@Override
public Fluid getBase(IJeiFluidIngredient ingredient) {
return ingredient.getFluid();
}
};

private FabricTypes() {}
}
Original file line number Diff line number Diff line change
@@ -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<CompoundTag> getTag();
}
27 changes: 27 additions & 0 deletions jei-bridge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions jei-bridge/src/main/resources/mixins.jeibridge.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
6 changes: 6 additions & 0 deletions jei-bridge/src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"description": "The default data for jeibridge",
"pack_format": 15
}
}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ include(
"amecs-api",
"forgeconfigapiport",
"extras-utils",
"kubejs-bridge"
"kubejs-bridge",
"jei-bridge"
)