Merge painter recipe types

This commit is contained in:
DBotThePony 2023-11-16 21:29:19 +07:00
parent b26f109f56
commit 280a8f3431
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 24 additions and 19 deletions

View File

@ -20,11 +20,17 @@ import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.core.collect.filter
import ru.dbotthepony.mc.otm.core.collect.filterIsInstance
import ru.dbotthepony.mc.otm.core.collect.filterNotNull
import ru.dbotthepony.mc.otm.core.collect.map
import ru.dbotthepony.mc.otm.core.collect.toList
import ru.dbotthepony.mc.otm.menu.decorative.PainterMenu
import ru.dbotthepony.mc.otm.menu.matter.MatterEntanglerMenu
import ru.dbotthepony.mc.otm.menu.tech.PlatePressMenu
import ru.dbotthepony.mc.otm.menu.tech.PoweredFurnaceMenu
import ru.dbotthepony.mc.otm.menu.tech.TwinPlatePressMenu
import ru.dbotthepony.mc.otm.recipe.PainterRecipe
import ru.dbotthepony.mc.otm.registry.MItems
import ru.dbotthepony.mc.otm.registry.MRecipes
import java.util.*
@ -91,7 +97,7 @@ class JEIPlugin : IModPlugin {
val level = minecraft.level ?: throw NullPointerException("No ClientLevel. OLOLOLOLOLOLO")
registration.addRecipes(PlatePressRecipeCategory.recipeType, level.recipeManager.getAllRecipesFor(MRecipes.PLATE_PRESS).filter { !it.value.isIncomplete }.map { it.value })
registration.addRecipes(PainterRecipeCategory.recipeType, level.recipeManager.getAllRecipesFor(MRecipes.PAINTER).filter { !it.value.isIncomplete }.map { it.value })
registration.addRecipes(PainterRecipeCategory.recipeType, level.recipeManager.getAllRecipesFor(MRecipes.PAINTER).iterator().filter { !it.value.isIncomplete }.map { it.value }.filterIsInstance<PainterRecipe>().toList())
registration.addRecipes(MatterEntanglerRecipeCategory.recipeType, level.recipeManager.getAllRecipesFor(MRecipes.MATTER_ENTANGLER).filter { !it.value.isIncomplete }.map { it.value })
registration.addRecipes(MicrowaveRecipeCategory.recipeType, level.recipeManager.getAllRecipesFor(MRecipes.MICROWAVE).filter { !it.value.isIncomplete }.map { it.value })
}

View File

@ -230,6 +230,8 @@ inline fun <T> Iterator<T>.reduce(identity: T, reducer: (T, T) -> T): T {
fun <T> Iterator<T?>.filterNotNull(): MutableIterator<T> = filter { it != null } as MutableIterator<T>
inline fun <reified T> Iterator<*>.filterIsInstance(): MutableIterator<T> = filter { it is T } as MutableIterator<T>
fun <T> Iterator<T>.any(predicate: Predicate<in T>): Boolean {
while (hasNext())
if (predicate.test(next()))

View File

@ -57,7 +57,7 @@ class PainterMenu(
return super.mayPlace(itemStack)
}
return super.mayPlace(itemStack) && inventory.player.level().recipeManager.byType(MRecipes.PAINTER).values.any { it.value.input.test(itemStack) }
return super.mayPlace(itemStack) && inventory.player.level().recipeManager.byType(MRecipes.PAINTER).values.any { it.value.matches(itemStack) }
}
}
@ -128,11 +128,7 @@ class PainterMenu(
private fun rescan() {
possibleRecipes.clear()
possibleRecipes.addAll(inventory.player.level().recipeManager.byType(MRecipes.PAINTER).values.iterator().filter { it.value.input.test(inputContainer[0]) })
if (!inputContainer[0].isEmpty && inputContainer[0].item is DyeableArmorItem) {
possibleRecipes.addAll(inventory.player.level().recipeManager.byType(MRecipes.PAINTER_ARMOR_DYE).values)
}
possibleRecipes.addAll(inventory.player.level().recipeManager.byType(MRecipes.PAINTER).values.iterator().filter { it.value.matches(inputContainer[0]) })
listeners.accept(Unit)
if (tile !is PainterBlockEntity) return
@ -140,7 +136,7 @@ class PainterMenu(
if (inputContainer.isEmpty || selectedRecipe == null) {
outputContainer.clearContent()
} else {
val recipe = inventory.player.level().recipeManager.byKey(selectedRecipe).get() as RecipeHolder<AbstractPainterRecipe>?
val recipe = inventory.player.level().recipeManager.byKey(selectedRecipe!!).get() as RecipeHolder<AbstractPainterRecipe>?
if (recipe == null || !recipe.value.canCraft(dyeStoredDirect) || !recipe.value.matches(inputContainer, inventory.player.level())) {
outputContainer.clearContent()

View File

@ -35,6 +35,12 @@ abstract class AbstractPainterRecipe(
) : IMatteryRecipe<Container> {
val dyes: Object2IntMap<DyeColor?> = Object2IntMaps.unmodifiable(Object2IntArrayMap(dyes))
abstract fun matches(value: ItemStack): Boolean
override fun matches(contaier: Container, level: Level): Boolean {
return !isIncomplete && matches(contaier[0])
}
override fun getToastSymbol(): ItemStack = ItemStack(MItems.PAINTER)
fun canCraft(storedDyes: Map<out DyeColor?, Int>): Boolean {
@ -110,9 +116,8 @@ class PainterRecipe(
dyes: Set<DyeColor?>
) : this(input, output, Object2IntArrayMap<DyeColor?>().also { map -> dyes.forEach { map[it] = 1 } })
override fun matches(p_44002_: Container, p_44003_: Level): Boolean {
if (isIncomplete) return false
return input.test(p_44002_[0])
override fun matches(value: ItemStack): Boolean {
return !isIncomplete && input.test(value)
}
override fun isIncomplete(): Boolean {
@ -176,11 +181,8 @@ class PainterArmorDyeRecipe(
dyes: Set<DyeColor?>
) : this(Object2IntArrayMap<DyeColor?>().also { map -> dyes.forEach { map[it] = 1 } })
override fun matches(contaier: Container, level: Level): Boolean {
if (this.isIncomplete) return false
val stack = contaier[0]
return (!stack.isEmpty && stack.item is DyeableArmorItem)
override fun matches(value: ItemStack): Boolean {
return !isIncomplete && value.item is DyeableArmorItem
}
override fun assemble(container: Container, registry: RegistryAccess): ItemStack {
@ -201,7 +203,7 @@ class PainterArmorDyeRecipe(
override fun getSerializer(): RecipeSerializer<*> = SERIALIZER
override fun getType(): RecipeType<*> = MRecipes.PAINTER_ARMOR_DYE
override fun getType(): RecipeType<*> = MRecipes.PAINTER
override fun isIncomplete(): Boolean = dyes.isEmpty()

View File

@ -33,8 +33,7 @@ object MRecipes {
}
val PLATE_PRESS by register<PlatePressRecipe>("plate_press")
val PAINTER by register<PainterRecipe>("painter")
val PAINTER_ARMOR_DYE by register<PainterArmorDyeRecipe>("painter_armor_dye")
val PAINTER by register<AbstractPainterRecipe>("painter")
val MATTER_ENTANGLER by register<IMatterEntanglerRecipe>("matter_entangler")
val MICROWAVE by register<MicrowaveRecipe>("microwave")