Skip to content

Commit

Permalink
more work on the guide, jei hates me
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Apr 23, 2024
1 parent 1b3b92d commit 78f6a13
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,9 @@ public void reload(ResourceManager manager) {
ResourceLoader.clear();
ResourceLoader.loadResources(manager);

// Must manually load JEI and REI so they have the custom model data correct
if (CompatUtils.isRecipeModLoaded()) {
if (CompatUtils.isJeiLoaded()) {
JeiIntegration.load();
}

if (CompatUtils.isReiLoaded()) {
ReiIntegration.load();
}
}

// Load the Book Contents
if (CompatUtils.isPatchouliLoaded()) {
CustomGuide.load();
// Must manually load REI so it has the custom model data correct
if (CompatUtils.isReiLoaded()) {
ReiIntegration.load();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.justahuman.slimefun_essentials.compat.jei;

import me.justahuman.slimefun_essentials.client.ResourceLoader;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
import me.justahuman.slimefun_essentials.client.SlimefunItemStack;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
import me.justahuman.slimefun_essentials.compat.jei.categories.AncientAltarCategory;
import me.justahuman.slimefun_essentials.compat.jei.categories.GridCategory;
import me.justahuman.slimefun_essentials.compat.jei.categories.ProcessCategory;
Expand All @@ -18,26 +18,27 @@
import mezz.jei.api.helpers.IJeiHelpers;
import mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.registration.IRecipeCatalystRegistration;
import mezz.jei.api.registration.IRecipeCategoryRegistration;
import mezz.jei.api.registration.IRecipeRegistration;
import mezz.jei.api.registration.IRecipeTransferRegistration;
import mezz.jei.api.registration.IRuntimeRegistration;
import mezz.jei.api.registration.ISubtypeRegistration;
import mezz.jei.api.runtime.IJeiRuntime;
import mezz.jei.library.load.registration.SubtypeRegistration;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.Generic3x3ContainerScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Set;

@JeiPlugin
public class JeiIntegration implements IModPlugin {
public static final JeiRecipeInterpreter RECIPE_INTERPRETER = new JeiRecipeInterpreter();
private static IRecipeCategoryRegistration categoryRegistration;
private static IRecipeRegistration recipeRegistration;
private static IRecipeCatalystRegistration catalystRegistration;
private static final Set<ProcessCategory> CATEGORIES = new HashSet<>();

@Override
@NotNull
Expand All @@ -47,6 +48,10 @@ public Identifier getPluginUid() {

@Override
public void registerRuntime(IRuntimeRegistration registration) {
for (ProcessCategory category : CATEGORIES) {
category.updateIcon();
}

registration.getIngredientManager().addIngredientsAtRuntime(VanillaTypes.ITEM_STACK, ResourceLoader.getSlimefunItems().values().stream().map(SlimefunItemStack::itemStack).toList());
}

Expand All @@ -61,23 +66,31 @@ public void registerItemSubtypes(ISubtypeRegistration iregistration) {
registration.getInterpreters().addInterpreter(VanillaTypes.ITEM_STACK, slimefunItemStack.itemStack().getItem(), new SlimefunIdInterpreter(oldInterpreter));
}
}

@Override
public void registerCategories(IRecipeCategoryRegistration registration) {
if (!Utils.shouldFunction()) {
return;
}

categoryRegistration = registration;
IJeiHelpers jeiHelpers = registration.getJeiHelpers();
IGuiHelper guiHelper = jeiHelpers.getGuiHelper();
for (SlimefunRecipeCategory recipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
final ProcessCategory category = getJeiCategory(guiHelper, recipeCategory, ResourceLoader.getSlimefunItems().get(recipeCategory.id()));
registration.addRecipeCategories(category);
CATEGORIES.add(category);
}
}

@Override
public void registerRecipes(IRecipeRegistration registration) {
if (!Utils.shouldFunction()) {
return;
}

recipeRegistration = registration;
for (SlimefunRecipeCategory recipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
registration.addRecipes(RecipeType.create(Utils.ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class), recipeCategory.recipes());
}
}

@Override
Expand All @@ -86,52 +99,37 @@ public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
return;
}

catalystRegistration = registration;
for (SlimefunRecipeCategory recipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
registration.addRecipeCatalyst(ResourceLoader.getSlimefunItems().get(recipeCategory.id()).itemStack(), RecipeType.create(Utils.ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class));
}
}

@Override
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
for (SlimefunRecipeCategory slimefunRecipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
if (slimefunRecipeCategory.type().contains("ancient_altar")) {
for (SlimefunRecipeCategory recipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
if (recipeCategory.type().contains("ancient_altar")) {
return;
}

final RecipeType<SlimefunRecipe> recipeType = RecipeType.create(Utils.ID, slimefunRecipeCategory.id().toLowerCase(), SlimefunRecipe.class);
if (slimefunRecipeCategory.type().contains("grid")) {
final RecipeType<SlimefunRecipe> recipeType = RecipeType.create(Utils.ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class);
if (recipeCategory.type().contains("grid")) {
registration.addRecipeTransferHandler(Generic3x3ContainerScreenHandler.class, ScreenHandlerType.GENERIC_3X3, recipeType, 0, 9, 9, 36);
}
}
}

public static void load() {
if (categoryRegistration == null || recipeRegistration == null || catalystRegistration == null) {
return;
}

IJeiHelpers jeiHelpers = categoryRegistration.getJeiHelpers();
IGuiHelper guiHelper = jeiHelpers.getGuiHelper();
for (SlimefunRecipeCategory slimefunRecipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
categoryRegistration.addRecipeCategories(getJeiCategory(guiHelper, slimefunRecipeCategory, slimefunRecipeCategory.getItemFromId()));
}

for (SlimefunRecipeCategory slimefunRecipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
recipeRegistration.addRecipes(RecipeType.create(Utils.ID, slimefunRecipeCategory.id().toLowerCase(), SlimefunRecipe.class), slimefunRecipeCategory.recipes());
catalystRegistration.addRecipeCatalyst(slimefunRecipeCategory.getItemFromId(), RecipeType.create(Utils.ID, slimefunRecipeCategory.id().toLowerCase(), SlimefunRecipe.class));
}
}

public static IRecipeCategory<SlimefunRecipe> getJeiCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, ItemStack catalyst) {
final String type = slimefunRecipeCategory.type();
public static ProcessCategory getJeiCategory(IGuiHelper guiHelper, SlimefunRecipeCategory recipeCategory, SlimefunItemStack catalyst) {
final String type = recipeCategory.type();
if (type.equals("ancient_altar")) {
return new AncientAltarCategory(guiHelper, slimefunRecipeCategory, catalyst);
return new AncientAltarCategory(guiHelper, recipeCategory, catalyst);
} else if (type.equals("smeltery")) {
return new SmelteryCategory(guiHelper, slimefunRecipeCategory, catalyst);
return new SmelteryCategory(guiHelper, recipeCategory, catalyst);
} else if (type.equals("reactor")) {
return new ReactorCategory(guiHelper, slimefunRecipeCategory, catalyst);
return new ReactorCategory(guiHelper, recipeCategory, catalyst);
} else if (type.contains("grid")) {
return new GridCategory(guiHelper, slimefunRecipeCategory, catalyst, TextureUtils.getSideSafe(type));
return new GridCategory(guiHelper, recipeCategory, catalyst, TextureUtils.getSideSafe(type));
} else {
return new ProcessCategory(guiHelper, slimefunRecipeCategory, catalyst);
return new ProcessCategory(guiHelper, recipeCategory, catalyst);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.justahuman.slimefun_essentials.compat.jei.categories;

import me.justahuman.slimefun_essentials.api.OffsetBuilder;
import me.justahuman.slimefun_essentials.client.SlimefunItemStack;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.compat.jei.JeiIntegration;
Expand All @@ -11,15 +12,14 @@
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class AncientAltarCategory extends ProcessCategory {
public AncientAltarCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, ItemStack catalyst) {
public AncientAltarCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, SlimefunItemStack catalyst) {
super(Type.ANCIENT_ALTAR, guiHelper, slimefunRecipeCategory, catalyst);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.justahuman.slimefun_essentials.compat.jei.categories;

import me.justahuman.slimefun_essentials.api.OffsetBuilder;
import me.justahuman.slimefun_essentials.client.SlimefunItemStack;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeComponent;
Expand All @@ -12,7 +13,6 @@
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

Expand All @@ -21,7 +21,7 @@

public class GridCategory extends ProcessCategory {
protected final int side;
public GridCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, ItemStack catalyst, int side) {
public GridCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, SlimefunItemStack catalyst, int side) {
super(Type.grid(side), guiHelper, slimefunRecipeCategory, catalyst);

this.side = side;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.common.cache.LoadingCache;
import me.justahuman.slimefun_essentials.api.OffsetBuilder;
import me.justahuman.slimefun_essentials.api.RecipeRenderer;
import me.justahuman.slimefun_essentials.client.SlimefunItemStack;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
import me.justahuman.slimefun_essentials.client.SlimefunLabel;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
Expand All @@ -23,7 +24,6 @@
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

Expand All @@ -33,25 +33,25 @@
public class ProcessCategory extends RecipeRenderer implements IRecipeCategory<SlimefunRecipe> {
protected final IGuiHelper guiHelper;
protected final SlimefunRecipeCategory slimefunRecipeCategory;
protected final ItemStack catalyst;
protected final IDrawable icon;
protected final SlimefunItemStack catalyst;
protected IDrawable icon;
protected final IDrawable background;
protected final IDrawableAnimated positiveEnergy;
protected final IDrawableAnimated negativeEnergy;
protected final LoadingCache<Integer, IDrawableAnimated> cachedArrows;
protected final LoadingCache<Integer, IDrawableAnimated> cachedBackwardsArrows;

public ProcessCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, ItemStack catalyst) {
public ProcessCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, SlimefunItemStack catalyst) {
this(Type.PROCESS, guiHelper, slimefunRecipeCategory, catalyst);
}

public ProcessCategory(Type type, IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, ItemStack catalyst) {
public ProcessCategory(Type type, IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, SlimefunItemStack catalyst) {
super(type);

this.guiHelper = guiHelper;
this.slimefunRecipeCategory = slimefunRecipeCategory;
this.catalyst = catalyst;
this.icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, catalyst);
this.icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, catalyst.itemStack());
this.background = guiHelper.drawableBuilder(TextureUtils.WIDGETS, 0, 0, 0, 0).addPadding(yPadding(), yPadding(), xPadding(), xPadding()).build();
this.positiveEnergy = guiHelper.drawableBuilder(TextureUtils.WIDGETS, TextureUtils.ENERGY_POSITIVE.u(), TextureUtils.ENERGY.v(), TextureUtils.ENERGY_WIDTH, TextureUtils.ENERGY_HEIGHT).buildAnimated(20, IDrawableAnimated.StartDirection.TOP, false);
this.negativeEnergy = guiHelper.drawableBuilder(TextureUtils.WIDGETS, TextureUtils.ENERGY_NEGATIVE.u(), TextureUtils.ENERGY.v(), TextureUtils.ENERGY_WIDTH, TextureUtils.ENERGY_HEIGHT).buildAnimated(20, IDrawableAnimated.StartDirection.BOTTOM, true);
Expand Down Expand Up @@ -92,20 +92,24 @@ public RecipeType<SlimefunRecipe> getRecipeType() {
@Override
@NotNull
public Text getTitle() {
return Text.translatable("slimefun_essentials.recipes.category.slimefun", this.catalyst.getName());
return Text.translatable("slimefun_essentials.recipes.category.slimefun", this.catalyst.itemStack().getName());
}

@Override
@NotNull
public IDrawable getBackground() {
return this.background;
}

@Override
@NotNull
public IDrawable getIcon() {
return this.icon;
}

public void updateIcon() {
this.icon = this.guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, this.catalyst.itemStack());;
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, SlimefunRecipe recipe, IFocusGroup focuses) {
Expand All @@ -125,7 +129,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, SlimefunRecipe recipe, IFocu
offsets.x().addSlot();
}
} else {
JeiIntegration.RECIPE_INTERPRETER.addIngredient(builder.addSlot(RecipeIngredientRole.INPUT, offsets.getX() + 1, offsets.slot() + 1), this.catalyst);
JeiIntegration.RECIPE_INTERPRETER.addIngredient(builder.addSlot(RecipeIngredientRole.INPUT, offsets.getX() + 1, offsets.slot() + 1), this.catalyst.itemStack());
offsets.x().addSlot();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.justahuman.slimefun_essentials.compat.jei.categories;

import me.justahuman.slimefun_essentials.api.OffsetBuilder;
import me.justahuman.slimefun_essentials.client.SlimefunItemStack;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.compat.jei.JeiIntegration;
Expand All @@ -11,15 +12,14 @@
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class ReactorCategory extends ProcessCategory {
public ReactorCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, ItemStack catalyst) {
public ReactorCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, SlimefunItemStack catalyst) {
super(Type.REACTOR, guiHelper, slimefunRecipeCategory, catalyst);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.justahuman.slimefun_essentials.compat.jei.categories;

import me.justahuman.slimefun_essentials.api.OffsetBuilder;
import me.justahuman.slimefun_essentials.client.SlimefunItemStack;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeComponent;
Expand All @@ -12,15 +13,14 @@
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class SmelteryCategory extends ProcessCategory {
public SmelteryCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, ItemStack catalyst) {
public SmelteryCategory(IGuiHelper guiHelper, SlimefunRecipeCategory slimefunRecipeCategory, SlimefunItemStack catalyst) {
super(Type.SMELTERY, guiHelper, slimefunRecipeCategory, catalyst);
}

Expand Down
Loading

0 comments on commit 78f6a13

Please sign in to comment.