Skip to content

Commit

Permalink
fix: comment out usage of Architectury JEI fluid ingredient type
Browse files Browse the repository at this point in the history
Current code crashes because the FLUID_STACK type isn't registered with JEI
The type needs to be registered, along with a helper and renderer and this
doesn't feel worth it, given that we already have working support for native
fluid types on all three platforms.
  • Loading branch information
desht committed Jun 4, 2024
1 parent 2cd2024 commit 28ee0ed
Showing 1 changed file with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.ftb.mods.ftblibrary.integration;

import dev.architectury.fluid.FluidStack;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.architectury.platform.Platform;
import dev.ftb.mods.ftblibrary.FTBLibrary;
Expand All @@ -17,7 +16,6 @@
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.handlers.IGlobalGuiHandler;
import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes;
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.api.registration.IGuiHandlerRegistration;
import mezz.jei.api.runtime.IClickableIngredient;
Expand All @@ -29,7 +27,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.material.Fluid;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
Expand Down Expand Up @@ -82,12 +79,15 @@ public Optional<IClickableIngredient<?>> getClickableIngredientUnderMouse(double
if (typed.isPresent()) {
return Optional.of(new ClickableIngredient<>(typed.get(), underMouse.area()));
}
} else if (underMouse.ingredient() instanceof FluidStack stack) {
// This should work if Arch has setup their fluidstack properly
Optional<ITypedIngredient<FluidStack>> typed = runtime.getIngredientManager().createTypedIngredient(FLUID_STACK, stack);
if (typed.isPresent()) {
return Optional.of(new ClickableIngredient<>(typed.get(), underMouse.area()));
}
// TODO this could work, but an Arch FLUID_STACK needs to be registered with JEI
// and this is non-trivial to do. The handleExtraIngredientTypes fallback below
// works fine for native FluidStacks on NeoForge/Fabric/Forge
// } else if (underMouse.ingredient() instanceof FluidStack stack) {
// // This should work if Arch has setup their fluidstack properly
// Optional<ITypedIngredient<FluidStack>> typed = runtime.getIngredientManager().createTypedIngredient(FLUID_STACK, stack);
// if (typed.isPresent()) {
// return Optional.of(new ClickableIngredient<>(typed.get(), underMouse.area()));
// }
} else {
// Allow us to fallback onto Fluid handlers for the native implementations
return handleExtraIngredientTypes(runtime, underMouse);
Expand Down Expand Up @@ -143,24 +143,25 @@ public Rect2i getArea() {
}
}

/**
* Wrapper around Archs fluid stack to provide JEI with the correct type for each platform
* @implNote This might not work.
*/
public static final IIngredientTypeWithSubtypes<Fluid, FluidStack> FLUID_STACK = new IIngredientTypeWithSubtypes<>() {
@Override
public Class<? extends FluidStack> getIngredientClass() {
return FluidStack.class;
}

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

@Override
public Fluid getBase(FluidStack ingredient) {
return ingredient.getFluid();
}
};
// TODO see above TODO about registering an Arch fluid stack ingredient type
// /**
// * Wrapper around Archs fluid stack to provide JEI with the correct type for each platform
// * @implNote This might not work.
// */
// public static final IIngredientTypeWithSubtypes<Fluid, FluidStack> FLUID_STACK = new IIngredientTypeWithSubtypes<>() {
// @Override
// public Class<? extends FluidStack> getIngredientClass() {
// return FluidStack.class;
// }
//
// @Override
// public Class<? extends Fluid> getIngredientBaseClass() {
// return Fluid.class;
// }
//
// @Override
// public Fluid getBase(FluidStack ingredient) {
// return ingredient.getFluid();
// }
// };
}

0 comments on commit 28ee0ed

Please sign in to comment.