1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
|
#include "stdafx.h"
#include "ItemRenderer.h"
#include "TileRenderer.h"
#include "entityRenderDispatcher.h"
#include "..\Minecraft.World\JavaMath.h"
#include "..\Minecraft.World\net.minecraft.world.entity.item.h"
#include "..\Minecraft.World\net.minecraft.world.item.h"
#include "..\Minecraft.World\net.minecraft.world.item.alchemy.h"
#include "..\Minecraft.World\net.minecraft.world.level.tile.h"
#include "..\Minecraft.World\StringHelpers.h"
#include "..\Minecraft.World\net.minecraft.world.h"
#include "Options.h"
#include "TextureAtlas.h"
#ifdef _XBOX
extern IDirect3DDevice9 *g_pD3DDevice;
#endif
ItemRenderer::ItemRenderer() : EntityRenderer()
{
random = new Random();
setColor = true;
blitOffset = 0;
shadowRadius = 0.15f;
shadowStrength = 0.75f;
// 4J added
m_bItemFrame= false;
}
ItemRenderer::~ItemRenderer()
{
delete random;
}
ResourceLocation *ItemRenderer::getTextureLocation(shared_ptr<Entity> entity)
{
shared_ptr<ItemEntity> itemEntity = dynamic_pointer_cast<ItemEntity>(entity);
return getTextureLocation(itemEntity->getItem()->getIconType());
}
ResourceLocation *ItemRenderer::getTextureLocation(int iconType)
{
if (iconType == Icon::TYPE_TERRAIN)
{
return &TextureAtlas::LOCATION_BLOCKS;//L"/terrain.png"));
}
else
{
#ifdef _XBOX
// 4J - make sure we've got linear sampling on minification here as non-mipmapped things like this currently
// default to having point sampling, which makes very small icons render rather badly
g_pD3DDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
#endif
return &TextureAtlas::LOCATION_ITEMS;//L"/gui/items.png"));
}
}
void ItemRenderer::render(shared_ptr<Entity> _itemEntity, double x, double y, double z, float rot, float a)
{
// 4J - dynamic cast required because we aren't using templates/generics in our version
shared_ptr<ItemEntity> itemEntity = dynamic_pointer_cast<ItemEntity>(_itemEntity);
bindTexture(itemEntity);
random->setSeed(187);
shared_ptr<ItemInstance> item = itemEntity->getItem();
if (item->getItem() == nullptr) return;
glPushMatrix();
float bob = Mth::sin((itemEntity->age + a) / 10.0f + itemEntity->bobOffs) * 0.1f + 0.1f;
float spin = ((itemEntity->age + a) / 20.0f + itemEntity->bobOffs) * Mth::RADDEG;
int count = 1;
if (itemEntity->getItem()->count > 1) count = 2;
if (itemEntity->getItem()->count > 5) count = 3;
if (itemEntity->getItem()->count > 20) count = 4;
if (itemEntity->getItem()->count > 40) count = 5;
glTranslatef(static_cast<float>(x), static_cast<float>(y) + bob, static_cast<float>(z));
glEnable(GL_RESCALE_NORMAL);
Tile *tile = Tile::tiles[item->id];
if (item->getIconType() == Icon::TYPE_TERRAIN && tile != nullptr && TileRenderer::canRender(tile->getRenderShape()))
{
glRotatef(spin, 0, 1, 0);
if (m_bItemFrame)
{
glScalef(1.25f, 1.25f, 1.25f);
glTranslatef(0, 0.05f, 0);
glRotatef(-90, 0, 1, 0);
}
float s = 1 / 4.0f;
int shape = tile->getRenderShape();
if (shape == Tile::SHAPE_CROSS_TEXTURE || shape == Tile::SHAPE_STEM || shape == Tile::SHAPE_LEVER || shape == Tile::SHAPE_TORCH )
{
s = 0.5f;
}
glScalef(s, s, s);
for (int i = 0; i < count; i++)
{
glPushMatrix();
if (i > 0)
{
float xo = (random->nextFloat() * 2 - 1) * 0.2f / s;
float yo = (random->nextFloat() * 2 - 1) * 0.2f / s;
float zo = (random->nextFloat() * 2 - 1) * 0.2f / s;
glTranslatef(xo, yo, zo);
}
// 4J - change brought forward from 1.8.2
float br = SharedConstants::TEXTURE_LIGHTING ? 1.0f : itemEntity->getBrightness(a);
tileRenderer->renderTile(tile, item->getAuxValue(), br);
glPopMatrix();
}
}
else if (item->getIconType() == Icon::TYPE_ITEM && item->getItem()->hasMultipleSpriteLayers())
{
if (m_bItemFrame)
{
glScalef(1 / 1.95f, 1 / 1.95f, 1 / 1.95f);
glTranslatef(0, -0.05f, 0);
glDisable(GL_LIGHTING);
}
else
{
glScalef(1 / 2.0f, 1 / 2.0f, 1 / 2.0f);
}
bindTexture(&TextureAtlas::LOCATION_ITEMS); // 4J was "/gui/items.png"
for (int layer = 0; layer <= 1; layer++)
{
random->setSeed(187);
Icon *icon = item->getItem()->getLayerIcon(item->getAuxValue(), layer);
float brightness = SharedConstants::TEXTURE_LIGHTING ? 1 : itemEntity->getBrightness(a);
if (setColor)
{
int col = Item::items[item->id]->getColor(item, layer);
float red = ((col >> 16) & 0xff) / 255.0f;
float g = ((col >> 8) & 0xff) / 255.0f;
float b = ((col) & 0xff) / 255.0f;
glColor4f(red * brightness, g * brightness, b * brightness, 1);
renderItemBillboard(itemEntity, icon, count, a, red * brightness, g * brightness, b * brightness);
}
else
{
renderItemBillboard(itemEntity, icon, count, a, 1, 1, 1);
}
}
}
else
{
if (m_bItemFrame)
{
glScalef(1 / 1.95f, 1 / 1.95f, 1 / 1.95f);
glTranslatef(0, -0.05f, 0);
glDisable(GL_LIGHTING);
}
else
{
glScalef(1 / 2.0f, 1 / 2.0f, 1 / 2.0f);
}
// 4J Stu - For rendering the static compass, we give it a non-zero aux value
if(item->id == Item::compass_Id) item->setAuxValue(255);
if(item->id == Item::compass_Id) item->setAuxValue(0);
Icon *icon = item->getIcon();
if (setColor)
{
int col = Item::items[item->id]->getColor(item,0);
float red = ((col >> 16) & 0xff) / 255.0f;
float g = ((col >> 8) & 0xff) / 255.0f;
float b = ((col) & 0xff) / 255.0f;
float brightness = SharedConstants::TEXTURE_LIGHTING ? 1 : itemEntity->getBrightness(a);
glColor4f(red * brightness, g * brightness, b * brightness, 1);
renderItemBillboard(itemEntity, icon, count, a, red * brightness, g * brightness, b * brightness);
}
else
{
renderItemBillboard(itemEntity, icon, count, a, 1, 1, 1);
}
}
glDisable(GL_RESCALE_NORMAL);
glPopMatrix();
if( m_bItemFrame )
{
glEnable(GL_LIGHTING);
}
}
void ItemRenderer::renderItemBillboard(shared_ptr<ItemEntity> entity, Icon *icon, int count, float a, float red, float green, float blue)
{
Tesselator *t = Tesselator::getInstance();
if (icon == nullptr) icon = entityRenderDispatcher->textures->getMissingIcon(entity->getItem()->getIconType());
float u0 = icon->getU0();
float u1 = icon->getU1();
float v0 = icon->getV0();
float v1 = icon->getV1();
float r = 1.0f;
float xo = 0.5f;
float yo = 0.25f;
if (entityRenderDispatcher->options->fancyGraphics)
{
// Consider forcing the mipmap LOD level to use, if this is to be rendered from a larger than standard source texture.
int iconWidth = icon->getWidth();
int LOD = -1; // Default to not doing anything special with LOD forcing
if( iconWidth == 32 )
{
LOD = 1; // Force LOD level 1 to achieve texture reads from 256x256 map
}
else if( iconWidth == 64 )
{
LOD = 2; // Force LOD level 2 to achieve texture reads from 256x256 map
}
RenderManager.StateSetForceLOD(LOD);
glPushMatrix();
if (m_bItemFrame)
{
glRotatef(180, 0, 1, 0);
}
else
{
glRotatef(((entity->age + a) / 20.0f + entity->bobOffs) * Mth::RADDEG, 0, 1, 0);
}
float width = 1 / 16.0f;
float margin = 0.35f / 16.0f;
shared_ptr<ItemInstance> item = entity->getItem();
int items = item->count;
if (items < 2)
{
count = 1;
}
else if (items < 16)
{
count = 2;
}
else if (items < 32)
{
count = 3;
}
else
{
count = 4;
}
glTranslatef(-xo, -yo, -((width + margin) * count / 2));
for (int i = 0; i < count; i++)
{
glTranslatef(0, 0, width + margin);
bool bIsTerrain = false;
if (item->getIconType() == Icon::TYPE_TERRAIN && Tile::tiles[item->id] != nullptr)
{
bIsTerrain = true;
bindTexture(&TextureAtlas::LOCATION_BLOCKS); // TODO: Do this sanely by Icon
}
else
{
bindTexture(&TextureAtlas::LOCATION_ITEMS); // TODO: Do this sanely by Icon
}
glColor4f(red, green, blue, 1);
// 4J Stu - u coords were swapped in Java
//ItemInHandRenderer::renderItem3D(t, u1, v0, u0, v1, icon->getSourceWidth(), icon->getSourceHeight(), width, false);
ItemInHandRenderer::renderItem3D(t, u0, v0, u1, v1, icon->getSourceWidth(), icon->getSourceHeight(), width, false, bIsTerrain);
if (item != nullptr && item->isFoil())
{
glDepthFunc(GL_EQUAL);
glDisable(GL_LIGHTING);
entityRenderDispatcher->textures->bindTexture(&ItemInHandRenderer::ENCHANT_GLINT_LOCATION);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_ONE);
float br = 0.76f;
glColor4f(0.5f * br, 0.25f * br, 0.8f * br, 1);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
float ss = 1 / 8.0f;
glScalef(ss, ss, ss);
float sx = Minecraft::currentTimeMillis() % (3000) / (3000.0f) * 8;
glTranslatef(sx, 0, 0);
glRotatef(-50, 0, 0, 1);
ItemInHandRenderer::renderItem3D(t, 0, 0, 1, 1, 255, 255, width, true, bIsTerrain);
glPopMatrix();
glPushMatrix();
glScalef(ss, ss, ss);
sx = Minecraft::currentTimeMillis() % (3000 + 1873) / (3000 + 1873.0f) * 8;
glTranslatef(-sx, 0, 0);
glRotatef(10, 0, 0, 1);
ItemInHandRenderer::renderItem3D(t, 0, 0, 1, 1, 255, 255, width, true, bIsTerrain);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
glDepthFunc(GL_LEQUAL);
}
}
glPopMatrix();
RenderManager.StateSetForceLOD(-1);
}
else
{
for (int i = 0; i < count; i++)
{
glPushMatrix();
if (i > 0)
{
float _xo = (random->nextFloat() * 2 - 1) * 0.3f;
float _yo = (random->nextFloat() * 2 - 1) * 0.3f;
float _zo = (random->nextFloat() * 2 - 1) * 0.3f;
glTranslatef(_xo, _yo, _zo);
}
if (!m_bItemFrame) glRotatef(180 - entityRenderDispatcher->playerRotY, 0, 1, 0);
glColor4f(red, green, blue, 1);
t->begin();
t->normal(0, 1, 0);
t->vertexUV((float)(0 - xo), (float)( 0 - yo), static_cast<float>(0), (float)( u0), (float)( v1));
t->vertexUV((float)(r - xo), (float)( 0 - yo), static_cast<float>(0), (float)( u1), (float)( v1));
t->vertexUV((float)(r - xo), (float)( 1 - yo), static_cast<float>(0), (float)( u1), (float)( v0));
t->vertexUV((float)(0 - xo), (float)( 1 - yo), static_cast<float>(0), (float)( u0), (float)( v0));
t->end();
glPopMatrix();
}
}
}
void ItemRenderer::renderGuiItem(Font *font, Textures *textures, shared_ptr<ItemInstance> item, float x, float y, float fScale, float fAlpha)
{
renderGuiItem(font,textures,item,x,y,fScale,fScale,fAlpha, true);
}
// 4J - this used to take x and y as ints, and no scale and alpha - but this interface is now implemented as a wrapper round this more fully featured one
void ItemRenderer::renderGuiItem(Font *font, Textures *textures, shared_ptr<ItemInstance> item, float x, float y, float fScaleX,float fScaleY, float fAlpha, bool useCompiled)
{
int itemId = item->id;
int itemAuxValue = item->getAuxValue();
Icon *itemIcon = item->getIcon();
if (item->getIconType() == Icon::TYPE_TERRAIN && TileRenderer::canRender(Tile::tiles[itemId]->getRenderShape()))
{
PIXBeginNamedEvent(0,"3D gui item render %d\n",itemId);
MemSect(31);
textures->bindTexture(&TextureAtlas::LOCATION_BLOCKS);
MemSect(0);
Tile *tile = Tile::tiles[itemId];
glPushMatrix();
// 4J - original code left here for reference
#if 0
glTranslatef((float)(x), (float)(y), 0.0f);
glScalef(fScale, fScale, fScale);
glTranslatef(-2.0f,3.0f, -3.0f + blitOffset);
glScalef(10.0f, 10.0f, 10.0f);
glTranslatef(1.0f, 0.5f, 8.0f);
glScalef(1.0f, 1.0f, -1.0f);
glRotatef(180.0f + 30.0f, 1.0f, 0.0f, 0.0f);
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
#else
glTranslatef(x, y, 0.0f); // Translate to screen coords
glScalef(16.0f*fScaleX, 16.0f*fScaleY, 1.0f); // Scale to 0 to 16*scale range
glTranslatef(0.5f,0.5f,0.0f); // Translate to 0 to 1 range
glScalef(0.55f,0.55f, -1.0f); // Scale to occupy full -0.5 to 0.5 bounding region (just touching top & bottom)
// 0.55 comes from 1/(1+sqrt(2)/sqrt(3)) which is determined by the angles that the cube is rotated in an orthographic projection
glRotatef(180.0f + 30.0f, 1.0f, 0.0f, 0.0f); // Rotate round x axis (centre at origin)
glRotatef(45.0f, 0.0f, 1.0f, 0.0f); // Rotate round y axis (centre at origin)
#endif
// 4J-PB - pass the alpha value in - the grass block render has the top surface coloured differently to the rest of the block
glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);
tileRenderer->renderTile(tile, itemAuxValue, 1, fAlpha, useCompiled);
glPopMatrix();
PIXEndNamedEvent();
}
else if (Item::items[itemId]->hasMultipleSpriteLayers())
{
PIXBeginNamedEvent(0,"Potion gui item render %d\n",itemIcon);
// special double-layered
glDisable(GL_LIGHTING);
ResourceLocation *location = getTextureLocation(item->getIconType());
textures->bindTexture(location);
for (int layer = 0; layer <= 1; layer++)
{
Icon *fillingIcon = Item::items[itemId]->getLayerIcon(itemAuxValue, layer);
int col = Item::items[itemId]->getColor(item, layer);
float r = ((col >> 16) & 0xff) / 255.0f;
float g = ((col >> 8) & 0xff) / 255.0f;
float b = ((col) & 0xff) / 255.0f;
if (setColor) glColor4f(r, g, b, fAlpha);
// scale the x and y by the scale factor
if((fScaleX!=1.0f) ||(fScaleY!=1.0f))
{
blit(x, y, fillingIcon, 16 * fScaleX, 16 * fScaleY);
}
else
{
blit(static_cast<int>(x), static_cast<int>(y), fillingIcon, 16, 16);
}
}
glEnable(GL_LIGHTING);
PIXEndNamedEvent();
}
else
{
PIXBeginNamedEvent(0,"2D gui item render %d\n",itemIcon);
glDisable(GL_LIGHTING);
MemSect(31);
if (item->getIconType() == Icon::TYPE_TERRAIN)
{
textures->bindTexture(&TextureAtlas::LOCATION_BLOCKS);//L"/terrain.png"));
}
else
{
textures->bindTexture(&TextureAtlas::LOCATION_ITEMS);//L"/gui/items.png"));
#ifdef _XBOX
// 4J - make sure we've got linear sampling on minification here as non-mipmapped things like this currently
// default to having point sampling, which makes very small icons render rather badly
g_pD3DDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
#endif
}
MemSect(0);
if (itemIcon == nullptr)
{
itemIcon = textures->getMissingIcon(item->getIconType());
}
int col = Item::items[itemId]->getColor(item,0);
float r = ((col >> 16) & 0xff) / 255.0f;
float g = ((col >> 8) & 0xff) / 255.0f;
float b = ((col) & 0xff) / 255.0f;
if (setColor) glColor4f(r, g, b, fAlpha);
// scale the x and y by the scale factor
if((fScaleX!=1.0f) ||(fScaleY!=1.0f))
{
blit(x, y, itemIcon, 16 * fScaleX, 16 * fScaleY);
}
else
{
blit(static_cast<int>(x), static_cast<int>(y), itemIcon, 16, 16);
}
glEnable(GL_LIGHTING);
PIXEndNamedEvent();
}
glEnable(GL_CULL_FACE);
}
// 4J - original interface, now just a wrapper for preceding overload
void ItemRenderer::renderGuiItem(Font *font, Textures *textures, shared_ptr<ItemInstance> item, int x, int y)
{
renderGuiItem(font, textures, item, static_cast<float>(x), static_cast<float>(y), 1.0f, 1.0f );
}
// 4J - this used to take x and y as ints, and no scale, alpha or foil - but this interface is now implemented as a wrapper round this more fully featured one
void ItemRenderer::renderAndDecorateItem(Font *font, Textures *textures, const shared_ptr<ItemInstance> item, float x, float y,float fScale,float fAlpha, bool isFoil)
{
if(item==nullptr) return;
renderAndDecorateItem(font, textures, item, x, y,fScale, fScale, fAlpha, isFoil, true);
}
// 4J - added isConstantBlended and blendFactor parameters. This is true if the gui item is being rendered from a context where it already has blending enabled to do general interface fading
// (ie from the gui rather than xui). In this case we dno't want to enable/disable blending, and do need to restore the blend state when we are done.
void ItemRenderer::renderAndDecorateItem(Font *font, Textures *textures, const shared_ptr<ItemInstance> item, float x, float y,float fScaleX, float fScaleY,float fAlpha, bool isFoil, bool isConstantBlended, bool useCompiled)
{
if (item == nullptr)
{
return;
}
renderGuiItem(font, textures, item, x, y,fScaleX,fScaleY,fAlpha, useCompiled);
if (isFoil || item->isFoil())
{
glDepthFunc(GL_GREATER);
glDisable(GL_LIGHTING);
glDepthMask(false);
textures->bindTexture(&ItemInHandRenderer::ENCHANT_GLINT_LOCATION); // 4J was "%blur%/misc/glint.png"
blitOffset -= 50;
if( !isConstantBlended ) glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ONE); // 4J - changed blend equation from GL_DST_COLOR, GL_DST_COLOR so we can fade this out
float blendFactor = isConstantBlended ? Gui::currentGuiBlendFactor : 1.0f;
glColor4f(0.5f * blendFactor, 0.25f * blendFactor, 0.8f * blendFactor, 1); // 4J - scale back colourisation with blendFactor
// scale the x and y by the scale factor
if((fScaleX!=1.0f) ||(fScaleY!=1.0f))
{
// 4J Stu - Scales were multiples of 20, making 16 to not overlap in xui scenes
blitGlint(x * 431278612 + y * 32178161, x - 2, y - 2, 16 * fScaleX, 16 * fScaleY);
}
else
{
blitGlint(x * 431278612 + y * 32178161, x - 2, y - 2, 20, 20);
}
glColor4f(1.0f, 1.0f, 1.0f, 1); // 4J added
if( !isConstantBlended ) glDisable(GL_BLEND);
glDepthMask(true);
blitOffset += 50;
glEnable(GL_LIGHTING);
glDepthFunc(GL_LEQUAL);
if( isConstantBlended ) glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
}
}
// 4J - original interface, now just a wrapper for preceding overload
void ItemRenderer::renderAndDecorateItem(Font *font, Textures *textures, const shared_ptr<ItemInstance> item, int x, int y)
{
renderAndDecorateItem( font, textures, item, static_cast<float>(x), static_cast<float>(y), 1.0f, 1.0f, item->isFoil() );
}
// 4J - a few changes here to get x, y, w, h in as floats (for xui rendering accuracy), and to align
// final pixels to the final screen resolution
void ItemRenderer::blitGlint(int id, float x, float y, float w, float h)
{
float us = 1.0f / 64.0f / 4;
float vs = 1.0f / 64.0f / 4;
// 4J - calculate what the pixel coordinates will be in final screen coordinates
float sfx = static_cast<float>(Minecraft::GetInstance()->width) / static_cast<float>(Minecraft::GetInstance()->width_phys);
float sfy = static_cast<float>(Minecraft::GetInstance()->height) / static_cast<float>(Minecraft::GetInstance()->height_phys);
float xx0 = x * sfx;
float xx1 = ( x + w ) * sfx;
float yy0 = y * sfy;
float yy1 = ( y + h ) * sfy;
// Round to whole pixels - rounding inwards so that we don't overlap any surrounding graphics
xx0 = ceilf(xx0);
xx1 = floorf(xx1);
yy0 = ceilf(yy0);
yy1 = floorf(yy1);
// Offset by half to get actual centre of pixel - again moving inwards to avoid overlap with surrounding graphics
xx0 += 0.5f;
xx1 -= 0.5f;
yy0 += 0.5f;
yy1 -= 0.5f;
// Convert back to game coordinate space
float xx0f = xx0 / sfx;
float xx1f = xx1 / sfx;
float yy0f = yy0 / sfy;
float yy1f = yy1 / sfy;
for (int i = 0; i < 2; i++)
{
if (i == 0) glBlendFunc(GL_SRC_COLOR, GL_ONE);
if (i == 1) glBlendFunc(GL_SRC_COLOR, GL_ONE);
float sx = Minecraft::currentTimeMillis() % (3000 + i * 1873) / (3000.0f + i * 1873) * 256;
float sy = 0;
Tesselator *t = Tesselator::getInstance();
float vv = 4;
if (i == 1) vv = -1;
t->begin();
t->vertexUV(xx0f, yy1f, blitOffset, (sx + h * vv) * us, (sy + h) * vs);
t->vertexUV(xx1f, yy1f, blitOffset, (sx + w + h * vv) * us, (sy + h) * vs);
t->vertexUV(xx1f, yy0f, blitOffset, (sx + w) * us, (sy + 0) * vs);
t->vertexUV(xx0f, yy0f, blitOffset, (sx + 0) * us, (sy + 0) * vs);
t->end();
}
}
void ItemRenderer::renderGuiItemDecorations(Font *font, Textures *textures, shared_ptr<ItemInstance> item, int x, int y, float fAlpha)
{
renderGuiItemDecorations(font, textures, item, x, y, L"", fAlpha);
}
void ItemRenderer::renderGuiItemDecorations(Font *font, Textures *textures, shared_ptr<ItemInstance> item, int x, int y, const wstring &countText, float fAlpha)
{
if (item == nullptr)
{
return;
}
if (item->count > 1 || !countText.empty() || item->GetForceNumberDisplay())
{
MemSect(31);
wstring amount = countText;
if(amount.empty())
{
int count = item->count;
if(count > 64)
{
amount = L"64+";
}
else
{
amount = std::to_wstring(item->count);
}
}
MemSect(0);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
font->drawShadow(amount, x + 19 - 2 - font->width(amount), y + 6 + 3, 0xffffff |(static_cast<unsigned int>(fAlpha * 0xff)<<24));
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}
if (item->isDamaged())
{
int p = static_cast<int>(Math::round(13.0 - (double)item->getDamageValue() * 13.0 / (double)item->getMaxDamage()));
int cc = static_cast<int>(Math::round(255.0 - (double)item->getDamageValue() * 255.0 / (double)item->getMaxDamage()));
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
Tesselator *t = Tesselator::getInstance();
int ca = (255 - cc) << 16 | (cc) << 8;
int cb = ((255 - cc) / 4) << 16 | (255 / 4) << 8;
fillRect(t, x + 2, y + 13, 13, 2, 0x000000);
fillRect(t, x + 2, y + 13, 12, 1, cb);
fillRect(t, x + 2, y + 13, p, 1, ca);
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glColor4f(1, 1, 1, 1);
}
else if(item->hasPotionStrengthBar())
{
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
Tesselator *t = Tesselator::getInstance();
fillRect(t, x + 3, y + 13, 11, 2, 0x000000);
//fillRect(t, x + 2, y + 13, 13, 1, 0x1dabc0);
fillRect(t, x + 3, y + 13, m_iPotionStrengthBarWidth[item->GetPotionStrength()], 2, 0x00e1eb);
fillRect(t, x + 2 + 3, y + 13, 1, 2, 0x000000);
fillRect(t, x + 2 + 3+3, y + 13, 1, 2, 0x000000);
fillRect(t, x + 2 + 3+3+3, y + 13, 1, 2, 0x000000);
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glColor4f(1, 1, 1, 1);
}
glDisable(GL_BLEND);
}
const int ItemRenderer::m_iPotionStrengthBarWidth[]=
{
3,6,9,11
};
void ItemRenderer::fillRect(Tesselator *t, int x, int y, int w, int h, int c)
{
t->begin();
t->color(c);
t->vertex(static_cast<float>(x + 0), static_cast<float>(y + 0), static_cast<float>(0));
t->vertex(static_cast<float>(x + 0), static_cast<float>(y + h), static_cast<float>(0));
t->vertex(static_cast<float>(x + w), static_cast<float>(y + h), static_cast<float>(0));
t->vertex(static_cast<float>(x + w), static_cast<float>(y + 0), static_cast<float>(0));
t->end();
}
// 4J - a few changes here to get x, y, w, h in as floats (for xui rendering accuracy), and to align
// final pixels to the final screen resolution
void ItemRenderer::blit(float x, float y, int sx, int sy, float w, float h)
{
float us = 1 / 256.0f;
float vs = 1 / 256.0f;
Tesselator *t = Tesselator::getInstance();
t->begin();
// 4J - calculate what the pixel coordinates will be in final screen coordinates
float sfx = static_cast<float>(Minecraft::GetInstance()->width) / static_cast<float>(Minecraft::GetInstance()->width_phys);
float sfy = static_cast<float>(Minecraft::GetInstance()->height) / static_cast<float>(Minecraft::GetInstance()->height_phys);
float xx0 = x * sfx;
float xx1 = ( x + w ) * sfx;
float yy0 = y * sfy;
float yy1 = ( y + h ) * sfy;
// Round to whole pixels - rounding inwards so that we don't overlap any surrounding graphics
xx0 = ceilf(xx0);
xx1 = floorf(xx1);
yy0 = ceilf(yy0);
yy1 = floorf(yy1);
// Offset by half to get actual centre of pixel - again moving inwards to avoid overlap with surrounding graphics
xx0 += 0.5f;
xx1 -= 0.5f;
yy0 += 0.5f;
yy1 -= 0.5f;
// Convert back to game coordinate space
float xx0f = xx0 / sfx;
float xx1f = xx1 / sfx;
float yy0f = yy0 / sfy;
float yy1f = yy1 / sfy;
// 4J - subtracting 0.5f (actual screen pixels, so need to compensate for physical & game width) from each x & y coordinate to compensate for centre of pixels in directx vs openGL
float f = ( 0.5f * static_cast<float>(Minecraft::GetInstance()->width) ) / static_cast<float>(Minecraft::GetInstance()->width_phys);
t->vertexUV(xx0f, yy1f, (float)( blitOffset), (float)( (sx + 0) * us), (float)( (sy + 16) * vs));
t->vertexUV(xx1f, yy1f, (float)( blitOffset), (float)( (sx + 16) * us), (float)( (sy + 16) * vs));
t->vertexUV(xx1f, yy0f, (float)( blitOffset), (float)( (sx + 16) * us), (float)( (sy + 0) * vs));
t->vertexUV(xx0f, yy0f, (float)( blitOffset), (float)( (sx + 0) * us), (float)( (sy + 0) * vs));
t->end();
}
void ItemRenderer::blit(float x, float y, Icon *tex, float w, float h)
{
Tesselator *t = Tesselator::getInstance();
t->begin();
// 4J - calculate what the pixel coordinates will be in final screen coordinates
float sfx = static_cast<float>(Minecraft::GetInstance()->width) / static_cast<float>(Minecraft::GetInstance()->width_phys);
float sfy = static_cast<float>(Minecraft::GetInstance()->height) / static_cast<float>(Minecraft::GetInstance()->height_phys);
float xx0 = x * sfx;
float xx1 = ( x + w ) * sfx;
float yy0 = y * sfy;
float yy1 = ( y + h ) * sfy;
// Round to whole pixels - rounding inwards so that we don't overlap any surrounding graphics
xx0 = ceilf(xx0);
xx1 = floorf(xx1);
yy0 = ceilf(yy0);
yy1 = floorf(yy1);
// Offset by half to get actual centre of pixel - again moving inwards to avoid overlap with surrounding graphics
xx0 += 0.5f;
xx1 -= 0.5f;
yy0 += 0.5f;
yy1 -= 0.5f;
// Convert back to game coordinate space
float xx0f = xx0 / sfx;
float xx1f = xx1 / sfx;
float yy0f = yy0 / sfy;
float yy1f = yy1 / sfy;
// 4J - subtracting 0.5f (actual screen pixels, so need to compensate for physical & game width) from each x & y coordinate to compensate for centre of pixels in directx vs openGL
float f = ( 0.5f * static_cast<float>(Minecraft::GetInstance()->width) ) / static_cast<float>(Minecraft::GetInstance()->width_phys);
t->vertexUV(xx0f, yy1f, blitOffset, tex->getU0(true), tex->getV1(true));
t->vertexUV(xx1f, yy1f, blitOffset, tex->getU1(true), tex->getV1(true));
t->vertexUV(xx1f, yy0f, blitOffset, tex->getU1(true), tex->getV0(true));
t->vertexUV(xx0f, yy0f, blitOffset, tex->getU0(true), tex->getV0(true));
t->end();
}
|