From c949e02610a547985fcc261767bbb8a090f8dd76 Mon Sep 17 00:00:00 2001 From: bdew Date: Tue, 17 Dec 2013 01:46:34 +0200 Subject: [PATCH] Hackery to work around compiler not seeing changes to GuiContainer by NEI --- src/net/bdew/gendustry/nei/BaseRecipeHandler.scala | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/net/bdew/gendustry/nei/BaseRecipeHandler.scala b/src/net/bdew/gendustry/nei/BaseRecipeHandler.scala index 36d12c8..4255680 100644 --- a/src/net/bdew/gendustry/nei/BaseRecipeHandler.scala +++ b/src/net/bdew/gendustry/nei/BaseRecipeHandler.scala @@ -18,6 +18,7 @@ import net.bdew.gendustry.nei.helpers.RecipeComponent import java.util import net.minecraft.item.ItemStack import codechicken.nei.PositionedStack +import net.minecraft.client.gui.inventory.GuiContainer abstract class BaseRecipeHandler extends TemplateRecipeHandler { val offset: Point @@ -33,8 +34,16 @@ abstract class BaseRecipeHandler extends TemplateRecipeHandler { super.drawExtras(recipe) } + val guiCls = classOf[GuiContainer] + val guiLeftField = guiCls.getField("guiLeft") + val guiTopField = guiCls.getField("guiTop") + + def getGuiOffset(gui: GuiContainer): Point = { + return new Point(guiLeftField.get(gui).asInstanceOf[Int], guiTopField.get(gui).asInstanceOf[Int]) + } + override def mouseClicked(gui: GuiRecipe, button: Int, recipe: Int): Boolean = { - val mrel = new Point(GuiDraw.getMousePosition) - gui.getRecipePosition(recipe) + offset - ((gui.guiLeft, gui.guiTop)) + val mrel = new Point(GuiDraw.getMousePosition) - gui.getRecipePosition(recipe) + offset - getGuiOffset(gui) for (component <- arecipes.get(recipe).asInstanceOf[CachedRecipeWithComponents].components) if (component.rect.contains(mrel) && component.mouseClick(button)) return true super.mouseClicked(gui, button, recipe) @@ -42,7 +51,7 @@ abstract class BaseRecipeHandler extends TemplateRecipeHandler { override def handleTooltip(gui: GuiRecipe, currenttip: util.List[String], recipe: Int) = { import scala.collection.JavaConversions._ - val mrel = new Point(GuiDraw.getMousePosition) - gui.getRecipePosition(recipe) + offset - ((gui.guiLeft, gui.guiTop)) + val mrel = new Point(GuiDraw.getMousePosition) - gui.getRecipePosition(recipe) + offset - getGuiOffset(gui) for (component <- arecipes.get(recipe).asInstanceOf[CachedRecipeWithComponents].components) if (component.rect.contains(mrel)) currenttip.addAll(component.getTooltip) super.handleTooltip(gui, currenttip, recipe)