Hbm-s-Nuclear-Tech-GIT/src/main/java/com/hbm/handler/nei/AnvilOverlayHandler.java
Mikhail Semenov e16be434f5 Add NEI overlay functionality so recipe on anvil can be selected via NEI.
This will allow to click plus-sign in NEI and NEI will select recipe on Anvil automatically.
2025-10-21 21:56:48 +02:00

38 lines
1.3 KiB
Java

package com.hbm.handler.nei;
import com.hbm.inventory.gui.GUIAnvil;
import com.hbm.inventory.recipes.anvil.AnvilRecipes.AnvilConstructionRecipe;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.IRecipeHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
/**
* Links NEI overlay interactions with the {@link GUIAnvil} so selecting a recipe focuses the anvil view.
*/
public class AnvilOverlayHandler implements IOverlayHandler {
/**
* {@inheritDoc}
*
* <p>When the NEI overlay is opened for the Nuclear Tech anvil, the GUI is instructed to focus the selected recipe.</p>
* <p>It will not craft the recepie. Only select it.</p>
*
* @param firstGui the GUI currently displaying the overlay
* @param recipe the NEI recipe handler backing the overlay
* @param recipeIndex index of the recipe within the handler
* @param maxTransfer whether NEI is performing a maximal transfer (ignored)
*/
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean maxTransfer) {
if(!(firstGui instanceof GUIAnvil) || !(recipe instanceof AnvilRecipeHandler)) {
return;
}
AnvilConstructionRecipe construction = ((AnvilRecipeHandler) recipe).getConstructionRecipe(recipeIndex);
if(construction != null) {
((GUIAnvil) firstGui).focusRecipe(construction);
}
}
}