| 1 | package net.minecraft.world.item.trading;
|
| 2 |
|
| 3 | import java.util.OptionalInt;
|
| 4 | import net.minecraft.network.chat.Component;
|
| 5 | import net.minecraft.sounds.SoundEvent;
|
| 6 | import net.minecraft.world.SimpleMenuProvider;
|
| 7 | import net.minecraft.world.entity.player.Player;
|
| 8 | import net.minecraft.world.inventory.MerchantMenu;
|
| 9 | import net.minecraft.world.item.ItemStack;
|
| 10 | import org.jspecify.annotations.Nullable;
|
| 11 |
|
| 12 | public interface Merchant {
|
| 13 | void setTradingPlayer(@Nullable Player player);
|
| 14 |
|
| 15 | @Nullable Player getTradingPlayer();
|
| 16 |
|
| 17 | MerchantOffers getOffers();
|
| 18 |
|
| 19 | void overrideOffers(MerchantOffers offers);
|
| 20 |
|
| 21 | void notifyTrade(MerchantOffer offer);
|
| 22 |
|
| 23 | void notifyTradeUpdated(ItemStack itemStack);
|
| 24 |
|
| 25 | int getVillagerXp();
|
| 26 |
|
| 27 | void overrideXp(final int xp);
|
| 28 |
|
| 29 | boolean showProgressBar();
|
| 30 |
|
| 31 | SoundEvent getNotifyTradeSound();
|
| 32 |
|
| 33 | default boolean canRestock() {
|
| 34 | return false;
|
| 35 | }
|
| 36 |
|
| 37 | default void openTradingScreen(final Player player, final Component title, final int level) {
|
| 38 | OptionalInt containerId = player.openMenu(new SimpleMenuProvider((id, inventory, p) -> new MerchantMenu(id, inventory, this), title));
|
| 39 | if (containerId.isPresent()) {
|
| 40 | MerchantOffers offers = this.getOffers();
|
| 41 | if (!offers.isEmpty()) {
|
| 42 | player.sendMerchantOffers(containerId.getAsInt(), offers, level, this.getVillagerXp(), this.showProgressBar(), this.canRestock());
|
| 43 | }
|
| 44 | }
|
| 45 | }
|
| 46 |
|
| 47 | boolean isClientSide();
|
| 48 |
|
| 49 | boolean stillValid(Player player);
|
| 50 | }
|
| 51 |
|