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 "ItemInHandRenderer.h"
3#include "TileRenderer.h"
4#include "Tesselator.h"
5#include "Textures.h"
6#include "TextureAtlas.h"
7#include "EntityRenderer.h"
8#include "PlayerRenderer.h"
9#include "EntityRenderDispatcher.h"
10#include "Lighting.h"
11#include "MultiplayerLocalPlayer.h"
12#include "Minimap.h"
13#include "MultiPlayerLevel.h"
14#include "..\Minecraft.World\net.minecraft.world.item.h"
15#include "..\Minecraft.World\net.minecraft.world.level.tile.h"
16#include "..\Minecraft.World\net.minecraft.world.entity.h"
17#include "..\Minecraft.World\net.minecraft.world.entity.player.h"
18#include "..\Minecraft.World\net.minecraft.world.level.h"
19#include "..\Minecraft.World\net.minecraft.world.h"
20
21ResourceLocation ItemInHandRenderer::ENCHANT_GLINT_LOCATION = ResourceLocation(TN__BLUR__MISC_GLINT);
22ResourceLocation ItemInHandRenderer::MAP_BACKGROUND_LOCATION = ResourceLocation(TN_MISC_MAPBG);
23ResourceLocation ItemInHandRenderer::UNDERWATER_LOCATION = ResourceLocation(TN_MISC_WATER);
24
25int ItemInHandRenderer::listItem = -1;
26int ItemInHandRenderer::listTerrain = -1;
27int ItemInHandRenderer::listGlint = -1;
28
29ItemInHandRenderer::ItemInHandRenderer(Minecraft *minecraft, bool optimisedMinimap)
30{
31 // 4J - added
32 height = 0;
33 oHeight = 0;
34 selectedItem = nullptr;
35 tileRenderer = new TileRenderer();
36 lastSlot = -1;
37
38 this->minecraft = minecraft;
39 minimap = new Minimap(minecraft->font, minecraft->options, minecraft->textures, optimisedMinimap);
40
41 // 4J - replaced mesh that is used to render held items with individual cubes, so we can make it all join up properly without seams. This
42 // has a lot more quads in it than the original, so is now precompiled with a UV matrix offset to put it in the final place for the
43 // current icon. Compile it on demand for the first ItemInHandRenderer (list is static)
44 if( listItem == -1 )
45 {
46 listItem = MemoryTracker::genLists(1);
47 float dd = 1 / 16.0f;
48
49 glNewList(listItem, GL_COMPILE);
50 Tesselator *t = Tesselator::getInstance();
51 t->begin();
52 for( int yp = 0; yp < 16; yp++ )
53 for( int xp = 0; xp < 16; xp++ )
54 {
55 float u = (15-xp) / 256.0f;
56 float v = (15-yp) / 256.0f;
57 u += 0.5f / 256.0f;
58 v += 0.5f / 256.0f;
59 float x0 = xp / 16.0f;
60 float x1 = x0 + 1.0f/16.0f;
61 float y0 = yp / 16.0f;
62 float y1 = y0 + 1.0f/16.0f;
63 float z0 = 0.0f;
64 float z1 = -dd;
65
66 t->normal(0, 0, 1);
67 t->vertexUV(x0, y0, z0, u, v);
68 t->vertexUV(x1, y0, z0, u, v);
69 t->vertexUV(x1, y1, z0, u, v);
70 t->vertexUV(x0, y1, z0, u, v);
71 t->normal(0, 0, -1);
72 t->vertexUV(x0, y1, z1, u, v);
73 t->vertexUV(x1, y1, z1, u, v);
74 t->vertexUV(x1, y0, z1, u, v);
75 t->vertexUV(x0, y0, z1, u, v);
76 t->normal(-1, 0, 0);
77 t->vertexUV(x0, y0, z1, u, v);
78 t->vertexUV(x0, y0, z0, u, v);
79 t->vertexUV(x0, y1, z0, u, v);
80 t->vertexUV(x0, y1, z1, u, v);
81 t->normal(1, 0, 0);
82 t->vertexUV(x1, y1, z1, u, v);
83 t->vertexUV(x1, y1, z0, u, v);
84 t->vertexUV(x1, y0, z0, u, v);
85 t->vertexUV(x1, y0, z1, u, v);
86 t->normal(0, 1, 0);
87 t->vertexUV(x1, y0, z0, u, v);
88 t->vertexUV(x0, y0, z0, u, v);
89 t->vertexUV(x0, y0, z1, u, v);
90 t->vertexUV(x1, y0, z1, u, v);
91 t->normal(0, -1, 0);
92 t->vertexUV(x1, y1, z1, u, v);
93 t->vertexUV(x0, y1, z1, u, v);
94 t->vertexUV(x0, y1, z0, u, v);
95 t->vertexUV(x1, y1, z0, u, v);
96 }
97 t->end();
98 glEndList();
99 }
100
101 // Terrain texture is a different layout from the item texture
102 if( listTerrain == -1 )
103 {
104 listTerrain = MemoryTracker::genLists(1);
105 float dd = 1 / 16.0f;
106
107 glNewList(listTerrain, GL_COMPILE);
108 Tesselator *t = Tesselator::getInstance();
109 t->begin();
110 for( int yp = 0; yp < 16; yp++ )
111 for( int xp = 0; xp < 16; xp++ )
112 {
113 float u = (15-xp) / 256.0f;
114 float v = (15-yp) / 512.0f;
115 u += 0.5f / 256.0f;
116 v += 0.5f / 512.0f;
117 float x0 = xp / 16.0f;
118 float x1 = x0 + 1.0f/16.0f;
119 float y0 = yp / 16.0f;
120 float y1 = y0 + 1.0f/16.0f;
121 float z0 = 0.0f;
122 float z1 = -dd;
123
124 t->normal(0, 0, 1);
125 t->vertexUV(x0, y0, z0, u, v);
126 t->vertexUV(x1, y0, z0, u, v);
127 t->vertexUV(x1, y1, z0, u, v);
128 t->vertexUV(x0, y1, z0, u, v);
129 t->normal(0, 0, -1);
130 t->vertexUV(x0, y1, z1, u, v);
131 t->vertexUV(x1, y1, z1, u, v);
132 t->vertexUV(x1, y0, z1, u, v);
133 t->vertexUV(x0, y0, z1, u, v);
134 t->normal(-1, 0, 0);
135 t->vertexUV(x0, y0, z1, u, v);
136 t->vertexUV(x0, y0, z0, u, v);
137 t->vertexUV(x0, y1, z0, u, v);
138 t->vertexUV(x0, y1, z1, u, v);
139 t->normal(1, 0, 0);
140 t->vertexUV(x1, y1, z1, u, v);
141 t->vertexUV(x1, y1, z0, u, v);
142 t->vertexUV(x1, y0, z0, u, v);
143 t->vertexUV(x1, y0, z1, u, v);
144 t->normal(0, 1, 0);
145 t->vertexUV(x1, y0, z0, u, v);
146 t->vertexUV(x0, y0, z0, u, v);
147 t->vertexUV(x0, y0, z1, u, v);
148 t->vertexUV(x1, y0, z1, u, v);
149 t->normal(0, -1, 0);
150 t->vertexUV(x1, y1, z1, u, v);
151 t->vertexUV(x0, y1, z1, u, v);
152 t->vertexUV(x0, y1, z0, u, v);
153 t->vertexUV(x1, y1, z0, u, v);
154 }
155 t->end();
156 glEndList();
157 }
158
159 // Also create special object for glint overlays - this is the same as the previous one, with a different UV scalings, and depth test set to equal
160 if( listGlint == -1 )
161 {
162 listGlint = MemoryTracker::genLists(1);
163 float dd = 1 / 16.0f;
164
165 glNewList(listGlint, GL_COMPILE);
166 glDepthFunc(GL_EQUAL);
167 Tesselator *t = Tesselator::getInstance();
168 t->begin();
169 for( int yp = 0; yp < 16; yp++ )
170 for( int xp = 0; xp < 16; xp++ )
171 {
172 float u0 = (15-xp) / 16.0f;
173 float v0 = (15-yp) / 16.0f;
174 float u1 = u0 - (1.0f/16.0f);
175 float v1 = v0 - (1.0f/16.0f);;
176
177 float x0 = xp / 16.0f;
178 float x1 = x0 + 1.0f/16.0f;
179 float y0 = yp / 16.0f;
180 float y1 = y0 + 1.0f/16.0f;
181 float z0 = 0.0f;
182 float z1 = -dd;
183
184 float br = 0.76f;
185 t->color(0.5f * br, 0.25f * br, 0.8f * br, 1.0f); // MGH - added the color here, as the glColour below wasn't making it through to render
186
187 t->normal(0, 0, 1);
188 t->vertexUV(x0, y0, z0, u0, v0);
189 t->vertexUV(x1, y0, z0, u1, v0);
190 t->vertexUV(x1, y1, z0, u1, v1);
191 t->vertexUV(x0, y1, z0, u0, v1);
192 t->normal(0, 0, -1);
193 t->vertexUV(x0, y1, z1, u0, v1);
194 t->vertexUV(x1, y1, z1, u1, v1);
195 t->vertexUV(x1, y0, z1, u1, v0);
196 t->vertexUV(x0, y0, z1, u0, v0);
197 t->normal(-1, 0, 0);
198 t->vertexUV(x0, y0, z1, u0, v0);
199 t->vertexUV(x0, y0, z0, u0, v0);
200 t->vertexUV(x0, y1, z0, u0, v1);
201 t->vertexUV(x0, y1, z1, u0, v1);
202 t->normal(1, 0, 0);
203 t->vertexUV(x1, y1, z1, u1, v1);
204 t->vertexUV(x1, y1, z0, u1, v1);
205 t->vertexUV(x1, y0, z0, u1, v0);
206 t->vertexUV(x1, y0, z1, u1, v0);
207 t->normal(0, 1, 0);
208 t->vertexUV(x1, y0, z0, u1, v0);
209 t->vertexUV(x0, y0, z0, u0, v0);
210 t->vertexUV(x0, y0, z1, u0, v0);
211 t->vertexUV(x1, y0, z1, u1, v0);
212 t->normal(0, -1, 0);
213 t->vertexUV(x1, y1, z1, u1, v1);
214 t->vertexUV(x0, y1, z1, u0, v1);
215 t->vertexUV(x0, y1, z0, u0, v1);
216 t->vertexUV(x1, y1, z0, u1, v1);
217 }
218 t->end();
219 glDepthFunc(GL_LEQUAL);
220 glEndList();
221 }
222
223}
224
225void ItemInHandRenderer::renderItem(shared_ptr<LivingEntity> mob, shared_ptr<ItemInstance> item, int layer, bool setColor/* = true*/)
226{
227 // 4J - code borrowed from render method below, although not factoring in brightness as that should already be being taken into account
228 // by texture lighting. This is for colourising things held in 3rd person view.
229 if ( (setColor) && (item != NULL) )
230 {
231 int col = Item::items[item->id]->getColor(item,0);
232 float red = ((col >> 16) & 0xff) / 255.0f;
233 float g = ((col >> 8) & 0xff) / 255.0f;
234 float b = ((col) & 0xff) / 255.0f;
235
236 glColor4f(red, g, b, 1);
237 }
238
239 glPushMatrix();
240 Tile *tile = Tile::tiles[item->id];
241 if (item->getIconType() == Icon::TYPE_TERRAIN && tile != NULL && TileRenderer::canRender(tile->getRenderShape()))
242 {
243 MemSect(31);
244 minecraft->textures->bindTexture(minecraft->textures->getTextureLocation(Icon::TYPE_TERRAIN));
245 MemSect(0);
246 tileRenderer->renderTile(Tile::tiles[item->id], item->getAuxValue(), SharedConstants::TEXTURE_LIGHTING ? 1.0f : mob->getBrightness(1)); // 4J - change brought forward from 1.8.2
247 }
248 else
249 {
250 MemSect(31);
251 Icon *icon = mob->getItemInHandIcon(item, layer);
252 if (icon == NULL)
253 {
254 glPopMatrix();
255 MemSect(0);
256 return;
257 }
258
259 bool bIsTerrain = item->getIconType() == Icon::TYPE_TERRAIN;
260 minecraft->textures->bindTexture(minecraft->textures->getTextureLocation(item->getIconType()));
261
262 MemSect(0);
263 Tesselator *t = Tesselator::getInstance();
264
265 // Consider forcing the mipmap LOD level to use, if this is to be rendered from a larger than standard source texture.
266 int iconWidth = icon->getWidth();
267 int LOD = -1; // Default to not doing anything special with LOD forcing
268 if( iconWidth == 32 )
269 {
270 LOD = 1; // Force LOD level 1 to achieve texture reads from 256x256 map
271 }
272 else if( iconWidth == 64 )
273 {
274 LOD = 2; // Force LOD level 2 to achieve texture reads from 256x256 map
275 }
276 RenderManager.StateSetForceLOD(LOD);
277
278 // 4J Original comment
279 // Yes, these are backwards.
280 // No, I don't know why.
281 // 4J Stu - Make them the right way round...u coords were swapped
282 float u0 = icon->getU0();
283 float u1 = icon->getU1();
284 float v0 = icon->getV0();
285 float v1 = icon->getV1();
286
287 float xo = 0.0f;
288 float yo = 0.3f;
289
290 glEnable(GL_RESCALE_NORMAL);
291 glTranslatef(-xo, -yo, 0);
292 float s = 1.5f;
293 glScalef(s, s, s);
294
295 glRotatef(50, 0, 1, 0);
296 glRotatef(45 + 290, 0, 0, 1);
297 glTranslatef(-15 / 16.0f, -1 / 16.0f, 0);
298 float dd = 1 / 16.0f;
299
300 renderItem3D(t, u0, v0, u1, v1, icon->getSourceWidth(), icon->getSourceHeight(), 1 / 16.0f, false, bIsTerrain);
301
302 if (item != NULL && item->isFoil() && layer == 0)
303 {
304 glDepthFunc(GL_EQUAL);
305 glDisable(GL_LIGHTING);
306 minecraft->textures->bindTexture(&ENCHANT_GLINT_LOCATION);
307 glEnable(GL_BLEND);
308 glBlendFunc(GL_SRC_COLOR, GL_ONE);
309 float br = 0.76f;
310 glColor4f(0.5f * br, 0.25f * br, 0.8f * br, 1); // MGH - for some reason this colour isn't making it through to the render, so I've added to the tesselator for the glint geom above
311 glMatrixMode(GL_TEXTURE);
312 glPushMatrix();
313 float ss = 1 / 8.0f;
314 glScalef(ss, ss, ss);
315 float sx = Minecraft::currentTimeMillis() % (3000) / (3000.0f) * 8;
316 glTranslatef(sx, 0, 0);
317 glRotatef(-50, 0, 0, 1);
318
319 renderItem3D(t, 0, 0, 1, 1, 256, 256, 1 / 16.0f, true, bIsTerrain);
320 glPopMatrix();
321 glPushMatrix();
322 glScalef(ss, ss, ss);
323 sx = System::currentTimeMillis() % (3000 + 1873) / (3000 + 1873.0f) * 8;
324 glTranslatef(-sx, 0, 0);
325 glRotatef(10, 0, 0, 1);
326 renderItem3D(t, 0, 0, 1, 1, 256, 256, 1 / 16.0f, true, bIsTerrain);
327 glPopMatrix();
328 glMatrixMode(GL_MODELVIEW);
329 glDisable(GL_BLEND);
330 glEnable(GL_LIGHTING);
331 glDepthFunc(GL_LEQUAL);
332 }
333
334 RenderManager.StateSetForceLOD(-1);
335
336 glDisable(GL_RESCALE_NORMAL);
337 }
338 glPopMatrix();
339}
340
341// 4J added useList parameter
342void ItemInHandRenderer::renderItem3D(Tesselator *t, float u0, float v0, float u1, float v1, int width, int height, float depth, bool isGlint, bool isTerrain)
343{
344 float r = 1.0f;
345
346 // 4J - replaced mesh that is used to render held items with individual cubes, so we can make it all join up properly without seams. This
347 // has a lot more quads in it than the original, so is now precompiled with a UV matrix offset to put it in the final place for the
348 // current icon
349
350 if( isGlint )
351 {
352 glCallList(listGlint);
353 }
354 else
355 {
356 // 4J - replaced mesh that is used to render held items with individual cubes, so we can make it all join up properly without seams. This
357 // has a lot more quads in it than the original, so is now precompiled with a UV matrix offset to put it in the final place for the
358 // current icon
359
360 glMatrixMode(GL_TEXTURE);
361 glLoadIdentity();
362 glTranslatef(u0, v0, 0);
363 glCallList(isTerrain? listTerrain : listItem);
364 glLoadIdentity();
365 glMatrixMode(GL_MODELVIEW);
366 }
367 // 4J added since we are setting the colour to other values at the start of the function now
368 glColor4f(1.0f,1.0f,1.0f,1.0f);
369}
370
371void ItemInHandRenderer::render(float a)
372{
373 float h = oHeight + (height - oHeight) * a;
374 shared_ptr<Player> player = minecraft->player;
375
376 // 4J - added so we can adjust the position of the hands for horizontal & vertical split screens
377 float fudgeX = 0.0f;
378 float fudgeY = 0.0f;
379 float fudgeZ = 0.0f;
380 bool splitHoriz = false;
381 shared_ptr<LocalPlayer> localPlayer = dynamic_pointer_cast<LocalPlayer>(player);
382 if( localPlayer )
383 {
384 if( localPlayer->m_iScreenSection == C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM ||
385 localPlayer->m_iScreenSection == C4JRender::VIEWPORT_TYPE_SPLIT_TOP )
386 {
387 fudgeY = 0.08f;
388 splitHoriz = true;
389 }
390 else if( localPlayer->m_iScreenSection == C4JRender::VIEWPORT_TYPE_SPLIT_LEFT ||
391 localPlayer->m_iScreenSection == C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT )
392 {
393 fudgeX = -0.18f;
394 }
395 }
396
397 float xr = player->xRotO + (player->xRot - player->xRotO) * a;
398
399 glPushMatrix();
400 glRotatef(xr, 1, 0, 0);
401 glRotatef(player->yRotO + (player->yRot - player->yRotO) * a, 0, 1, 0);
402 Lighting::turnOn();
403 glPopMatrix();
404
405 if (localPlayer)
406 {
407 float xrr = localPlayer->xBobO + (localPlayer->xBob - localPlayer->xBobO) * a;
408 float yrr = localPlayer->yBobO + (localPlayer->yBob - localPlayer->yBobO) * a;
409 // 4J - was using player->xRot and yRot directly here rather than interpolating between old & current with a
410 float yr = player->yRotO + (player->yRot - player->yRotO) * a;
411 glRotatef((xr - xrr) * 0.1f, 1, 0, 0);
412 glRotatef((yr - yrr) * 0.1f, 0, 1, 0);
413 }
414
415 shared_ptr<ItemInstance> item = selectedItem;
416
417 float br = minecraft->level->getBrightness(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z));
418 // 4J - change brought forward from 1.8.2
419 if (SharedConstants::TEXTURE_LIGHTING)
420 {
421 br = 1;
422 int col = minecraft->level->getLightColor(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z), 0);
423 int u = col % 65536;
424 int v = col / 65536;
425 glMultiTexCoord2f(GL_TEXTURE1, u / 1.0f, v / 1.0f);
426 glColor4f(1, 1, 1, 1);
427 }
428 if (item != NULL)
429 {
430 int col = Item::items[item->id]->getColor(item,0);
431 float red = ((col >> 16) & 0xff) / 255.0f;
432 float g = ((col >> 8) & 0xff) / 255.0f;
433 float b = ((col) & 0xff) / 255.0f;
434
435 glColor4f(br * red, br * g, br * b, 1);
436 }
437 else
438 {
439 glColor4f(br, br, br, 1);
440 }
441
442 if (item != NULL && item->id == Item::map->id)
443 {
444 glPushMatrix();
445 float d = 0.8f;
446
447 // 4J - move the map away a bit if we're in horizontal split screen, so it doesn't clip out of the save zone
448 if( splitHoriz )
449 {
450 glTranslatef(0.0f, 0.0f, -0.3f );
451 }
452
453 {
454 float swing = player->getAttackAnim(a);
455
456 float swing1 = Mth::sin(swing * PI);
457 float swing2 = Mth::sin((sqrt(swing)) * PI);
458 glTranslatef(-swing2 * 0.4f, Mth::sin(sqrt(swing) * PI * 2) * 0.2f, -swing1 * 0.2f);
459 }
460
461 float tilt = 1 - xr / 45.0f + 0.1f;
462 if (tilt < 0) tilt = 0;
463 if (tilt > 1) tilt = 1;
464 tilt = -Mth::cos(tilt * PI) * 0.5f + 0.5f;
465
466 glTranslatef(0.0f, 0.0f * d - (1 - h) * 1.2f - tilt * 0.5f + 0.04f, -0.9f * d);
467
468 glRotatef(90, 0, 1, 0);
469 glRotatef((tilt) * -85, 0, 0, 1);
470 glEnable(GL_RESCALE_NORMAL);
471
472
473 {
474 // 4J-PB - if we've got a player texture, use that
475 //glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadHttpTexture(minecraft->player->customTextureUrl, minecraft->player->getTexture()));
476 glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadMemTexture(minecraft->player->customTextureUrl, minecraft->player->getTexture()));
477 minecraft->textures->clearLastBoundId();
478 for (int i = 0; i < 2; i++)
479 {
480 int flip = i * 2 - 1;
481 glPushMatrix();
482
483 glTranslatef(-0.0f, -0.6f, 1.1f * flip);
484 glRotatef((float)(-45 * flip), 1, 0, 0);
485 glRotatef(-90, 0, 0, 1);
486 glRotatef(59, 0, 0, 1);
487 glRotatef((float)(-65 * flip), 0, 1, 0);
488
489 EntityRenderer *er = EntityRenderDispatcher::instance->getRenderer(minecraft->player);
490 PlayerRenderer *playerRenderer = (PlayerRenderer *) er;
491 float ss = 1;
492 glScalef(ss, ss, ss);
493
494 // Can't turn off the hand if the player is holding a map
495 shared_ptr<ItemInstance> itemInstance = player->inventory->getSelected();
496 if ((itemInstance && (itemInstance->getItem()->id==Item::map_Id)) || app.GetGameSettings(localPlayer->GetXboxPad(),eGameSetting_DisplayHand)!=0 )
497 {
498 playerRenderer->renderHand();
499 }
500 glPopMatrix();
501 }
502 }
503
504 {
505 float swing = player->getAttackAnim(a);
506 float swing3 = Mth::sin(swing * swing * PI);
507 float swing2 = Mth::sin(sqrt(swing) * PI);
508 glRotatef(-swing3 * 20, 0, 1, 0);
509 glRotatef(-swing2 * 20, 0, 0, 1);
510 glRotatef(-swing2 * 80, 1, 0, 0);
511 }
512
513 float ss = 0.38f;
514 glScalef(ss, ss, ss);
515
516 glRotatef(90, 0, 1, 0);
517 glRotatef(180, 0, 0, 1);
518
519 glTranslatef(-1, -1, +0);
520
521 float s = 2 / 128.0f;
522 glScalef(s, s, s);
523
524 MemSect(31);
525 minecraft->textures->bindTexture(&MAP_BACKGROUND_LOCATION); // 4J was L"/misc/mapbg.png"
526 MemSect(0);
527 Tesselator *t = Tesselator::getInstance();
528
529// glNormal3f(0, 0, -1); // 4J - changed to use tesselator
530 t->begin();
531 int vo = 7;
532 t->normal(0,0,-1);
533 t->vertexUV((float)(0 - vo), (float)( 128 + vo), (float)( 0), (float)( 0), (float)( 1));
534 t->vertexUV((float)(128 + vo), (float)( 128 + vo), (float)( 0), (float)( 1), (float)( 1));
535 t->vertexUV((float)(128 + vo), (float)( 0 - vo), (float)( 0), (float)( 1), (float)( 0));
536 t->vertexUV((float)(0 - vo), (float)( 0 - vo), (float)( 0), (float)( 0), (float)( 0));
537 t->end();
538
539 shared_ptr<MapItemSavedData> data = Item::map->getSavedData(item, minecraft->level);
540 PIXBeginNamedEvent(0,"Minimap render");
541 if(data != NULL) minimap->render(minecraft->player, minecraft->textures, data, minecraft->player->entityId);
542 PIXEndNamedEvent();
543
544 glPopMatrix();
545 }
546 else if (item != NULL)
547 {
548 glPushMatrix();
549 float d = 0.8f;
550
551#if defined __ORBIS__ || defined __PS3__
552 static const float swingPowFactor = 1.0f;
553#else
554 static const float swingPowFactor = 4.0f; // 4J added, to slow the swing down when nearest the player for avoiding luminance flash issues
555#endif
556 if (player->getUseItemDuration() > 0)
557 {
558 UseAnim anim = item->getUseAnimation();
559 if ( (anim == UseAnim_eat) || (anim == UseAnim_drink) )
560 {
561 float t = (player->getUseItemDuration() - a + 1);
562 float swing = 1 - (t / item->getUseDuration());
563
564 float is = 1 - swing;
565 is = is * is * is;
566 is = is * is * is;
567 is = is * is * is;
568 float iss = 1 - is;
569 glTranslatef(0, Mth::abs(Mth::cos(t / 4 * PI) * 0.1f) * (swing > 0.2 ? 1 : 0), 0);
570 glTranslatef(iss * 0.6f, -iss * 0.5f, 0);
571 glRotatef(iss * 90, 0, 1, 0);
572 glRotatef(iss * 10, 1, 0, 0);
573 glRotatef(iss * 30, 0, 0, 1);
574 }
575 }
576 else
577 {
578 float swing = powf(player->getAttackAnim(a),swingPowFactor);
579
580 float swing1 = Mth::sin(swing * PI);
581 float swing2 = Mth::sin((sqrt(swing)) * PI);
582 glTranslatef(-swing2 * 0.4f, Mth::sin(sqrt(swing) * PI * 2) * 0.2f, -swing1 * 0.2f);
583
584 }
585
586 glTranslatef(0.7f * d, -0.65f * d - (1 - h) * 0.6f, -0.9f * d);
587 glTranslatef(fudgeX, fudgeY, fudgeZ); // 4J added
588
589 glRotatef(45, 0, 1, 0);
590 glEnable(GL_RESCALE_NORMAL);
591
592 float swing = powf(player->getAttackAnim(a),swingPowFactor);
593 float swing3 = Mth::sin(swing * swing * PI);
594 float swing2 = Mth::sin(sqrt(swing) * PI);
595 glRotatef(-swing3 * 20, 0, 1, 0);
596 glRotatef(-swing2 * 20, 0, 0, 1);
597 glRotatef(-swing2 * 80, 1, 0, 0);
598
599 float ss = 0.4f;
600 glScalef(ss, ss, ss);
601
602 if (player->getUseItemDuration() > 0)
603 {
604 UseAnim anim = item->getUseAnimation();
605 if (anim == UseAnim_block)
606 {
607 glTranslatef(-0.5f, 0.2f, 0.0f);
608 glRotatef(30, 0, 1, 0);
609 glRotatef(-80, 1, 0, 0);
610 glRotatef(60, 0, 1, 0);
611 }
612 else if (anim == UseAnim_bow)
613 {
614
615 glRotatef(-18, 0, 0, 1);
616 glRotatef(-12, 0, 1, 0);
617 glRotatef(-8, 1, 0, 0);
618 glTranslatef(-0.9f, 0.2f, 0.0f);
619 float timeHeld = (item->getUseDuration() - (player->getUseItemDuration() - a + 1));
620 float pow = timeHeld / (float) (BowItem::MAX_DRAW_DURATION);
621 pow = ((pow * pow) + pow * 2) / 3;
622 if (pow > 1) pow = 1;
623 if (pow > 0.1f)
624 {
625 glTranslatef(0, Mth::sin((timeHeld - 0.1f) * 1.3f) * 0.01f * (pow - 0.1f), 0);
626 }
627 glTranslatef(0, 0, pow * 0.1f);
628
629 glRotatef(-45 - 290, 0, 0, 1);
630 glRotatef(-50, 0, 1, 0);
631 glTranslatef(0, 0.5f, 0);
632 float ys = 1 + pow * 0.2f;
633 glScalef(1, 1, ys);
634 glTranslatef(0, -0.5f, 0);
635 glRotatef(50, 0, 1, 0);
636 glRotatef(45 + 290, 0, 0, 1);
637 }
638 }
639
640
641 if (item->getItem()->isMirroredArt())
642 {
643 glRotatef(180, 0, 1, 0);
644 }
645
646 if (item->getItem()->hasMultipleSpriteLayers())
647 {
648 // special case for potions, refactor this when we get more
649 // items that have two layers
650 renderItem(player, item, 0, false);
651
652 int col = Item::items[item->id]->getColor(item, 1);
653 float red = ((col >> 16) & 0xff) / 255.0f;
654 float g = ((col >> 8) & 0xff) / 255.0f;
655 float b = ((col) & 0xff) / 255.0f;
656
657 glColor4f(br * red, br * g, br * b, 1);
658
659 renderItem(player, item, 1, false);
660 }
661 else
662 {
663 renderItem(player, item, 0, false);
664 }
665 glPopMatrix();
666 }
667 else if (!player->isInvisible())
668 {
669 glPushMatrix();
670 float d = 0.8f;
671
672 {
673 float swing = player->getAttackAnim(a);
674
675 float swing1 = Mth::sin(swing * PI);
676 float swing2 = Mth::sin((sqrt(swing)) * PI);
677 glTranslatef(-swing2 * 0.3f, Mth::sin(sqrt(swing) * PI * 2) * 0.4f, -swing1 * 0.4f);
678 }
679
680 glTranslatef(0.8f * d, -0.75f * d - (1 - h) * 0.6f, -0.9f * d);
681 glTranslatef(fudgeX, fudgeY, fudgeZ); // 4J added
682
683 glRotatef(45, 0, 1, 0);
684 glEnable(GL_RESCALE_NORMAL);
685 {
686 float swing = player->getAttackAnim(a);
687 float swing3 = Mth::sin(swing * swing * PI);
688 float swing2 = Mth::sin(sqrt(swing) * PI);
689 glRotatef(swing2 * 70, 0, 1, 0);
690 glRotatef(-swing3 * 20, 0, 0, 1);
691 }
692
693 // 4J-PB - if we've got a player texture, use that
694
695 //glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadHttpTexture(minecraft->player->customTextureUrl, minecraft->player->getTexture()));
696
697 MemSect(31);
698 glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadMemTexture(minecraft->player->customTextureUrl, minecraft->player->getTexture()));
699 MemSect(0);
700 minecraft->textures->clearLastBoundId();
701 glTranslatef(-1.0f, +3.6f, +3.5f);
702 glRotatef(120, 0, 0, 1);
703 glRotatef(180 + 20, 1, 0, 0);
704 glRotatef(-90 - 45, 0, 1, 0);
705 glScalef(1.5f / 24.0f * 16, 1.5f / 24.0f * 16, 1.5f / 24.0f * 16);
706 glTranslatef(5.6f, 0, 0);
707
708 EntityRenderer *er = EntityRenderDispatcher::instance->getRenderer(minecraft->player);
709 PlayerRenderer *playerRenderer = (PlayerRenderer *) er;
710 float ss = 1;
711 glScalef(ss, ss, ss);
712 MemSect(31);
713 // Can't turn off the hand if the player is holding a map
714 shared_ptr<ItemInstance> itemInstance = player->inventory->getSelected();
715
716 if ( (itemInstance && (itemInstance->getItem()->id==Item::map_Id)) || app.GetGameSettings(localPlayer->GetXboxPad(),eGameSetting_DisplayHand)!=0 )
717 {
718 playerRenderer->renderHand();
719 }
720 MemSect(0);
721 glPopMatrix();
722 }
723
724 glDisable(GL_RESCALE_NORMAL);
725 Lighting::turnOff();
726
727}
728
729void ItemInHandRenderer::renderScreenEffect(float a)
730{
731 glDisable(GL_ALPHA_TEST);
732 if (minecraft->player->isOnFire())
733 {
734 renderFire(a);
735 }
736
737 if (minecraft->player->isInWall()) // Inside a tile
738 {
739 int x = Mth::floor(minecraft->player->x);
740 int y = Mth::floor(minecraft->player->y);
741 int z = Mth::floor(minecraft->player->z);
742
743 int tile = minecraft->level->getTile(x, y, z);
744 if (minecraft->level->isSolidBlockingTile(x, y, z))
745 {
746 renderTex(a, Tile::tiles[tile]->getTexture(2));
747 }
748 else
749 {
750 for (int i = 0; i < 8; i++)
751 {
752 float xo = ((i >> 0) % 2 - 0.5f) * minecraft->player->bbWidth * 0.9f;
753 float yo = ((i >> 1) % 2 - 0.5f) * minecraft->player->bbHeight * 0.2f;
754 float zo = ((i >> 2) % 2 - 0.5f) * minecraft->player->bbWidth * 0.9f;
755 int xt = Mth::floor(x + xo);
756 int yt = Mth::floor(y + yo);
757 int zt = Mth::floor(z + zo);
758 if (minecraft->level->isSolidBlockingTile(xt, yt, zt))
759 {
760 tile = minecraft->level->getTile(xt, yt, zt);
761 }
762 }
763 }
764
765 if (Tile::tiles[tile] != NULL) renderTex(a, Tile::tiles[tile]->getTexture(2));
766 }
767
768 if (minecraft->player->isUnderLiquid(Material::water))
769 {
770 MemSect(31);
771 minecraft->textures->bindTexture(&UNDERWATER_LOCATION); // 4J was L"/misc/water.png"
772 MemSect(0);
773 renderWater(a);
774 }
775 glEnable(GL_ALPHA_TEST);
776
777}
778
779void ItemInHandRenderer::renderTex(float a, Icon *slot)
780{
781 minecraft->textures->bindTexture(&TextureAtlas::LOCATION_BLOCKS); // TODO: get this data from Icon
782
783 Tesselator *t = Tesselator::getInstance();
784
785 float br = 0.1f;
786 br = 0.1f;
787 glColor4f(br, br, br, 0.5f);
788
789 glPushMatrix();
790
791 float x0 = -1;
792 float x1 = +1;
793 float y0 = -1;
794 float y1 = +1;
795 float z0 = -0.5f;
796
797 float r = 2 / 256.0f;
798 float u0 = slot->getU0();
799 float u1 = slot->getU1();
800 float v0 = slot->getV0();
801 float v1 = slot->getV1();
802
803 t->begin();
804 t->vertexUV((float)(x0), (float)( y0), (float)( z0), (float)( u1), (float)( v1));
805 t->vertexUV((float)(x1), (float)( y0), (float)( z0), (float)( u0), (float)( v1));
806 t->vertexUV((float)(x1), (float)( y1), (float)( z0), (float)( u0), (float)( v0));
807 t->vertexUV((float)(x0), (float)( y1), (float)( z0), (float)( u1), (float)( v0));
808 t->end();
809 glPopMatrix();
810
811 glColor4f(1, 1, 1, 1);
812
813}
814
815void ItemInHandRenderer::renderWater(float a)
816{
817 minecraft->textures->bindTexture(&UNDERWATER_LOCATION);
818
819 Tesselator *t = Tesselator::getInstance();
820
821 float br = minecraft->player->getBrightness(a);
822 glColor4f(br, br, br, 0.5f);
823 glEnable(GL_BLEND);
824 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
825
826 glPushMatrix();
827
828 float size = 4;
829
830 float x0 = -1;
831 float x1 = +1;
832 float y0 = -1;
833 float y1 = +1;
834 float z0 = -0.5f;
835
836 float uo = -minecraft->player->yRot / 64.0f;
837 float vo = +minecraft->player->xRot / 64.0f;
838
839 t->begin();
840 t->vertexUV((float)(x0), (float)( y0), (float)( z0), (float)( size + uo), (float)( size + vo));
841 t->vertexUV((float)(x1), (float)( y0), (float)( z0), (float)( 0 + uo), (float)( size + vo));
842 t->vertexUV((float)(x1), (float)( y1), (float)( z0), (float)( 0 + uo), (float)( 0 + vo));
843 t->vertexUV((float)(x0), (float)( y1), (float)( z0), (float)( size + uo), (float)( 0 + vo));
844 t->end();
845 glPopMatrix();
846
847 glColor4f(1, 1, 1, 1);
848 glDisable(GL_BLEND);
849
850}
851
852void ItemInHandRenderer::renderFire(float a)
853{
854 Tesselator *t = Tesselator::getInstance();
855
856 unsigned int col = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Fire_Overlay );
857 float aCol = ( (col>>24)&0xFF )/255.0f;
858 float rCol = ( (col>>16)&0xFF )/255.0f;
859 float gCol = ( (col>>8)&0xFF )/255.0;
860 float bCol = ( col&0xFF )/255.0;
861
862 glColor4f(rCol, gCol, bCol, aCol);
863 glEnable(GL_BLEND);
864 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
865
866 float size = 1;
867 for (int i = 0; i < 2; i++)
868 {
869 glPushMatrix();
870 Icon *slot = Tile::fire->getTextureLayer(1);
871 minecraft->textures->bindTexture(&TextureAtlas::LOCATION_BLOCKS); // TODO: Get this from Icon
872
873 float u0 = slot->getU0(true);
874 float u1 = slot->getU1(true);
875 float v0 = slot->getV0(true);
876 float v1 = slot->getV1(true);
877
878 float x0 = (0 - size) / 2;
879 float x1 = x0 + size;
880 float y0 = 0 - size / 2;
881 float y1 = y0 + size;
882 float z0 = -0.5f;
883 glTranslatef(-(i * 2 - 1) * 0.24f, -0.3f, 0);
884 glRotatef((i * 2 - 1) * 10.0f, 0, 1, 0);
885
886 t->begin();
887 t->vertexUV((float)(x0), (float)( y0), (float)( z0), (float)( u1), (float)( v1));
888 t->vertexUV((float)(x1), (float)( y0), (float)( z0), (float)( u0), (float)( v1));
889 t->vertexUV((float)(x1), (float)( y1), (float)( z0), (float)( u0), (float)( v0));
890 t->vertexUV((float)(x0), (float)( y1), (float)( z0), (float)( u1), (float)( v0));
891 t->end();
892 glPopMatrix();
893 }
894 glColor4f(1, 1, 1, 1);
895 glDisable(GL_BLEND);
896
897}
898
899void ItemInHandRenderer::tick()
900{
901 oHeight = height;
902
903
904 shared_ptr<Player> player = minecraft->player;
905 shared_ptr<ItemInstance> nextTile = player->inventory->getSelected();
906
907 bool matches = lastSlot == player->inventory->selected && nextTile == selectedItem;
908 if (selectedItem == NULL && nextTile == NULL)
909 {
910 matches = true;
911 }
912 if (nextTile != NULL && selectedItem != NULL && nextTile != selectedItem && nextTile->id == selectedItem->id && nextTile->getAuxValue() == selectedItem->getAuxValue())
913 {
914 selectedItem = nextTile;
915 matches = true;
916 }
917
918 float max = 0.4f;
919 float tHeight = matches ? 1.0f : 0;
920 float dd = tHeight - height;
921 if (dd < -max) dd = -max;
922 if (dd > max) dd = max;
923
924 height += dd;
925 if (height < 0.1f)
926 {
927 selectedItem = nextTile;
928 lastSlot = player->inventory->selected;
929 }
930
931}
932
933void ItemInHandRenderer::itemPlaced()
934{
935 height = 0;
936}
937
938void ItemInHandRenderer::itemUsed()
939{
940 height = 0;
941}
942