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 "AbstractContainerScreen.h"
3#include "ItemRenderer.h"
4#include "MultiplayerLocalPlayer.h"
5#include "Lighting.h"
6#include "GameMode.h"
7#include "KeyMapping.h"
8#include "Options.h"
9#include "..\Minecraft.World\net.minecraft.world.inventory.h"
10#include "..\Minecraft.World\net.minecraft.locale.h"
11#include "..\Minecraft.World\net.minecraft.world.item.h"
12
13ItemRenderer *AbstractContainerScreen::itemRenderer = new ItemRenderer();
14
15AbstractContainerScreen::AbstractContainerScreen(AbstractContainerMenu *menu)
16{
17 // 4J - added initialisers
18 imageWidth = 176;
19 imageHeight = 166;
20
21 this->menu = menu;
22}
23
24void AbstractContainerScreen::init()
25{
26 Screen::init();
27 minecraft->player->containerMenu = menu;
28// leftPos = (width - imageWidth) / 2;
29// topPos = (height - imageHeight) / 2;
30
31}
32
33void AbstractContainerScreen::render(int xm, int ym, float a)
34{
35 // 4J Stu - Not used
36#if 0
37 renderBackground();
38 int xo = (width - imageWidth) / 2;
39 int yo = (height - imageHeight) / 2;
40
41 renderBg(a);
42
43 glPushMatrix();
44 glRotatef(120, 1, 0, 0);
45 Lighting::turnOn();
46 glPopMatrix();
47
48 glPushMatrix();
49 glTranslatef((float)xo, (float)yo, 0);
50
51 glColor4f(1, 1, 1, 1);
52 glEnable(GL_RESCALE_NORMAL);
53
54 Slot *hoveredSlot = NULL;
55
56 AUTO_VAR(itEnd, menu->slots->end());
57 for (AUTO_VAR(it, menu->slots->begin()); it != itEnd; it++)
58 {
59 Slot *slot = *it; //menu->slots->at(i);
60
61 renderSlot(slot);
62
63 if (isHovering(slot, xm, ym))
64 {
65 hoveredSlot = slot;
66
67 glDisable(GL_LIGHTING);
68 glDisable(GL_DEPTH_TEST);
69
70 int x = slot->x;
71 int y = slot->y;
72 fillGradient(x, y, x + 16, y + 16, 0x80ffffff, 0x80ffffff);
73 glEnable(GL_LIGHTING);
74 glEnable(GL_DEPTH_TEST);
75 }
76 }
77
78 shared_ptr<Inventory> inventory = minecraft->player->inventory;
79 if (inventory->getCarried() != NULL)
80 {
81 glTranslatef(0, 0, 32);
82 // Slot old = carriedSlot;
83 // carriedSlot = null;
84 itemRenderer->renderGuiItem(font, minecraft->textures, inventory->getCarried(), xm - xo - 8, ym - yo - 8);
85 itemRenderer->renderGuiItemDecorations(font, minecraft->textures, inventory->getCarried(), xm - xo - 8, ym - yo - 8);
86 // carriedSlot = old;
87 }
88 glDisable(GL_RESCALE_NORMAL);
89 Lighting::turnOff();
90
91 glDisable(GL_LIGHTING);
92 glDisable(GL_DEPTH_TEST);
93
94 renderLabels();
95
96 if (inventory->getCarried() == NULL && hoveredSlot != NULL && hoveredSlot->hasItem())
97 {
98
99 wstring elementName = trimString(Language::getInstance()->getElementName(hoveredSlot->getItem()->getDescriptionId()));
100
101 if (elementName.length() > 0)
102 {
103 int x = xm - xo + 12;
104 int y = ym - yo - 12;
105 int width = font->width(elementName);
106 fillGradient(x - 3, y - 3, x + width + 3, y + 8 + 3, 0xc0000000, 0xc0000000);
107
108 font->drawShadow(elementName, x, y, 0xffffffff);
109 }
110
111 }
112
113 glPopMatrix();
114
115 Screen::render(xm, ym, a);
116 glEnable(GL_LIGHTING);
117 glEnable(GL_DEPTH_TEST);
118#endif
119}
120
121void AbstractContainerScreen::renderLabels()
122{
123}
124
125void AbstractContainerScreen::renderSlot(Slot *slot)
126{
127 // 4J Unused
128#if 0
129 int x = slot->x;
130 int y = slot->y;
131 shared_ptr<ItemInstance> item = slot->getItem();
132
133 if (item == NULL)
134 {
135 int icon = slot->getNoItemIcon();
136 if (icon >= 0)
137 {
138 glDisable(GL_LIGHTING);
139 minecraft->textures->bind(minecraft->textures->loadTexture(TN_GUI_ITEMS));//L"/gui/items.png"));
140 blit(x, y, icon % 16 * 16, icon / 16 * 16, 16, 16);
141 glEnable(GL_LIGHTING);
142 return;
143 }
144 }
145
146 itemRenderer->renderGuiItem(font, minecraft->textures, item, x, y);
147 itemRenderer->renderGuiItemDecorations(font, minecraft->textures, item, x, y);
148#endif
149}
150
151Slot *AbstractContainerScreen::findSlot(int x, int y)
152{
153 AUTO_VAR(itEnd, menu->slots->end());
154 for (AUTO_VAR(it, menu->slots->begin()); it != itEnd; it++)
155 {
156 Slot *slot = *it; //menu->slots->at(i);
157 if (isHovering(slot, x, y)) return slot;
158 }
159 return NULL;
160}
161
162bool AbstractContainerScreen::isHovering(Slot *slot, int xm, int ym)
163{
164 int xo = (width - imageWidth) / 2;
165 int yo = (height - imageHeight) / 2;
166 xm -= xo;
167 ym -= yo;
168
169 return xm >= slot->x - 1 && xm < slot->x + 16 + 1 && ym >= slot->y - 1 && ym < slot->y + 16 + 1;
170
171}
172
173void AbstractContainerScreen::mouseClicked(int x, int y, int buttonNum)
174{
175 Screen::mouseClicked(x, y, buttonNum);
176 if (buttonNum == 0 || buttonNum == 1)
177 {
178 Slot *slot = findSlot(x, y);
179
180 int xo = (width - imageWidth) / 2;
181 int yo = (height - imageHeight) / 2;
182 bool clickedOutside = (x < xo || y < yo || x >= xo + imageWidth || y >= yo + imageHeight);
183
184 int slotId = -1;
185 if (slot != NULL) slotId = slot->index;
186
187 if (clickedOutside)
188 {
189 slotId = AbstractContainerMenu::CLICKED_OUTSIDE;
190 }
191
192 if (slotId != -1)
193 {
194 bool quickKey = slotId != AbstractContainerMenu::CLICKED_OUTSIDE && (Keyboard::isKeyDown(Keyboard::KEY_LSHIFT) || Keyboard::isKeyDown(Keyboard::KEY_RSHIFT));
195 minecraft->gameMode->handleInventoryMouseClick(menu->containerId, slotId, buttonNum, quickKey, minecraft->player);
196 }
197 }
198
199}
200
201void AbstractContainerScreen::mouseReleased(int x, int y, int buttonNum)
202{
203 if (buttonNum == 0)
204 {
205 }
206}
207
208void AbstractContainerScreen::keyPressed(wchar_t eventCharacter, int eventKey)
209{
210 if (eventKey == Keyboard::KEY_ESCAPE || eventKey == minecraft->options->keyBuild->key)
211 {
212 minecraft->player->closeContainer();
213 }
214}
215
216void AbstractContainerScreen::removed()
217{
218 if (minecraft->player == NULL) return;
219}
220
221void AbstractContainerScreen::slotsChanged(shared_ptr<Container> container)
222{
223}
224
225bool AbstractContainerScreen::isPauseScreen()
226{
227 return false;
228}
229
230void AbstractContainerScreen::tick()
231{
232 Screen::tick();
233 if (!minecraft->player->isAlive() || minecraft->player->removed) minecraft->player->closeContainer();
234
235}