Skip to content

Commit

Permalink
feat: support recipe querying for fluid ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Jun 8, 2024
1 parent 1e5f7b1 commit c20e6c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.jei;

import dev.architectury.fluid.FluidStack;
import dev.ftb.mods.ftbquests.client.ClientQuestFile;
import dev.ftb.mods.ftbxmodcompat.FTBXModCompat;
import dev.ftb.mods.ftbxmodcompat.ftbquests.QuestItems;
Expand Down Expand Up @@ -74,4 +75,14 @@ public static void showRecipes(ItemStack stack) {
));
}
}

public static void showRecipes(FluidStack stack) {
if (runtime != null) {
var nativeStack = runtime.getJeiHelpers().getPlatformFluidHelper().create(stack.getFluid(), stack.getAmount());
runtime.getIngredientManager().getIngredientTypeChecked(nativeStack)
.ifPresent(type -> runtime.getRecipesGui().show(
runtime.getJeiHelpers().getFocusFactory().createFocus(RecipeIngredientRole.OUTPUT, type, nativeStack)
));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.jei.helper;

import dev.architectury.fluid.FluidStack;
import dev.ftb.mods.ftbxmodcompat.FTBXModCompat;
import dev.ftb.mods.ftbxmodcompat.ftbquests.jei.FTBQuestsJEIIntegration;
import dev.ftb.mods.ftbxmodcompat.ftbquests.jei.LootCrateRecipeManagerPlugin;
Expand All @@ -17,6 +18,11 @@ public void showRecipes(ItemStack itemStack) {
FTBQuestsJEIIntegration.showRecipes(itemStack);
}

@Override
public void showRecipes(FluidStack fluidStack) {
FTBQuestsJEIIntegration.showRecipes(fluidStack);
}

@Override
public String getHelperName() {
return "JEI";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.rei;

import dev.architectury.fluid.FluidStack;
import dev.ftb.mods.ftbxmodcompat.FTBXModCompat;
import dev.ftb.mods.ftbxmodcompat.ftbquests.recipemod_common.WrappedLootCrate;
import dev.ftb.mods.ftbxmodcompat.ftbquests.recipemod_common.WrappedQuest;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.entry.filtering.base.BasicFilteringRule;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
import me.shedaniel.rei.api.client.registry.screen.ExclusionZones;
import me.shedaniel.rei.api.client.registry.screen.ExclusionZonesProvider;
import me.shedaniel.rei.api.client.view.ViewSearchBuilder;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.type.EntryDefinition;
import me.shedaniel.rei.api.common.entry.type.EntryType;
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry;
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.item.ItemStack;

import java.util.Collection;

public class FTBQuestsREIIntegration implements REIClientPlugin {
private static BasicFilteringRule.MarkDirty cratesChanged;

Expand Down Expand Up @@ -50,12 +46,17 @@ public void registerBasicEntryFiltering(BasicFilteringRule<?> rule) {
}

public static void showRecipes(ItemStack stack) {
for (EntryDefinition<?> definition : EntryTypeRegistry.getInstance().values()) {
if (definition.getType() == VanillaEntryTypes.ITEM) {
ViewSearchBuilder.builder()
.addRecipesFor(EntryStack.of(VanillaEntryTypes.ITEM, stack))
.open();
}
showRecipes(stack, VanillaEntryTypes.ITEM);
}

public static void showRecipes(FluidStack stack) {
showRecipes(stack, VanillaEntryTypes.FLUID);
}

private static <T> void showRecipes(T stack, EntryType<T> type) {
EntryDefinition<T> definition = EntryTypeRegistry.getInstance().get(type);
if (definition != null) {
ViewSearchBuilder.builder().addRecipesFor(EntryStack.of(definition, stack)).open();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbxmodcompat.ftbquests.rei.helper;

import dev.architectury.fluid.FluidStack;
import dev.ftb.mods.ftbxmodcompat.ftbquests.recipemod_common.BaseRecipeHelper;
import dev.ftb.mods.ftbxmodcompat.ftbquests.rei.FTBQuestsREIIntegration;
import dev.ftb.mods.ftbxmodcompat.ftbquests.rei.LootCrateDisplayGenerator;
Expand All @@ -12,6 +13,11 @@ public void showRecipes(ItemStack stack) {
FTBQuestsREIIntegration.showRecipes(stack);
}

@Override
public void showRecipes(FluidStack stack) {
FTBQuestsREIIntegration.showRecipes(stack);
}

@Override
public String getHelperName() {
return "REI";
Expand Down

0 comments on commit c20e6c4

Please sign in to comment.