diff --git a/src/main/java/codechicken/nei/LICENSE.txt b/src/main/java/codechicken/nei/LICENSE.txt new file mode 100644 index 000000000..186cfbbc0 --- /dev/null +++ b/src/main/java/codechicken/nei/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 ChickenBones + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/src/main/java/codechicken/nei/VisiblityData.java b/src/main/java/codechicken/nei/VisiblityData.java new file mode 100644 index 000000000..f5753aa8e --- /dev/null +++ b/src/main/java/codechicken/nei/VisiblityData.java @@ -0,0 +1,38 @@ +package codechicken.nei; + +public class VisiblityData +{ + public boolean showUtilityButtons = true; + public boolean showStateButtons = true; + /** + * Item panel and associated buttons + */ + public boolean showItemPanel = true; + /** + * Item and search section + */ + public boolean showItemSection = true; + /** + * Dropdown and Item search field + */ + public boolean showSearchSection = true; + /** + * All widgets except options button + */ + public boolean showWidgets = true; + /** + * The entire NEI interface, aka hidden + */ + public boolean showNEI = true; + public boolean enableDeleteMode = true; + + public void translateDependancies() + { + if(!showNEI) + showWidgets = false; + if(!showWidgets) + showItemSection = showUtilityButtons = showStateButtons = false; + if(!showItemSection) + showSearchSection = showItemPanel = false; + } +} diff --git a/src/main/java/codechicken/nei/api/INEIGuiHandler.java b/src/main/java/codechicken/nei/api/INEIGuiHandler.java new file mode 100644 index 000000000..9ca8fb6cb --- /dev/null +++ b/src/main/java/codechicken/nei/api/INEIGuiHandler.java @@ -0,0 +1,49 @@ +package codechicken.nei.api; + +import codechicken.nei.VisiblityData; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; + +import java.util.List; + +/** + * If this is implemented on a gui, it will be automatically registered + */ +public interface INEIGuiHandler +{ + public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility); + + /** + * NEI will give the specified item to the InventoryRange returned if the player's inventory is full. + * return null for no range + */ + public Iterable getItemSpawnSlots(GuiContainer gui, ItemStack item); + + /** + * @return A list of TaggedInventoryAreas that will be used with the savestates. + */ + public List getInventoryAreas(GuiContainer gui); + + /** + * Handles clicks while an itemstack has been dragged from the item panel. Use this to set configurable slots and the like. + * Changes made to the stackSize of the dragged stack will be kept + * @param gui The current gui instance + * @param mousex The x position of the mouse + * @param mousey The y position of the mouse + * @param draggedStack The stack being dragged from the item panel + * @param button The button presed + * @return True if the drag n drop was handled. False to resume processing through other routes. The held stack will be deleted if draggedStack.stackSize == 0 + */ + public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button); + + /** + * Used to prevent the item panel from drawing on top of other gui elements. + * This function will also be called with a 1x1 size rectangle on the mouse position for determining if the given coordinate should override item panel functions such as scrolling + * @param x The x coordinate of the rectangle bounding the slot + * @param y The y coordinate of the rectangle bounding the slot + * @param w The w coordinate of the rectangle bounding the slot + * @param h The h coordinate of the rectangle bounding the slot + * @return true if the item panel slot within the specified rectangle should not be rendered. + */ + public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h); +} diff --git a/src/main/java/codechicken/nei/api/TaggedInventoryArea.java b/src/main/java/codechicken/nei/api/TaggedInventoryArea.java new file mode 100644 index 000000000..b50d2e239 --- /dev/null +++ b/src/main/java/codechicken/nei/api/TaggedInventoryArea.java @@ -0,0 +1,48 @@ +package codechicken.nei.api; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import java.util.HashSet; + +public class TaggedInventoryArea +{ + public HashSet slots = new HashSet(); + public String tagName; + /** + * Only for player inventories. + */ + private IInventory inventory; + /** + * Other inventories + */ + private Container container; + + public TaggedInventoryArea(InventoryPlayer invPlayer) + { + this("InventoryPlayer", 0, 39, null); + inventory = invPlayer; + } + + public TaggedInventoryArea(String name, int first, int last, Container container) + { + this.container = container; + tagName = name; + for(int i = first; i <= last; i++) + slots.add(i); + } + + public ItemStack getStackInSlot(int i) + { + if(inventory != null) + return inventory.getStackInSlot(i); + return container.getSlot(i).getStack(); + } + + public boolean isContainer() + { + return inventory == null; + } +} diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index 1f22de848..c1af240dd 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -14,6 +14,10 @@ import java.awt.Color; import java.util.Collection; import java.util.List; +import codechicken.nei.VisiblityData; +import codechicken.nei.api.INEIGuiHandler; +import codechicken.nei.api.TaggedInventoryArea; + import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.OpenGlHelper; @@ -45,7 +49,7 @@ import forestry.core.interfaces.IPowerHandler; import forestry.core.proxy.Proxies; import forestry.core.utils.FontColour; -public abstract class GuiForestry extends GuiContainer { +public abstract class GuiForestry extends GuiContainer implements INEIGuiHandler { /* WIDGETS */ protected WidgetManager widgetManager; @@ -572,4 +576,22 @@ public abstract class GuiForestry extends GuiContainer { return tip; } } + + /* NEI */ + @Override + public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) { return null; } + @Override + public Iterable getItemSpawnSlots(GuiContainer gui, ItemStack item) { return null; } + @Override + public List getInventoryAreas(GuiContainer gui) { return null; } + @Override + public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) { return false; } + + @Override + public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) { + if (gui instanceof GuiForestry) + return ((GuiForestry)gui).ledgerManager.ledgerOverlaps(x, y, w, h); + else + return false; + } } diff --git a/src/main/java/forestry/core/gui/LedgerManager.java b/src/main/java/forestry/core/gui/LedgerManager.java index 1e9353e8a..57f1934df 100755 --- a/src/main/java/forestry/core/gui/LedgerManager.java +++ b/src/main/java/forestry/core/gui/LedgerManager.java @@ -117,4 +117,8 @@ public class LedgerManager { } + public boolean ledgerOverlaps(int x, int y, int width, int height) { + return getAtPosition(x + width, y + height) != null || getAtPosition(x + width, y) != null || getAtPosition(x, y + height) != null || getAtPosition(x, y) != null; + } + }