-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lazy cooking recipe conversion with automatic fluid detection (#99)
- Loading branch information
1 parent
0e956a6
commit 37fec21
Showing
5 changed files
with
67 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/kotlin/com/possible_triangle/sliceanddice/compat/LazyMixingRecipe.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.possible_triangle.sliceanddice.compat | ||
|
||
import com.possible_triangle.sliceanddice.config.Configs | ||
import com.simibubi.create.content.fluids.transfer.EmptyingRecipe | ||
import com.simibubi.create.content.kinetics.mixer.MixingRecipe | ||
import com.simibubi.create.content.processing.recipe.ProcessingRecipeBuilder.ProcessingRecipeParams | ||
import com.simibubi.create.foundation.fluid.FluidIngredient | ||
import net.minecraft.core.NonNullList | ||
import net.minecraft.world.item.crafting.Ingredient | ||
import net.minecraftforge.fluids.FluidStack | ||
|
||
private fun <T> Collection<T>.toNonnullList() = let { | ||
NonNullList.createWithCapacity<T>(it.size).apply { | ||
addAll(it) | ||
} | ||
} | ||
|
||
class LazyMixingRecipe(params: ProcessingRecipeParams) : MixingRecipe(params) { | ||
|
||
private var emptyingRecipes: Collection<EmptyingRecipe> = emptyList() | ||
private var resolved = false | ||
private lateinit var resolvedIngredients: NonNullList<Ingredient> | ||
private lateinit var resolvedFluidIngredients: NonNullList<FluidIngredient> | ||
|
||
fun withRecipeLookup(emptyingRecipes: Collection<EmptyingRecipe>) = apply { | ||
this.emptyingRecipes = emptyingRecipes | ||
} | ||
|
||
private fun fluidOf(ingredient: Ingredient): FluidStack { | ||
if (!Configs.SERVER.REPLACE_FLUID_CONTAINERS.get()) return FluidStack.EMPTY | ||
val fluids = ingredient.items.mapNotNull { stack -> | ||
emptyingRecipes.find { | ||
val required = it.ingredients[0] | ||
required.test(stack) | ||
}?.resultingFluid | ||
} | ||
|
||
return fluids.minByOrNull { it.amount } ?: FluidStack.EMPTY | ||
} | ||
|
||
private fun resolve() { | ||
if (resolved) return | ||
val replaceable = super.ingredients | ||
.associateWith { fluidOf(it) } | ||
.filterValues { !it.isEmpty } | ||
.mapValues { FluidIngredient.fromFluidStack(it.value) } | ||
|
||
resolvedIngredients = super.ingredients.filterNot { replaceable.containsKey(it) }.toNonnullList() | ||
resolvedFluidIngredients = (super.fluidIngredients + replaceable.values).toNonnullList() | ||
resolved = true | ||
} | ||
|
||
override fun getIngredients(): NonNullList<Ingredient> { | ||
resolve() | ||
return resolvedIngredients | ||
} | ||
|
||
override fun getFluidIngredients(): NonNullList<FluidIngredient> { | ||
resolve() | ||
return resolvedFluidIngredients | ||
} | ||
|
||
} |
4 changes: 1 addition & 3 deletions
4
src/main/kotlin/com/possible_triangle/sliceanddice/config/ServerConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
src/main/resources/data/sliceanddice/recipes/mixing/creamed_corn_from_fluid.json
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
src/main/resources/data/sliceanddice/recipes/mixing/pumpkin_soup_from_fluid.json
This file was deleted.
Oops, something went wrong.