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 "Container.h"
3#include "net.minecraft.world.item.h"
4#include "Slot.h"
5#include "GenericStats.h"
6#include "..\Minecraft.Client\StatsCounter.h"
7#include "..\Minecraft.Client\Minecraft.h"
8#include "..\Minecraft.Client\LocalPlayer.h"
9#include "ContainerMenu.h"
10
11ContainerMenu::ContainerMenu(shared_ptr<Container> inventory, shared_ptr<Container> container) : AbstractContainerMenu()
12{
13 this->container = container;
14 containerRows = container->getContainerSize() / 9;
15 container->startOpen();
16
17 int yo = (containerRows - 4) * 18;
18
19 for (int y = 0; y < containerRows; y++)
20 {
21 for (int x = 0; x < 9; x++)
22 {
23 addSlot(new Slot(container, x + y * 9, 8 + x * 18, 18 + y * 18));
24 }
25 }
26
27 for (int y = 0; y < 3; y++)
28 {
29 for (int x = 0; x < 9; x++)
30 {
31 addSlot(new Slot(inventory, x + y * 9 + 9, 8 + x * 18, 103 + y * 18 + yo));
32 }
33 }
34 for (int x = 0; x < 9; x++)
35 {
36 addSlot(new Slot(inventory, x, 8 + x * 18, 161 + yo));
37 }
38}
39
40bool ContainerMenu::stillValid(shared_ptr<Player> player)
41{
42 return container->stillValid(player);
43}
44
45shared_ptr<ItemInstance> ContainerMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex)
46{
47 shared_ptr<ItemInstance> clicked = nullptr;
48 Slot *slot = slots.at(slotIndex);
49 if (slot != NULL && slot->hasItem())
50 {
51 shared_ptr<ItemInstance> stack = slot->getItem();
52 clicked = stack->copy();
53
54 if (slotIndex < containerRows * 9)
55 {
56 if(!moveItemStackTo(stack, containerRows * 9, (int)slots.size(), true))
57 {
58 // 4J Stu - Brought forward from 1.2
59 return nullptr;
60 }
61 }
62 else
63 {
64 if(!moveItemStackTo(stack, 0, containerRows * 9, false))
65 {
66 // 4J Stu - Brought forward from 1.2
67 return nullptr;
68 }
69 }
70 if (stack->count == 0)
71 {
72 slot->set(nullptr);
73 }
74 else
75 {
76 slot->setChanged();
77 }
78 }
79 return clicked;
80}
81
82void ContainerMenu::removed(shared_ptr<Player> player)
83{
84 AbstractContainerMenu::removed(player);
85 container->stopOpen();
86}
87
88shared_ptr<Container> ContainerMenu::getContainer()
89{
90 return container;
91}
92
93shared_ptr<ItemInstance> ContainerMenu::clicked(int slotIndex, int buttonNum, int clickType, shared_ptr<Player> player, bool looped) // 4J Added looped param
94{
95 shared_ptr<ItemInstance> out = AbstractContainerMenu::clicked(slotIndex, buttonNum, clickType, player, looped);
96
97#ifdef _EXTENDED_ACHIEVEMENTS
98 shared_ptr<LocalPlayer> localPlayer = dynamic_pointer_cast<LocalPlayer>(player);
99
100 if (localPlayer != NULL) // 4J-JEV: For "Chestful o'Cobblestone" achievement.
101 {
102 int cobblecount = 0;
103 for (int i = 0; i < container->getContainerSize(); i++)
104 {
105 shared_ptr<ItemInstance> item = container->getItem(i);
106 if ( (item != nullptr) && (item->id == Tile::cobblestone_Id) )
107 {
108 cobblecount += item->GetCount();
109 }
110 }
111
112 // 4J-JEV: This check performed on XboxOne servers, for other platforms check here.
113#ifndef _DURANGO
114 StatsCounter *sc = Minecraft::GetInstance()->stats[localPlayer->GetXboxPad()];
115 int minedCount = sc->getTotalValue(GenericStats::blocksMined(Tile::stone_Id)) + sc->getTotalValue(GenericStats::blocksMined(Tile::cobblestone_Id));
116 if (cobblecount >= 1728 && minedCount >= 1728 )
117#endif
118 {
119 localPlayer->awardStat(GenericStats::chestfulOfCobblestone(),GenericStats::param_chestfulOfCobblestone(cobblecount));
120 }
121 }
122#endif
123
124 return out;
125}