Skip to content

Commit

Permalink
Reimplement JEI integration (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz authored Sep 13, 2024
1 parent fe0fde0 commit ac6a5b3
Show file tree
Hide file tree
Showing 17 changed files with 481 additions and 14 deletions.
20 changes: 16 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ repositories {
includeGroup "top.theillusivec4.curios"
}
}
maven {
name = "blamejared"
url = "https://maven.blamejared.com/"
content {
includeGroup "mezz.jei"
}
}
maven {
name 'modmaven'
url "https://modmaven.dev/"
Expand Down Expand Up @@ -49,16 +56,21 @@ dependencies {

// compile against provided APIs
compileOnly "dev.emi:emi-neoforge:${emi_version}:api"
compileOnly "mezz.jei:jei-${project.jei_minecraft_version}-neoforge-api:${project.jei_version}"
if (project.runtime_itemlist_mod != "rei") {
compileOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}"
}

if (project.runtime_itemlist_mod == "emi") {
runtimeOnly "dev.emi:emi-neoforge:${emi_version}"

compileOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}"
} else if (project.runtime_itemlist_mod == "rei") {
implementation "me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}"
} else if (project.runtime_itemlist_mod == "jei") {
runtimeOnly "mezz.jei:jei-${project.jei_minecraft_version}-neoforge:${project.jei_version}"
} else if (project.runtime_itemlist_mod == "none") {
compileOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}"
// none
} else {
throw new GradleException("Unknown setting for project.runtime_itemlist_mod=${project.runtime_itemlist_mod}. Supported: emi, rei and none")
throw new GradleException("Unknown setting for project.runtime_itemlist_mod=${project.runtime_itemlist_mod}. Supported: emi, rei, jei and none")
}

compileOnly "top.theillusivec4.curios:curios-neoforge:${project.curios_version}:api"
Expand Down
8 changes: 6 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ minecraft_version=1.21
cloth_config_version=15.0.127

rei_version=16.0.729
emi_version=1.1.10+1.21
# latest emi versions: https://maven.terraformersmc.com/releases/dev/emi/emi-neoforge/maven-metadata.xml
emi_version=1.1.13+1.21.1
# latest jei versions: https://maven.blamejared.com/mezz/jei/jei-1.21.1-neoforge/maven-metadata.xml
jei_version=19.18.3.203
jei_minecraft_version=1.21.1
neoforge_version=21.0.143
curios_version=7.0.0-beta.3+1.20.4

# Switch between none, emi and rei
# Switch between none, emi, rei, and jei
runtime_itemlist_mod=emi

#########################################################
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/owmii/powah/compat/common/FluidCoolant.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package owmii.powah.compat.common;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
Expand All @@ -14,7 +13,7 @@
import owmii.powah.api.FluidCoolantConfig;

public record FluidCoolant(ResourceLocation id, Fluid fluid, Set<BucketItem> buckets, int coldness) {
public static Collection<FluidCoolant> getAll() {
public static List<FluidCoolant> getAll() {
List<FluidCoolant> result = new ArrayList<>();

var dataMap = BuiltInRegistries.FLUID.getDataMap(FluidCoolantConfig.DATA_MAP_TYPE);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/owmii/powah/compat/common/MagmatorFuel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package owmii.powah.compat.common;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
Expand All @@ -14,7 +13,7 @@
import owmii.powah.api.MagmatorFuelValue;

public record MagmatorFuel(ResourceLocation id, Fluid fluid, Set<BucketItem> buckets, int heat) {
public static Collection<MagmatorFuel> getAll() {
public static List<MagmatorFuel> getAll() {
List<MagmatorFuel> result = new ArrayList<>();

var dataMap = BuiltInRegistries.FLUID.getDataMap(MagmatorFuelValue.DATA_MAP_TYPE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package owmii.powah.compat.common;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
Expand All @@ -12,7 +12,7 @@
import owmii.powah.api.PassiveHeatSourceConfig;

public record PassiveHeatSource(ResourceLocation id, @Nullable Block block, @Nullable Fluid fluid, int heat) {
public static Collection<PassiveHeatSource> getAll() {
public static List<PassiveHeatSource> getAll() {
var result = new ArrayList<PassiveHeatSource>();

for (var entry : BuiltInRegistries.BLOCK.getDataMap(PassiveHeatSourceConfig.BLOCK_DATA_MAP).entrySet()) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/owmii/powah/compat/common/SolidCoolant.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package owmii.powah.compat.common;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -11,7 +10,7 @@
import owmii.powah.api.SolidCoolantConfig;

public record SolidCoolant(ResourceLocation id, Item item, int amount, int temperature) {
public static Collection<SolidCoolant> getAll() {
public static List<SolidCoolant> getAll() {
List<SolidCoolant> result = new ArrayList<>();

for (var entry : BuiltInRegistries.ITEM.getDataMap(SolidCoolantConfig.DATA_MAP_TYPE).entrySet()) {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/owmii/powah/compat/jei/AbstractCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package owmii.powah.compat.jei;

import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.ItemLike;

public abstract class AbstractCategory<T> implements IRecipeCategory<T> {
private final Component title;
private final IDrawable background;
private final IDrawable icon;

public AbstractCategory(IGuiHelper guiHelper, ItemLike iconItemLike, Component title, IDrawable background) {
this.title = title;
this.background = background;
this.icon = guiHelper.createDrawableItemLike(iconItemLike);
}

@Override
public final Component getTitle() {
return title;
}

@Override
public final IDrawable getBackground() {
return background;
}

@Override
public final IDrawable getIcon() {
return icon;
}
}
9 changes: 9 additions & 0 deletions src/main/java/owmii/powah/compat/jei/Assets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package owmii.powah.compat.jei;

import net.minecraft.resources.ResourceLocation;
import owmii.powah.Powah;

public class Assets {
public static final ResourceLocation ENERGIZING = ResourceLocation.fromNamespaceAndPath(Powah.MOD_ID, "textures/gui/jei/energizing.png");
public static final ResourceLocation MISC = ResourceLocation.fromNamespaceAndPath(Powah.MOD_ID, "textures/gui/jei/misc.png");
}
64 changes: 64 additions & 0 deletions src/main/java/owmii/powah/compat/jei/JeiEnergizingCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package owmii.powah.compat.jei;

import java.util.List;
import java.util.function.Supplier;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.crafting.RecipeHolder;
import owmii.powah.block.Blcks;
import owmii.powah.block.energizing.EnergizingRecipe;
import owmii.powah.recipe.Recipes;
import owmii.powah.util.Util;

public class JeiEnergizingCategory extends AbstractCategory<RecipeHolder<EnergizingRecipe>> {
public static final Supplier<RecipeType<RecipeHolder<EnergizingRecipe>>> TYPE = RecipeType.createFromDeferredVanilla(Recipes.ENERGIZING);

public JeiEnergizingCategory(IGuiHelper guiHelper) {
super(guiHelper, Blcks.ENERGIZING_ORB.get(), Component.translatable("gui.powah.jei.category.energizing"),
guiHelper.drawableBuilder(Assets.ENERGIZING, 0, 0, 160, 38).addPadding(1, 0, 0, 0).build());
}

@Override
public RecipeType<RecipeHolder<EnergizingRecipe>> getRecipeType() {
return TYPE.get();
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder<EnergizingRecipe> recipeHolder, IFocusGroup focuses) {
var recipe = recipeHolder.value();
var ingredients = recipe.getIngredients();
int size = ingredients.size();
for (int i = 0; i < size; i++) {
builder.addSlot(RecipeIngredientRole.INPUT, (i * 20) + 4, 5)
.addIngredients(ingredients.get(i));
}

builder.addSlot(RecipeIngredientRole.OUTPUT, 137, 5)
.addItemStack(recipe.getResultItem());
}

@Override
public void draw(RecipeHolder<EnergizingRecipe> recipeHolder, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX,
double mouseY) {
var recipe = recipeHolder.value();
var minecraft = Minecraft.getInstance();
guiGraphics.drawString(minecraft.font, I18n.get("info.lollipop.fe", Util.addCommas(recipe.getEnergy())), 2, 29, 0x444444, false);
}

public static List<RecipeHolder<EnergizingRecipe>> getAllRecipes() {
var minecraft = Minecraft.getInstance();
var level = minecraft.level;
assert level != null;
var recipeManager = level.getRecipeManager();

return recipeManager.getAllRecipesFor(Recipes.ENERGIZING.get());
}
}
43 changes: 43 additions & 0 deletions src/main/java/owmii/powah/compat/jei/JeiFluidCoolantCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package owmii.powah.compat.jei;

import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Items;
import owmii.powah.Powah;
import owmii.powah.compat.common.FluidCoolant;

public class JeiFluidCoolantCategory extends AbstractCategory<FluidCoolant> {
public static final RecipeType<FluidCoolant> TYPE = RecipeType.create(Powah.MOD_ID, "coolant", FluidCoolant.class);

public JeiFluidCoolantCategory(IGuiHelper guiHelper) {
super(guiHelper, Items.WATER_BUCKET, Component.translatable("gui.powah.jei.category.coolant"),
guiHelper.drawableBuilder(Assets.MISC, 0, 0, 160, 24).addPadding(1, 0, 0, 0).build());
}

@Override
public RecipeType<FluidCoolant> getRecipeType() {
return TYPE;
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, FluidCoolant recipe, IFocusGroup focuses) {
builder.addSlot(RecipeIngredientRole.INPUT, 4, 5)
.addFluidStack(recipe.fluid());
}

@Override
public void draw(FluidCoolant recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) {
var minecraft = Minecraft.getInstance();
guiGraphics.drawString(minecraft.font, I18n.get("info.lollipop.temperature") + ": "
+ I18n.get("info.lollipop.temperature.c", "" + ChatFormatting.DARK_AQUA + recipe.coldness()), 30, 9, 0x444444, false);
}
}
49 changes: 49 additions & 0 deletions src/main/java/owmii/powah/compat/jei/JeiHeatSourceCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package owmii.powah.compat.jei;

import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.Blocks;
import owmii.powah.Powah;
import owmii.powah.compat.common.PassiveHeatSource;

public class JeiHeatSourceCategory extends AbstractCategory<PassiveHeatSource> {
public static final RecipeType<PassiveHeatSource> TYPE = RecipeType.create(Powah.MOD_ID, "heat_source", PassiveHeatSource.class);

public JeiHeatSourceCategory(IGuiHelper guiHelper) {
super(guiHelper, Blocks.MAGMA_BLOCK, Component.translatable("gui.powah.jei.category.heat.sources"),
guiHelper.drawableBuilder(Assets.MISC, 0, 0, 160, 24).addPadding(1, 0, 0, 0).build());
}

@Override
public RecipeType<PassiveHeatSource> getRecipeType() {
return TYPE;
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, PassiveHeatSource recipe, IFocusGroup focuses) {
var input = builder.addSlot(RecipeIngredientRole.INPUT, 4, 5);

if (recipe.block() != null) {
input.addItemLike(recipe.block());
}
if (recipe.fluid() != null) {
input.addFluidStack(recipe.fluid());
}
}

@Override
public void draw(PassiveHeatSource recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) {
var minecraft = Minecraft.getInstance();
guiGraphics.drawString(minecraft.font, ChatFormatting.DARK_GRAY + I18n.get("info.lollipop.temperature") + ": "
+ ChatFormatting.RESET + I18n.get("info.lollipop.temperature.c", recipe.heat()), 30, 9, 0xc43400, false);
}
}
41 changes: 41 additions & 0 deletions src/main/java/owmii/powah/compat/jei/JeiMagmatorCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package owmii.powah.compat.jei;

import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import owmii.powah.Powah;
import owmii.powah.block.Blcks;
import owmii.powah.block.Tier;
import owmii.powah.compat.common.MagmatorFuel;

public class JeiMagmatorCategory extends AbstractCategory<MagmatorFuel> {
public static final RecipeType<MagmatorFuel> TYPE = RecipeType.create(Powah.MOD_ID, "magmatic", MagmatorFuel.class);

public JeiMagmatorCategory(IGuiHelper guiHelper) {
super(guiHelper, Blcks.MAGMATOR.get(Tier.BASIC), Component.translatable("gui.powah.jei.category.magmatic"),
guiHelper.drawableBuilder(Assets.MISC, 0, 0, 160, 24).addPadding(1, 0, 0, 0).build());
}

@Override
public RecipeType<MagmatorFuel> getRecipeType() {
return TYPE;
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, MagmatorFuel recipe, IFocusGroup focuses) {
builder.addSlot(RecipeIngredientRole.INPUT, 4, 5)
.addFluidStack(recipe.fluid());
}

@Override
public void draw(MagmatorFuel recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) {
var minecraft = Minecraft.getInstance();
guiGraphics.drawString(minecraft.font, recipe.heat() + " FE/100 mb", 27, 9, 0x444444, false);
}
}
Loading

0 comments on commit ac6a5b3

Please sign in to comment.