mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 18:30:27 -04:00
Also highlight slots for items hovered in NEI.
This commit is contained in:
parent
6761983cd6
commit
e2365d498d
@ -4,9 +4,11 @@ import li.cil.oc.client.Textures
|
|||||||
import li.cil.oc.common.Tier
|
import li.cil.oc.common.Tier
|
||||||
import li.cil.oc.common.container.{ComponentSlot, Player}
|
import li.cil.oc.common.container.{ComponentSlot, Player}
|
||||||
import li.cil.oc.util.RenderState
|
import li.cil.oc.util.RenderState
|
||||||
|
import li.cil.oc.util.mods.NEI
|
||||||
import net.minecraft.client.renderer.Tessellator
|
import net.minecraft.client.renderer.Tessellator
|
||||||
import net.minecraft.client.renderer.texture.TextureMap
|
import net.minecraft.client.renderer.texture.TextureMap
|
||||||
import net.minecraft.inventory.{Container, Slot}
|
import net.minecraft.inventory.{Container, Slot}
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.util.StatCollector
|
import net.minecraft.util.StatCollector
|
||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
@ -15,6 +17,8 @@ import scala.collection.convert.WrapAsScala._
|
|||||||
abstract class DynamicGuiContainer(container: Container) extends CustomGuiContainer(container) {
|
abstract class DynamicGuiContainer(container: Container) extends CustomGuiContainer(container) {
|
||||||
protected var hoveredSlot: Option[Slot] = None
|
protected var hoveredSlot: Option[Slot] = None
|
||||||
|
|
||||||
|
protected var hoveredStackNEI: Option[ItemStack] = None
|
||||||
|
|
||||||
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) {
|
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) {
|
||||||
fontRenderer.drawString(
|
fontRenderer.drawString(
|
||||||
StatCollector.translateToLocal("container.inventory"),
|
StatCollector.translateToLocal("container.inventory"),
|
||||||
@ -30,6 +34,7 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
|
|||||||
hoveredSlot = (inventorySlots.inventorySlots collect {
|
hoveredSlot = (inventorySlots.inventorySlots collect {
|
||||||
case slot: Slot if isPointInRegion(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY) => slot
|
case slot: Slot if isPointInRegion(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY) => slot
|
||||||
}).headOption
|
}).headOption
|
||||||
|
hoveredStackNEI = NEI.hoveredStack(this, mouseX, mouseY)
|
||||||
super.drawScreen(mouseX, mouseY, dt)
|
super.drawScreen(mouseX, mouseY, dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,20 +64,27 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
|
|||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mc.thePlayer.inventory.getItemStack == null) hoveredSlot.foreach(hovered => {
|
if (mc.thePlayer.inventory.getItemStack == null) {
|
||||||
val currentIsInPlayerInventory = isInPlayerInventory(slot)
|
val currentIsInPlayerInventory = isInPlayerInventory(slot)
|
||||||
val hoveredIsInPlayerInventory = isInPlayerInventory(hovered)
|
val drawHighlight = hoveredSlot match {
|
||||||
if (currentIsInPlayerInventory != hoveredIsInPlayerInventory) {
|
case Some(hovered) =>
|
||||||
if ((currentIsInPlayerInventory && slot.getHasStack && hovered.isItemValid(slot.getStack)) ||
|
val hoveredIsInPlayerInventory = isInPlayerInventory(hovered)
|
||||||
(hoveredIsInPlayerInventory && hovered.getHasStack && slot.isItemValid(hovered.getStack))) {
|
(currentIsInPlayerInventory != hoveredIsInPlayerInventory) &&
|
||||||
GL11.glDisable(GL11.GL_DEPTH_TEST)
|
((currentIsInPlayerInventory && slot.getHasStack && hovered.isItemValid(slot.getStack)) ||
|
||||||
GL11.glDisable(GL11.GL_LIGHTING)
|
(hoveredIsInPlayerInventory && hovered.getHasStack && slot.isItemValid(hovered.getStack)))
|
||||||
drawGradientRect(slot.xDisplayPosition, slot.yDisplayPosition, slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, 0x80FFFFFF, 0x80FFFFFF)
|
case _ => hoveredStackNEI match {
|
||||||
GL11.glEnable(GL11.GL_LIGHTING)
|
case Some(stack) => !currentIsInPlayerInventory && slot.isItemValid(stack)
|
||||||
GL11.glEnable(GL11.GL_DEPTH_TEST)
|
case _ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
if (drawHighlight) {
|
||||||
|
GL11.glDisable(GL11.GL_DEPTH_TEST)
|
||||||
|
GL11.glDisable(GL11.GL_LIGHTING)
|
||||||
|
drawGradientRect(slot.xDisplayPosition, slot.yDisplayPosition, slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, 0x80FFFFFF, 0x80FFFFFF)
|
||||||
|
GL11.glEnable(GL11.GL_LIGHTING)
|
||||||
|
GL11.glEnable(GL11.GL_DEPTH_TEST)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
package li.cil.oc.util.mods
|
package li.cil.oc.util.mods
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.inventory.GuiContainer
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
object NEI {
|
object NEI {
|
||||||
private lazy val layoutManagerClass = try {
|
private lazy val (layoutManagerClass, getInstance, getStackUnderMouse) = try {
|
||||||
Class.forName("codechicken.nei.LayoutManager")
|
val layoutManager = Class.forName("codechicken.nei.LayoutManager")
|
||||||
|
val getInstance = layoutManager.getMethod("instance")
|
||||||
|
val getStackUnderMouse = layoutManager.getMethod("getStackUnderMouse", classOf[GuiContainer], classOf[Int], classOf[Int])
|
||||||
|
(layoutManager, getInstance, getStackUnderMouse)
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
case _: Throwable => null
|
case _: Throwable => (null, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
def isInputFocused =
|
def isInputFocused =
|
||||||
@ -15,4 +21,12 @@ object NEI {
|
|||||||
catch {
|
catch {
|
||||||
case _: Throwable => false
|
case _: Throwable => false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def hoveredStack(container: GuiContainer, mouseX: Int, mouseY: Int): Option[ItemStack] = {
|
||||||
|
if (Mods.NotEnoughItems.isAvailable && layoutManagerClass != null && getInstance != null && getStackUnderMouse != null)
|
||||||
|
try return Option(getStackUnderMouse.invoke(getInstance.invoke(null), container, mouseX.underlying(), mouseY.underlying()).asInstanceOf[ItemStack]) catch {
|
||||||
|
case t: Throwable => println(t)
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user