diff --git a/src/main/java/codechicken/nei/config/IMCHandler.java b/src/main/java/codechicken/nei/config/IMCHandler.java index 22c361b8..06ab21af 100644 --- a/src/main/java/codechicken/nei/config/IMCHandler.java +++ b/src/main/java/codechicken/nei/config/IMCHandler.java @@ -64,7 +64,7 @@ public class IMCHandler { final boolean requiresMod = tag.getBoolean("modRequired"); final String excludedModId = tag.hasKey("excludedModId") ? tag.getString("excludedModId") : null; - if (handler.equals("") || modName.equals("") || modId.equals("")) { + if (handler.isEmpty() || modName.isEmpty() || modId.isEmpty()) { NEIClientConfig.logger.warn("Missing relevant information to registerHandlerInfo!"); return; } @@ -74,7 +74,7 @@ public class IMCHandler { HandlerInfo info = new HandlerInfo(handler, modName, modId, requiresMod, excludedModId); final String imageResource = tag.hasKey("imageResource") ? tag.getString("imageResource") : null; - if (imageResource != null && !imageResource.equals("")) { + if (imageResource != null && !imageResource.isEmpty()) { info.setImage( imageResource, tag.getInteger("imageX"), @@ -84,7 +84,7 @@ public class IMCHandler { } if (!info.hasImageOrItem()) { final String itemName = tag.getString("itemName"); - if (itemName != null && !itemName.equals("")) { + if (itemName != null && !itemName.isEmpty()) { info.setItem(itemName, tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null); } } @@ -103,6 +103,10 @@ public class IMCHandler { NEIClientConfig.logger.info("Error setting handler dimensions for " + handler); } + // true if not set to false + info.setShowFavoritesButton(!tag.hasKey("showFavoritesButton") || tag.getBoolean("showFavoritesButton")); + info.setShowOverlayButton(!tag.hasKey("showOverlayButton") || tag.getBoolean("showOverlayButton")); + GuiRecipeTab.handlerAdderFromIMC.remove(handler); GuiRecipeTab.handlerAdderFromIMC.put(handler, info); } diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 4a9eca95..22ce311c 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -462,8 +462,7 @@ public abstract class GuiRecipe extends GuiContainer i if (!cacheKey.equals(this.recipePageCacheKey)) { this.recipePageCacheKey = cacheKey; - for (int refIndex = 0; refIndex < indices.size(); refIndex++) { - final int recipeIndex = indices.get(refIndex); + for (final int recipeIndex : indices) { for (PositionedStack pStack : handler.original.getIngredientStacks(recipeIndex)) { pStack.setPermutationToRender(pStack.getFilteredPermutations().get(0)); } @@ -472,7 +471,8 @@ public abstract class GuiRecipe extends GuiContainer i final int xOffset = (limitToOneRecipe ? 0 : guiLeft) + xSize - BORDER_PADDING; final int yOffset = (limitToOneRecipe ? -BUTTON_HEIGHT : guiTop - 18) + getRefIndexPosition(0).y; final int height = handlerInfo.getHeight() - yShift; - final boolean showFavorites = NEIClientConfig.favoritesEnabled(); + final boolean showFavorites = NEIClientConfig.favoritesEnabled() && handlerInfo.getShowFavoritesButton(); + final boolean showOverlay = handlerInfo.getShowOverlayButton(); final UpdateRecipeButtonsEvent.Pre preEvent = new UpdateRecipeButtonsEvent.Pre( this, xOffset, @@ -484,7 +484,6 @@ public abstract class GuiRecipe extends GuiContainer i if (MinecraftForge.EVENT_BUS.post(preEvent)) { buttons = preEvent.buttonList; } else { - for (int refIndex = 0; refIndex < indices.size(); refIndex++) { final int recipeIndex = indices.get(refIndex); @@ -493,20 +492,19 @@ public abstract class GuiRecipe extends GuiContainer i continue; } - GuiRecipeButton button = new GuiOverlayButton( - firstGui, - RecipeHandlerRef.of(handler.original, recipeIndex), - xOffset - GuiRecipeButton.BUTTON_WIDTH, - yOffset + height * (refIndex + 1)); - - buttons.add(button); - - if (showFavorites) { + int x = xOffset - GuiRecipeButton.BUTTON_WIDTH; + int y = yOffset + height * (refIndex + 1); + if (showOverlay) { buttons.add( - new GuiFavoriteButton( + new GuiOverlayButton( + firstGui, RecipeHandlerRef.of(handler.original, recipeIndex), - button.xPosition, - button.yPosition - button.height - 1)); + x, + y)); + y -= GuiRecipeButton.BUTTON_HEIGHT + 1; + } + if (showFavorites) { + buttons.add(new GuiFavoriteButton(RecipeHandlerRef.of(handler.original, recipeIndex), x, y)); } } @@ -522,6 +520,10 @@ public abstract class GuiRecipe extends GuiContainer i buttons.removeIf(GuiFavoriteButton.class::isInstance); } + if (!showOverlay) { + buttons.removeIf(GuiOverlayButton.class::isInstance); + } + /** compatibility with old format */ this.overlayButtons = buttons.stream().filter(GuiOverlayButton.class::isInstance) .toArray(GuiOverlayButton[]::new); diff --git a/src/main/java/codechicken/nei/recipe/HandlerInfo.java b/src/main/java/codechicken/nei/recipe/HandlerInfo.java index ce1d2dd0..a2784ab0 100644 --- a/src/main/java/codechicken/nei/recipe/HandlerInfo.java +++ b/src/main/java/codechicken/nei/recipe/HandlerInfo.java @@ -28,6 +28,8 @@ public class HandlerInfo { private int height = DEFAULT_HEIGHT; private int width = DEFAULT_WIDTH; private int maxRecipesPerPage = DEFAULT_MAX_PER_PAGE; + private boolean showFavoritesButton = true; + private boolean showOverlayButton = true; private ItemStack itemStack = null; private DrawableResource image = null; @@ -112,6 +114,22 @@ public class HandlerInfo { this.yShift = yShift; } + public boolean getShowFavoritesButton() { + return this.showFavoritesButton; + } + + public void setShowFavoritesButton(boolean showFavoritesButton) { + this.showFavoritesButton = showFavoritesButton; + } + + public boolean getShowOverlayButton() { + return this.showOverlayButton; + } + + public void setShowOverlayButton(boolean showOverlayButton) { + this.showOverlayButton = showOverlayButton; + } + public static class Builder { private final HandlerInfo info;