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.entity.player.h"
3#include "net.minecraft.world.level.tile.entity.h"
4#include "net.minecraft.world.item.h"
5#include "net.minecraft.world.item.alchemy.h"
6#include "net.minecraft.stats.h"
7#include "BrewingStandMenu.h"
8
9BrewingStandMenu::BrewingStandMenu(shared_ptr<Inventory> inventory, shared_ptr<BrewingStandTileEntity> brewingStand)
10{
11 tc = 0;
12
13 this->brewingStand = brewingStand;
14
15 addSlot(new PotionSlot(dynamic_pointer_cast<Player>( inventory->player->shared_from_this() ), brewingStand, 0, 56, 46));
16 addSlot(new PotionSlot(dynamic_pointer_cast<Player>( inventory->player->shared_from_this() ), brewingStand, 1, 79, 53));
17 addSlot(new PotionSlot(dynamic_pointer_cast<Player>( inventory->player->shared_from_this() ), brewingStand, 2, 102, 46));
18 ingredientSlot = addSlot(new IngredientsSlot(brewingStand, 3, 79, 17));
19
20 for (int y = 0; y < 3; y++)
21 {
22 for (int x = 0; x < 9; x++)
23 {
24 addSlot(new Slot(inventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
25 }
26 }
27 for (int x = 0; x < 9; x++)
28 {
29 addSlot(new Slot(inventory, x, 8 + x * 18, 142));
30 }
31}
32
33void BrewingStandMenu::addSlotListener(ContainerListener *listener)
34{
35 AbstractContainerMenu::addSlotListener(listener);
36 listener->setContainerData(this, 0, brewingStand->getBrewTime());
37}
38
39void BrewingStandMenu::broadcastChanges()
40{
41 AbstractContainerMenu::broadcastChanges();
42
43 //for (int i = 0; i < containerListeners->size(); i++)
44 for(AUTO_VAR(it, containerListeners.begin()); it != containerListeners.end(); ++it)
45 {
46 ContainerListener *listener = *it; //containerListeners.at(i);
47 if (tc != brewingStand->getBrewTime())
48 {
49 listener->setContainerData(this, 0, brewingStand->getBrewTime());
50 }
51 }
52 tc = brewingStand->getBrewTime();
53}
54
55void BrewingStandMenu::setData(int id, int value)
56{
57 if (id == 0) brewingStand->setBrewTime(value);
58}
59
60bool BrewingStandMenu::stillValid(shared_ptr<Player> player)
61{
62 return brewingStand->stillValid(player);
63}
64
65shared_ptr<ItemInstance> BrewingStandMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex)
66{
67 shared_ptr<ItemInstance> clicked = nullptr;
68 Slot *slot = slots.at(slotIndex);
69 Slot *IngredientSlot = slots.at(INGREDIENT_SLOT);
70 Slot *PotionSlot1 = slots.at(BOTTLE_SLOT_START);
71 Slot *PotionSlot2 = slots.at(BOTTLE_SLOT_START+1);
72 Slot *PotionSlot3 = slots.at(BOTTLE_SLOT_START+2);
73
74 if (slot != NULL && slot->hasItem())
75 {
76 shared_ptr<ItemInstance> stack = slot->getItem();
77 clicked = stack->copy();
78
79 if ((slotIndex >= BOTTLE_SLOT_START && slotIndex <= BOTTLE_SLOT_END) || (slotIndex == INGREDIENT_SLOT))
80 {
81 if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, true))
82 {
83 return nullptr;
84 }
85 slot->onQuickCraft(stack, clicked);
86 }
87 else if (!ingredientSlot->hasItem() && ingredientSlot->mayPlace(stack))
88 {
89 if (!moveItemStackTo(stack, INGREDIENT_SLOT, INGREDIENT_SLOT + 1, false))
90 {
91 return nullptr;
92 }
93 }
94 else if (PotionSlot::mayPlaceItem(clicked))
95 {
96 if (!moveItemStackTo(stack, BOTTLE_SLOT_START, BOTTLE_SLOT_END + 1, false))
97 {
98 return nullptr;
99 }
100 }
101 else if (slotIndex >= INV_SLOT_START && slotIndex < INV_SLOT_END)
102 {
103 // 4J-PB - if the item is an ingredient, quickmove it into the ingredient slot
104 if( (Item::items[stack->id]->hasPotionBrewingFormula() || (stack->id == Item::netherwart_seeds_Id) ) &&
105 (!IngredientSlot->hasItem() || (stack->id==IngredientSlot->getItem()->id) ) )
106 {
107 if(!moveItemStackTo(stack, INGREDIENT_SLOT, INGREDIENT_SLOT+1, false))
108 {
109 return nullptr;
110 }
111 }
112 // potion?
113 else if((stack->id==Item::potion_Id) &&(!PotionSlot1->hasItem() || !PotionSlot2->hasItem() || !PotionSlot3->hasItem()))
114 {
115 if(!moveItemStackTo(stack, BOTTLE_SLOT_START, BOTTLE_SLOT_END+1, false))
116 {
117 return nullptr;
118 }
119 }
120 else if (!moveItemStackTo(stack, USE_ROW_SLOT_START, USE_ROW_SLOT_END, false))
121 {
122 return nullptr;
123 }
124 }
125 else if (slotIndex >= USE_ROW_SLOT_START && slotIndex < USE_ROW_SLOT_END)
126 {
127 // 4J-PB - if the item is an ingredient, quickmove it into the ingredient slot
128 if((Item::items[stack->id]->hasPotionBrewingFormula() || (stack->id == Item::netherwart_seeds_Id)) &&
129 (!IngredientSlot->hasItem() || (stack->id==IngredientSlot->getItem()->id) ))
130 {
131 if(!moveItemStackTo(stack, INGREDIENT_SLOT, INGREDIENT_SLOT+1, false))
132 {
133 return nullptr;
134 }
135 }
136 // potion?
137 else if((stack->id==Item::potion_Id) &&(!PotionSlot1->hasItem() || !PotionSlot2->hasItem() || !PotionSlot3->hasItem()))
138 {
139 if(!moveItemStackTo(stack, BOTTLE_SLOT_START, BOTTLE_SLOT_END+1, false))
140 {
141 return nullptr;
142 }
143 }
144 else if (!moveItemStackTo(stack, INV_SLOT_START, INV_SLOT_END, false))
145 {
146 return nullptr;
147 }
148 }
149 else
150 {
151 if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, false))
152 {
153 return nullptr;
154 }
155 }
156 if (stack->count == 0)
157 {
158 slot->set(nullptr);
159 }
160 else
161 {
162 slot->setChanged();
163 }
164 if (stack->count == clicked->count)
165 {
166 return nullptr;
167 }
168 else
169 {
170 slot->onTake(player, stack);
171 }
172 }
173 return clicked;
174}
175
176BrewingStandMenu::PotionSlot::PotionSlot(shared_ptr<Player> player, shared_ptr<Container> container, int slot, int x, int y) : Slot(container, slot, x, y)
177{
178 this->player = player;
179}
180
181bool BrewingStandMenu::PotionSlot::mayPlace(shared_ptr<ItemInstance> item)
182{
183 return mayPlaceItem(item);
184}
185
186int BrewingStandMenu::PotionSlot::getMaxStackSize() const
187{
188 return 1;
189}
190
191void BrewingStandMenu::PotionSlot::onTake(shared_ptr<Player> player, shared_ptr<ItemInstance> carried)
192{
193 if (carried->id == Item::potion_Id && carried->getAuxValue() > 0) this->player->awardStat(GenericStats::potion(),GenericStats::param_potion());
194 Slot::onTake(player, carried);
195}
196
197bool BrewingStandMenu::PotionSlot::mayCombine(shared_ptr<ItemInstance> second)
198{
199 return false;
200}
201
202bool BrewingStandMenu::PotionSlot::mayPlaceItem(shared_ptr<ItemInstance> item)
203{
204 return item != NULL && (item->id == Item::potion_Id || item->id == Item::glassBottle_Id);
205}
206
207
208
209BrewingStandMenu::IngredientsSlot::IngredientsSlot(shared_ptr<Container> container, int slot, int x, int y) : Slot(container, slot, x ,y)
210{
211}
212
213bool BrewingStandMenu::IngredientsSlot::mayPlace(shared_ptr<ItemInstance> item)
214{
215 if (item != NULL)
216 {
217 if (PotionBrewing::SIMPLIFIED_BREWING)
218 {
219 return Item::items[item->id]->hasPotionBrewingFormula();
220 }
221 else
222 {
223 return Item::items[item->id]->hasPotionBrewingFormula() || item->id == Item::netherwart_seeds_Id || item->id == Item::bucket_water_Id;
224 }
225 }
226 return false;
227}
228
229bool BrewingStandMenu::IngredientsSlot::mayCombine(shared_ptr<ItemInstance> second)
230{
231 return false;
232}
233
234int BrewingStandMenu::IngredientsSlot::getMaxStackSize() const
235{
236 return 64;
237}