Skip to content

Commit

Permalink
Allow MTEs / recipe map workables to directly control their JEI categ…
Browse files Browse the repository at this point in the history
…ories (#2479)
  • Loading branch information
M-W-K authored Jun 6, 2024
1 parent 72e2ef2 commit 71816dd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import gregtech.api.capability.IMultiblockController;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.RecipeMaps;
import gregtech.api.recipes.category.ICategoryOverride;
import gregtech.api.unification.material.Materials;
import gregtech.api.util.GTLog;
import gregtech.common.ConfigHolder;
Expand All @@ -28,7 +30,7 @@
import static gregtech.api.capability.GregtechDataCodes.BOILER_HEAT;
import static gregtech.api.capability.GregtechDataCodes.BOILER_LAST_TICK_STEAM;

public class BoilerRecipeLogic extends AbstractRecipeLogic {
public class BoilerRecipeLogic extends AbstractRecipeLogic implements ICategoryOverride {

private static final long STEAM_PER_WATER = 160;

Expand Down Expand Up @@ -347,4 +349,14 @@ private static FluidStack getBoilerFluidFromContainer(@NotNull IFluidHandler flu
}
return drainedWater;
}

@Override
public @NotNull RecipeMap<?> @NotNull [] getJEIRecipeMapCategoryOverrides() {
return new RecipeMap<?>[] { RecipeMaps.COMBUSTION_GENERATOR_FUELS, RecipeMaps.SEMI_FLUID_GENERATOR_FUELS };
}

@Override
public @NotNull String @NotNull [] getJEICategoryOverrides() {
return new String[] { "minecraft.fuel" };
}
}
51 changes: 51 additions & 0 deletions src/main/java/gregtech/api/recipes/category/ICategoryOverride.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gregtech.api.recipes.category;

import gregtech.api.recipes.RecipeMap;

import org.jetbrains.annotations.NotNull;

/**
* When a registered mte's class or recipe logic implements this interface, the mte is associated with the override's
* recipe maps in JEI.
*/
public interface ICategoryOverride {

/**
* Controls whether the override should be performed or not.
* Useful to disable overrides if a class's parent implements this interface.
*
* @return whether the override should be performed or not
*/
default boolean shouldOverride() {
return true;
}

/**
* Controls whether the normal logic for determining JEI category association should be completely replaced.
*
* @return whether to ignore normal logic or not
*/
default boolean shouldReplace() {
return true;
}

/**
* The actual overrides for JEI recipe map category association.
*
* @return an array of recipe maps the mte should be associated with in JEI. Can be empty, but not null.
*/
default @NotNull RecipeMap<?> @NotNull [] getJEIRecipeMapCategoryOverrides() {
return new RecipeMap[] {};
}

/**
* Allows JEI category association using JEI's underlying API.
* Use this to associate a multiblock with solid, burnable fuel recipes for example.
*
* @return an array of recipe category UUIDs that are valid for JEI's
* {@link mezz.jei.api.IModRegistry#addRecipeCatalyst(Object, String...)} method.
*/
default @NotNull String @NotNull [] getJEICategoryOverrides() {
return new String[] {};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.recipes.ModHandler;
import gregtech.api.recipes.category.ICategoryOverride;
import gregtech.client.renderer.texture.Textures;

import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -18,7 +19,7 @@

import org.jetbrains.annotations.NotNull;

public class SteamCoalBoiler extends SteamBoiler {
public class SteamCoalBoiler extends SteamBoiler implements ICategoryOverride {

public SteamCoalBoiler(ResourceLocation metaTileEntityId, boolean isHighPressure) {
super(metaTileEntityId, isHighPressure, Textures.COAL_BOILER_OVERLAY);
Expand Down Expand Up @@ -92,4 +93,9 @@ public ModularUI createUI(EntityPlayer player) {
GuiTextures.PROGRESS_BAR_BOILER_FUEL.get(isHighPressure), MoveType.VERTICAL)
.build(getHolder(), player);
}

@Override
public @NotNull String @NotNull [] getJEICategoryOverrides() {
return new String[] { "minecraft.fuel" };
}
}
27 changes: 20 additions & 7 deletions src/main/java/gregtech/integration/jei/JustEnoughItemsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import gregtech.api.modules.GregTechModule;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.RecipeMaps;
import gregtech.api.recipes.category.GTRecipeCategory;
import gregtech.api.recipes.category.ICategoryOverride;
import gregtech.api.recipes.ingredients.GTRecipeOreInput;
import gregtech.api.recipes.ingredients.IntCircuitIngredient;
import gregtech.api.recipes.machines.IScannerRecipeMap;
Expand Down Expand Up @@ -194,10 +194,29 @@ public void register(IModRegistry registry) {
for (ResourceLocation metaTileEntityId : GregTechAPI.MTE_REGISTRY.getKeys()) {
MetaTileEntity metaTileEntity = GregTechAPI.MTE_REGISTRY.getObject(metaTileEntityId);
assert metaTileEntity != null;

if (metaTileEntity instanceof ICategoryOverride override && override.shouldOverride()) {
for (RecipeMap<?> recipeMap : override.getJEIRecipeMapCategoryOverrides()) {
registerRecipeMapCatalyst(registry, recipeMap, metaTileEntity);
}
if (override.getJEICategoryOverrides().length != 0)
registry.addRecipeCatalyst(metaTileEntity.getStackForm(), override.getJEICategoryOverrides());
if (override.shouldReplace()) continue;
}

if (metaTileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_CONTROLLABLE, null) != null) {
IControllable workableCapability = metaTileEntity
.getCapability(GregtechTileCapabilities.CAPABILITY_CONTROLLABLE, null);

if (workableCapability instanceof ICategoryOverride override && override.shouldOverride()) {
for (RecipeMap<?> recipeMap : override.getJEIRecipeMapCategoryOverrides()) {
registerRecipeMapCatalyst(registry, recipeMap, metaTileEntity);
}
if (override.getJEICategoryOverrides().length != 0)
registry.addRecipeCatalyst(metaTileEntity.getStackForm(), override.getJEICategoryOverrides());
if (override.shouldReplace()) continue;
}

if (workableCapability instanceof AbstractRecipeLogic logic) {
if (metaTileEntity instanceof IMultipleRecipeMaps) {
for (RecipeMap<?> recipeMap : ((IMultipleRecipeMaps) metaTileEntity).getAvailableRecipeMaps()) {
Expand All @@ -210,12 +229,6 @@ public void register(IModRegistry registry) {
}
}

String semiFluidMapId = GTValues.MODID + ":" + RecipeMaps.SEMI_FLUID_GENERATOR_FUELS.getUnlocalizedName();
registry.addRecipeCatalyst(MetaTileEntities.LARGE_BRONZE_BOILER.getStackForm(), semiFluidMapId);
registry.addRecipeCatalyst(MetaTileEntities.LARGE_STEEL_BOILER.getStackForm(), semiFluidMapId);
registry.addRecipeCatalyst(MetaTileEntities.LARGE_TITANIUM_BOILER.getStackForm(), semiFluidMapId);
registry.addRecipeCatalyst(MetaTileEntities.LARGE_TUNGSTENSTEEL_BOILER.getStackForm(), semiFluidMapId);

List<OreByProduct> oreByproductList = new ArrayList<>();
for (Material material : GregTechAPI.materialManager.getRegisteredMaterials()) {
if (material.hasProperty(PropertyKey.ORE)) {
Expand Down

0 comments on commit 71816dd

Please sign in to comment.