the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.inventory.h"
3#include "net.minecraft.world.item.trading.h"
4#include "MerchantResultSlot.h"
5
6MerchantResultSlot::MerchantResultSlot(Player *player, shared_ptr<Merchant> merchant, shared_ptr<MerchantContainer> slots, int id, int x, int y) : Slot(slots, id, x, y)
7{
8 this->player = player;
9 this->merchant = merchant;
10 this->slots = slots;
11 removeCount = 0;
12}
13
14bool MerchantResultSlot::mayPlace(shared_ptr<ItemInstance> item)
15{
16 return false;
17}
18
19shared_ptr<ItemInstance> MerchantResultSlot::remove(int c)
20{
21 if (hasItem())
22 {
23 removeCount += min(c, getItem()->count);
24 }
25 return Slot::remove(c);
26}
27
28void MerchantResultSlot::onQuickCraft(shared_ptr<ItemInstance> picked, int count)
29{
30 removeCount += count;
31 checkTakeAchievements(picked);
32}
33
34void MerchantResultSlot::checkTakeAchievements(shared_ptr<ItemInstance> carried)
35{
36 carried->onCraftedBy(player->level, dynamic_pointer_cast<Player>(player->shared_from_this()), removeCount);
37 removeCount = 0;
38}
39
40void MerchantResultSlot::onTake(shared_ptr<Player> player, shared_ptr<ItemInstance> carried)
41{
42 checkTakeAchievements(carried);
43
44 MerchantRecipe *activeRecipe = slots->getActiveRecipe();
45 if (activeRecipe != NULL)
46 {
47 shared_ptr<ItemInstance> item1 = slots->getItem(MerchantMenu::PAYMENT1_SLOT);
48 shared_ptr<ItemInstance> item2 = slots->getItem(MerchantMenu::PAYMENT2_SLOT);
49
50 // remove payment items, but remember slots may have switched
51 if (removePaymentItemsIfMatching(activeRecipe, item1, item2) || removePaymentItemsIfMatching(activeRecipe, item2, item1))
52 {
53 merchant->notifyTrade(activeRecipe);
54
55 if (item1 && item1->count <= 0)
56 {
57 item1 = nullptr;
58 }
59 if (item2 && item2->count <= 0)
60 {
61 item2 = nullptr;
62 }
63 slots->setItem(MerchantMenu::PAYMENT1_SLOT, item1);
64 slots->setItem(MerchantMenu::PAYMENT2_SLOT, item2);
65 }
66 }
67}
68
69bool MerchantResultSlot::mayCombine(shared_ptr<ItemInstance> second)
70{
71 return false;
72}
73
74bool MerchantResultSlot::removePaymentItemsIfMatching(MerchantRecipe *activeRecipe, shared_ptr<ItemInstance> a, shared_ptr<ItemInstance> b)
75{
76 shared_ptr<ItemInstance> buyA = activeRecipe->getBuyAItem();
77 shared_ptr<ItemInstance> buyB = activeRecipe->getBuyBItem();
78
79 if (a != NULL && a->id == buyA->id)
80 {
81 if (buyB != NULL && b != NULL && buyB->id == b->id)
82 {
83 a->count -= buyA->count;
84 b->count -= buyB->count;
85 return true;
86 }
87 else if (buyB == NULL && b == NULL)
88 {
89 a->count -= buyA->count;
90 return true;
91 }
92 }
93 return false;
94}