diff --git a/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketMenu.java b/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketMenu.java index e5ccdd8..f14ca75 100644 --- a/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketMenu.java +++ b/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketMenu.java @@ -3,11 +3,14 @@ import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.container.DefaultContainer; import net.blay09.mods.farmingforblockheads.api.MarketCategory; +import net.blay09.mods.farmingforblockheads.api.Payment; import net.blay09.mods.farmingforblockheads.block.ModBlocks; import net.blay09.mods.farmingforblockheads.network.MarketPlaceRecipeMessage; import net.blay09.mods.farmingforblockheads.recipe.MarketRecipe; import net.blay09.mods.farmingforblockheads.recipe.MarketRecipeDisplay; import net.blay09.mods.farmingforblockheads.recipe.ModRecipes; +import net.blay09.mods.farmingforblockheads.registry.MarketDefaultsRegistry; +import net.blay09.mods.farmingforblockheads.registry.PaymentImpl; import net.blay09.mods.farmingforblockheads.registry.SimpleHolder; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.recipebook.ServerPlaceRecipe; @@ -392,4 +395,16 @@ private Comparator sorting() { public boolean containsRecipeDisplayId(RecipeDisplayId recipeDisplayId) { return recipes.stream().anyMatch(it -> it.id().equals(recipeDisplayId)); } + + public Optional getExpectedPayment() { + if (serverSelectedRecipe != null) { + return Optional.of(MarketDefaultsRegistry.resolvePayment(serverSelectedRecipe.value())); + } else if (selectedRecipeDisplayEntry != null && selectedRecipeDisplayEntry.display() instanceof MarketRecipeDisplay marketRecipeDisplay) { + final var contextMap = SlotDisplayContext.fromLevel(player.level()); + final var paymentItems = marketRecipeDisplay.payment().resolveForStacks(contextMap); + final var ingredient = Ingredient.of(paymentItems.stream().map(ItemStack::getItem)); + return Optional.of(new PaymentImpl(ingredient, 0, Optional.empty())); + } + return Optional.empty(); + } } diff --git a/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketPaymentContainer.java b/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketPaymentContainer.java index 55798cd..700e655 100644 --- a/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketPaymentContainer.java +++ b/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketPaymentContainer.java @@ -1,6 +1,7 @@ package net.blay09.mods.farmingforblockheads.menu; import net.blay09.mods.balm.api.container.DefaultContainer; +import net.blay09.mods.farmingforblockheads.api.Payment; import net.minecraft.world.entity.player.StackedItemContents; import net.minecraft.world.inventory.StackedContentsCompatible; import net.minecraft.world.item.ItemStack; @@ -40,4 +41,9 @@ public void fillStackedContents(StackedItemContents stackedItemContents) { public RecipeInput asRecipeInput() { return new SingleRecipeInput(getItem(0)); } + + public void removePayment(int slot) { + final var expectedPayment = menu.getExpectedPayment(); + removeItem(slot, expectedPayment.map(Payment::count).orElse(1)); + } } diff --git a/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketResultSlot.java b/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketResultSlot.java index 8320133..71a8837 100644 --- a/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketResultSlot.java +++ b/common/src/main/java/net/blay09/mods/farmingforblockheads/menu/MarketResultSlot.java @@ -63,7 +63,7 @@ public void onTake(Player player, ItemStack itemStack) { final var paymentSlot = 0; var paymentStack = paymentSlots.getItem(paymentSlot); if (!paymentStack.isEmpty()) { - paymentSlots.removeItem(paymentSlot, 1); + paymentSlots.removePayment(paymentSlot); paymentStack = this.paymentSlots.getItem(paymentSlot); }