the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include "Container.h"
4#include "net.minecraft.world.item.h"
5#include "net.minecraft.world.item.crafting.h"
6#include "Slot.h"
7
8Slot::Slot(shared_ptr<Container> container, int slot, int x, int y) : container( container ), slot( slot )
9{
10 this->x = x;
11 this->y = y;
12
13 this->index = 0;
14}
15
16void Slot::onQuickCraft(shared_ptr<ItemInstance> picked, shared_ptr<ItemInstance> original)
17{
18 if (picked == NULL || original == NULL)
19 {
20 return;
21 }
22 if (picked->id != original->id)
23 {
24 return;
25 }
26 int count = original->count - picked->count;
27 if (count > 0)
28 {
29 onQuickCraft(picked, count);
30 }
31}
32
33
34void Slot::onQuickCraft(shared_ptr<ItemInstance> picked, int count)
35{
36}
37
38void Slot::checkTakeAchievements(shared_ptr<ItemInstance> picked)
39{
40}
41
42void Slot::swap(Slot *other)
43{
44 shared_ptr<ItemInstance> item1 = container->getItem(slot);
45 shared_ptr<ItemInstance> item2 = other->container->getItem(other->slot);
46
47 if (item1 != NULL && item1->count > other->getMaxStackSize())
48 {
49 if (item2 != NULL) return;
50 item2 = item1->remove(item1->count - other->getMaxStackSize());
51 }
52 if (item2 != NULL && item2->count > getMaxStackSize())
53 {
54 if (item1 != NULL) return;
55 item1 = item2->remove(item2->count - getMaxStackSize());
56 }
57 other->container->setItem(other->slot, item1);
58
59 container->setItem(slot, item2);
60 setChanged();
61}
62
63void Slot::onTake(shared_ptr<Player> player, shared_ptr<ItemInstance> carried)
64{
65 setChanged();
66}
67
68bool Slot::mayPlace(shared_ptr<ItemInstance> item)
69{
70 return true;
71}
72
73shared_ptr<ItemInstance> Slot::getItem()
74{
75 return container->getItem(slot);
76}
77
78bool Slot::hasItem()
79{
80 return getItem() != NULL;
81}
82
83void Slot::set(shared_ptr<ItemInstance> item)
84{
85 container->setItem(slot, item);
86 setChanged();
87}
88
89void Slot::setChanged()
90{
91 container->setChanged();
92}
93
94int Slot::getMaxStackSize() const
95{
96 return container->getMaxStackSize();
97}
98
99Icon *Slot::getNoItemIcon()
100{
101 return NULL;
102}
103
104shared_ptr<ItemInstance> Slot::remove(int c)
105{
106 return container->removeItem(slot, c);
107}
108
109bool Slot::isAt(shared_ptr<Container> c, int s)
110{
111 return c == container && s == slot;
112}
113
114bool Slot::mayPickup(shared_ptr<Player> player)
115{
116 return true;
117}
118
119bool Slot::isActive()
120{
121 return true;
122}
123
124bool Slot::mayCombine(shared_ptr<ItemInstance> second)
125{
126 shared_ptr<ItemInstance> first = getItem();
127
128 if(first == NULL || second == NULL) return false;
129
130 ArmorItem *thisItem = dynamic_cast<ArmorItem *>(first->getItem());
131 if(thisItem)
132 {
133 bool thisIsDyableArmor = thisItem->getMaterial() == ArmorItem::ArmorMaterial::CLOTH;
134 bool itemIsDye = second->id == Item::dye_powder_Id;
135 return thisIsDyableArmor && itemIsDye;
136 }
137 // 4J Stu - This condition taken from Recipes::getItemFor to repair items, but added the damaged check to skip when the result is pointless
138 else if (first != NULL && second != NULL && first->id == second->id && first->count == 1 && second->count == 1 && Item::items[first->id]->canBeDepleted() && (first->isDamaged() || second->isDamaged()) )
139 {
140 // 4J Stu - Don't allow combinining enchanted items, the enchantment will be lost. They can use the anvil for this
141 return !first->isEnchanted() && !second->isEnchanted();
142 }
143 return false;
144}
145
146shared_ptr<ItemInstance> Slot::combine(shared_ptr<ItemInstance> item)
147{
148 shared_ptr<ItemInstance> result = nullptr;
149 shared_ptr<ItemInstance> first = getItem();
150
151 shared_ptr<CraftingContainer> craftSlots = shared_ptr<CraftingContainer>( new CraftingContainer(NULL, 2, 2) );
152 craftSlots->setItem(0, item);
153 craftSlots->setItem(1, first);
154
155 ArmorItem *thisItem = dynamic_cast<ArmorItem *>(first->getItem());
156 if(thisItem)
157 {
158 result = ArmorDyeRecipe::assembleDyedArmor(craftSlots);
159 }
160 else
161 {
162 result = Recipes::getInstance()->getItemFor(craftSlots, NULL);
163 }
164
165 craftSlots->setItem(0, nullptr);
166 craftSlots->setItem(1, nullptr);
167 return result;
168}