Skip to content

Commit

Permalink
Close #3168 Implement IJeiFeatures to let mods disable the InventoryE…
Browse files Browse the repository at this point in the history
…ffectRendererGuiHandler
  • Loading branch information
mezz committed Jan 28, 2024
1 parent 99d5d0a commit 593848c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Common/src/main/java/mezz/jei/common/Internal.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class Internal {
private static IClientToggleState toggleState;
@Nullable
private static IJeiClientConfigs jeiClientConfigs;
private static final JeiFeatures jeiFeatures = new JeiFeatures();

private Internal() {

Expand Down Expand Up @@ -74,4 +75,8 @@ public static IJeiClientConfigs getJeiClientConfigs() {
public static void setJeiClientConfigs(IJeiClientConfigs jeiClientConfigs) {
Internal.jeiClientConfigs = jeiClientConfigs;
}

public static JeiFeatures getJeiFeatures() {
return jeiFeatures;
}
}
16 changes: 16 additions & 0 deletions Common/src/main/java/mezz/jei/common/JeiFeatures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mezz.jei.common;

import mezz.jei.api.runtime.IJeiFeatures;

public class JeiFeatures implements IJeiFeatures {
private boolean inventoryEffectRendererGuiHandlerEnabled = true;

@Override
public void disableInventoryEffectRendererGuiHandler() {
inventoryEffectRendererGuiHandlerEnabled = false;
}

public boolean getInventoryEffectRendererGuiHandlerEnabled() {
return inventoryEffectRendererGuiHandlerEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.advanced.IRecipeManagerPlugin;
import mezz.jei.api.recipe.category.extensions.IRecipeCategoryDecorator;
import mezz.jei.api.runtime.IJeiFeatures;

/**
* The IAdvancedRegistration instance is passed to your mod plugin in {@link IModPlugin#registerAdvanced(IAdvancedRegistration)}.
Expand All @@ -26,4 +27,12 @@ public interface IAdvancedRegistration {
* @since 15.1.0
*/
<T> void addRecipeCategoryDecorator(RecipeType<T> recipeType, IRecipeCategoryDecorator<T> decorator);

/**
* Get access to disable various JEI features.
* This may be needed by mods that substantially change hard-coded vanilla behaviors.
*
* @since 17.3.0
*/
IJeiFeatures getJeiFeatures();
}
23 changes: 23 additions & 0 deletions CommonApi/src/main/java/mezz/jei/api/runtime/IJeiFeatures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package mezz.jei.api.runtime;

import mezz.jei.api.gui.handlers.IGuiContainerHandler;
import mezz.jei.api.registration.IAdvancedRegistration;

/**
* Provides access for mod plugins to disable various JEI features.
* This may be needed by mods that substantially change hard-coded vanilla behaviors.
*
* Get an instance from {@link IAdvancedRegistration#getJeiFeatures()}
*
* @since 17.3.0
*/
public interface IJeiFeatures {
/**
* Disable JEI's Inventory Effect Renderer {@link IGuiContainerHandler}.
* This is used by JEI in order to move out of the way of potion effects shown next to the inventory.
* It can be disabled by mods that remove this behavior or substitute their own.
*
* @since 17.3.0
*/
void disableInventoryEffectRendererGuiHandler();
}
6 changes: 4 additions & 2 deletions Library/src/main/java/mezz/jei/library/load/PluginLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper;
import mezz.jei.api.runtime.IIngredientManager;
import mezz.jei.api.runtime.IIngredientVisibility;
import mezz.jei.api.runtime.IJeiFeatures;
import mezz.jei.api.runtime.IScreenHelper;
import mezz.jei.common.Internal;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.platform.IPlatformFluidHelperInternal;
import mezz.jei.common.platform.Services;
import mezz.jei.core.util.LoggedTimer;
import mezz.jei.common.util.StackHelper;
import mezz.jei.core.util.LoggedTimer;
import mezz.jei.library.config.IModIdFormatConfig;
import mezz.jei.library.config.RecipeCategorySortingConfig;
import mezz.jei.library.focus.FocusFactory;
Expand Down Expand Up @@ -128,7 +129,8 @@ public RecipeManager createRecipeManager(
PluginCaller.callOnPlugins("Registering recipe catalysts", plugins, p -> p.registerRecipeCatalysts(recipeCatalystRegistration));
ImmutableListMultimap<ResourceLocation, ITypedIngredient<?>> recipeCatalysts = recipeCatalystRegistration.getRecipeCatalysts();

AdvancedRegistration advancedRegistration = new AdvancedRegistration(jeiHelpers);
IJeiFeatures jeiFeatures = Internal.getJeiFeatures();
AdvancedRegistration advancedRegistration = new AdvancedRegistration(jeiHelpers, jeiFeatures);
PluginCaller.callOnPlugins("Registering advanced plugins", plugins, p -> p.registerAdvanced(advancedRegistration));
List<IRecipeManagerPlugin> recipeManagerPlugins = advancedRegistration.getRecipeManagerPlugins();
ImmutableListMultimap<RecipeType<?>, IRecipeCategoryDecorator<?>> recipeCategoryExtensions = advancedRegistration.getRecipeCategoryDecorators();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mezz.jei.api.recipe.advanced.IRecipeManagerPlugin;
import mezz.jei.api.recipe.category.extensions.IRecipeCategoryDecorator;
import mezz.jei.api.registration.IAdvancedRegistration;
import mezz.jei.api.runtime.IJeiFeatures;
import mezz.jei.common.util.ErrorUtil;
import mezz.jei.core.collect.ListMultiMap;
import org.apache.logging.log4j.LogManager;
Expand All @@ -21,9 +22,11 @@ public class AdvancedRegistration implements IAdvancedRegistration {
private final List<IRecipeManagerPlugin> recipeManagerPlugins = new ArrayList<>();
private final ListMultiMap<RecipeType<?>, IRecipeCategoryDecorator<?>> recipeCategoryDecorators = new ListMultiMap<>();
private final IJeiHelpers jeiHelpers;
private final IJeiFeatures jeiFeatures;

public AdvancedRegistration(IJeiHelpers jeiHelpers) {
public AdvancedRegistration(IJeiHelpers jeiHelpers, IJeiFeatures jeiFeatures) {
this.jeiHelpers = jeiHelpers;
this.jeiFeatures = jeiFeatures;
}

@Override
Expand All @@ -48,6 +51,11 @@ public IJeiHelpers getJeiHelpers() {
return jeiHelpers;
}

@Override
public IJeiFeatures getJeiFeatures() {
return jeiFeatures;
}

@Unmodifiable
public List<IRecipeManagerPlugin> getRecipeManagerPlugins() {
return List.copyOf(recipeManagerPlugins);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mezz.jei.library.plugins.vanilla;

import mezz.jei.api.gui.handlers.IGuiContainerHandler;
import mezz.jei.common.Internal;
import mezz.jei.common.platform.IPlatformRenderHelper;
import mezz.jei.common.platform.IPlatformScreenHelper;
import mezz.jei.common.platform.Services;
Expand All @@ -23,6 +24,9 @@ public final class InventoryEffectRendererGuiHandler<T extends AbstractContainer
@SuppressWarnings("JavadocReference")
@Override
public List<Rect2i> getGuiExtraAreas(EffectRenderingInventoryScreen<T> containerScreen) {
if (!Internal.getJeiFeatures().getInventoryEffectRendererGuiHandlerEnabled()) {
return List.of();
}
Minecraft minecraft = Minecraft.getInstance();
LocalPlayer player = minecraft.player;
if (player == null) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ curseHomepageUrl=https://www.curseforge.com/minecraft/mc-mods/jei
jUnitVersion=5.8.2

# Version
specificationVersion=17.2.0
specificationVersion=17.3.0

# Workaround for Spotless bug
# https://github.com/diffplug/spotless/issues/834
Expand Down

0 comments on commit 593848c

Please sign in to comment.