|
| 1 | +package li.cil.oc.integration.jei |
| 2 | + |
| 3 | +import java.util |
| 4 | +import javax.annotation.Nonnull |
| 5 | + |
| 6 | +import li.cil.oc.Localization |
| 7 | +import li.cil.oc.api |
| 8 | +import mezz.jei.api.IItemRegistry |
| 9 | +import mezz.jei.api.recipe.BlankRecipeWrapper |
| 10 | +import mezz.jei.api.recipe.IRecipeHandler |
| 11 | +import mezz.jei.api.recipe.VanillaRecipeCategoryUid |
| 12 | +import net.minecraft.client.Minecraft |
| 13 | +import net.minecraft.item.ItemStack |
| 14 | +import net.minecraftforge.fml.client.config.GuiButtonExt |
| 15 | + |
| 16 | +import scala.collection.convert.WrapAsJava._ |
| 17 | +import scala.collection.convert.WrapAsScala._ |
| 18 | + |
| 19 | +object ManualUsageHandler { |
| 20 | + |
| 21 | + def getRecipes(registry: IItemRegistry): util.List[_] = registry.getItemList.collect { |
| 22 | + case stack: ItemStack => api.Manual.pathFor(stack) match { |
| 23 | + case s: String => new ManualUsageRecipe(stack, s) |
| 24 | + case _ => |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + object ManualUsageRecipeHandler extends IRecipeHandler[ManualUsageRecipe] { |
| 29 | + override def getRecipeWrapper(recipe: ManualUsageRecipe) = recipe |
| 30 | + |
| 31 | + override def getRecipeCategoryUid = VanillaRecipeCategoryUid.DESCRIPTION |
| 32 | + |
| 33 | + override def isRecipeValid(recipe: ManualUsageRecipe) = true |
| 34 | + |
| 35 | + override def getRecipeClass = classOf[ManualUsageRecipe] |
| 36 | + } |
| 37 | + |
| 38 | + class ManualUsageRecipe(stack: ItemStack, path: String) extends BlankRecipeWrapper { |
| 39 | + lazy val button = new GuiButtonExt(0, (160 - 100) / 2, 10, 100, 20, Localization.localizeImmediately("nei.usage.oc.Manual")) |
| 40 | + |
| 41 | + override def getInputs: util.List[_] = List(stack) |
| 42 | + |
| 43 | + override def drawInfo(@Nonnull minecraft: Minecraft, recipeWidth: Int, recipeHeight: Int, mouseX: Int, mouseY: Int): Unit = { |
| 44 | + button.displayString = Localization.localizeImmediately("nei.usage.oc.Manual") |
| 45 | + button.xPosition = (recipeWidth - button.width) / 2 |
| 46 | + button.yPosition = button.height / 2 |
| 47 | + button.drawButton(minecraft, mouseX, mouseY) |
| 48 | + } |
| 49 | + |
| 50 | + override def handleClick(@Nonnull minecraft: Minecraft, mouseX: Int, mouseY: Int, mouseButton: Int): Boolean = { |
| 51 | + if (button.mousePressed(minecraft, mouseX, mouseY)) { |
| 52 | + minecraft.thePlayer.closeScreen() |
| 53 | + api.Manual.openFor(minecraft.thePlayer) |
| 54 | + api.Manual.navigate(path) |
| 55 | + true |
| 56 | + } |
| 57 | + else false |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments