Commits
Y2K_ authored and md_5 committed 76fd7c056d2
51 51 | public record MenuTypeData<V extends InventoryView, B extends InventoryViewBuilder<V>>(Class<V> viewClass, Supplier<B> viewBuilder) { |
52 52 | } |
53 53 | |
54 54 | // This is a temporary measure that will likely be removed with the rewrite of HumanEntity#open[] methods |
55 55 | public static void openMerchantMenu(EntityPlayer player, ContainerMerchant merchant) { |
56 56 | final IMerchant minecraftMerchant = ((CraftMerchant) merchant.getBukkitView().getMerchant()).getMerchant(); |
57 57 | int level = 1; |
58 58 | if (minecraftMerchant instanceof EntityVillager villager) { |
59 59 | level = villager.getVillagerData().getLevel(); |
60 60 | } |
61 + | |
62 + | if (minecraftMerchant.getTradingPlayer() != null) { // merchant's can only have one trader |
63 + | minecraftMerchant.getTradingPlayer().closeContainer(); |
64 + | } |
65 + | |
61 66 | minecraftMerchant.setTradingPlayer(player); |
62 67 | |
63 68 | player.connection.send(new PacketPlayOutOpenWindow(merchant.containerId, Containers.MERCHANT, merchant.getTitle())); |
64 69 | player.containerMenu = merchant; |
65 70 | player.initMenu(merchant); |
66 71 | // Copy IMerchant#openTradingScreen |
67 72 | MerchantRecipeList merchantrecipelist = minecraftMerchant.getOffers(); |
68 73 | |
69 74 | if (!merchantrecipelist.isEmpty()) { |
70 75 | player.sendMerchantOffers(merchant.containerId, merchantrecipelist, level, minecraftMerchant.getVillagerXp(), minecraftMerchant.showProgressBar(), minecraftMerchant.canRestock()); |