From 668f70db2177b819262079a132ad1d66b07bb10b Mon Sep 17 00:00:00 2001 From: vomiter-scp-zh <97169118+vomiter-scp-zh@users.noreply.github.com> Date: Sun, 26 Jul 2026 23:22:08 +0800 Subject: [PATCH] fix oven recipe and tarte skillet issue --- .../extradelight/ExtraDelightItems.java | 16 ++---- .../DynamicContainerFeastItem.java | 54 +++++++++++++++++++ .../workstations/oven/OvenBlockEntity.java | 4 +- .../workstations/oven/recipes/OvenRecipe.java | 15 ++++-- 4 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/lance5057/extradelight/items/dynamicfood/DynamicContainerFeastItem.java diff --git a/src/main/java/com/lance5057/extradelight/ExtraDelightItems.java b/src/main/java/com/lance5057/extradelight/ExtraDelightItems.java index c3096c8ec..9e008035e 100644 --- a/src/main/java/com/lance5057/extradelight/ExtraDelightItems.java +++ b/src/main/java/com/lance5057/extradelight/ExtraDelightItems.java @@ -30,6 +30,7 @@ import com.lance5057.extradelight.items.ShuckableCorn; import com.lance5057.extradelight.items.ToolTipConsumableItem; import com.lance5057.extradelight.items.XocolatlItem; +import com.lance5057.extradelight.items.dynamicfood.DynamicContainerFeastItem; import com.lance5057.extradelight.items.dynamicfood.DynamicJam; import com.lance5057.extradelight.items.dynamicfood.DynamicToast; import com.lance5057.extradelight.items.dynamicfood.api.DynamicItemComponent; @@ -2689,19 +2690,8 @@ public int getBurnTime(ItemStack itemStack, @Nullable RecipeType recipeType) .advancementMeal().isHotFood().finish(); public static final DeferredItem TARTE_TATIN_IN_PAN = EDItemGenerator - .register("tarte_tatin_in_pan", () -> new SolidBucketItem(ExtraDelightBlocks.TARTE_TATIN.get(), - SoundEvents.DYE_USE, stack1Item()) { - @Override - public InteractionResult useOn(UseOnContext context) { - InteractionResult interactionresult = super.useOn(context); - Player player = context.getPlayer(); - if (interactionresult.consumesAction() && player != null) { - player.setItemInHand(context.getHand(), new ItemStack(ModItems.SKILLET.get())); - } - - return interactionresult; - } - }).advancementFeast().finish(); + .register("tarte_tatin_in_pan", () -> new DynamicContainerFeastItem(ExtraDelightBlocks.TARTE_TATIN.get(), + SoundEvents.DYE_USE, stack1Item().craftRemainder(ModItems.SKILLET.get()))).advancementFeast().finish(); public static final DeferredItem TARTE_TATIN = EDItemGenerator .register("tarte_tatin", () -> new BlockItem(ExtraDelightBlocks.TARTE_TATIN.get(), stack1Item())) diff --git a/src/main/java/com/lance5057/extradelight/items/dynamicfood/DynamicContainerFeastItem.java b/src/main/java/com/lance5057/extradelight/items/dynamicfood/DynamicContainerFeastItem.java new file mode 100644 index 000000000..7d3b10495 --- /dev/null +++ b/src/main/java/com/lance5057/extradelight/items/dynamicfood/DynamicContainerFeastItem.java @@ -0,0 +1,54 @@ +package com.lance5057.extradelight.items.dynamicfood; + +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.SolidBucketItem; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.Block; +import vectorwing.farmersdelight.common.item.component.ItemStackWrapper; +import vectorwing.farmersdelight.common.registry.ModDataComponents; + +import java.util.Optional; + +public class DynamicContainerFeastItem extends SolidBucketItem { + + public DynamicContainerFeastItem( + Block p_151187_, + SoundEvent p_151188_, + Properties p_151189_ + ) { + super(p_151187_, p_151188_, p_151189_); + } + + @Override + public InteractionResult useOn(UseOnContext context) { + ItemStack cached = context.getItemInHand().copy(); + InteractionResult interactionresult = super.useOn(context); + Player player = context.getPlayer(); + + if (interactionresult.consumesAction() && player != null) { + player.setItemInHand(context.getHand(), getCraftingRemainingItem(cached)); + } + + return interactionresult; + } + + public ItemStack getCraftingRemainingItem(ItemStack itemStack) + { + if (!hasCraftingRemainingItem(itemStack)) { + return ItemStack.EMPTY; + } + var toReturn = Optional.ofNullable(itemStack.get(ModDataComponents.CONTAINER)) + .map(ItemStackWrapper::getStack) + .orElse(Items.ACACIA_BOAT.getDefaultInstance()); + if (toReturn.isEmpty()) { + assert this.getCraftingRemainingItem() != null; + return new ItemStack(this.getCraftingRemainingItem()); + } + return toReturn; + } + +} diff --git a/src/main/java/com/lance5057/extradelight/workstations/oven/OvenBlockEntity.java b/src/main/java/com/lance5057/extradelight/workstations/oven/OvenBlockEntity.java index 916e859d6..d7a50c3c4 100644 --- a/src/main/java/com/lance5057/extradelight/workstations/oven/OvenBlockEntity.java +++ b/src/main/java/com/lance5057/extradelight/workstations/oven/OvenBlockEntity.java @@ -269,7 +269,7 @@ private boolean hasInput() { protected boolean canCook(OvenRecipe recipe) { if (hasInput()) { - ItemStack resultStack = recipe.getResultItem(this.level.registryAccess()); + ItemStack resultStack = recipe.assemble(new RecipeWrapper(inventory), this.level.registryAccess()).copy(); // Vessel Required if (inventory.getStackInSlot(CONTAINER_SLOT).getItem() != recipe.getOutputContainer().getItem()) @@ -307,7 +307,7 @@ private boolean processCooking(RecipeHolder recipe, OvenBlockEntity cookTime = 0; mealContainerStack = recipe.value().getOutputContainer(); ItemStack containerInputStack = inventory.getStackInSlot(CONTAINER_SLOT); - ItemStack resultStack = recipe.value().getResultItem(this.level.registryAccess()); + ItemStack resultStack = recipe.value().assemble(new RecipeWrapper(inventory), this.level.registryAccess()).copy(); ItemStack storedMealStack = inventory.getStackInSlot(OUTPUT_SLOT); if (storedMealStack.isEmpty()) { inventory.setStackInSlot(OUTPUT_SLOT, resultStack.copy()); diff --git a/src/main/java/com/lance5057/extradelight/workstations/oven/recipes/OvenRecipe.java b/src/main/java/com/lance5057/extradelight/workstations/oven/recipes/OvenRecipe.java index 2941ade16..ef8a4c9ff 100644 --- a/src/main/java/com/lance5057/extradelight/workstations/oven/recipes/OvenRecipe.java +++ b/src/main/java/com/lance5057/extradelight/workstations/oven/recipes/OvenRecipe.java @@ -1,7 +1,9 @@ package com.lance5057.extradelight.workstations.oven.recipes; +import com.lance5057.extradelight.ExtraDelight; import com.lance5057.extradelight.ExtraDelightItems; import com.lance5057.extradelight.ExtraDelightRecipes; +import com.lance5057.extradelight.items.dynamicfood.DynamicContainerFeastItem; import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; @@ -18,11 +20,14 @@ import net.minecraft.world.level.Level; import net.neoforged.neoforge.common.util.RecipeMatcher; import net.neoforged.neoforge.items.wrapper.RecipeWrapper; +import vectorwing.farmersdelight.common.item.component.ItemStackWrapper; +import vectorwing.farmersdelight.common.registry.ModDataComponents; public class OvenRecipe implements Recipe { public static final int INPUT_SLOTS = 9; + public static final int CONTAINER_SLOT = 10; - private final String group; + private final String group; // private final OvenRecipeBookTab tab; private final NonNullList inputItems; public final ItemStack output; @@ -82,8 +87,12 @@ public ItemStack getOutputContainer() { } @Override - public ItemStack assemble(RecipeWrapper input, Provider registries) { - return this.output.copy(); + public ItemStack assemble(RecipeWrapper recipeWrapper, Provider registries) { + ItemStack result = output.copy(); + if(result.getItem() instanceof DynamicContainerFeastItem && !recipeWrapper.getItem(CONTAINER_SLOT).isEmpty()){ + result.set(ModDataComponents.CONTAINER.get(), new ItemStackWrapper(recipeWrapper.getItem(CONTAINER_SLOT).copyWithCount(1))); + } + return result; } public float getExperience() {