From f85b53438939d3020d27cb4b3fff486f18494b5a Mon Sep 17 00:00:00 2001 From: mezz Date: Mon, 22 Feb 2016 23:57:06 -0800 Subject: [PATCH] Move JEI items out of the way of ledgers --- .../java/forestry/core/gui/GuiForestry.java | 38 +++---------------- .../forestry/core/gui/ledgers/Ledger.java | 17 +++++++++ .../core/gui/ledgers/LedgerManager.java | 21 +++++++--- .../factory/recipes/jei/FactoryJeiPlugin.java | 25 ++++++++++++ 4 files changed, 63 insertions(+), 38 deletions(-) diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index af86e7ba8..ea168fb27 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.core.gui; +import javax.annotation.Nonnull; +import java.awt.Rectangle; import java.io.IOException; import java.util.List; @@ -269,38 +271,8 @@ public abstract class GuiForestry ext super.drawGradientRect(par1, par2, par3, par4, par5, par6); } - /* NEI */ - /*@Override - @Optional.Method(modid = "NotEnoughItems") - public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) { - return null; + @Nonnull + public List getExtraGuiAreas() { + return ledgerManager.getLedgerAreas(); } - - @Override - @Optional.Method(modid = "NotEnoughItems") - public Iterable getItemSpawnSlots(GuiContainer gui, ItemStack item) { - return Collections.emptyList(); - } - - @Override - @Optional.Method(modid = "NotEnoughItems") - public List getInventoryAreas(GuiContainer gui) { - return Collections.emptyList(); - } - - @Override - @Optional.Method(modid = "NotEnoughItems") - public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) { - return false; - } - - @Override - @Optional.Method(modid = "NotEnoughItems") - 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/ledgers/Ledger.java b/src/main/java/forestry/core/gui/ledgers/Ledger.java index a88119e51..f27f04203 100644 --- a/src/main/java/forestry/core/gui/ledgers/Ledger.java +++ b/src/main/java/forestry/core/gui/ledgers/Ledger.java @@ -23,6 +23,7 @@ import org.lwjgl.opengl.GL11; import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.SessionVars; +import forestry.core.gui.GuiForestry; import forestry.core.proxy.Proxies; import forestry.core.render.ForestryResource; @@ -54,6 +55,8 @@ public abstract class Ledger { protected float currentWidth = minWidth; protected float currentHeight = minHeight; + private int x; + private int y; private final ResourceLocation texture; @@ -78,6 +81,11 @@ public abstract class Ledger { maxTextWidth = maxWidth - 18; } + public Rectangle getArea() { + GuiForestry gui = manager.gui; + return new Rectangle(gui.getGuiLeft() + x, gui.getGuiTop() + y, (int) currentWidth, (int) currentHeight); + } + // adjust the update's move amount to match the look of 60 fps (16.67 ms per update) private static final float msPerUpdate = 16.667f; private long lastUpdateTime = 0; @@ -131,6 +139,15 @@ public abstract class Ledger { return Math.round(currentWidth); } + public void setPosition(int x, int y) { + this.x = x; + this.y = y; + } + + public final void draw() { + draw(x, y); + } + public abstract void draw(int x, int y); public abstract String getTooltip(); diff --git a/src/main/java/forestry/core/gui/ledgers/LedgerManager.java b/src/main/java/forestry/core/gui/ledgers/LedgerManager.java index e1f5079b1..9b96f2c14 100644 --- a/src/main/java/forestry/core/gui/ledgers/LedgerManager.java +++ b/src/main/java/forestry/core/gui/ledgers/LedgerManager.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.core.gui.ledgers; +import javax.annotation.Nonnull; +import java.awt.Rectangle; import java.util.ArrayList; import java.util.List; @@ -110,6 +112,18 @@ public class LedgerManager { return null; } + @Nonnull + public List getLedgerAreas() { + List areas = new ArrayList<>(); + for (Ledger ledger : ledgers) { + if (ledger.isVisible()) { + Rectangle area = ledger.getArea(); + areas.add(area); + } + } + return areas; + } + public void drawLedgers() { int yPos = 8; for (Ledger ledger : ledgers) { @@ -120,7 +134,8 @@ public class LedgerManager { } GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - ledger.draw(gui.getSizeX(), yPos); + ledger.setPosition(gui.getSizeX(), yPos); + ledger.draw(); yPos += ledger.getHeight(); } @@ -184,10 +199,6 @@ 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; - } - public int getMaxWidth() { return maxWidth; } diff --git a/src/main/java/forestry/factory/recipes/jei/FactoryJeiPlugin.java b/src/main/java/forestry/factory/recipes/jei/FactoryJeiPlugin.java index b76fbf443..3fded24b7 100644 --- a/src/main/java/forestry/factory/recipes/jei/FactoryJeiPlugin.java +++ b/src/main/java/forestry/factory/recipes/jei/FactoryJeiPlugin.java @@ -1,7 +1,14 @@ package forestry.factory.recipes.jei; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.awt.Rectangle; +import java.util.List; + +import net.minecraft.client.gui.inventory.GuiContainer; + +import forestry.core.gui.GuiForestry; import forestry.core.recipes.jei.ForestryRecipeCategoryUid; import forestry.factory.gui.ContainerWorktable; import forestry.factory.recipes.jei.bottler.BottlerRecipeCategory; @@ -36,6 +43,7 @@ import mezz.jei.api.IGuiHelper; import mezz.jei.api.IJeiHelpers; import mezz.jei.api.IModRegistry; import mezz.jei.api.JEIPlugin; +import mezz.jei.api.gui.IAdvancedGuiHandler; import mezz.jei.api.recipe.VanillaRecipeCategoryUid; import mezz.jei.api.recipe.transfer.IRecipeTransferRegistry; @@ -77,5 +85,22 @@ public class FactoryJeiPlugin extends BlankModPlugin { IRecipeTransferRegistry transferRegistry = registry.getRecipeTransferRegistry(); transferRegistry.addRecipeTransferHandler(ContainerWorktable.class, VanillaRecipeCategoryUid.CRAFTING, 19, 9, 1, 36); + + registry.addAdvancedGuiHandlers(new ForestryAdvancedGuiHandler()); + } + + private static class ForestryAdvancedGuiHandler implements IAdvancedGuiHandler { + @Nonnull + @Override + public Class getGuiContainerClass() { + return GuiForestry.class; + } + + @Nullable + @Override + public List getGuiExtraAreas(GuiForestry guiContainer) { + GuiForestry guiForestry = (GuiForestry) guiContainer; + return guiForestry.getExtraGuiAreas(); + } } }