Update energy container upgrade recipe
This commit is contained in:
parent
aaecbf8ae5
commit
eaefda867d
@ -1,73 +1,32 @@
|
|||||||
package ru.dbotthepony.mc.otm.recipe
|
package ru.dbotthepony.mc.otm.recipe
|
||||||
|
|
||||||
import com.mojang.serialization.Codec
|
import com.mojang.serialization.Codec
|
||||||
import net.minecraft.core.NonNullList
|
import com.mojang.serialization.MapCodec
|
||||||
|
import net.minecraft.core.HolderLookup
|
||||||
import net.minecraft.core.RegistryAccess
|
import net.minecraft.core.RegistryAccess
|
||||||
|
import net.minecraft.core.component.DataComponents
|
||||||
import net.minecraft.network.FriendlyByteBuf
|
import net.minecraft.network.FriendlyByteBuf
|
||||||
import net.minecraft.world.inventory.CraftingContainer
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
|
import net.minecraft.network.codec.StreamCodec
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.item.crafting.CraftingBookCategory
|
import net.minecraft.world.item.crafting.CraftingBookCategory
|
||||||
import net.minecraft.world.item.crafting.CraftingRecipe
|
import net.minecraft.world.item.crafting.CraftingInput
|
||||||
import net.minecraft.world.item.crafting.Ingredient
|
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer
|
import net.minecraft.world.item.crafting.RecipeSerializer
|
||||||
import net.minecraft.world.item.crafting.RecipeType
|
|
||||||
import net.minecraft.world.item.crafting.ShapedRecipe
|
import net.minecraft.world.item.crafting.ShapedRecipe
|
||||||
|
import net.minecraft.world.item.crafting.ShapedRecipePattern
|
||||||
|
import net.minecraft.world.item.enchantment.ItemEnchantments
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraftforge.common.crafting.IShapedRecipe
|
|
||||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||||
import ru.dbotthepony.mc.otm.container.util.iterator
|
import ru.dbotthepony.mc.otm.container.util.iterator
|
||||||
import ru.dbotthepony.mc.otm.container.util.stream
|
|
||||||
import ru.dbotthepony.mc.otm.core.filterNotNull
|
import ru.dbotthepony.mc.otm.core.filterNotNull
|
||||||
|
|
||||||
class EnergyContainerRecipe(val parent: ShapedRecipe) : CraftingRecipe, IShapedRecipe<CraftingContainer> by parent {
|
class EnergyContainerRecipe(group: String, category: CraftingBookCategory, pattern: ShapedRecipePattern, result: ItemStack, showNotification: Boolean = true) : ShapedRecipe(group, category, pattern, result, showNotification) {
|
||||||
override fun canCraftInDimensions(p_43999_: Int, p_44000_: Int): Boolean {
|
constructor(parent: ShapedRecipe) : this(parent.group, parent.category(), parent.pattern, parent.result, parent.showNotification())
|
||||||
return parent.canCraftInDimensions(p_43999_, p_44000_)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getResultItem(p_267052_: RegistryAccess): ItemStack {
|
override fun assemble(container: CraftingInput, registryAccess: HolderLookup.Provider): ItemStack {
|
||||||
return parent.getResultItem(p_267052_)
|
val itemStack = super.assemble(container, registryAccess)
|
||||||
}
|
|
||||||
|
|
||||||
override fun category(): CraftingBookCategory {
|
val battery = container.items().stream()
|
||||||
return parent.category()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getRemainingItems(p_44004_: CraftingContainer): NonNullList<ItemStack> {
|
|
||||||
return parent.getRemainingItems(p_44004_)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getIngredients(): NonNullList<Ingredient> {
|
|
||||||
return parent.ingredients
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isSpecial(): Boolean {
|
|
||||||
return parent.isSpecial
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showNotification(): Boolean {
|
|
||||||
return parent.showNotification()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getGroup(): String {
|
|
||||||
return parent.group
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getToastSymbol(): ItemStack {
|
|
||||||
return parent.toastSymbol
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isIncomplete(): Boolean {
|
|
||||||
return parent.isIncomplete
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getType(): RecipeType<*> {
|
|
||||||
return parent.type
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun assemble(container: CraftingContainer, registryAccess: RegistryAccess): ItemStack {
|
|
||||||
val itemStack = parent.assemble(container, registryAccess)
|
|
||||||
|
|
||||||
val battery = container.stream()
|
|
||||||
.filter { !it.isEmpty }
|
.filter { !it.isEmpty }
|
||||||
.map { it.matteryEnergy }
|
.map { it.matteryEnergy }
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
@ -78,10 +37,16 @@ class EnergyContainerRecipe(val parent: ShapedRecipe) : CraftingRecipe, IShapedR
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (itemStack.isEnchantable) {
|
if (itemStack.isEnchantable) {
|
||||||
for (it in container.iterator()) {
|
for (it in container.items()) {
|
||||||
if (it.isEnchanted) {
|
val enchantments = it[DataComponents.ENCHANTMENTS]
|
||||||
for ((key, value) in it.allEnchantments) {
|
|
||||||
itemStack.enchant(key, value)
|
if (enchantments != null) {
|
||||||
|
itemStack[DataComponents.ENCHANTMENTS] = ItemEnchantments.Mutable(itemStack.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY)).let {
|
||||||
|
for ((key, level) in enchantments.entrySet()) {
|
||||||
|
it.upgrade(key, level)
|
||||||
|
}
|
||||||
|
|
||||||
|
it.toImmutable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,8 +55,8 @@ class EnergyContainerRecipe(val parent: ShapedRecipe) : CraftingRecipe, IShapedR
|
|||||||
return itemStack
|
return itemStack
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun matches(container: CraftingContainer, level: Level): Boolean {
|
override fun matches(container: CraftingInput, level: Level): Boolean {
|
||||||
return parent.matches(container, level) && !container.stream().anyMatch { it.isDamaged }
|
return super.matches(container, level) && container.items().none { it.isDamaged }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSerializer(): RecipeSerializer<EnergyContainerRecipe> {
|
override fun getSerializer(): RecipeSerializer<EnergyContainerRecipe> {
|
||||||
@ -100,19 +65,19 @@ class EnergyContainerRecipe(val parent: ShapedRecipe) : CraftingRecipe, IShapedR
|
|||||||
|
|
||||||
companion object : RecipeSerializer<EnergyContainerRecipe> {
|
companion object : RecipeSerializer<EnergyContainerRecipe> {
|
||||||
private val codec by lazy {
|
private val codec by lazy {
|
||||||
RecipeSerializer.SHAPED_RECIPE.codec().xmap(::EnergyContainerRecipe, EnergyContainerRecipe::parent)
|
RecipeSerializer.SHAPED_RECIPE.codec().xmap(::EnergyContainerRecipe, { it })
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun codec(): Codec<EnergyContainerRecipe> {
|
private val streamCodec by lazy {
|
||||||
|
RecipeSerializer.SHAPED_RECIPE.streamCodec().map(::EnergyContainerRecipe, { it })
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun codec(): MapCodec<EnergyContainerRecipe> {
|
||||||
return codec
|
return codec
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromNetwork(data: FriendlyByteBuf): EnergyContainerRecipe? {
|
override fun streamCodec(): StreamCodec<RegistryFriendlyByteBuf, EnergyContainerRecipe> {
|
||||||
return ShapedRecipe.Serializer.SHAPED_RECIPE.fromNetwork(data)?.let(::EnergyContainerRecipe)
|
return streamCodec
|
||||||
}
|
|
||||||
|
|
||||||
override fun toNetwork(buff: FriendlyByteBuf, value: EnergyContainerRecipe) {
|
|
||||||
ShapedRecipe.Serializer.SHAPED_RECIPE.toNetwork(buff, value.parent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_1696
|
|||||||
public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen menu
|
public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen menu
|
||||||
public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen playerInventoryTitle
|
public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen playerInventoryTitle
|
||||||
|
|
||||||
|
public net.minecraft.world.item.crafting.ShapedRecipe result
|
||||||
|
|
||||||
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen clickedSlot
|
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen clickedSlot
|
||||||
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen snapbackEnd
|
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen snapbackEnd
|
||||||
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen quickdropSlot
|
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen quickdropSlot
|
||||||
|
Loading…
Reference in New Issue
Block a user