mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-17 19:15:13 +00:00
Use shortcut key to trigger overlay recipe (#248)
* Use shortcut key to trigger overlay recipe * Add a way to remove overlay renderer * Change of implementation * Fix crash
This commit is contained in:
1 parent
91e9b2a5ae
commit
d735cc2a38
6 files changed
+94
-63
No files matched your search
@@ -346,12 +346,8 @@ public class BookmarkPanel extends PanelWidget
|
||||
public BookmarkRecipeId getBookmarkRecipeId(ItemStack stackA)
|
||||
{
|
||||
|
||||
final Point mousePos = getMousePosition();
|
||||
final ItemPanelSlot slot = getSlotMouseOver(mousePos.x, mousePos.y);
|
||||
|
||||
if (slot != null && StackInfo.equalItemAndNBT(slot.item, stackA, true)) {
|
||||
return ((BookmarkGrid) grid).getRecipeId(slot.slotIndex);
|
||||
}
|
||||
BookmarkRecipeId mouseOverRecipeId = getBookmarkMouseOverRecipeId(stackA);
|
||||
if (mouseOverRecipeId != null) return mouseOverRecipeId;
|
||||
|
||||
BookmarkRecipeId recipeId = ((BookmarkGrid) grid).findRecipeId(stackA);
|
||||
|
||||
@@ -367,6 +363,25 @@ public class BookmarkPanel extends PanelWidget
|
||||
return recipeId;
|
||||
}
|
||||
|
||||
public BookmarkRecipeId getBookmarkMouseOverRecipeId(ItemStack stackA)
|
||||
{
|
||||
final Point mousePos = getMousePosition();
|
||||
final ItemPanelSlot slot = getSlotMouseOver(mousePos.x, mousePos.y);
|
||||
|
||||
if (slot != null) {
|
||||
if (stackA == null || StackInfo.equalItemAndNBT(slot.item, stackA, true)) {
|
||||
return ((BookmarkGrid) grid).getRecipeId(slot.slotIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public BookmarkRecipeId getBookmarkMouseOverRecipeId()
|
||||
{
|
||||
return getBookmarkMouseOverRecipeId(null);
|
||||
}
|
||||
|
||||
protected String getNamespaceLabelText(boolean shortFormat)
|
||||
{
|
||||
String activePage = String.valueOf(activeNamespaceIndex + 1);
|
||||
|
||||
@@ -299,6 +299,7 @@ public class NEIClientConfig {
|
||||
API.addKeyBind("gui.hide", Keyboard.KEY_O);
|
||||
API.addKeyBind("gui.search", Keyboard.KEY_F);
|
||||
API.addKeyBind("gui.bookmark", Keyboard.KEY_A);
|
||||
API.addKeyBind("gui.overlay", Keyboard.KEY_S);
|
||||
API.addKeyBind("gui.hide_bookmarks", Keyboard.KEY_B);
|
||||
API.addKeyBind("world.chunkoverlay", Keyboard.KEY_F9);
|
||||
API.addKeyBind("world.moboverlay", Keyboard.KEY_F7);
|
||||
|
||||
@@ -2,6 +2,7 @@ package codechicken.nei.recipe;
|
||||
|
||||
import codechicken.core.TaskProfiler;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
@@ -9,7 +10,6 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
@@ -19,28 +19,32 @@ import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GuiCraftingRecipe extends GuiRecipe
|
||||
{
|
||||
public class GuiCraftingRecipe extends GuiRecipe {
|
||||
public static boolean openRecipeGui(String outputId, Object... results) {
|
||||
return openRecipeGui(outputId, false, results);
|
||||
}
|
||||
|
||||
|
||||
public static boolean openRecipeGui(String outputId, Boolean overlay, Object... results) {
|
||||
Minecraft mc = NEIClientUtils.mc();
|
||||
GuiScreen prevscreen = mc.currentScreen;// instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null;
|
||||
|
||||
ArrayList<ICraftingHandler> handlers;
|
||||
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
|
||||
profiler.start("recipe.concurrent.crafting");
|
||||
|
||||
|
||||
// Pre-find the fuels so we're not fighting over it
|
||||
FuelRecipeHandler.findFuelsOnceParallel();
|
||||
|
||||
try {
|
||||
handlers = serialCraftingHandlers.stream().map(h -> h.getRecipeHandler(outputId, results))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
handlers.addAll(ItemList.forkJoinPool.submit(() -> craftinghandlers.parallelStream()
|
||||
.map(h -> h.getRecipeHandler(outputId, results))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new))).get());
|
||||
.map(h -> h.getRecipeHandler(outputId, results))
|
||||
.filter(h -> h.numRecipes() > 0)
|
||||
.collect(Collectors.toCollection(ArrayList::new))).get());
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
@@ -62,22 +66,30 @@ public class GuiCraftingRecipe extends GuiRecipe
|
||||
BookmarkRecipeId recipeId = null;
|
||||
|
||||
if ("item".equals(outputId)) {
|
||||
recipeId = getRecipeId(prevscreen, (ItemStack)results[0]);
|
||||
recipeId = getRecipeId(prevscreen, (ItemStack) results[0]);
|
||||
}
|
||||
|
||||
GuiCraftingRecipe gui = new GuiCraftingRecipe(prevscreen, handlers, recipeId);
|
||||
|
||||
|
||||
mc.displayGuiScreen(gui);
|
||||
|
||||
if (NEIClientConfig.saveCurrentRecipeInBookmarksEnabled() && !NEIClientUtils.shiftKey()) {
|
||||
gui.openTargetRecipe(gui.recipeId);
|
||||
if (NEIClientConfig.saveCurrentRecipeInBookmarksEnabled())
|
||||
if (!NEIClientUtils.shiftKey() || overlay) {
|
||||
gui.openTargetRecipe(gui.recipeId);
|
||||
}
|
||||
|
||||
if (overlay) {
|
||||
if (!NEIClientConfig.saveCurrentRecipeInBookmarksEnabled() || gui.recipeId == null) {
|
||||
mc.displayGuiScreen(prevscreen);
|
||||
return false;
|
||||
}
|
||||
gui.overlayRecipe(gui.recipeId.position);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static BookmarkRecipeId getRecipeId(GuiScreen gui, ItemStack stackover)
|
||||
{
|
||||
protected static BookmarkRecipeId getRecipeId(GuiScreen gui, ItemStack stackover) {
|
||||
|
||||
if (gui instanceof GuiRecipe) {
|
||||
final List<PositionedStack> ingredients = ((GuiRecipe) gui).getFocusedRecipeIngredients();
|
||||
@@ -91,8 +103,7 @@ public class GuiCraftingRecipe extends GuiRecipe
|
||||
return ItemPanels.bookmarkPanel.getBookmarkRecipeId(stackover);
|
||||
}
|
||||
|
||||
private GuiCraftingRecipe(GuiScreen prevgui, ArrayList<ICraftingHandler> handlers, BookmarkRecipeId recipeId)
|
||||
{
|
||||
private GuiCraftingRecipe(GuiScreen prevgui, ArrayList<ICraftingHandler> handlers, BookmarkRecipeId recipeId) {
|
||||
this(prevgui, handlers);
|
||||
this.recipeId = recipeId;
|
||||
}
|
||||
@@ -104,10 +115,10 @@ public class GuiCraftingRecipe extends GuiRecipe
|
||||
|
||||
public static void registerRecipeHandler(ICraftingHandler handler) {
|
||||
final String handlerId = handler.getHandlerId();
|
||||
if(craftinghandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)) || serialCraftingHandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)))
|
||||
if (craftinghandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)) || serialCraftingHandlers.stream().anyMatch(h -> h.getHandlerId().equals(handlerId)))
|
||||
return;
|
||||
|
||||
if(NEIClientConfig.serialHandlers.contains(handlerId))
|
||||
if (NEIClientConfig.serialHandlers.contains(handlerId))
|
||||
serialCraftingHandlers.add(handler);
|
||||
else
|
||||
craftinghandlers.add(handler);
|
||||
|
||||
@@ -446,16 +446,19 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
|
||||
setRecipePage(--recipetype);
|
||||
}
|
||||
|
||||
private void overlayRecipe(int recipe) {
|
||||
protected void overlayRecipe(int recipe) {
|
||||
if (handler == null || !handler.hasOverlay(firstGui, firstGui.inventorySlots, recipe)) {
|
||||
mc.displayGuiScreen(firstGui);
|
||||
return;
|
||||
}
|
||||
final IRecipeOverlayRenderer renderer = handler.getOverlayRenderer(firstGui, recipe);
|
||||
final IOverlayHandler overlayHandler = handler.getOverlayHandler(firstGui, recipe);
|
||||
final boolean shift = NEIClientUtils.shiftKey();
|
||||
|
||||
if (handler != null && (renderer == null || shift)) {
|
||||
mc.displayGuiScreen(firstGui);
|
||||
mc.displayGuiScreen(firstGui);
|
||||
if (renderer == null || shift) {
|
||||
overlayHandler.overlayRecipe(firstGui, currenthandlers.get(recipetype), recipe, shift);
|
||||
} else if (renderer != null) {
|
||||
mc.displayGuiScreen(firstGui);
|
||||
} else {
|
||||
LayoutManager.overlayRenderer = renderer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class RecipeItemInputHandler implements IContainerInputHandler
|
||||
{
|
||||
public class RecipeItemInputHandler implements IContainerInputHandler {
|
||||
@Override
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode)
|
||||
{
|
||||
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
|
||||
ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);
|
||||
if(stackover == null)
|
||||
return false;
|
||||
if (stackover == null) return false;
|
||||
|
||||
if(keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
|
||||
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
|
||||
return GuiCraftingRecipe.openRecipeGui("item", stackover.copy());
|
||||
|
||||
if(keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
|
||||
if (keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
|
||||
return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
|
||||
|
||||
if (keyCode == NEIClientConfig.getKeyBinding("gui.bookmark")) {
|
||||
@@ -39,68 +39,68 @@ public class RecipeItemInputHandler implements IContainerInputHandler
|
||||
ItemPanels.bookmarkPanel.addOrRemoveItem(stackover.copy(), handlerName, ingredients);
|
||||
}
|
||||
|
||||
if (keyCode == NEIClientConfig.getKeyBinding("gui.overlay")) {
|
||||
if (NEIClientUtils.controlKey()) {
|
||||
LayoutManager.overlayRenderer = null;
|
||||
return true;
|
||||
}
|
||||
if (!NEIClientConfig.saveCurrentRecipeInBookmarksEnabled()) return false;
|
||||
final BookmarkRecipeId mouseOverRecipeId = ItemPanels.bookmarkPanel.getBookmarkMouseOverRecipeId();
|
||||
if (mouseOverRecipeId == null || mouseOverRecipeId.ingredients == null || mouseOverRecipeId.ingredients.isEmpty())
|
||||
return false;
|
||||
return GuiCraftingRecipe.openRecipeGui("item", true, stackover.copy());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button)
|
||||
{
|
||||
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);
|
||||
|
||||
if(stackover == null)
|
||||
return false;
|
||||
if (stackover == null) return false;
|
||||
|
||||
if (!(gui instanceof GuiRecipe))
|
||||
return false;
|
||||
if (!(gui instanceof GuiRecipe)) return false;
|
||||
|
||||
//disabled open recipe gui if hold shift (player have move recipe)
|
||||
if (button == 0 && ItemPanels.bookmarkPanel.getStackMouseOver(mousex, mousey) != null && NEIClientUtils.shiftKey()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(button == 0)
|
||||
return GuiCraftingRecipe.openRecipeGui("item", stackover.copy());
|
||||
if (button == 0) return GuiCraftingRecipe.openRecipeGui("item", stackover.copy());
|
||||
|
||||
if(button == 1)
|
||||
return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
|
||||
if (button == 1) return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID)
|
||||
{
|
||||
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button)
|
||||
{
|
||||
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button)
|
||||
{
|
||||
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiContainer gui, char keyChar, int keyID)
|
||||
{
|
||||
public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled)
|
||||
{
|
||||
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled)
|
||||
{
|
||||
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime)
|
||||
{
|
||||
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user