minecraft-src/net/minecraft/world/item/trading/Merchant.java
2025-07-04 03:15:13 +03:00

54 lines
1.6 KiB
Java

package net.minecraft.world.item.trading;
import java.util.OptionalInt;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.SimpleMenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.MerchantMenu;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
public interface Merchant {
void setTradingPlayer(@Nullable Player tradingPlayer);
@Nullable
Player getTradingPlayer();
MerchantOffers getOffers();
void overrideOffers(MerchantOffers offers);
void notifyTrade(MerchantOffer offer);
/**
* Notifies the merchant of a possible merchant recipe being fulfilled or not. Usually, this is just a sound byte being played depending on whether the suggested {@link net.minecraft.world.item.ItemStack} is not empty.
*/
void notifyTradeUpdated(ItemStack stack);
int getVillagerXp();
void overrideXp(int xp);
boolean showProgressBar();
SoundEvent getNotifyTradeSound();
default boolean canRestock() {
return false;
}
default void openTradingScreen(Player player, Component displayName, int level) {
OptionalInt optionalInt = player.openMenu(new SimpleMenuProvider((i, inventory, playerx) -> new MerchantMenu(i, inventory, this), displayName));
if (optionalInt.isPresent()) {
MerchantOffers merchantOffers = this.getOffers();
if (!merchantOffers.isEmpty()) {
player.sendMerchantOffers(optionalInt.getAsInt(), merchantOffers, level, this.getVillagerXp(), this.showProgressBar(), this.canRestock());
}
}
}
boolean isClientSide();
boolean stillValid(Player player);
}