Skip to content

Commit 1c50b92

Browse files
authored
Merge pull request #696 from pylonmc/idra/early-game-smelting-rework
Early game smelting rework
2 parents b85843e + 3fa40c9 commit 1c50b92

10 files changed

Lines changed: 73 additions & 28 deletions

File tree

rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarFluidBufferBlock.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ interface RebarFluidBufferBlock : RebarFluidBlock {
9494
* the corresponding buffer.
9595
*/
9696
fun canSetFluid(fluid: RebarFluid, amount: Double): Boolean
97-
= amount >= 0 && amount <= fluidData(fluid).capacity + FLUID_EPSILON
97+
= fluid in fluidBuffers && amount >= 0 && amount <= fluidData(fluid).capacity + FLUID_EPSILON
9898

9999
/**
100100
* Sets a fluid buffer only if the new amount of fluid is greater

rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarRecipeProcessor.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,29 @@ interface RebarRecipeProcessor<T: RebarRecipe> {
5050
@ApiStatus.NonExtendable
5151
get() = recipeProcessorData.recipeTicksRemaining
5252

53+
val recipeTimeTicks: Int?
54+
@ApiStatus.NonExtendable
55+
get() = recipeProcessorData.recipeTimeTicks
56+
57+
val recipeProgress: Double?
58+
@ApiStatus.NonExtendable
59+
get() = recipeTimeTicks?.let { recipeTicksRemaining?.toDouble()?.div(it) }
60+
5361
val isProcessingRecipe: Boolean
5462
@ApiStatus.NonExtendable
5563
get() = currentRecipe != null
5664

5765
var recipeProgressItem: ProgressItem
66+
@ApiStatus.NonExtendable
5867
get() = recipeProcessorData.progressItem ?: error("No recipe progress item was set")
68+
/**
69+
* Set the progress item that should be updated as the recipe progresses. Optional.
70+
*
71+
* Call once in your place constructor. Do not call this function again after that.
72+
* If you need to modify the progress item, use `getProgressItem()` and modify the
73+
* itemstack returned from that instead.
74+
*/
75+
@ApiStatus.NonExtendable
5976
set(progressItem) {
6077
recipeProcessorData.progressItem = progressItem
6178
}
@@ -65,9 +82,7 @@ interface RebarRecipeProcessor<T: RebarRecipe> {
6582
get() = recipeProcessorData.lastRecipe
6683

6784
/**
68-
* Set the progress item that should be updated as the recipe progresses. Optional.
69-
*
70-
* Set once in your place constructor.
85+
* Call once in your place constructor.
7186
*/
7287
@ApiStatus.NonExtendable
7388
fun setRecipeType(type: RecipeType<T>) {

rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class ItemButton @JvmOverloads constructor(
217217
}
218218

219219
@JvmStatic
220-
fun from(stack: ItemStack?): Item {
220+
fun of(stack: ItemStack?): Item {
221221
if (stack == null) {
222222
return EMPTY
223223
}
@@ -226,7 +226,7 @@ class ItemButton @JvmOverloads constructor(
226226
}
227227

228228
@JvmStatic
229-
fun from(stack: ItemStack?, preDisplayDecorator: (ItemStack, Player) -> ItemStack): Item {
229+
fun of(stack: ItemStack?, preDisplayDecorator: (ItemStack, Player) -> ItemStack): Item {
230230
if (stack == null) {
231231
return EMPTY
232232
}
@@ -235,7 +235,7 @@ class ItemButton @JvmOverloads constructor(
235235
}
236236

237237
@JvmStatic
238-
fun from(input: RecipeInput.Item?): Item {
238+
fun of(input: RecipeInput.Item?): Item {
239239
if (input == null) {
240240
return EMPTY
241241
}
@@ -244,10 +244,29 @@ class ItemButton @JvmOverloads constructor(
244244
}
245245

246246
@JvmStatic
247-
fun from(choice: RecipeChoice?): Item = when (choice) {
247+
fun of(choice: RecipeChoice?): Item = when (choice) {
248248
is RecipeChoice.MaterialChoice -> ItemButton(choice.choices.map(::ItemStack))
249249
is RecipeChoice.ExactChoice -> ItemButton(choice.choices)
250250
else -> EMPTY
251251
}
252+
253+
@JvmStatic @JvmOverloads
254+
fun of(stacks: List<ItemStack>, preDisplayDecorator: (ItemStack, Player) -> ItemStack = { stack, _ -> stack })
255+
= ItemButton(stacks, preDisplayDecorator)
256+
/**
257+
* @param stacks The items to display. If multiple are provided, the button will automatically
258+
* cycle through all of them. You must supply at least one item
259+
*/
260+
@JvmStatic
261+
fun of(vararg stacks: ItemStack)
262+
= ItemButton(stacks.toList())
263+
264+
/**
265+
* @param stacks The items to display. If multiple are provided, the button will automatically
266+
* cycle through all of them. You must supply at least one item
267+
*/
268+
@JvmStatic
269+
fun of(stack: ItemStack, preDisplayDecorator: (ItemStack, Player) -> ItemStack)
270+
= ItemButton(stack, preDisplayDecorator)
252271
}
253272
}

rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidRecipesPage.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package io.github.pylonmc.rebar.guide.pages.fluid
33
import io.github.pylonmc.rebar.content.guide.RebarGuide
44
import io.github.pylonmc.rebar.guide.pages.base.PagedGuidePage
55
import io.github.pylonmc.rebar.recipe.FluidOrItem
6+
import io.github.pylonmc.rebar.recipe.RebarRecipe
7+
import io.github.pylonmc.rebar.recipe.RebarRecipe.Companion.priority
68
import io.github.pylonmc.rebar.registry.RebarRegistry
79
import io.github.pylonmc.rebar.util.gui.GuiItems
810
import io.github.pylonmc.rebar.util.rebarKey
@@ -21,13 +23,21 @@ open class FluidRecipesPage(fluidKey: NamespacedKey) : PagedGuidePage {
2123
val pages: MutableList<Gui>
2224
get() {
2325
val pages = mutableListOf<Gui>()
26+
val recipes = mutableListOf<RebarRecipe>()
2427
for (type in RebarRegistry.RECIPE_TYPES) {
2528
for (recipe in type.recipes) {
2629
if (!recipe.isHidden && recipe.isOutput(fluid)) {
27-
recipe.display()?.let { pages.add(it) }
30+
recipes.add(recipe)
2831
}
2932
}
3033
}
34+
recipes.sortByDescending { it.priority }
35+
for (recipe in recipes) {
36+
val display = recipe.display()
37+
if (display != null) {
38+
pages.add(display)
39+
}
40+
}
3141
return pages
3242
}
3343

rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/RebarRecipe.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface RebarRecipe : Keyed {
1616

1717
fun isInput(stack: ItemStack) = inputs.any { input ->
1818
when (input) {
19-
is RecipeInput.Item -> stack in input
19+
is RecipeInput.Item -> input.matchesIgnoringAmount(stack)
2020
else -> false
2121
}
2222
}

rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/RecipeInput.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ sealed interface RecipeInput {
2323
representativeItems.first()
2424
}
2525

26-
fun matches(itemStack: ItemStack): Boolean {
27-
if (itemStack.amount < amount) return false
28-
return contains(itemStack)
26+
fun matches(itemStack: ItemStack?): Boolean {
27+
if (itemStack == null || itemStack.amount < amount) return false
28+
return matchesIgnoringAmount(itemStack)
2929
}
3030

31-
operator fun contains(itemStack: ItemStack): Boolean = ItemTypeWrapper(itemStack) in items
31+
fun matchesIgnoringAmount(itemStack: ItemStack?): Boolean = itemStack != null && ItemTypeWrapper(itemStack) in items
3232
}
3333

3434
@JvmRecord
@@ -41,12 +41,12 @@ sealed interface RecipeInput {
4141
require(fluids.isNotEmpty()) { "Fluids set must not be empty" }
4242
}
4343

44-
fun matches(fluid: RebarFluid, amountMillibuckets: Double): Boolean {
45-
if (amountMillibuckets < this.amountMillibuckets) return false
44+
fun matches(fluid: RebarFluid?, amountMillibuckets: Double): Boolean {
45+
if (fluid == null || amountMillibuckets < this.amountMillibuckets) return false
4646
return contains(fluid)
4747
}
4848

49-
operator fun contains(fluid: RebarFluid): Boolean = fluid in fluids
49+
operator fun contains(fluid: RebarFluid?): Boolean = fluid in fluids
5050
}
5151

5252
companion object {

rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Cooking.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sealed class CookingRecipeWrapper(final override val recipe: CookingRecipe<*>) :
3434
)
3535
.addIngredient('#', GuiItems.backgroundBlack())
3636
.addIngredient('b', ItemStack(displayBlock))
37-
.addIngredient('i', ItemButton.from(recipe.inputChoice))
37+
.addIngredient('i', ItemButton.of(recipe.inputChoice))
3838
.addIngredient(
3939
'f', GuiItems.progressCyclingItem(
4040
recipe.cookingTime,
@@ -47,7 +47,7 @@ sealed class CookingRecipeWrapper(final override val recipe: CookingRecipe<*>) :
4747
)
4848
)
4949
)
50-
.addIngredient('o', ItemButton.from(recipe.result))
50+
.addIngredient('o', ItemButton.of(recipe.result))
5151
.build()
5252
}
5353

rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class ShapedRecipeWrapper(override val recipe: ShapedRecipe) : CraftingRecipeWra
3737
"# # # # # # # # #",
3838
)
3939
.addIngredient('#', GuiItems.backgroundBlack())
40-
.addIngredient('b', ItemButton.from(ItemStack(Material.CRAFTING_TABLE)))
41-
.addIngredient('r', ItemButton.from(recipe.result))
40+
.addIngredient('b', ItemButton.of(ItemStack(Material.CRAFTING_TABLE)))
41+
.addIngredient('r', ItemButton.of(recipe.result))
4242
.build()
4343

4444
val height = recipe.shape.size
@@ -54,7 +54,7 @@ class ShapedRecipeWrapper(override val recipe: ShapedRecipe) : CraftingRecipeWra
5454

5555
private fun getDisplaySlot(recipe: ShapedRecipe, x: Int, y: Int): Item {
5656
val character = recipe.shape[y][x]
57-
return ItemButton.from(recipe.choiceMap[character])
57+
return ItemButton.of(recipe.choiceMap[character])
5858
}
5959
}
6060

@@ -73,7 +73,7 @@ sealed class AShapelessRecipeWrapper(recipe: CraftingRecipe) : CraftingRecipeWra
7373
"# # # # # # # # #",
7474
)
7575
.addIngredient('#', GuiItems.backgroundBlack())
76-
.addIngredient('b', ItemButton.from(ItemStack(Material.CRAFTING_TABLE)))
76+
.addIngredient('b', ItemButton.of(ItemStack(Material.CRAFTING_TABLE)))
7777
.addIngredient('0', getDisplaySlot(0))
7878
.addIngredient('1', getDisplaySlot(1))
7979
.addIngredient('2', getDisplaySlot(2))
@@ -87,7 +87,7 @@ sealed class AShapelessRecipeWrapper(recipe: CraftingRecipe) : CraftingRecipeWra
8787
.build()
8888

8989
private fun getDisplaySlot(index: Int): Item {
90-
return ItemButton.from(choiceList.getOrNull(index))
90+
return ItemButton.of(choiceList.getOrNull(index))
9191
}
9292
}
9393

rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Smithing.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ sealed class SmithingRecipeWrapper(recipe: SmithingRecipe) : VanillaRecipeWrappe
3232
"# # # # # # # # #",
3333
)
3434
.addIngredient('#', GuiItems.backgroundBlack())
35-
.addIngredient('b', ItemButton.from(ItemStack(Material.SMITHING_TABLE)))
35+
.addIngredient('b', ItemButton.of(ItemStack(Material.SMITHING_TABLE)))
3636
.addIngredient('0', ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE))
37-
.addIngredient('1', ItemButton.from(recipe.base))
38-
.addIngredient('2', ItemButton.from(recipe.addition))
39-
.addIngredient('r', ItemButton.from(recipe.result))
37+
.addIngredient('1', ItemButton.of(recipe.base))
38+
.addIngredient('2', ItemButton.of(recipe.addition))
39+
.addIngredient('r', ItemButton.of(recipe.result))
4040
.build()
4141

4242
override fun getKey(): NamespacedKey = recipe.key

rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/ProgressItem.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ open class ProgressItem @JvmOverloads constructor(
5454

5555
fun setItem(item: Item) {
5656
this.item = item
57+
notifyWindows()
5758
}
5859

5960
fun setItem(stack: ItemStack) {

0 commit comments

Comments
 (0)