mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-12 08:50:04 -04:00
Removed NEI usage handler for documentation, added button opening manual instead.
This commit is contained in:
parent
bb3ecce24c
commit
fe1cd7917b
5
src/main/resources/oc_at.cfg
Normal file
5
src/main/resources/oc_at.cfg
Normal file
@ -0,0 +1,5 @@
|
||||
# OpenComputers access transformer config
|
||||
public net.minecraft.client.gui.inventory.GuiContainer field_146999_f #xSize
|
||||
public net.minecraft.client.gui.inventory.GuiContainer field_147000_g #ySize
|
||||
public net.minecraft.client.gui.inventory.GuiContainer field_147003_i #guiLeft
|
||||
public net.minecraft.client.gui.inventory.GuiContainer field_147009_r #guiTop
|
@ -1,28 +0,0 @@
|
||||
package li.cil.oc.integration.nei
|
||||
|
||||
import codechicken.nei.recipe.IUsageHandler
|
||||
import li.cil.oc.Localization
|
||||
import li.cil.oc.api
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
class GeneralUsageHandler(pages: Option[Array[String]]) extends PagedUsageHandler(pages) {
|
||||
def this() = this(None)
|
||||
|
||||
override def getRecipeName = "Manual"
|
||||
|
||||
override def getUsageHandler(input: String, ingredients: AnyRef*): IUsageHandler = {
|
||||
if (input == "item") {
|
||||
ingredients.collectFirst {
|
||||
case stack: ItemStack if api.Items.get(stack) != null && Localization.canLocalize(usageKey(stack)) =>
|
||||
val fullDocumentation = wrap(Localization.localizeImmediately(usageKey(stack)).replaceAllLiterally("[nl]", "\n"), 160).mkString("\n")
|
||||
val pages = fullDocumentation.lines.grouped(12).map(_.mkString("\n")).toArray
|
||||
new GeneralUsageHandler(Option(pages))
|
||||
}.getOrElse(this)
|
||||
}
|
||||
else this
|
||||
}
|
||||
|
||||
private def usageKey(stack: ItemStack) = stack.getUnlocalizedName.stripSuffix(".name").replaceFirst("""\d+$""", "") + ".usage"
|
||||
}
|
87
src/main/scala/li/cil/oc/integration/nei/ManualHandler.scala
Normal file
87
src/main/scala/li/cil/oc/integration/nei/ManualHandler.scala
Normal file
@ -0,0 +1,87 @@
|
||||
package li.cil.oc.integration.nei
|
||||
|
||||
import java.util
|
||||
|
||||
import codechicken.lib.gui.GuiDraw
|
||||
import codechicken.nei.PositionedStack
|
||||
import codechicken.nei.api.IOverlayHandler
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer
|
||||
import codechicken.nei.recipe.GuiRecipe
|
||||
import codechicken.nei.recipe.IUsageHandler
|
||||
import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.client.gui
|
||||
import li.cil.oc.common.GuiType
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiButton
|
||||
import net.minecraft.client.gui.inventory.GuiContainer
|
||||
import net.minecraft.inventory.Container
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class ManualHandler(path: Option[String]) extends IUsageHandler {
|
||||
def this() = this(None)
|
||||
|
||||
var lastMouseX = 0
|
||||
var lastMouseY = 0
|
||||
val button = new GuiButton(0, 34, 20, 100, 20, "Open Manual")
|
||||
|
||||
override def getRecipeName = "Manual"
|
||||
|
||||
override def getUsageHandler(input: String, ingredients: AnyRef*): IUsageHandler = {
|
||||
if (input == "item") {
|
||||
ingredients.collectFirst {
|
||||
case stack: ItemStack if api.Items.get(stack) != null => new ManualHandler(Option(api.Items.get(stack).name + ".md"))
|
||||
}.getOrElse(this)
|
||||
}
|
||||
else this
|
||||
}
|
||||
|
||||
override def recipiesPerPage = 1
|
||||
|
||||
override def numRecipes = 1
|
||||
|
||||
override def drawForeground(recipe: Int): Unit = Minecraft.getMinecraft.currentScreen match {
|
||||
case container: GuiContainer =>
|
||||
val pos = GuiDraw.getMousePosition
|
||||
button.drawButton(Minecraft.getMinecraft, pos.x - container.guiLeft - 5, pos.y - container.guiTop - 16)
|
||||
case _ =>
|
||||
}
|
||||
|
||||
override def drawBackground(i: Int): Unit = {}
|
||||
|
||||
override def getIngredientStacks(i: Int) = new util.ArrayList[PositionedStack]()
|
||||
|
||||
override def getOtherStacks(i: Int) = new util.ArrayList[PositionedStack]()
|
||||
|
||||
override def getResultStack(i: Int) = null
|
||||
|
||||
override def onUpdate(): Unit = {}
|
||||
|
||||
override def hasOverlay(gui: GuiContainer, container: Container, i: Int): Boolean = false
|
||||
|
||||
override def getOverlayHandler(gui: GuiContainer, i: Int): IOverlayHandler = null
|
||||
|
||||
override def getOverlayRenderer(gui: GuiContainer, i: Int): IRecipeOverlayRenderer = null
|
||||
|
||||
override def handleTooltip(gui: GuiRecipe, tooltip: util.List[String], i: Int): util.List[String] = tooltip
|
||||
|
||||
override def handleItemTooltip(gui: GuiRecipe, stack: ItemStack, tooltip: util.List[String], i: Int): util.List[String] = tooltip
|
||||
|
||||
override def keyTyped(gui: GuiRecipe, char: Char, code: Int, recipe: Int): Boolean = false
|
||||
|
||||
override def mouseClicked(container: GuiRecipe, btn: Int, recipe: Int): Boolean = container match {
|
||||
case container: GuiContainer =>
|
||||
val pos = GuiDraw.getMousePosition
|
||||
val mc = Minecraft.getMinecraft
|
||||
if (button.mousePressed(mc, pos.x - container.guiLeft - 5, pos.y - container.guiTop - 16)) {
|
||||
mc.thePlayer.openGui(OpenComputers, GuiType.Manual.id, mc.theWorld, 0, 0, 0)
|
||||
mc.currentScreen match {
|
||||
case manual: gui.Manual => path.foreach(manual.pushPage)
|
||||
case _ =>
|
||||
}
|
||||
true
|
||||
}
|
||||
else false
|
||||
case _ => false
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ class NEIOpenComputersConfig extends IConfigureNEI {
|
||||
override def loadConfig() {
|
||||
// Non-alphabetic order haunts my OCD, but I want the "Manual" to show up
|
||||
// before the API doc.
|
||||
API.registerUsageHandler(new GeneralUsageHandler())
|
||||
API.registerUsageHandler(new ManualHandler())
|
||||
API.registerUsageHandler(new CallbackDocHandler())
|
||||
|
||||
// Add option to show items' ore dictionary name in tooltips.
|
||||
|
Loading…
x
Reference in New Issue
Block a user