Skip to content

Commit

Permalink
wip: Continue port to Minecraft 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 19, 2024
1 parent a3e4656 commit 51bfefc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -392,4 +395,16 @@ private Comparator<RecipeDisplayEntry> sorting() {
public boolean containsRecipeDisplayId(RecipeDisplayId recipeDisplayId) {
return recipes.stream().anyMatch(it -> it.id().equals(recipeDisplayId));
}

public Optional<Payment> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 51bfefc

Please sign in to comment.