EnergyContainerRecipe now inherits ShapedRecipe

This commit is contained in:
DBotThePony 2022-09-13 19:13:44 +07:00
parent 85ebbbf905
commit e1ce6a9d3f
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 18 additions and 10 deletions

View File

@ -75,7 +75,6 @@ class JEIPlugin : IModPlugin {
val level = minecraft.level ?: throw NullPointerException("No ClientLevel. OLOLOLOLOLOLO")
registration.addRecipes(PlatePressRecipeCategory.recipeType, level.recipeManager.getAllRecipesFor(MRecipes.PLATE_PRESS).filter { !it.isIncomplete })
registration.addRecipes(RecipeTypes.CRAFTING, level.recipeManager.getAllRecipesFor(RecipeType.CRAFTING).filterIsInstance<EnergyContainerRecipe>().map { it.parent })
}
override fun registerRecipeTransferHandlers(registration: IRecipeTransferRegistration) {

View File

@ -1,11 +1,13 @@
package ru.dbotthepony.mc.otm.recipe
import com.google.gson.JsonObject
import net.minecraft.core.NonNullList
import net.minecraft.network.FriendlyByteBuf
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.inventory.CraftingContainer
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.crafting.CraftingRecipe
import net.minecraft.world.item.crafting.Ingredient
import net.minecraft.world.item.crafting.RecipeSerializer
import net.minecraft.world.item.crafting.ShapedRecipe
import net.minecraft.world.level.Level
@ -16,10 +18,17 @@ import ru.dbotthepony.mc.otm.core.set
import ru.dbotthepony.mc.otm.core.tagNotNull
class EnergyContainerRecipe(
val parent: ShapedRecipe
) : CraftingRecipe by parent {
p_44153_: ResourceLocation,
p_44154_: String,
p_44155_: Int,
p_44156_: Int,
p_44157_: NonNullList<Ingredient>,
p_44158_: ItemStack,
) : ShapedRecipe(p_44153_, p_44154_, p_44155_, p_44156_, p_44157_, p_44158_) {
constructor(parent: ShapedRecipe) : this(parent.id, parent.group, parent.width, parent.height, parent.ingredients, parent.resultItem)
override fun assemble(container: CraftingContainer): ItemStack {
val itemStack = parent.assemble(container)
val itemStack = super.assemble(container)
val battery = container.stream()
.filter { !it.isEmpty }
@ -35,7 +44,7 @@ class EnergyContainerRecipe(
}
override fun matches(p_44002_: CraftingContainer, p_44003_: Level): Boolean {
return parent.matches(p_44002_, p_44003_) && !p_44002_.stream().anyMatch { it.isDamaged }
return super.matches(p_44002_, p_44003_) && !p_44002_.stream().anyMatch { it.isDamaged }
}
override fun getSerializer(): RecipeSerializer<*> {
@ -44,16 +53,15 @@ class EnergyContainerRecipe(
companion object : RecipeSerializer<EnergyContainerRecipe> {
override fun fromJson(p_44103_: ResourceLocation, p_44104_: JsonObject): EnergyContainerRecipe {
return EnergyContainerRecipe(ShapedRecipe.Serializer.SHAPED_RECIPE.fromJson(p_44103_, p_44104_))
return EnergyContainerRecipe(Serializer.SHAPED_RECIPE.fromJson(p_44103_, p_44104_))
}
override fun fromNetwork(p_44105_: ResourceLocation, p_44106_: FriendlyByteBuf): EnergyContainerRecipe? {
return ShapedRecipe.Serializer.SHAPED_RECIPE.fromNetwork(p_44105_, p_44106_)?.let(::EnergyContainerRecipe)
return Serializer.SHAPED_RECIPE.fromNetwork(p_44105_, p_44106_)?.let(::EnergyContainerRecipe)
}
override fun toNetwork(p_44101_: FriendlyByteBuf, p_44102_: EnergyContainerRecipe) {
ShapedRecipe.Serializer.SHAPED_RECIPE.toNetwork(p_44101_, p_44102_.parent)
Serializer.SHAPED_RECIPE.toNetwork(p_44101_, p_44102_)
}
}
}

View File

@ -13,6 +13,7 @@ import net.minecraft.world.item.crafting.Recipe
import net.minecraft.world.item.crafting.RecipeSerializer
import net.minecraft.world.item.crafting.RecipeType
import net.minecraft.world.level.Level
import net.minecraftforge.common.ForgeHooks
import org.apache.logging.log4j.LogManager
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.block.entity.PlatePressBlockEntity
@ -52,7 +53,7 @@ class PlatePressRecipe(
}
override fun isIncomplete(): Boolean {
return !(input.items.any { it.item != Items.BARRIER } && output.items.any { it.item != Items.BARRIER })
return ForgeHooks.hasNoElements(input) || ForgeHooks.hasNoElements(output)
}
override fun assemble(p_44001_: Container): ItemStack = outputStack.copy()