Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions src/main/java/com/lance5057/extradelight/ExtraDelightItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2689,19 +2690,8 @@ public int getBurnTime(ItemStack itemStack, @Nullable RecipeType<?> recipeType)
.advancementMeal().isHotFood().finish();

public static final DeferredItem<Item> 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<Item> TARTE_TATIN = EDItemGenerator
.register("tarte_tatin", () -> new BlockItem(ExtraDelightBlocks.TARTE_TATIN.get(), stack1Item()))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -307,7 +307,7 @@ private boolean processCooking(RecipeHolder<OvenRecipe> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<RecipeWrapper> {
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<Ingredient> inputItems;
public final ItemStack output;
Expand Down Expand Up @@ -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() {
Expand Down