Skip to content

Commit 2c76bd3

Browse files
author
PriestOfFern
committed
add requirement rendering to gas crafter jei ui
1 parent bb269df commit 2c76bd3

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

common/src/main/kotlin/org/valkyrienskies/clockwork/ClockworkGuiTextures.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ enum class ClockworkGuiTextures(
3535

3636
SMART_DUCT_BG("smart_duct", 0,0,165, 73),
3737

38-
3938
COMMAND_SEAT("command_seat", 173, 159),
40-
WANDER_TOOL_BACKGROUND("overlay", 0, 0, 16, 16);
39+
WANDER_TOOL_BACKGROUND("overlay", 0, 0, 16, 16),
40+
41+
JEI_BAR("jei-widgets", 0, 201, 169, 19),
42+
JEI_DARKER_BAR("jei-widgets", 0, 221, 169, 19);
4143

4244
constructor(location: String, width: Int, height: Int) : this(
4345
ResourceLocation(

common/src/main/kotlin/org/valkyrienskies/clockwork/compat/jei/ClockworkJEI.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class ClockworkJEI() : IModPlugin {
4747
private val ID: ResourceLocation = ClockworkMod.asResource("jei_plugin")
4848
var runtime: IJeiRuntime? = null
4949

50+
5051
private fun loadCategories() {
5152
allCategories.clear()
5253

@@ -55,7 +56,7 @@ class ClockworkJEI() : IModPlugin {
5556
.catalyst { ClockworkBlocks.GAS_CRAFTER.get() }
5657
.catalyst { AllBlocks.BASIN.get() }
5758
.itemIcon(ClockworkBlocks.GAS_CRAFTER.get())
58-
.emptyBackground(177, 103)
59+
.background(GasCrafterCategory.GasCraftingRecipeBackground)
5960
.build(
6061
"gas_crafting",
6162
CreateRecipeCategory.Factory { info: CreateRecipeCategory.Info<GasCraftingRecipe> ->

common/src/main/kotlin/org/valkyrienskies/clockwork/compat/jei/GasCrafterCategory.kt

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import com.simibubi.create.foundation.item.ItemHelper
1212
import com.simibubi.create.foundation.utility.CreateLang
1313
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder
1414
import mezz.jei.api.gui.builder.IRecipeSlotBuilder
15+
import mezz.jei.api.gui.drawable.IDrawable
1516
import mezz.jei.api.gui.ingredient.IRecipeSlotsView
1617
import mezz.jei.api.recipe.IFocusGroup
1718
import mezz.jei.api.recipe.RecipeIngredientRole
1819
import net.minecraft.client.Minecraft
1920
import net.minecraft.client.gui.GuiGraphics
2021
import net.minecraft.world.item.ItemStack
22+
import org.valkyrienskies.clockwork.ClockworkGuiTextures
2123
import org.valkyrienskies.clockwork.content.logistics.gas.crafter.GasCraftingRecipe
2224
import org.valkyrienskies.kelvin.api.recipe.KelvinGasIngredient
2325
import org.valkyrienskies.kelvin.integration.jei.GasIngredientRenderer
@@ -27,19 +29,17 @@ import javax.annotation.ParametersAreNonnullByDefault
2729

2830

2931
@ParametersAreNonnullByDefault
30-
class GasCrafterCategory(info: Info<GasCraftingRecipe>) : CreateRecipeCategory<GasCraftingRecipe>(info) {
32+
class GasCrafterCategory(val info: Info<GasCraftingRecipe>) : CreateRecipeCategory<GasCraftingRecipe>(info) {
3133
private val crafter = AnimatedGasCrafter()
3234
private val heater = AnimatedBlazeBurner()
3335

34-
3536
override fun draw(
3637
recipe: GasCraftingRecipe,
3738
iRecipeSlotsView: IRecipeSlotsView,
3839
graphics: GuiGraphics,
3940
mouseX: Double,
4041
mouseY: Double
4142
) {
42-
4343
val requiredHeat = recipe.getRequiredHeat()
4444

4545
val noHeat = requiredHeat == HeatCondition.NONE
@@ -63,13 +63,25 @@ class GasCrafterCategory(info: Info<GasCraftingRecipe>) : CreateRecipeCategory<G
6363
if (requiredHeat != HeatCondition.NONE) heater.withHeat(requiredHeat.visualizeAsBlazeBurner())
6464
.draw(graphics, getBackground()!!.getWidth() / 2 + 3, 55)
6565
crafter.draw(graphics, getBackground()!!.getWidth() / 2 + 3, 34)
66+
67+
68+
var i = if (requiredHeat == HeatCondition.NONE) 0 else 1
69+
70+
if (recipe.gasRecipe?.requirements != null)
71+
recipe.gasRecipe!!.requirements.forEach {
72+
ClockworkGuiTextures.JEI_DARKER_BAR.render(graphics, 4, 80+20*i)
73+
graphics.drawString(Minecraft.getInstance().font, it.key.get_text(it.value), 7, 85+20*i, 16777215)
74+
i++
75+
}
6676
}
6777

6878
override fun setRecipe(
6979
builder: IRecipeLayoutBuilder,
7080
recipe: GasCraftingRecipe,
7181
focuses: IFocusGroup
7282
) {
83+
(background as? GasCraftingRecipeBackground)?.currentRecipe = recipe
84+
7385
val condensedIngredients = ItemHelper.condenseIngredients(recipe.getIngredients())
7486

7587
var size = condensedIngredients.size + recipe.getFluidIngredients().size + (recipe.gasRecipe?.gasses?.size ?: 0)
@@ -147,6 +159,25 @@ class GasCrafterCategory(info: Info<GasCraftingRecipe>) : CreateRecipeCategory<G
147159
}
148160
}
149161

162+
object GasCraftingRecipeBackground : IDrawable {
163+
var currentRecipe: GasCraftingRecipe? = null
164+
165+
override fun getWidth(): Int = 177
166+
167+
override fun getHeight(): Int {
168+
val recipe = currentRecipe ?: return 103
169+
170+
171+
val requirementCount = recipe.gasRecipe?.requirements?.size ?: return 103
172+
val calculatedHeight = 103 + (requirementCount * 20)
173+
174+
return calculatedHeight
175+
}
176+
177+
override fun draw(guiGraphics: GuiGraphics, xOffset: Int, yOffset: Int) {
178+
// Empty background
179+
}
180+
}
150181

151182
companion object {
152183

common/src/main/resources/assets/vs_clockwork/textures/gui/jei-widgets.png

Loading

0 commit comments

Comments
 (0)