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 "TileRenderer.h"
4#include "GameRenderer.h"
5#include "Minecraft.h"
6#include "Textures.h"
7#include "..\Minecraft.World\net.minecraft.world.level.h"
8#include "..\Minecraft.World\net.minecraft.world.level.tile.h"
9#include "..\Minecraft.World\net.minecraft.world.level.material.h"
10#include "..\Minecraft.World\net.minecraft.h"
11#include "..\Minecraft.World\net.minecraft.world.h"
12#include "Tesselator.h"
13#include "EntityTileRenderer.h"
14#include "Options.h"
15
16bool TileRenderer::fancy = true;
17
18const float smallUV = ( 1.0f / 16.0f );
19
20void TileRenderer::_init()
21{
22 fixedTexture = NULL;
23 xFlipTexture = false;
24 noCulling = false;
25 applyAmbienceOcclusion = false;
26 setColor = true;
27 northFlip = FLIP_NONE;
28 southFlip = FLIP_NONE;
29 eastFlip = FLIP_NONE;
30 westFlip = FLIP_NONE;
31 upFlip = FLIP_NONE;
32 downFlip = FLIP_NONE;
33
34 tileShapeX0 = 0.0;
35 tileShapeX1 = 0.0;
36 tileShapeY0 = 0.0;
37 tileShapeY1 = 0.0;
38 tileShapeZ0 = 0.0;
39 tileShapeZ1 = 0.0;
40 fixedShape = false;
41 smoothShapeLighting = false;
42 minecraft = Minecraft::GetInstance();
43
44 xMin = 0;
45 yMin = 0;
46 zMin = 0;
47 cache = NULL;
48}
49
50bool TileRenderer::isTranslucentAt(LevelSource *level, int x, int y, int z)
51{
52 if( cache )
53 {
54 int id = ( ( x - xMin2) << 10 ) + ( ( y - yMin2 ) << 5 ) + ( z - zMin2 );
55 if ( ( id & 0xffff8000) == 0 ) // Check 0 <= id <= 32767
56 {
57 assert (id >= 0 );
58 assert (id <= 32 * 32 * 32);
59 if( cache[id] & cache_isTranslucentAt_valid ) return ( ( cache[id] & cache_isTranslucentAt_flag ) == cache_isTranslucentAt_flag );
60
61 bool ret = Tile::transculent[level->getTile(x,y,z)];
62
63 if( ret )
64 {
65 cache[id] |= cache_isTranslucentAt_valid | cache_isTranslucentAt_flag;
66 }
67 else
68 {
69 cache[id] |= cache_isTranslucentAt_valid;
70 }
71 return ret;
72 }
73 }
74 return Tile::transculent[level->getTile(x,y,z)];
75}
76
77float TileRenderer::getShadeBrightness(Tile *tt, LevelSource *level, int x, int y, int z)
78{
79 if( cache )
80 {
81 int id = ( ( x - xMin2) << 10 ) + ( ( y - yMin2 ) << 5 ) + ( z - zMin2 );
82 if ( ( id & 0xffff8000) == 0 ) // Check 0 <= id <= 32767
83 {
84 if( cache[id] & cache_isSolidBlockingTile_valid ) return ( ( cache[id] & cache_isSolidBlockingTile_flag ) ? 0.2f : 1.0f);
85
86 bool isSolidBlocking = level->isSolidBlockingTile(x, y, z);
87
88 if( isSolidBlocking )
89 {
90 cache[id] |= cache_isSolidBlockingTile_valid | cache_isSolidBlockingTile_flag;
91 }
92 else
93 {
94 cache[id] |= cache_isSolidBlockingTile_valid;
95 }
96 return ( isSolidBlocking ? 0.2f : 1.0f);
97 }
98 }
99 return tt->getShadeBrightness(level, x, y, z);
100}
101
102int TileRenderer::getLightColor( Tile *tt, LevelSource *level, int x, int y, int z)
103{
104 if( cache )
105 {
106 int id = ( ( x - xMin2) << 10 ) + ( ( y - yMin2 ) << 5 ) + ( z - zMin2 );
107 if ( ( id & 0xffff8000) == 0 ) // Check 0 <= id <= 32767
108 {
109 // Don't use the cache for liquid tiles, as they are the only type that seem to have their own implementation of getLightColor that actually is important.
110 // Without this we get patches of dark water where their lighting value is 0, it needs to pull in light from the tile above to work
111 if( ( tt->id >= Tile::water_Id ) && ( tt->id <= Tile::calmLava_Id ) ) return tt->getLightColor(level, x, y, z);
112
113 if( cache[id] & cache_getLightColor_valid ) return cache[id] & cache_getLightColor_mask;
114
115 // Not in cache. Have we got the tile type cached? We can pass this as a parameter to Tile::getLightColor( or -1 if we don't) so that underlying things
116 // don't have to get the tile again.
117 int tileId = -1;
118 int xx = x - xMin;
119 int zz = z - zMin;
120 if( ( xx >= 0 ) && ( xx <= 15 ) && ( zz >= 0 ) && ( zz <= 15 ) && ( y >= 0 ) && ( y < Level::maxBuildHeight ) )
121 {
122 int indexY = y;
123 int offset = 0;
124 if(indexY >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT)
125 {
126 indexY -= Level::COMPRESSED_CHUNK_SECTION_HEIGHT;
127 offset = Level::COMPRESSED_CHUNK_SECTION_TILES;
128 }
129
130 unsigned char ucTileId = tileIds[ offset + ( ( ( xx + 0 ) << 11 ) | ( ( zz + 0 ) << 7 ) | ( indexY + 0 ) ) ];
131 // Tiles that were determined to be invisible (by being surrounded by solid stuff) will be set to 255 rather than their actual ID
132 if( ucTileId != 255 )
133 {
134 tileId = (int)ucTileId;
135 }
136 }
137 int ret = tt->getLightColor(level, x, y, z, tileId);
138 cache[id] |= ( ( ret & cache_getLightColor_mask ) | cache_getLightColor_valid );
139 return ret;
140 }
141 }
142 return tt->getLightColor(level, x, y, z);
143}
144
145TileRenderer::TileRenderer( LevelSource* level, int xMin, int yMin, int zMin, unsigned char *tileIds )
146{
147 this->level = level;
148 _init();
149 this->xMin = xMin;
150 this->yMin = yMin;
151 this->zMin = zMin;
152 this->xMin2 = xMin-2;
153 this->yMin2 = yMin-2;
154 this->zMin2 = zMin-2;
155 this->tileIds = tileIds;
156 cache = new unsigned int[32*32*32];
157 XMemSet(cache,0,32*32*32*sizeof(unsigned int));
158}
159
160TileRenderer::~TileRenderer()
161{
162 delete cache;
163}
164
165TileRenderer::TileRenderer( LevelSource* level )
166{
167 this->level = level;
168 _init();
169}
170
171TileRenderer::TileRenderer()
172{
173 this->level = NULL;
174 _init();
175}
176
177void TileRenderer::setFixedTexture( Icon *fixedTexture )
178{
179 this->fixedTexture = fixedTexture;
180}
181
182void TileRenderer::clearFixedTexture()
183{
184 this->fixedTexture = NULL;
185}
186
187bool TileRenderer::hasFixedTexture()
188{
189#ifdef __PSVITA__
190 // AP - alpha cut out is expensive on vita. Pass on the Alpha Cut out flag to the tesselator
191 if(fixedTexture)
192 {
193 Tesselator* t = Tesselator::getInstance();
194 t->setAlphaCutOut( fixedTexture->getFlags() & Icon::IS_ALPHA_CUT_OUT );
195 }
196#endif
197
198 return fixedTexture != NULL;
199}
200
201void TileRenderer::setShape(float x0, float y0, float z0, float x1, float y1, float z1)
202{
203 if (!fixedShape)
204 {
205 tileShapeX0 = x0;
206 tileShapeX1 = x1;
207 tileShapeY0 = y0;
208 tileShapeY1 = y1;
209 tileShapeZ0 = z0;
210 tileShapeZ1 = z1;
211 smoothShapeLighting = (tileShapeX0 > 0 || tileShapeX1 < 1 || tileShapeY0 > 0 || tileShapeY1 < 1 || tileShapeZ0 > 0 || tileShapeZ1 < 1);
212 }
213}
214
215void TileRenderer::setShape(Tile *tt)
216{
217 if (!fixedShape)
218 {
219 tileShapeX0 = tt->getShapeX0();
220 tileShapeX1 = tt->getShapeX1();
221 tileShapeY0 = tt->getShapeY0();
222 tileShapeY1 = tt->getShapeY1();
223 tileShapeZ0 = tt->getShapeZ0();
224 tileShapeZ1 = tt->getShapeZ1();
225 smoothShapeLighting = (tileShapeX0 > 0 || tileShapeX1 < 1 || tileShapeY0 > 0 || tileShapeY1 < 1 || tileShapeZ0 > 0 || tileShapeZ1 < 1);
226 }
227}
228
229void TileRenderer::setFixedShape(float x0, float y0, float z0, float x1, float y1, float z1)
230{
231 tileShapeX0 = x0;
232 tileShapeX1 = x1;
233 tileShapeY0 = y0;
234 tileShapeY1 = y1;
235 tileShapeZ0 = z0;
236 tileShapeZ1 = z1;
237 fixedShape = true;
238
239 smoothShapeLighting = (tileShapeX0 > 0 || tileShapeX1 < 1 || tileShapeY0 > 0 || tileShapeY1 < 1 || tileShapeZ0 > 0 || tileShapeZ1 < 1);
240}
241
242void TileRenderer::clearFixedShape()
243{
244 fixedShape = false;
245}
246
247void TileRenderer::tesselateInWorldFixedTexture( Tile* tile, int x, int y, int z, Icon *fixedTexture ) // 4J renamed to differentiate from tesselateInWorld
248{
249 this->setFixedTexture(fixedTexture);
250 tesselateInWorld( tile, x, y, z );
251 this->clearFixedTexture();
252}
253
254void TileRenderer::tesselateInWorldNoCulling( Tile* tile, int x, int y, int z, int forceData,
255 shared_ptr< TileEntity > forceEntity ) // 4J added forceData, forceEntity param
256{
257 noCulling = true;
258 tesselateInWorld( tile, x, y, z, forceData );
259 noCulling = false;
260}
261
262bool TileRenderer::tesselateInWorld( Tile* tt, int x, int y, int z, int forceData,
263 shared_ptr< TileEntity > forceEntity ) // 4J added forceData, forceEntity param
264{
265 Tesselator* t = Tesselator::getInstance();
266 int shape = tt->getRenderShape();
267 tt->updateShape( level, x, y, z, forceData, forceEntity );
268 // AP - now that the culling is done earlier we don't need to call setShape until later on (only for SHAPE_BLOCK)
269 if( shape != Tile::SHAPE_BLOCK )
270 {
271 setShape(tt);
272 }
273 t->setMipmapEnable( Tile::mipmapEnable[tt->id] ); // 4J added
274
275 bool retVal = false;
276 switch(shape)
277 {
278 case Tile::SHAPE_BLOCK:
279 {
280 // 4J - added these faceFlags so we can detect whether this block is going to have no visible faces and early out
281 // the original code checked noCulling and shouldRenderFace directly where faceFlags is used now
282 // AP - I moved this check from tesselateBlockInWorldWithAmbienceOcclusionTexLighting to be even earlier to speed up early rejection.
283 // The flags are then passed down to avoid creating them again.
284 // These changes in combination have more than halved the time it takes to reject a block on Vita
285 int faceFlags = 0;
286 if ( noCulling )
287 {
288 faceFlags = 0x3f;
289 }
290 else
291 {
292 // these block types can take advantage of a faster version of shouldRenderFace
293 // there are others but this is an easy check which covers the majority
294 // Note: This now covers rock, grass, dirt, stoneBrice, wood, sapling, unbreakable, sand, gravel, goldOre, ironOre, coalOre, treeTrunk
295 if( ( tt->id <= Tile::unbreakable_Id ) ||
296 ( ( tt->id >= Tile::sand_Id ) && ( tt->id <= Tile::treeTrunk_Id ) ) )
297 {
298 faceFlags = tt->getFaceFlags( level, x, y, z );
299 }
300 else
301 {
302 faceFlags |= tt->shouldRenderFace( level, x, y - 1, z, 0 ) ? 0x01 : 0;
303 faceFlags |= tt->shouldRenderFace( level, x, y + 1, z, 1 ) ? 0x02 : 0;
304 faceFlags |= tt->shouldRenderFace( level, x, y, z - 1, 2 ) ? 0x04 : 0;
305 faceFlags |= tt->shouldRenderFace( level, x, y, z + 1, 3 ) ? 0x08 : 0;
306 faceFlags |= tt->shouldRenderFace( level, x - 1, y, z, 4 ) ? 0x10 : 0;
307 faceFlags |= tt->shouldRenderFace( level, x + 1, y, z, 5 ) ? 0x20 : 0;
308 }
309 }
310 if ( faceFlags == 0 )
311 {
312 retVal = false;
313 break;
314 }
315
316 // now we need to set the shape
317 setShape(tt);
318
319 retVal = tesselateBlockInWorld( tt, x, y, z, faceFlags );
320 }
321 break;
322 case Tile::SHAPE_TREE:
323 retVal = tesselateTreeInWorld(tt, x, y, z);
324 break;
325 case Tile::SHAPE_QUARTZ:
326 retVal = tesselateQuartzInWorld(tt, x, y, z);
327 break;
328 case Tile::SHAPE_WATER:
329 retVal = tesselateWaterInWorld( tt, x, y, z );
330 break;
331 case Tile::SHAPE_CACTUS:
332 retVal = tesselateCactusInWorld( tt, x, y, z );
333 break;
334 case Tile::SHAPE_CROSS_TEXTURE:
335 retVal = tesselateCrossInWorld( tt, x, y, z );
336 break;
337 case Tile::SHAPE_STEM:
338 retVal = tesselateStemInWorld( tt, x, y, z );
339 break;
340 case Tile::SHAPE_LILYPAD:
341 retVal = tesselateLilypadInWorld( tt, x, y, z );
342 break;
343 case Tile::SHAPE_ROWS:
344 retVal = tesselateRowInWorld( tt, x, y, z );
345 break;
346 case Tile::SHAPE_TORCH:
347 retVal = tesselateTorchInWorld( tt, x, y, z );
348 break;
349 case Tile::SHAPE_FIRE:
350 retVal = tesselateFireInWorld( (FireTile *)tt, x, y, z );
351 break;
352 case Tile::SHAPE_RED_DUST:
353 retVal = tesselateDustInWorld( tt, x, y, z );
354 break;
355 case Tile::SHAPE_LADDER:
356 retVal = tesselateLadderInWorld( tt, x, y, z );
357 break;
358 case Tile::SHAPE_DOOR:
359 retVal = tesselateDoorInWorld( tt, x, y, z );
360 break;
361 case Tile::SHAPE_RAIL:
362 retVal = tesselateRailInWorld( ( RailTile* )tt, x, y, z );
363 break;
364 case Tile::SHAPE_STAIRS:
365 retVal = tesselateStairsInWorld( (StairTile *)tt, x, y, z );
366 break;
367 case Tile::SHAPE_EGG:
368 retVal = tesselateEggInWorld((EggTile*) tt, x, y, z);
369 break;
370 case Tile::SHAPE_FENCE:
371 retVal = tesselateFenceInWorld( ( FenceTile* )tt, x, y, z );
372 break;
373 case Tile::SHAPE_WALL:
374 retVal = tesselateWallInWorld( (WallTile *) tt, x, y, z);
375 break;
376 case Tile::SHAPE_LEVER:
377 retVal = tesselateLeverInWorld( tt, x, y, z );
378 break;
379 case Tile::SHAPE_TRIPWIRE_SOURCE:
380 retVal = tesselateTripwireSourceInWorld(tt, x, y, z);
381 break;
382 case Tile::SHAPE_TRIPWIRE:
383 retVal = tesselateTripwireInWorld(tt, x, y, z);
384 break;
385 case Tile::SHAPE_BED:
386 retVal = tesselateBedInWorld( tt, x, y, z );
387 break;
388 case Tile::SHAPE_REPEATER:
389 retVal = tesselateRepeaterInWorld((RepeaterTile *)tt, x, y, z);
390 break;
391 case Tile::SHAPE_DIODE:
392 retVal = tesselateDiodeInWorld( (DiodeTile *)tt, x, y, z );
393 break;
394 case Tile::SHAPE_COMPARATOR:
395 retVal = tesselateComparatorInWorld((ComparatorTile *)tt, x, y, z);
396 break;
397 case Tile::SHAPE_PISTON_BASE:
398 retVal = tesselatePistonBaseInWorld( tt, x, y, z, false, forceData );
399 break;
400 case Tile::SHAPE_PISTON_EXTENSION:
401 retVal = tesselatePistonExtensionInWorld( tt, x, y, z, true, forceData );
402 break;
403 case Tile::SHAPE_IRON_FENCE:
404 retVal = tesselateThinFenceInWorld( ( ThinFenceTile* )tt, x, y, z );
405 break;
406 case Tile::SHAPE_THIN_PANE:
407 retVal = tesselateThinPaneInWorld(tt, x, y, z);
408 break;
409 case Tile::SHAPE_VINE:
410 retVal = tesselateVineInWorld( tt, x, y, z );
411 break;
412 case Tile::SHAPE_FENCE_GATE:
413 retVal = tesselateFenceGateInWorld( ( FenceGateTile* )tt, x, y, z );
414 break;
415 case Tile::SHAPE_CAULDRON:
416 retVal = tesselateCauldronInWorld((CauldronTile* ) tt, x, y, z);
417 break;
418 case Tile::SHAPE_FLOWER_POT:
419 retVal = tesselateFlowerPotInWorld((FlowerPotTile *) tt, x, y, z);
420 break;
421 case Tile::SHAPE_ANVIL:
422 retVal = tesselateAnvilInWorld((AnvilTile *) tt, x, y, z);
423 break;
424 case Tile::SHAPE_BREWING_STAND:
425 retVal = tesselateBrewingStandInWorld((BrewingStandTile* ) tt, x, y, z);
426 break;
427 case Tile::SHAPE_PORTAL_FRAME:
428 retVal = tesselateAirPortalFrameInWorld((TheEndPortalFrameTile *)tt, x, y, z);
429 break;
430 case Tile::SHAPE_COCOA:
431 retVal = tesselateCocoaInWorld((CocoaTile *)tt, x, y, z);
432 break;
433 case Tile::SHAPE_BEACON:
434 retVal = tesselateBeaconInWorld(tt, x, y, z);
435 break;
436 case Tile::SHAPE_HOPPER:
437 retVal = tesselateHopperInWorld(tt, x, y, z);
438 break;
439 };
440
441
442 t->setMipmapEnable( true ); // 4J added
443 return retVal;
444
445}
446
447bool TileRenderer::tesselateAirPortalFrameInWorld(TheEndPortalFrameTile *tt, int x, int y, int z)
448{
449 int data = level->getData(x, y, z);
450
451 int direction = data & 3;
452 if (direction == Direction::SOUTH)
453 {
454 upFlip = FLIP_180;
455 }
456 else if (direction == Direction::EAST)
457 {
458 upFlip = FLIP_CW;
459 }
460 else if (direction == Direction::WEST)
461 {
462 upFlip = FLIP_CCW;
463 }
464
465 if (!TheEndPortalFrameTile::hasEye(data))
466 {
467 setShape(0, 0, 0, 1, 13.0f / 16.0f, 1);
468 tesselateBlockInWorld(tt, x, y, z);
469
470 upFlip = FLIP_NONE;
471 return true;
472 }
473
474 noCulling = true;
475 setShape(0, 0, 0, 1, 13.0f / 16.0f, 1);
476 tesselateBlockInWorld(tt, x, y, z);
477 setFixedTexture(tt->getEye());
478 setShape(4.0f / 16.0f, 13.0f / 16.0f, 4.0f / 16.0f, 12.0f / 16.0f, 1, 12.0f / 16.0f);
479 tesselateBlockInWorld(tt, x, y, z);
480 noCulling = false;
481 clearFixedTexture();
482
483 upFlip = FLIP_NONE;
484 return true;
485}
486
487bool TileRenderer::tesselateBedInWorld( Tile* tt, int x, int y, int z )
488{
489 Tesselator* t = Tesselator::getInstance();
490
491 int data = level->getData( x, y, z );
492 int direction = BedTile::getDirection( data );
493 bool isHead = BedTile::isHeadPiece( data );
494
495 float c10 = 0.5f;
496 float c11 = 1.0f;
497 float c2 = 0.8f;
498 float c3 = 0.6f;
499
500 float r11 = c11;
501 float g11 = c11;
502 float b11 = c11;
503
504 float r10 = c10;
505 float r2 = c2;
506 float r3 = c3;
507
508 float g10 = c10;
509 float g2 = c2;
510 float g3 = c3;
511
512 float b10 = c10;
513 float b2 = c2;
514 float b3 = c3;
515
516 // 4J - change brought forward from 1.8.2
517 int centerColor;
518 float centerBrightness;
519 if ( SharedConstants::TEXTURE_LIGHTING )
520 {
521 centerColor = getLightColor(tt, level, x, y, z );
522 }
523 else
524 {
525 centerBrightness = tt->getBrightness( level, x, y, z );
526 }
527
528 // render wooden underside
529 {
530 // 4J - change brought forward from 1.8.2
531 if ( SharedConstants::TEXTURE_LIGHTING )
532 {
533 t->tex2( centerColor );
534 t->color( r10, g10, b10 );
535 }
536 else
537 {
538 t->color( r10 * centerBrightness, g10 * centerBrightness, b10 * centerBrightness );
539 }
540
541 Icon *tex = getTexture( tt, level, x, y, z, Facing::DOWN );
542
543 float u0 = tex->getU0(true);
544 float u1 = tex->getU1(true);
545 float v0 = tex->getV0(true);
546 float v1 = tex->getV1(true);
547
548 float x0 = x + tileShapeX0;
549 float x1 = x + tileShapeX1;
550 float y0 = y + tileShapeY0 + 3.0 / 16.0;
551 float z0 = z + tileShapeZ0;
552 float z1 = z + tileShapeZ1;
553
554 t->vertexUV( x0 , y0 , z1 , u0 , v1 );
555 t->vertexUV( x0 , y0 , z0 , u0 , v0 );
556 t->vertexUV( x1 , y0 , z0 , u1 , v0 );
557 t->vertexUV( x1 , y0 , z1 , u1 , v1 );
558 }
559
560 // render bed top
561 // 4J - change brought forward from 1.8.2
562 if ( SharedConstants::TEXTURE_LIGHTING )
563 {
564 t->tex2( getLightColor(tt, level, x, y + 1, z ) );
565 t->color( r11, g11, b11 );
566 }
567 else
568 {
569 float brightness = tt->getBrightness( level, x, y + 1, z );
570 t->color( r11 * brightness, g11 * brightness, b11 * brightness );
571 }
572
573 Icon *tex = getTexture( tt, level, x, y, z, Facing::UP );
574
575 float u0 = tex->getU0(true);
576 float u1 = tex->getU1(true);
577 float v0 = tex->getV0(true);
578 float v1 = tex->getV1(true);
579
580 float topLeftU = u0;
581 float topRightU = u1;
582 float topLeftV = v0;
583 float topRightV = v0;
584 float bottomLeftU = u0;
585 float bottomRightU = u1;
586 float bottomLeftV = v1;
587 float bottomRightV = v1;
588
589 if ( direction == Direction::SOUTH )
590 {
591 // rotate 90 degrees clockwise
592 topRightU = u0;
593 topLeftV = v1;
594 bottomLeftU = u1;
595 bottomRightV = v0;
596 }
597 else if ( direction == Direction::NORTH )
598 {
599 // rotate 90 degrees counter-clockwise
600 topLeftU = u1;
601 topRightV = v1;
602 bottomRightU = u0;
603 bottomLeftV = v0;
604 }
605 else if ( direction == Direction::EAST )
606 {
607 // rotate 180 degrees
608 topLeftU = u1;
609 topRightV = v1;
610 bottomRightU = u0;
611 bottomLeftV = v0;
612 topRightU = u0;
613 topLeftV = v1;
614 bottomLeftU = u1;
615 bottomRightV = v0;
616 }
617
618 float x0 = x + tileShapeX0;
619 float x1 = x + tileShapeX1;
620 float y1 = y + tileShapeY1;
621 float z0 = z + tileShapeZ0;
622 float z1 = z + tileShapeZ1;
623
624 t->vertexUV( x1 , y1 , z1 , bottomLeftU ,bottomLeftV );
625 t->vertexUV( x1 , y1 , z0 , topLeftU , topLeftV );
626 t->vertexUV( x0 , y1 , z0 , topRightU ,topRightV );
627 t->vertexUV( x0 , y1 , z1 , bottomRightU ,bottomRightV );
628
629 // determine which edge to skip (the one between foot and head piece)
630 int skipEdge = Direction::DIRECTION_FACING[direction];
631 if ( isHead )
632 {
633 skipEdge = Direction::DIRECTION_FACING[Direction::DIRECTION_OPPOSITE[direction]];
634 }
635 // and which edge to x-flip
636 int flipEdge = Facing::WEST;
637 switch ( direction )
638 {
639 case Direction::NORTH:
640 break;
641 case Direction::SOUTH:
642 flipEdge = Facing::EAST;
643 break;
644 case Direction::EAST:
645 flipEdge = Facing::NORTH;
646 break;
647 case Direction::WEST:
648 flipEdge = Facing::SOUTH;
649 break;
650 }
651
652 if ( ( skipEdge != Facing::NORTH ) && ( noCulling || tt->shouldRenderFace( level, x, y, z - 1, Facing::NORTH ) ) )
653 {
654 if ( SharedConstants::TEXTURE_LIGHTING )
655 {
656 t->tex2( tileShapeZ0 > 0 ? centerColor : getLightColor(tt, level, x, y, z - 1 ) );
657 t->color( r2, g2, b2 );
658 }
659 else
660 {
661 float br = tt->getBrightness( level, x, y, z - 1 );
662 if ( tileShapeZ0 > 0 ) br = centerBrightness;
663 t->color( r2 * br, g2 * br, b2 * br );
664 }
665 xFlipTexture = flipEdge == Facing::NORTH;
666 renderNorth( tt, x, y, z, getTexture( tt, level, x, y, z, 2 ) );
667 }
668
669 if ( ( skipEdge != Facing::SOUTH ) && ( noCulling || tt->shouldRenderFace( level, x, y, z + 1, Facing::SOUTH ) ) )
670 {
671 if ( SharedConstants::TEXTURE_LIGHTING )
672 {
673 t->tex2( tileShapeZ1 < 1 ? centerColor : getLightColor(tt, level, x, y, z + 1 ) );
674 t->color( r2, g2, b2 );
675 }
676 else
677 {
678 float br = tt->getBrightness( level, x, y, z + 1 );
679 if ( tileShapeZ1 < 1 ) br = centerBrightness;
680 t->color( r2 * br, g2 * br, b2 * br );
681 }
682
683 xFlipTexture = flipEdge == Facing::SOUTH;
684 renderSouth( tt, x, y, z, getTexture( tt, level, x, y, z, 3 ) );
685 }
686
687 if ( ( skipEdge != Facing::WEST ) && ( noCulling || tt->shouldRenderFace( level, x - 1, y, z, Facing::WEST ) ) )
688 {
689 if ( SharedConstants::TEXTURE_LIGHTING )
690 {
691 t->tex2( tileShapeZ0 > 0 ? centerColor : getLightColor(tt, level, x - 1, y, z ) );
692 t->color( r3, g3, b3 );
693 }
694 else
695 {
696 float br = tt->getBrightness( level, x - 1, y, z );
697 if ( tileShapeX0 > 0 ) br = centerBrightness;
698 t->color( r3 * br, g3 * br, b3 * br );
699 }
700 xFlipTexture = flipEdge == Facing::WEST;
701 renderWest( tt, x, y, z, getTexture( tt, level, x, y, z, 4 ) );
702 }
703
704 if ( ( skipEdge != Facing::EAST ) && ( noCulling || tt->shouldRenderFace( level, x + 1, y, z, Facing::EAST ) ) )
705 {
706 if ( SharedConstants::TEXTURE_LIGHTING )
707 {
708 t->tex2( tileShapeZ1 < 1 ? centerColor : getLightColor(tt, level, x + 1, y, z ) );
709 t->color( r3, g3, b3 );
710 }
711 else
712 {
713 float br = tt->getBrightness( level, x + 1, y, z );
714 if ( tileShapeX1 < 1 ) br = centerBrightness;
715 t->color( r3 * br, g3 * br, b3 * br );
716 }
717 xFlipTexture = flipEdge == Facing::EAST;
718 renderEast( tt, x, y, z, getTexture( tt, level, x, y, z, 5 ) );
719 }
720 xFlipTexture = false;
721 return true;
722
723}
724
725bool TileRenderer::tesselateBrewingStandInWorld(BrewingStandTile *tt, int x, int y, int z)
726{
727 // bounding box first
728 setShape(7.0f / 16.0f, 0.0f, 7.0f / 16.0f, 9.0f / 16.0f, 14.0f / 16.0f, 9.0f / 16.0f);
729 tesselateBlockInWorld(tt, x, y, z);
730
731 setFixedTexture(tt->getBaseTexture());
732
733 // Fix faceculling when attached to blocks
734 noCulling = true;
735 setShape(9.0f / 16.0f, 0.0f, 5.0f / 16.0f, 15.0f / 16.0f, 2 / 16.0f, 11.0f / 16.0f);
736 tesselateBlockInWorld(tt, x, y, z);
737 setShape(2.0f / 16.0f, 0.0f, 1.0f / 16.0f, 8.0f / 16.0f, 2 / 16.0f, 7.0f / 16.0f);
738 tesselateBlockInWorld(tt, x, y, z);
739 setShape(2.0f / 16.0f, 0.0f, 9.0f / 16.0f, 8.0f / 16.0f, 2 / 16.0f, 15.0f / 16.0f);
740 tesselateBlockInWorld(tt, x, y, z);
741 noCulling = false;
742
743 clearFixedTexture();
744
745 Tesselator *t = Tesselator::getInstance();
746
747 float br;
748 if (SharedConstants::TEXTURE_LIGHTING)
749 {
750 t->tex2(getLightColor(tt, level, x, y, z));
751 br = 1;
752 }
753 else
754 {
755 br = tt->getBrightness(level, x, y, z);
756 }
757 int col = tt->getColor(level, x, y, z);
758 float r = ((col >> 16) & 0xff) / 255.0f;
759 float g = ((col >> 8) & 0xff) / 255.0f;
760 float b = ((col) & 0xff) / 255.0f;
761
762 t->color(br * r, br * g, br * b);
763
764 Icon *tex = getTexture(tt, 0, 0);
765
766 if (hasFixedTexture()) tex = fixedTexture;
767 float v0 = tex->getV0(true);
768 float v1 = tex->getV1(true);
769
770 int data = level->getData(x, y, z);
771
772 for (int arm = 0; arm < 3; arm++)
773 {
774
775 float angle = arm * PI * 2.0f / 3.0f + PI * 0.5f;
776
777 float u0 = tex->getU(8, true);
778 float u1 = tex->getU1(true);
779 if ((data & (1 << arm)) != 0)
780 {
781 u1 = tex->getU0(true);
782 }
783
784 float x0 = x + 8.0f / 16.0f;
785 float x1 = x + 8.0f / 16.0f + sin(angle) * 8.0f / 16.0f;
786 float z0 = z + 8.0f / 16.0f;
787 float z1 = z + 8.0f / 16.0f + cos(angle) * 8.0f / 16.0f;
788
789 t->vertexUV(x0, y + 1.0f, z0, u0, v0);
790 t->vertexUV(x0, y + 0.0f, z0, u0, v1);
791 t->vertexUV(x1, y + 0.0f, z1, u1, v1);
792 t->vertexUV(x1, y + 1.0f, z1, u1, v0);
793
794 t->vertexUV(x1, y + 1.0f, z1, u1, v0);
795 t->vertexUV(x1, y + 0.0f, z1, u1, v1);
796 t->vertexUV(x0, y + 0.0f, z0, u0, v1);
797 t->vertexUV(x0, y + 1.0f, z0, u0, v0);
798 }
799
800 tt->updateDefaultShape();
801
802 return true;
803}
804
805bool TileRenderer::tesselateCauldronInWorld(CauldronTile *tt, int x, int y, int z)
806{
807 // bounding box first
808 tesselateBlockInWorld(tt, x, y, z);
809
810 Tesselator *t = Tesselator::getInstance();
811
812 float br;
813 if (SharedConstants::TEXTURE_LIGHTING)
814 {
815 t->tex2(getLightColor(tt, level, x, y, z));
816 br = 1;
817 }
818 else
819 {
820 br = tt->getBrightness(level, x, y, z);
821 }
822 int col = tt->getColor(level, x, y, z);
823 float r = ((col >> 16) & 0xff) / 255.0f;
824 float g = ((col >> 8) & 0xff) / 255.0f;
825 float b = ((col) & 0xff) / 255.0f;
826
827 t->color(br * r, br * g, br * b);
828
829 // render inside
830 Icon *insideTex = tt->getTexture(Facing::NORTH);
831 const float cWidth = ( 2.0f / 16.0f ) - ( 1.0f / 128.0f ); // 4J - Moved by 1/128th (smallest movement possible with our vertex storage) to remove gap at edge of cauldron
832 renderEast(tt, x - 1.0f + cWidth, y, z, insideTex);
833 renderWest(tt, x + 1.0f - cWidth, y, z, insideTex);
834 renderSouth(tt, x, y, z - 1.0f + cWidth, insideTex);
835 renderNorth(tt, x, y, z + 1.0f - cWidth, insideTex);
836
837 Icon *bottomTex = CauldronTile::getTexture(CauldronTile::TEXTURE_INSIDE);
838 renderFaceUp(tt, x, y - 1.0f + 4.0f / 16.0f, z, bottomTex);
839 renderFaceDown(tt, x, y + 1.0f - 12.0f / 16.0f, z, bottomTex);
840
841 int waterLevel = level->getData(x, y, z);
842 if (waterLevel > 0)
843 {
844 Icon *liquidTex = LiquidTile::getTexture(LiquidTile::TEXTURE_WATER_STILL);
845
846 if (waterLevel > 3)
847 {
848 waterLevel = 3;
849 }
850
851 renderFaceUp(tt, x, y - 1.0f + (6.0f + waterLevel * 3.0f) / 16.0f, z, liquidTex);
852 }
853
854 return true;
855
856}
857
858bool TileRenderer::tesselateFlowerPotInWorld(FlowerPotTile *tt, int x, int y, int z)
859{
860 // bounding box first
861 tesselateBlockInWorld(tt, x, y, z);
862
863 Tesselator *t = Tesselator::getInstance();
864
865 float br;
866 if (SharedConstants::TEXTURE_LIGHTING)
867 {
868 t->tex2(tt->getLightColor(level, x, y, z));
869 br = 1;
870 }
871 else
872 {
873 br = tt->getBrightness(level, x, y, z);
874 }
875 int col = tt->getColor(level, x, y, z);
876 Icon *tex = getTexture(tt, 0);
877 float r = ((col >> 16) & 0xff) / 255.0f;
878 float g = ((col >> 8) & 0xff) / 255.0f;
879 float b = ((col) & 0xff) / 255.0f;
880
881 if (GameRenderer::anaglyph3d)
882 {
883 float cr = (r * 30 + g * 59 + b * 11) / 100;
884 float cg = (r * 30 + g * 70) / (100);
885 float cb = (r * 30 + b * 70) / (100);
886
887 r = cr;
888 g = cg;
889 b = cb;
890 }
891 t->color(br * r, br * g, br * b);
892
893 // render inside
894
895 float halfWidth = (6.0f / 16.0f) / 2 - 0.001f;
896 renderEast(tt, x - 0.5f + halfWidth, y, z, tex);
897 renderWest(tt, x + 0.5f - halfWidth, y, z, tex);
898 renderSouth(tt, x, y, z - 0.5f + halfWidth, tex);
899 renderNorth(tt, x, y, z + 0.5f - halfWidth, tex);
900
901 renderFaceUp(tt, x, y - 0.5f + halfWidth + 3.0f / 16.0f, z, getTexture(Tile::dirt));
902
903 int type = level->getData(x, y, z);
904
905 if (type != 0)
906 {
907 float xOff = 0;
908 float yOff = 4;
909 float zOff = 0;
910 Tile *plant = NULL;
911
912 switch (type)
913 {
914 case FlowerPotTile::TYPE_FLOWER_RED:
915 plant = Tile::rose;
916 break;
917 case FlowerPotTile::TYPE_FLOWER_YELLOW:
918 plant = Tile::flower;
919 break;
920 case FlowerPotTile::TYPE_MUSHROOM_BROWN:
921 plant = Tile::mushroom_brown;
922 break;
923 case FlowerPotTile::TYPE_MUSHROOM_RED:
924 plant = Tile::mushroom_red;
925 break;
926 }
927
928 t->addOffset(xOff / 16.0f, yOff / 16.0f, zOff / 16.0f);
929
930 if (plant != NULL)
931 {
932 tesselateInWorld(plant, x, y, z);
933 }
934 else
935 {
936 if (type == FlowerPotTile::TYPE_CACTUS)
937 {
938
939 // Force drawing of all faces else the cactus misses faces
940 // when a block is adjacent
941 noCulling = true;
942
943 float halfSize = 0.25f / 2;
944 setShape(0.5f - halfSize, 0.0f, 0.5f - halfSize, 0.5f + halfSize, 0.25f, 0.5f + halfSize);
945 tesselateBlockInWorld(Tile::cactus, x, y, z);
946 setShape(0.5f - halfSize, 0.25f, 0.5f - halfSize, 0.5f + halfSize, 0.5f, 0.5f + halfSize);
947 tesselateBlockInWorld(Tile::cactus, x, y, z);
948 setShape(0.5f - halfSize, 0.5f, 0.5f - halfSize, 0.5f + halfSize, 0.75f, 0.5f + halfSize);
949 tesselateBlockInWorld(Tile::cactus, x, y, z);
950
951 noCulling = false;
952
953 setShape(0, 0, 0, 1, 1, 1);
954 }
955 else if (type == FlowerPotTile::TYPE_SAPLING_DEFAULT)
956 {
957 tesselateCrossTexture(Tile::sapling, Sapling::TYPE_DEFAULT, x, y, z, 0.75f);
958 }
959 else if (type == FlowerPotTile::TYPE_SAPLING_BIRCH)
960 {
961 tesselateCrossTexture(Tile::sapling, Sapling::TYPE_BIRCH, x, y, z, 0.75f);
962 }
963 else if (type == FlowerPotTile::TYPE_SAPLING_EVERGREEN)
964 {
965 tesselateCrossTexture(Tile::sapling, Sapling::TYPE_EVERGREEN, x, y, z, 0.75f);
966 }
967 else if (type == FlowerPotTile::TYPE_SAPLING_JUNGLE)
968 {
969 tesselateCrossTexture(Tile::sapling, Sapling::TYPE_JUNGLE, x, y, z, 0.75f);
970 }
971 else if (type == FlowerPotTile::TYPE_FERN)
972 {
973 col = Tile::tallgrass->getColor(level, x, y, z);
974 r = ((col >> 16) & 0xff) / 255.0f;
975 g = ((col >> 8) & 0xff) / 255.0f;
976 b = ((col) & 0xff) / 255.0f;
977 t->color(br * r, br * g, br * b);
978 tesselateCrossTexture(Tile::tallgrass, TallGrass::FERN, x, y, z, 0.75f);
979 }
980 else if (type == FlowerPotTile::TYPE_DEAD_BUSH)
981 {
982 tesselateCrossTexture(Tile::deadBush, TallGrass::FERN, x, y, z, 0.75f);
983 }
984 }
985
986 t->addOffset(-xOff / 16.0f, -yOff / 16.0f, -zOff / 16.0f);
987 }
988
989 return true;
990}
991
992bool TileRenderer::tesselateAnvilInWorld(AnvilTile *tt, int x, int y, int z)
993{
994 return tesselateAnvilInWorld(tt, x, y, z, level->getData(x, y, z));
995
996}
997
998bool TileRenderer::tesselateAnvilInWorld(AnvilTile *tt, int x, int y, int z, int data)
999{
1000 Tesselator *t = Tesselator::getInstance();
1001
1002 float br;
1003 if (SharedConstants::TEXTURE_LIGHTING)
1004 {
1005 t->tex2(tt->getLightColor(level, x, y, z));
1006 br = 1;
1007 }
1008 else
1009 {
1010 br = tt->getBrightness(level, x, y, z);
1011 }
1012 int col = tt->getColor(level, x, y, z);
1013 float r = ((col >> 16) & 0xff) / 255.0f;
1014 float g = ((col >> 8) & 0xff) / 255.0f;
1015 float b = ((col) & 0xff) / 255.0f;
1016
1017 if (GameRenderer::anaglyph3d)
1018 {
1019 float cr = (r * 30 + g * 59 + b * 11) / 100;
1020 float cg = (r * 30 + g * 70) / (100);
1021 float cb = (r * 30 + b * 70) / (100);
1022
1023 r = cr;
1024 g = cg;
1025 b = cb;
1026 }
1027 t->color(br * r, br * g, br * b);
1028
1029 return tesselateAnvilInWorld(tt, x, y, z, data, false);
1030}
1031
1032bool TileRenderer::tesselateAnvilInWorld(AnvilTile *tt, int x, int y, int z, int data, bool render)
1033{
1034 int facing = render ? 0 : data & 3;
1035 bool rotate = false;
1036 float bottom = 0;
1037
1038 switch (facing)
1039 {
1040 case Direction::NORTH:
1041 eastFlip = FLIP_CW;
1042 westFlip = FLIP_CCW;
1043 break;
1044 case Direction::SOUTH:
1045 eastFlip = FLIP_CCW;
1046 westFlip = FLIP_CW;
1047 upFlip = FLIP_180;
1048 downFlip = FLIP_180;
1049 break;
1050 case Direction::WEST:
1051 northFlip = FLIP_CW;
1052 southFlip = FLIP_CCW;
1053 upFlip = FLIP_CCW;
1054 downFlip = FLIP_CW;
1055 rotate = true;
1056 break;
1057 case Direction::EAST:
1058 northFlip = FLIP_CCW;
1059 southFlip = FLIP_CW;
1060 upFlip = FLIP_CW;
1061 downFlip = FLIP_CCW;
1062 rotate = true;
1063 break;
1064 }
1065
1066 bottom = tesselateAnvilPiece(tt, x, y, z, AnvilTile::PART_BASE, bottom, 12.0f / 16.0f, 4.0f / 16.0f, 12.0f / 16.0f, rotate, render, data);
1067 bottom = tesselateAnvilPiece(tt, x, y, z, AnvilTile::PART_JOINT, bottom, 8.0f / 16.0f, 1.0f / 16.0f, 10.0f / 16.0f, rotate, render, data);
1068 bottom = tesselateAnvilPiece(tt, x, y, z, AnvilTile::PART_COLUMN, bottom, 4.0f / 16.0f, 5.0f / 16.0f, 8.0f / 16.0f, rotate, render, data);
1069 bottom = tesselateAnvilPiece(tt, x, y, z, AnvilTile::PART_TOP, bottom, 10.0f / 16.0f, 6.0f / 16.0f, 16.0f / 16.0f, rotate, render, data);
1070
1071 setShape(0, 0, 0, 1, 1, 1);
1072 northFlip = FLIP_NONE;
1073 southFlip = FLIP_NONE;
1074 eastFlip = FLIP_NONE;
1075 westFlip = FLIP_NONE;
1076 upFlip = FLIP_NONE;
1077 downFlip = FLIP_NONE;
1078
1079 return true;
1080}
1081
1082float TileRenderer::tesselateAnvilPiece(AnvilTile *tt, int x, int y, int z, int part, float bottom, float width, float height, float length, bool rotate, bool render, int data)
1083{
1084 if (rotate)
1085 {
1086 float swap = width;
1087 width = length;
1088 length = swap;
1089 }
1090
1091 width /= 2;
1092 length /= 2;
1093
1094 tt->part = part;
1095 setShape(0.5f - width, bottom, 0.5f - length, 0.5f + width, bottom + height, 0.5f + length);
1096
1097 if (render)
1098 {
1099 Tesselator *t = Tesselator::getInstance();
1100 t->begin();
1101 t->normal(0, -1, 0);
1102 renderFaceDown(tt, 0, 0, 0, getTexture(tt, 0, data));
1103 t->end();
1104
1105 t->begin();
1106 t->normal(0, 1, 0);
1107 renderFaceUp(tt, 0, 0, 0, getTexture(tt, 1, data));
1108 t->end();
1109
1110 t->begin();
1111 t->normal(0, 0, -1);
1112 renderNorth(tt, 0, 0, 0, getTexture(tt, 2, data));
1113 t->end();
1114
1115 t->begin();
1116 t->normal(0, 0, 1);
1117 renderSouth(tt, 0, 0, 0, getTexture(tt, 3, data));
1118 t->end();
1119
1120 t->begin();
1121 t->normal(-1, 0, 0);
1122 renderWest(tt, 0, 0, 0, getTexture(tt, 4, data));
1123 t->end();
1124
1125 t->begin();
1126 t->normal(1, 0, 0);
1127 renderEast(tt, 0, 0, 0, getTexture(tt, 5, data));
1128 t->end();
1129 }
1130 else
1131 {
1132 tesselateBlockInWorld(tt, x, y, z);
1133 }
1134
1135 return bottom + height;
1136}
1137
1138
1139
1140bool TileRenderer::tesselateTorchInWorld( Tile* tt, int x, int y, int z )
1141{
1142 int dir = level->getData( x, y, z );
1143
1144 Tesselator* t = Tesselator::getInstance();
1145
1146 if ( SharedConstants::TEXTURE_LIGHTING )
1147 {
1148 t->tex2( getLightColor(tt, level, x, y, z ) );
1149 t->color( 1.0f, 1.0f, 1.0f );
1150 }
1151 else
1152 {
1153 float br = tt->getBrightness( level, x, y, z );
1154 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
1155 t->color( br, br, br );
1156 }
1157
1158 float r = 0.40f;
1159 float r2 = 0.5f - r;
1160 float h = 0.20f;
1161 if ( dir == 1 )
1162 {
1163 tesselateTorch( tt, (float)x - r2, (float)y + h, (float)z, -r, 0.0f, 0 );
1164 }
1165 else if ( dir == 2 )
1166 {
1167 tesselateTorch( tt, (float)x + r2, (float)y + h, (float)z, +r, 0.0f, 0 );
1168 }
1169 else if ( dir == 3 )
1170 {
1171 tesselateTorch( tt, (float)x, (float)y + h, z - r2, 0.0f, -r, 0 );
1172 }
1173 else if ( dir == 4 )
1174 {
1175 tesselateTorch( tt, (float)x, (float)y + h, (float)z + r2, 0.0f, +r, 0 );
1176 }
1177 else
1178 {
1179 tesselateTorch( tt, (float)x, (float)y, (float)z, 0.0f, 0.0f, 0 );
1180 }
1181 return true;
1182
1183}
1184
1185bool TileRenderer::tesselateRepeaterInWorld(RepeaterTile *tt, int x, int y, int z)
1186{
1187 int data = level->getData(x, y, z);
1188 int dir = data & DiodeTile::DIRECTION_MASK;
1189 int delay = (data & RepeaterTile::DELAY_MASK) >> RepeaterTile::DELAY_SHIFT;
1190
1191 Tesselator *t = Tesselator::getInstance();
1192
1193 if (SharedConstants::TEXTURE_LIGHTING)
1194 {
1195 t->tex2(tt->getLightColor(level, x, y, z));
1196 t->color(1.0f, 1.0f, 1.0f);
1197 }
1198 else
1199 {
1200 float br = tt->getBrightness(level, x, y, z);
1201 if (Tile::lightEmission[tt->id] > 0) br = 1.0f;
1202 t->color(br, br, br);
1203 }
1204
1205 double h = -3.0f / 16.0f;
1206 bool hasLockSignal = tt->isLocked(level, x, y, z, data);
1207 double transmitterX = 0;
1208 double transmitterZ = 0;
1209 double receiverX = 0;
1210 double receiverZ = 0;
1211
1212 switch (dir)
1213 {
1214 case Direction::SOUTH:
1215 receiverZ = -5.0f / 16.0f;
1216 transmitterZ = RepeaterTile::DELAY_RENDER_OFFSETS[delay];
1217 break;
1218 case Direction::NORTH:
1219 receiverZ = 5.0f / 16.0f;
1220 transmitterZ = -RepeaterTile::DELAY_RENDER_OFFSETS[delay];
1221 break;
1222 case Direction::EAST:
1223 receiverX = -5.0f / 16.0f;
1224 transmitterX = RepeaterTile::DELAY_RENDER_OFFSETS[delay];
1225 break;
1226 case Direction::WEST:
1227 receiverX = 5.0f / 16.0f;
1228 transmitterX = -RepeaterTile::DELAY_RENDER_OFFSETS[delay];
1229 break;
1230 }
1231
1232 // render transmitter
1233 if (!hasLockSignal)
1234 {
1235 tesselateTorch((Tile *)tt, x + transmitterX, y + h, z + transmitterZ, 0, 0, 0);
1236 }
1237 else
1238 {
1239 Icon *lockTex = getTexture(Tile::unbreakable);
1240 setFixedTexture(lockTex);
1241
1242 float west = 2.0f;
1243 float east = 14.0f;
1244 float north = 7.0f;
1245 float south = 9.0f;
1246
1247 switch (dir)
1248 {
1249 case Direction::SOUTH:
1250 case Direction::NORTH:
1251 break;
1252 case Direction::EAST:
1253 case Direction::WEST:
1254 west = 7.f;
1255 east = 9.f;
1256 north = 2.f;
1257 south = 14.f;
1258 break;
1259 }
1260 setShape(west / 16.0f + (float) transmitterX, 2.f / 16.0f, north / 16.0f + (float) transmitterZ, east / 16.0f + (float) transmitterX, 4.f / 16.0f, south / 16.0f + (float) transmitterZ);
1261 double u0 = lockTex->getU(west);
1262 double v0 = lockTex->getV(north);
1263 double u1 = lockTex->getU(east);
1264 double v1 = lockTex->getV(south);
1265 t->vertexUV(x + west / 16.0f + transmitterX, y + 4.0f / 16.0f, z + north / 16.0f + transmitterZ, u0, v0);
1266 t->vertexUV(x + west / 16.0f + transmitterX, y + 4.0f / 16.0f, z + south / 16.0f + transmitterZ, u0, v1);
1267 t->vertexUV(x + east / 16.0f + transmitterX, y + 4.0f / 16.0f, z + south / 16.0f + transmitterZ, u1, v1);
1268 t->vertexUV(x + east / 16.0f + transmitterX, y + 4.0f / 16.0f, z + north / 16.0f + transmitterZ, u1, v0);
1269 tesselateBlockInWorld(tt, x, y, z);
1270 setShape(0, 0, 0, 1, 2.0f / 16.0f, 1);
1271 clearFixedTexture();
1272 }
1273
1274 if (SharedConstants::TEXTURE_LIGHTING)
1275 {
1276 t->tex2(tt->getLightColor(level, x, y, z));
1277 t->color(1.0f, 1.0f, 1.0f);
1278 }
1279 else
1280 {
1281 float br = tt->getBrightness(level, x, y, z);
1282 if (Tile::lightEmission[tt->id] > 0) br = 1.0f;
1283 t->color(br, br, br);
1284 }
1285
1286 // render receiver
1287 tesselateTorch(tt, x + receiverX, y + h, z + receiverZ, 0, 0, 0);
1288
1289 // render floor
1290 tesselateDiodeInWorld(tt, x, y, z);
1291
1292 return true;
1293}
1294
1295bool TileRenderer::tesselateComparatorInWorld(ComparatorTile *tt, int x, int y, int z)
1296{
1297 Tesselator *t = Tesselator::getInstance();
1298
1299 if (SharedConstants::TEXTURE_LIGHTING)
1300 {
1301 t->tex2(tt->getLightColor(level, x, y, z));
1302 t->color(1.0f, 1.0f, 1.0f);
1303 }
1304 else
1305 {
1306 float br = tt->getBrightness(level, x, y, z);
1307 if (Tile::lightEmission[tt->id] > 0) br = 1.0f;
1308 t->color(br, br, br);
1309 }
1310
1311 int data = level->getData(x, y, z);
1312 int dir = data & DirectionalTile::DIRECTION_MASK;
1313 double extenderX = 0;
1314 double extenderY = -3.0f / 16.0f;
1315 double extenderZ = 0;
1316 double inputXStep = 0;
1317 double inputZStep = 0;
1318 Icon *extenderTex;
1319
1320 if (tt->isReversedOutputSignal(data))
1321 {
1322 extenderTex = Tile::redstoneTorch_on->getTexture(Facing::DOWN);
1323 }
1324 else
1325 {
1326 extenderY -= 3 / 16.0f;
1327 extenderTex = Tile::redstoneTorch_off->getTexture(Facing::DOWN);
1328 }
1329
1330 switch (dir)
1331 {
1332 case Direction::SOUTH:
1333 extenderZ = -5.0f / 16.0f;
1334 inputZStep = 1;
1335 break;
1336 case Direction::NORTH:
1337 extenderZ = 5.0f / 16.0f;
1338 inputZStep = -1;
1339 break;
1340 case Direction::EAST:
1341 extenderX = -5.0f / 16.0f;
1342 inputXStep = 1;
1343 break;
1344 case Direction::WEST:
1345 extenderX = 5.0f / 16.0f;
1346 inputXStep = -1;
1347 break;
1348 }
1349
1350 // Render the two input torches
1351 tesselateTorch((Tile *)tt, x + (4 / 16.0f * inputXStep) + (3 / 16.0f * inputZStep), y - 3 / 16.0f, z + (4 / 16.0f * inputZStep) + (3 / 16.0f * inputXStep), 0, 0, data);
1352 tesselateTorch((Tile *)tt, x + (4 / 16.0f * inputXStep) + (-3 / 16.0f * inputZStep), y - 3 / 16.0f, z + (4 / 16.0f * inputZStep) + (-3 / 16.0f * inputXStep), 0, 0, data);
1353
1354 setFixedTexture(extenderTex);
1355 tesselateTorch((Tile *)tt, x + extenderX, y + extenderY, z + extenderZ, 0, 0, data);
1356 clearFixedTexture();
1357
1358 tesselateDiodeInWorld((DiodeTile *)tt, x, y, z, dir);
1359
1360 return true;
1361}
1362
1363bool TileRenderer::tesselateDiodeInWorld(DiodeTile *tt, int x, int y, int z)
1364{
1365 Tesselator *t = Tesselator::getInstance();
1366
1367 tesselateDiodeInWorld(tt, x, y, z, level->getData(x, y, z) & DiodeTile::DIRECTION_MASK);
1368
1369 return true;
1370}
1371
1372void TileRenderer::tesselateDiodeInWorld( DiodeTile* tt, int x, int y, int z, int dir )
1373{
1374 // render half-block edges
1375 tesselateBlockInWorld( tt, x, y, z );
1376
1377 Tesselator* t = Tesselator::getInstance();
1378
1379 if ( SharedConstants::TEXTURE_LIGHTING )
1380 {
1381 t->tex2( getLightColor(tt, level, x, y, z ) );
1382 t->color( 1.0f, 1.0f, 1.0f );
1383 }
1384 else
1385 {
1386 float br = tt->getBrightness( level, x, y, z );
1387 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
1388 t->color( br, br, br );
1389 }
1390
1391 int data = level->getData(x, y, z);
1392
1393 // 4J-JEV - It's now been moved.
1394 // 4J Stu - This block gets moved in a later version, but we don't need that yet
1395
1396
1397 Icon *tex = getTexture(tt, Facing::UP, data);
1398 float u0 = tex->getU0(true);
1399 float u1 = tex->getU1(true);
1400 float v0 = tex->getV0(true);
1401 float v1 = tex->getV1(true);
1402
1403 float r = 2.0f / 16.0f;
1404
1405 float x0 = ( float )( x + 1.0f );
1406 float x1 = ( float )( x + 1.0f );
1407 float x2 = ( float )( x + 0.0f );
1408 float x3 = ( float )( x + 0.0f );
1409
1410 float z0 = ( float )( z + 0.0f );
1411 float z1 = ( float )( z + 1.0f );
1412 float z2 = ( float )( z + 1.0f );
1413 float z3 = ( float )( z + 0.0f );
1414
1415 float y0 = ( float )( y + r );
1416
1417 if ( dir == Direction::NORTH )
1418 {
1419 // rotate 180 degrees
1420 x0 = x1 = ( float )( x + 0.0f );
1421 x2 = x3 = ( float )( x + 1.0f );
1422 z0 = z3 = ( float )( z + 1.0f );
1423 z1 = z2 = ( float )( z + 0.0f );
1424 }
1425 else if ( dir == Direction::EAST )
1426 {
1427 // rotate 90 degrees counter-clockwise
1428 x0 = x3 = ( float )( x + 0.0f );
1429 x1 = x2 = ( float )( x + 1.0f );
1430 z0 = z1 = ( float )( z + 0.0f );
1431 z2 = z3 = ( float )( z + 1.0f );
1432 }
1433 else if ( dir == Direction::WEST )
1434 {
1435 // rotate 90 degrees clockwise
1436 x0 = x3 = ( float )( x + 1.0f );
1437 x1 = x2 = ( float )( x + 0.0f );
1438 z0 = z1 = ( float )( z + 1.0f );
1439 z2 = z3 = ( float )( z + 0.0f );
1440 }
1441
1442 t->vertexUV( x3 , y0 , z3 , u0 , v0 );
1443 t->vertexUV( x2 , y0 , z2 , u0 , v1 );
1444 t->vertexUV( x1 , y0 , z1 , u1 , v1 );
1445 t->vertexUV( x0 , y0 , z0 , u1 , v0 );
1446}
1447
1448void TileRenderer::tesselatePistonBaseForceExtended( Tile* tile, int x, int y, int z, int forceData ) // 4J added forceData param
1449{
1450 noCulling = true;
1451 tesselatePistonBaseInWorld( tile, x, y, z, true, forceData );
1452 noCulling = false;
1453}
1454
1455bool TileRenderer::tesselatePistonBaseInWorld( Tile* tt, int x, int y, int z, bool forceExtended, int forceData ) // 4J added forceData param
1456{
1457 int data = ( forceData == -1 ) ? level->getData( x, y, z ) : forceData;
1458 bool extended = forceExtended || ( data & PistonBaseTile::EXTENDED_BIT ) != 0;
1459 int facing = PistonBaseTile::getFacing( data );
1460
1461 const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
1462
1463 if ( extended )
1464 {
1465 switch ( facing )
1466 {
1467 case Facing::DOWN:
1468 northFlip = FLIP_180;
1469 southFlip = FLIP_180;
1470 eastFlip = FLIP_180;
1471 westFlip = FLIP_180;
1472 setShape( 0.0f, thickness, 0.0f, 1.0f, 1.0f, 1.0f );
1473 break;
1474 case Facing::UP:
1475 setShape( 0.0f, 0.0f, 0.0f, 1.0f, 1.0f - thickness, 1.0f );
1476 break;
1477 case Facing::NORTH:
1478 eastFlip = FLIP_CW;
1479 westFlip = FLIP_CCW;
1480 setShape( 0.0f, 0.0f, thickness, 1.0f, 1.0f, 1.0f );
1481 break;
1482 case Facing::SOUTH:
1483 eastFlip = FLIP_CCW;
1484 westFlip = FLIP_CW;
1485 upFlip = FLIP_180;
1486 downFlip = FLIP_180;
1487 setShape( 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f - thickness );
1488 break;
1489 case Facing::WEST:
1490 northFlip = FLIP_CW;
1491 southFlip = FLIP_CCW;
1492 upFlip = FLIP_CCW;
1493 downFlip = FLIP_CW;
1494 setShape( thickness, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f );
1495 break;
1496 case Facing::EAST:
1497 northFlip = FLIP_CCW;
1498 southFlip = FLIP_CW;
1499 upFlip = FLIP_CW;
1500 downFlip = FLIP_CCW;
1501 setShape( 0.0f, 0.0f, 0.0f, 1.0f - thickness, 1.0f, 1.0f );
1502 break;
1503 }
1504 // weird way of telling the piston to use the
1505 // "inside" texture for the forward-facing edge
1506 ((PistonBaseTile *) tt)->updateShape((float) tileShapeX0, (float) tileShapeY0, (float) tileShapeZ0, (float) tileShapeX1, (float) tileShapeY1, (float) tileShapeZ1);
1507 tesselateBlockInWorld( tt, x, y, z );
1508 northFlip = FLIP_NONE;
1509 southFlip = FLIP_NONE;
1510 eastFlip = FLIP_NONE;
1511 westFlip = FLIP_NONE;
1512 upFlip = FLIP_NONE;
1513 downFlip = FLIP_NONE;
1514 ((PistonBaseTile *) tt)->updateShape((float) tileShapeX0, (float) tileShapeY0, (float) tileShapeZ0, (float) tileShapeX1, (float) tileShapeY1, (float) tileShapeZ1);
1515 }
1516 else
1517 {
1518 switch ( facing )
1519 {
1520 case Facing::DOWN:
1521 northFlip = FLIP_180;
1522 southFlip = FLIP_180;
1523 eastFlip = FLIP_180;
1524 westFlip = FLIP_180;
1525 break;
1526 case Facing::UP:
1527 break;
1528 case Facing::NORTH:
1529 eastFlip = FLIP_CW;
1530 westFlip = FLIP_CCW;
1531 break;
1532 case Facing::SOUTH:
1533 eastFlip = FLIP_CCW;
1534 westFlip = FLIP_CW;
1535 upFlip = FLIP_180;
1536 downFlip = FLIP_180;
1537 break;
1538 case Facing::WEST:
1539 northFlip = FLIP_CW;
1540 southFlip = FLIP_CCW;
1541 upFlip = FLIP_CCW;
1542 downFlip = FLIP_CW;
1543 break;
1544 case Facing::EAST:
1545 northFlip = FLIP_CCW;
1546 southFlip = FLIP_CW;
1547 upFlip = FLIP_CW;
1548 downFlip = FLIP_CCW;
1549 break;
1550 }
1551 tesselateBlockInWorld( tt, x, y, z );
1552 northFlip = FLIP_NONE;
1553 southFlip = FLIP_NONE;
1554 eastFlip = FLIP_NONE;
1555 westFlip = FLIP_NONE;
1556 upFlip = FLIP_NONE;
1557 downFlip = FLIP_NONE;
1558 }
1559
1560 return true;
1561
1562}
1563
1564void TileRenderer::renderPistonArmUpDown( float x0, float x1, float y0, float y1, float z0, float z1, float br,
1565 float armLengthPixels )
1566{
1567 Icon *armTex = PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX);
1568 if (hasFixedTexture()) armTex = fixedTexture;
1569
1570 Tesselator* t = Tesselator::getInstance();
1571
1572 // upwards arm
1573 float u00 = armTex->getU0(true);
1574 float v00 = armTex->getV0(true);
1575 float u11 = armTex->getU(armLengthPixels, true);
1576 float v11 = armTex->getV(PistonBaseTile::PLATFORM_THICKNESS, true);
1577
1578 t->color( br, br, br );
1579
1580 t->vertexUV( x0, y1, z0, u11, v00 );
1581 t->vertexUV( x0, y0, z0, u00, v00 );
1582 t->vertexUV( x1, y0, z1, u00, v11 );
1583 t->vertexUV( x1, y1, z1, u11, v11 );
1584
1585}
1586
1587void TileRenderer::renderPistonArmNorthSouth( float x0, float x1, float y0, float y1, float z0, float z1,
1588 float br, float armLengthPixels )
1589{
1590 Icon *armTex = PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX);
1591 if (hasFixedTexture()) armTex = fixedTexture;
1592
1593 Tesselator* t = Tesselator::getInstance();
1594
1595 // upwards arm
1596 float u00 = armTex->getU0(true);
1597 float v00 = armTex->getV0(true);
1598 float u11 = armTex->getU(armLengthPixels, true);
1599 float v11 = armTex->getV(PistonBaseTile::PLATFORM_THICKNESS, true);
1600
1601 t->color( br, br, br );
1602
1603 t->vertexUV( x0, y0, z1, u11, v00 );
1604 t->vertexUV( x0, y0, z0, u00, v00 );
1605 t->vertexUV( x1, y1, z0, u00, v11 );
1606 t->vertexUV( x1, y1, z1, u11, v11 );
1607}
1608
1609void TileRenderer::renderPistonArmEastWest( float x0, float x1, float y0, float y1, float z0, float z1, float br,
1610 float armLengthPixels )
1611{
1612 Icon *armTex = PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX);
1613 if (hasFixedTexture()) armTex = fixedTexture;
1614
1615 Tesselator* t = Tesselator::getInstance();
1616
1617 // upwards arm
1618 float u00 = armTex->getU0(true);
1619 float v00 = armTex->getV0(true);
1620 float u11 = armTex->getU(armLengthPixels, true);
1621 float v11 = armTex->getV(PistonBaseTile::PLATFORM_THICKNESS, true);
1622
1623 t->color( br, br, br );
1624
1625 t->vertexUV( x1, y0, z0, u11, v00 );
1626 t->vertexUV( x0, y0, z0, u00, v00 );
1627 t->vertexUV( x0, y1, z1, u00, v11 );
1628 t->vertexUV( x1, y1, z1, u11, v11 );
1629}
1630
1631void TileRenderer::tesselatePistonArmNoCulling( Tile* tile, int x, int y, int z, bool fullArm, int forceData ) // 4J added forceData param
1632{
1633 noCulling = true;
1634 tesselatePistonExtensionInWorld( tile, x, y, z, fullArm );
1635 noCulling = false;
1636}
1637
1638bool TileRenderer::tesselatePistonExtensionInWorld( Tile* tt, int x, int y, int z, bool fullArm, int forceData ) // 4J added forceData param
1639{
1640 int data = ( forceData == -1 ) ? level->getData( x, y, z ) : forceData;
1641 int facing = PistonExtensionTile::getFacing( data );
1642
1643 const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
1644 const float leftEdge = ( 8.0f - ( PistonBaseTile::PLATFORM_THICKNESS / 2.0f ) ) / 16.0f;
1645 const float rightEdge = ( 8.0f + ( PistonBaseTile::PLATFORM_THICKNESS / 2.0f ) ) / 16.0f;
1646 const float br = tt->getBrightness( level, x, y, z );
1647 const float armLength = fullArm ? 1.0f : 0.5f;
1648 const float armLengthPixels = fullArm ? 16.0f : 8.0f;
1649
1650 Tesselator* t = Tesselator::getInstance();
1651 switch ( facing )
1652 {
1653 case Facing::DOWN:
1654 northFlip = FLIP_180;
1655 southFlip = FLIP_180;
1656 eastFlip = FLIP_180;
1657 westFlip = FLIP_180;
1658 setShape( 0.0f, 0.0f, 0.0f, 1.0f, thickness, 1.0f );
1659 tesselateBlockInWorld( tt, x, y, z );
1660
1661 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1662 renderPistonArmUpDown( x + leftEdge, x + rightEdge, y + thickness, y + thickness + armLength,
1663 z + rightEdge, z + rightEdge, br * 0.8f, armLengthPixels );
1664 renderPistonArmUpDown( x + rightEdge, x + leftEdge, y + thickness, y + thickness + armLength, z + leftEdge,
1665 z + leftEdge, br * 0.8f, armLengthPixels );
1666 renderPistonArmUpDown( x + leftEdge, x + leftEdge, y + thickness, y + thickness + armLength, z + leftEdge,
1667 z + rightEdge, br * 0.6f, armLengthPixels );
1668 renderPistonArmUpDown( x + rightEdge, x + rightEdge, y + thickness, y + thickness + armLength,
1669 z + rightEdge, z + leftEdge, br * 0.6f, armLengthPixels );
1670
1671 break;
1672 case Facing::UP:
1673 setShape( 0.0f, 1.0f - thickness, 0.0f, 1.0f, 1.0f, 1.0f );
1674 tesselateBlockInWorld( tt, x, y, z );
1675
1676 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1677 renderPistonArmUpDown( x + leftEdge, x + rightEdge, y - thickness + 1.0f - armLength, y - thickness + 1.0f,
1678 z + rightEdge, z + rightEdge, br * 0.8f, armLengthPixels );
1679 renderPistonArmUpDown( x + rightEdge, x + leftEdge, y - thickness + 1.0f - armLength, y - thickness + 1.0f,
1680 z + leftEdge, z + leftEdge, br * 0.8f, armLengthPixels );
1681 renderPistonArmUpDown( x + leftEdge, x + leftEdge, y - thickness + 1.0f - armLength, y - thickness + 1.0f,
1682 z + leftEdge, z + rightEdge, br * 0.6f, armLengthPixels );
1683 renderPistonArmUpDown( x + rightEdge, x + rightEdge, y - thickness + 1.0f - armLength,
1684 y - thickness + 1.0f, z + rightEdge, z + leftEdge, br * 0.6f, armLengthPixels );
1685 break;
1686 case Facing::NORTH:
1687 eastFlip = FLIP_CW;
1688 westFlip = FLIP_CCW;
1689 setShape( 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, thickness );
1690 tesselateBlockInWorld( tt, x, y, z );
1691
1692 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1693 renderPistonArmNorthSouth( x + leftEdge, x + leftEdge, y + rightEdge, y + leftEdge, z + thickness,
1694 z + thickness + armLength, br * 0.6f, armLengthPixels );
1695 renderPistonArmNorthSouth( x + rightEdge, x + rightEdge, y + leftEdge, y + rightEdge, z + thickness,
1696 z + thickness + armLength, br * 0.6f, armLengthPixels );
1697 renderPistonArmNorthSouth( x + leftEdge, x + rightEdge, y + leftEdge, y + leftEdge, z + thickness,
1698 z + thickness + armLength, br * 0.5f, armLengthPixels );
1699 renderPistonArmNorthSouth( x + rightEdge, x + leftEdge, y + rightEdge, y + rightEdge, z + thickness,
1700 z + thickness + armLength, br, armLengthPixels );
1701 break;
1702 case Facing::SOUTH:
1703 eastFlip = FLIP_CCW;
1704 westFlip = FLIP_CW;
1705 upFlip = FLIP_180;
1706 downFlip = FLIP_180;
1707 setShape( 0.0f, 0.0f, 1.0f - thickness, 1.0f, 1.0f, 1.0f );
1708 tesselateBlockInWorld( tt, x, y, z );
1709
1710 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1711 renderPistonArmNorthSouth( x + leftEdge, x + leftEdge, y + rightEdge, y + leftEdge,
1712 z - thickness + 1.0f - armLength, z - thickness + 1.0f, br * 0.6f,
1713 armLengthPixels );
1714 renderPistonArmNorthSouth( x + rightEdge, x + rightEdge, y + leftEdge, y + rightEdge,
1715 z - thickness + 1.0f - armLength, z - thickness + 1.0f, br * 0.6f,
1716 armLengthPixels );
1717 renderPistonArmNorthSouth( x + leftEdge, x + rightEdge, y + leftEdge, y + leftEdge,
1718 z - thickness + 1.0f - armLength, z - thickness + 1.0f, br * 0.5f,
1719 armLengthPixels );
1720 renderPistonArmNorthSouth( x + rightEdge, x + leftEdge, y + rightEdge, y + rightEdge,
1721 z - thickness + 1.0f - armLength, z - thickness + 1.0f, br, armLengthPixels );
1722 break;
1723 case Facing::WEST:
1724 northFlip = FLIP_CW;
1725 southFlip = FLIP_CCW;
1726 upFlip = FLIP_CCW;
1727 downFlip = FLIP_CW;
1728 setShape( 0.0f, 0.0f, 0.0f, thickness, 1.0f, 1.0f );
1729 tesselateBlockInWorld( tt, x, y, z ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1730
1731 t->tex2( getLightColor(tt, level, x, y , z ) );
1732 renderPistonArmEastWest( x + thickness, x + thickness + armLength, y + leftEdge, y + leftEdge,
1733 z + rightEdge, z + leftEdge, br * 0.5f, armLengthPixels );
1734 renderPistonArmEastWest( x + thickness, x + thickness + armLength, y + rightEdge, y + rightEdge,
1735 z + leftEdge, z + rightEdge, br, armLengthPixels );
1736 renderPistonArmEastWest( x + thickness, x + thickness + armLength, y + leftEdge, y + rightEdge,
1737 z + leftEdge, z + leftEdge, br * 0.6f, armLengthPixels );
1738 renderPistonArmEastWest( x + thickness, x + thickness + armLength, y + rightEdge, y + leftEdge,
1739 z + rightEdge, z + rightEdge, br * 0.6f, armLengthPixels );
1740 break;
1741 case Facing::EAST:
1742 northFlip = FLIP_CCW;
1743 southFlip = FLIP_CW;
1744 upFlip = FLIP_CW;
1745 downFlip = FLIP_CCW;
1746 setShape( 1.0f - thickness, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f );
1747 tesselateBlockInWorld( tt, x, y, z );
1748
1749 t->tex2( getLightColor(tt, level, x, y , z ) ); // 4J added - renderPistonArmDown doesn't set its own tex2 so just inherited from previous tesselateBlockInWorld
1750 renderPistonArmEastWest( x - thickness + 1.0f - armLength, x - thickness + 1.0f, y + leftEdge,
1751 y + leftEdge, z + rightEdge, z + leftEdge, br * 0.5f, armLengthPixels );
1752 renderPistonArmEastWest( x - thickness + 1.0f - armLength, x - thickness + 1.0f, y + rightEdge,
1753 y + rightEdge, z + leftEdge, z + rightEdge, br, armLengthPixels );
1754 renderPistonArmEastWest( x - thickness + 1.0f - armLength, x - thickness + 1.0f, y + leftEdge,
1755 y + rightEdge, z + leftEdge, z + leftEdge, br * 0.6f, armLengthPixels );
1756 renderPistonArmEastWest( x - thickness + 1.0f - armLength, x - thickness + 1.0f, y + rightEdge,
1757 y + leftEdge, z + rightEdge, z + rightEdge, br * 0.6f, armLengthPixels );
1758 break;
1759 }
1760 northFlip = FLIP_NONE;
1761 southFlip = FLIP_NONE;
1762 eastFlip = FLIP_NONE;
1763 westFlip = FLIP_NONE;
1764 upFlip = FLIP_NONE;
1765 downFlip = FLIP_NONE;
1766 setShape( 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f );
1767
1768 return true;
1769
1770}
1771
1772bool TileRenderer::tesselateLeverInWorld( Tile* tt, int x, int y, int z )
1773{
1774 int data = level->getData( x, y, z );
1775
1776 int dir = data & 7;
1777 bool flipped = ( data & 8 ) > 0;
1778
1779 Tesselator* t = Tesselator::getInstance();
1780
1781 bool hadFixed = hasFixedTexture();
1782 if (!hadFixed) this->setFixedTexture(getTexture(Tile::cobblestone));
1783 float w1 = 4.0f / 16.0f;
1784 float w2 = 3.0f / 16.0f;
1785 float h = 3.0f / 16.0f;
1786
1787 if ( dir == 5 )
1788 {
1789 setShape( 0.5f - w2, 0.0f, 0.5f - w1, 0.5f + w2, h, 0.5f + w1 );
1790 }
1791 else if ( dir == 6 )
1792 {
1793 setShape( 0.5f - w1, 0.0f, 0.5f - w2, 0.5f + w1, h, 0.5f + w2 );
1794 }
1795 else if ( dir == 4 )
1796 {
1797 setShape( 0.5f - w2, 0.5f - w1, 1.0f - h, 0.5f + w2, 0.5f + w1, 1.0f );
1798 }
1799 else if ( dir == 3 )
1800 {
1801 setShape( 0.5f - w2, 0.5f - w1, 0, 0.5f + w2, 0.5f + w1, h );
1802 }
1803 else if ( dir == 2 )
1804 {
1805 setShape( 1.0f - h, 0.5f - w1, 0.5f - w2, 1.0f, 0.5f + w1, 0.5f + w2 );
1806 }
1807 else if ( dir == 1 )
1808 {
1809 setShape( 0, 0.5f - w1, 0.5f - w2, h, 0.5f + w1, 0.5f + w2 );
1810 }
1811 else if (dir == 0)
1812 {
1813 setShape(0.5f - w1, 1 - h, 0.5f - w2, 0.5f + w1, 1, 0.5f + w2);
1814 }
1815 else if (dir == 7)
1816 {
1817 setShape(0.5f - w2, 1 - h, 0.5f - w1, 0.5f + w2, 1, 0.5f + w1);
1818 }
1819 this->tesselateBlockInWorld( tt, x, y, z );
1820
1821 if ( !hadFixed ) this->clearFixedTexture();
1822
1823 float br;
1824 if ( SharedConstants::TEXTURE_LIGHTING )
1825 {
1826 t->tex2( getLightColor(tt, level, x, y, z ) );
1827 br = 1;
1828 }
1829 else
1830 {
1831 br = tt->getBrightness( level, x, y, z );
1832 }
1833 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
1834 t->color( br, br, br );
1835 Icon *tex = getTexture(tt, 0);
1836
1837 if (hasFixedTexture()) tex = fixedTexture;
1838 float u0 = tex->getU0(true);
1839 float v0 = tex->getV0(true);
1840 float u1 = tex->getU1(true);
1841 float v1 = tex->getV1(true);
1842
1843 Vec3* corners[8];
1844 float xv = 1.0f / 16.0f;
1845 float zv = 1.0f / 16.0f;
1846 float yv = 10.0f / 16.0f;
1847 corners[0] = Vec3::newTemp( -xv, -0, -zv );
1848 corners[1] = Vec3::newTemp( +xv, -0, -zv );
1849 corners[2] = Vec3::newTemp( +xv, -0, +zv );
1850 corners[3] = Vec3::newTemp( -xv, -0, +zv );
1851 corners[4] = Vec3::newTemp( -xv, +yv, -zv );
1852 corners[5] = Vec3::newTemp( +xv, +yv, -zv );
1853 corners[6] = Vec3::newTemp( +xv, +yv, +zv );
1854 corners[7] = Vec3::newTemp( -xv, +yv, +zv );
1855
1856 for ( int i = 0; i < 8; i++ )
1857 {
1858 if ( flipped )
1859 {
1860 corners[i]->z -= 1 / 16.0f;
1861 corners[i]->xRot( 40 * PI / 180 );
1862 }
1863 else
1864 {
1865 corners[i]->z += 1 / 16.0f;
1866 corners[i]->xRot( -40 * PI / 180 );
1867 }
1868 if (dir == 0 || dir == 7)
1869 {
1870 corners[i]->zRot(180 * PI / 180);
1871 }
1872 if ( dir == 6 || dir == 0 )
1873 {
1874 corners[i]->yRot( 90 * PI / 180 );
1875 }
1876
1877 if ( dir > 0 && dir < 5 )
1878 {
1879 corners[i]->y -= 6 / 16.0f;
1880 corners[i]->xRot( 90 * PI / 180 );
1881
1882 if ( dir == 4 ) corners[i]->yRot( 0 * PI / 180 );
1883 if ( dir == 3 ) corners[i]->yRot( 180 * PI / 180 );
1884 if ( dir == 2 ) corners[i]->yRot( 90 * PI / 180 );
1885 if ( dir == 1 ) corners[i]->yRot( -90 * PI / 180 );
1886
1887 corners[i]->x += x + 0.5;
1888 corners[i]->y += y + 8 / 16.0f;
1889 corners[i]->z += z + 0.5;
1890 }
1891 else if (dir == 0 || dir == 7)
1892 {
1893 corners[i]->x += x + 0.5;
1894 corners[i]->y += y + 14 / 16.0f;
1895 corners[i]->z += z + 0.5;
1896 }
1897 else
1898 {
1899 corners[i]->x += x + 0.5;
1900 corners[i]->y += y + 2 / 16.0f;
1901 corners[i]->z += z + 0.5;
1902 }
1903 }
1904
1905 Vec3* c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL;
1906 for ( int i = 0; i < 6; i++ )
1907 {
1908 if ( i == 0 )
1909 {
1910 u0 = tex->getU(7, true);
1911 v0 = tex->getV(6, true);
1912 u1 = tex->getU(9, true);
1913 v1 = tex->getV(8, true);
1914 }
1915 else if ( i == 2 )
1916 {
1917 u0 = tex->getU(7, true);
1918 v0 = tex->getV(6, true);
1919 u1 = tex->getU(9, true);
1920 v1 = tex->getV1(true);
1921 }
1922 if ( i == 0 )
1923 {
1924 c0 = corners[0];
1925 c1 = corners[1];
1926 c2 = corners[2];
1927 c3 = corners[3];
1928 }
1929 else if ( i == 1 )
1930 {
1931 c0 = corners[7];
1932 c1 = corners[6];
1933 c2 = corners[5];
1934 c3 = corners[4];
1935 }
1936 else if ( i == 2 )
1937 {
1938 c0 = corners[1];
1939 c1 = corners[0];
1940 c2 = corners[4];
1941 c3 = corners[5];
1942 }
1943 else if ( i == 3 )
1944 {
1945 c0 = corners[2];
1946 c1 = corners[1];
1947 c2 = corners[5];
1948 c3 = corners[6];
1949 }
1950 else if ( i == 4 )
1951 {
1952 c0 = corners[3];
1953 c1 = corners[2];
1954 c2 = corners[6];
1955 c3 = corners[7];
1956 }
1957 else if ( i == 5 )
1958 {
1959 c0 = corners[0];
1960 c1 = corners[3];
1961 c2 = corners[7];
1962 c3 = corners[4];
1963 }
1964 t->vertexUV( ( float )( c0->x ), ( float )( c0->y ), ( float )( c0->z ), ( float )( u0 ), ( float )( v1 ) );
1965 t->vertexUV( ( float )( c1->x ), ( float )( c1->y ), ( float )( c1->z ), ( float )( u1 ), ( float )( v1 ) );
1966 t->vertexUV( ( float )( c2->x ), ( float )( c2->y ), ( float )( c2->z ), ( float )( u1 ), ( float )( v0 ) );
1967 t->vertexUV( ( float )( c3->x ), ( float )( c3->y ), ( float )( c3->z ), ( float )( u0 ), ( float )( v0 ) );
1968 }
1969 return true;
1970
1971}
1972
1973bool TileRenderer::tesselateTripwireSourceInWorld(Tile *tt, int x, int y, int z)
1974{
1975 Tesselator *t = Tesselator::getInstance();
1976 int data = level->getData(x, y, z);
1977 int dir = data & TripWireSourceTile::MASK_DIR;
1978 bool attached = (data & TripWireSourceTile::MASK_ATTACHED) == TripWireSourceTile::MASK_ATTACHED;
1979 bool powered = (data & TripWireSourceTile::MASK_POWERED) == TripWireSourceTile::MASK_POWERED;
1980 bool suspended = !level->isTopSolidBlocking(x, y - 1, z);
1981
1982 bool hadFixed = hasFixedTexture();
1983 if (!hadFixed) this->setFixedTexture(getTexture(Tile::wood));
1984
1985 float boxHeight = 4 / 16.0f;
1986 float boxWidth = 2 / 16.0f;
1987 float boxDepth = 2 / 16.0f;
1988
1989 float boxy0 = 0.3f - boxHeight;
1990 float boxy1 = 0.3f + boxHeight;
1991 if (dir == Direction::NORTH)
1992 {
1993 setShape(0.5f - boxWidth, boxy0, 1 - boxDepth, 0.5f + boxWidth, boxy1, 1);
1994 }
1995 else if (dir == Direction::SOUTH)
1996 {
1997 setShape(0.5f - boxWidth, boxy0, 0, 0.5f + boxWidth, boxy1, boxDepth);
1998 }
1999 else if (dir == Direction::WEST)
2000 {
2001 setShape(1 - boxDepth, boxy0, 0.5f - boxWidth, 1, boxy1, 0.5f + boxWidth);
2002 }
2003 else if (dir == Direction::EAST)
2004 {
2005 setShape(0, boxy0, 0.5f - boxWidth, boxDepth, boxy1, 0.5f + boxWidth);
2006 }
2007
2008 this->tesselateBlockInWorld(tt, x, y, z);
2009 if (!hadFixed) this->clearFixedTexture();
2010
2011 float brightness;
2012 if (SharedConstants::TEXTURE_LIGHTING)
2013 {
2014 t->tex2(tt->getLightColor(level, x, y, z));
2015 brightness = 1;
2016 }
2017 else
2018 {
2019 brightness = tt->getBrightness(level, x, y, z);
2020 }
2021 if (Tile::lightEmission[tt->id] > 0) brightness = 1.0f;
2022 t->color(brightness, brightness, brightness);
2023 Icon *tex = getTexture(tt, 0);
2024
2025 if (hasFixedTexture()) tex = fixedTexture;
2026 double u0 = tex->getU0();
2027 double v0 = tex->getV0();
2028 double u1 = tex->getU1();
2029 double v1 = tex->getV1();
2030
2031 Vec3 *corners[8];
2032 float stickWidth = 0.75f / 16.0f;
2033 float stickHeight = 0.75f / 16.0f;
2034 float stickLength = 5 / 16.0f;
2035 corners[0] = Vec3::newTemp(-stickWidth, -0, -stickHeight);
2036 corners[1] = Vec3::newTemp(+stickWidth, -0, -stickHeight);
2037 corners[2] = Vec3::newTemp(+stickWidth, -0, +stickHeight);
2038 corners[3] = Vec3::newTemp(-stickWidth, -0, +stickHeight);
2039 corners[4] = Vec3::newTemp(-stickWidth, +stickLength, -stickHeight);
2040 corners[5] = Vec3::newTemp(+stickWidth, +stickLength, -stickHeight);
2041 corners[6] = Vec3::newTemp(+stickWidth, +stickLength, +stickHeight);
2042 corners[7] = Vec3::newTemp(-stickWidth, +stickLength, +stickHeight);
2043
2044 for (int i = 0; i < 8; i++)
2045 {
2046 corners[i]->z += 1 / 16.0f;
2047
2048 if (powered)
2049 {
2050 corners[i]->xRot(30 * PI / 180);
2051 corners[i]->y -= 7 / 16.0f;
2052 }
2053 else if (attached)
2054 {
2055 corners[i]->xRot(5 * PI / 180);
2056 corners[i]->y -= 7 / 16.0f;
2057 }
2058 else
2059 {
2060 corners[i]->xRot(-40 * PI / 180);
2061 corners[i]->y -= 6 / 16.0f;
2062 }
2063
2064 corners[i]->xRot(90 * PI / 180);
2065
2066 if (dir == Direction::NORTH) corners[i]->yRot(0 * PI / 180);
2067 if (dir == Direction::SOUTH) corners[i]->yRot(180 * PI / 180);
2068 if (dir == Direction::WEST) corners[i]->yRot(90 * PI / 180);
2069 if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180);
2070
2071 corners[i]->x += x + 0.5;
2072 corners[i]->y += y + 5 / 16.0f;
2073 corners[i]->z += z + 0.5;
2074 }
2075
2076 Vec3 *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL;
2077 int stickX0 = 7;
2078 int stickX1 = 9;
2079 int stickY0 = 9;
2080 int stickY1 = 16;
2081
2082 for (int i = 0; i < 6; i++)
2083 {
2084 if (i == 0)
2085 {
2086 c0 = corners[0];
2087 c1 = corners[1];
2088 c2 = corners[2];
2089 c3 = corners[3];
2090 u0 = tex->getU(stickX0);
2091 v0 = tex->getV(stickY0);
2092 u1 = tex->getU(stickX1);
2093 v1 = tex->getV(stickY0 + 2);
2094 }
2095 else if (i == 1)
2096 {
2097 c0 = corners[7];
2098 c1 = corners[6];
2099 c2 = corners[5];
2100 c3 = corners[4];
2101 }
2102 else if (i == 2)
2103 {
2104 c0 = corners[1];
2105 c1 = corners[0];
2106 c2 = corners[4];
2107 c3 = corners[5];
2108 u0 = tex->getU(stickX0);
2109 v0 = tex->getV(stickY0);
2110 u1 = tex->getU(stickX1);
2111 v1 = tex->getV(stickY1);
2112 }
2113 else if (i == 3)
2114 {
2115 c0 = corners[2];
2116 c1 = corners[1];
2117 c2 = corners[5];
2118 c3 = corners[6];
2119 }
2120 else if (i == 4)
2121 {
2122 c0 = corners[3];
2123 c1 = corners[2];
2124 c2 = corners[6];
2125 c3 = corners[7];
2126 }
2127 else if (i == 5)
2128 {
2129 c0 = corners[0];
2130 c1 = corners[3];
2131 c2 = corners[7];
2132 c3 = corners[4];
2133 }
2134 t->vertexUV(c0->x, c0->y, c0->z, u0, v1);
2135 t->vertexUV(c1->x, c1->y, c1->z, u1, v1);
2136 t->vertexUV(c2->x, c2->y, c2->z, u1, v0);
2137 t->vertexUV(c3->x, c3->y, c3->z, u0, v0);
2138 }
2139
2140
2141 float hoopWidth = 1.5f / 16.0f;
2142 float hoopHeight = 1.5f / 16.0f;
2143 float hoopLength = 0.5f / 16.0f;
2144 corners[0] = Vec3::newTemp(-hoopWidth, -0, -hoopHeight);
2145 corners[1] = Vec3::newTemp(+hoopWidth, -0, -hoopHeight);
2146 corners[2] = Vec3::newTemp(+hoopWidth, -0, +hoopHeight);
2147 corners[3] = Vec3::newTemp(-hoopWidth, -0, +hoopHeight);
2148 corners[4] = Vec3::newTemp(-hoopWidth, +hoopLength, -hoopHeight);
2149 corners[5] = Vec3::newTemp(+hoopWidth, +hoopLength, -hoopHeight);
2150 corners[6] = Vec3::newTemp(+hoopWidth, +hoopLength, +hoopHeight);
2151 corners[7] = Vec3::newTemp(-hoopWidth, +hoopLength, +hoopHeight);
2152
2153 for (int i = 0; i < 8; i++)
2154 {
2155 corners[i]->z += 3.5f / 16.0f;
2156
2157 if (powered)
2158 {
2159 corners[i]->y -= 1.5 / 16.0f;
2160 corners[i]->z -= 2.6 / 16.0f;
2161 corners[i]->xRot(0 * PI / 180);
2162 }
2163 else if (attached)
2164 {
2165 corners[i]->y += 0.25 / 16.0f;
2166 corners[i]->z -= 2.75 / 16.0f;
2167 corners[i]->xRot(10 * PI / 180);
2168 }
2169 else
2170 {
2171 corners[i]->xRot(50 * PI / 180);
2172 }
2173
2174 if (dir == Direction::NORTH) corners[i]->yRot(0 * PI / 180);
2175 if (dir == Direction::SOUTH) corners[i]->yRot(180 * PI / 180);
2176 if (dir == Direction::WEST) corners[i]->yRot(90 * PI / 180);
2177 if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180);
2178
2179 corners[i]->x += x + 0.5;
2180 corners[i]->y += y + 5 / 16.0f;
2181 corners[i]->z += z + 0.5;
2182 }
2183
2184 int hoopX0 = 5;
2185 int hoopX1 = 11;
2186 int hoopY0 = 3;
2187 int hoopY1 = 9;
2188
2189 for (int i = 0; i < 6; i++)
2190 {
2191 if (i == 0)
2192 {
2193 c0 = corners[0];
2194 c1 = corners[1];
2195 c2 = corners[2];
2196 c3 = corners[3];
2197 u0 = tex->getU(hoopX0);
2198 v0 = tex->getV(hoopY0);
2199 u1 = tex->getU(hoopX1);
2200 v1 = tex->getV(hoopY1);
2201 }
2202 else if (i == 1)
2203 {
2204 c0 = corners[7];
2205 c1 = corners[6];
2206 c2 = corners[5];
2207 c3 = corners[4];
2208 }
2209 else if (i == 2)
2210 {
2211 c0 = corners[1];
2212 c1 = corners[0];
2213 c2 = corners[4];
2214 c3 = corners[5];
2215 u0 = tex->getU(hoopX0);
2216 v0 = tex->getV(hoopY0);
2217 u1 = tex->getU(hoopX1);
2218 v1 = tex->getV(hoopY0 + 2);
2219 }
2220 else if (i == 3)
2221 {
2222 c0 = corners[2];
2223 c1 = corners[1];
2224 c2 = corners[5];
2225 c3 = corners[6];
2226 }
2227 else if (i == 4)
2228 {
2229 c0 = corners[3];
2230 c1 = corners[2];
2231 c2 = corners[6];
2232 c3 = corners[7];
2233 }
2234 else if (i == 5)
2235 {
2236 c0 = corners[0];
2237 c1 = corners[3];
2238 c2 = corners[7];
2239 c3 = corners[4];
2240 }
2241 t->vertexUV(c0->x, c0->y, c0->z, u0, v1);
2242 t->vertexUV(c1->x, c1->y, c1->z, u1, v1);
2243 t->vertexUV(c2->x, c2->y, c2->z, u1, v0);
2244 t->vertexUV(c3->x, c3->y, c3->z, u0, v0);
2245 }
2246
2247 if (attached)
2248 {
2249 double hoopBottomY = corners[0]->y;
2250 float width = 0.5f / 16.0f;
2251 float top = 0.5f - (width / 2);
2252 float bottom = top + width;
2253 Icon *wireTex = getTexture(Tile::tripWire);
2254 double wireX0 = wireTex->getU0();
2255 double wireY0 = wireTex->getV(attached ? 2 : 0);
2256 double wireX1 = wireTex->getU1();
2257 double wireY1 = wireTex->getV(attached ? 4 : 2);
2258 double floating = (suspended ? 3.5f : 1.5f) / 16.0;
2259
2260 brightness = tt->getBrightness(level, x, y, z) * 0.75f;
2261 t->color(brightness, brightness, brightness);
2262
2263 if (dir == Direction::NORTH)
2264 {
2265 t->vertexUV(x + top, y + floating, z + 0.25, wireX0, wireY0);
2266 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX0, wireY1);
2267 t->vertexUV(x + bottom, y + floating, z, wireX1, wireY1);
2268 t->vertexUV(x + top, y + floating, z, wireX1, wireY0);
2269
2270 t->vertexUV(x + top, hoopBottomY, z + 0.5, wireX0, wireY0);
2271 t->vertexUV(x + bottom, hoopBottomY, z + 0.5, wireX0, wireY1);
2272 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX1, wireY1);
2273 t->vertexUV(x + top, y + floating, z + 0.25, wireX1, wireY0);
2274 }
2275 else if (dir == Direction::SOUTH)
2276 {
2277 t->vertexUV(x + top, y + floating, z + 0.75, wireX0, wireY0);
2278 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX0, wireY1);
2279 t->vertexUV(x + bottom, hoopBottomY, z + 0.5, wireX1, wireY1);
2280 t->vertexUV(x + top, hoopBottomY, z + 0.5, wireX1, wireY0);
2281
2282 t->vertexUV(x + top, y + floating, z + 1, wireX0, wireY0);
2283 t->vertexUV(x + bottom, y + floating, z + 1, wireX0, wireY1);
2284 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX1, wireY1);
2285 t->vertexUV(x + top, y + floating, z + 0.75, wireX1, wireY0);
2286 }
2287 else if (dir == Direction::WEST)
2288 {
2289 t->vertexUV(x, y + floating, z + bottom, wireX0, wireY1);
2290 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX1, wireY1);
2291 t->vertexUV(x + 0.25, y + floating, z + top, wireX1, wireY0);
2292 t->vertexUV(x, y + floating, z + top, wireX0, wireY0);
2293
2294 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX0, wireY1);
2295 t->vertexUV(x + 0.5, hoopBottomY, z + bottom, wireX1, wireY1);
2296 t->vertexUV(x + 0.5, hoopBottomY, z + top, wireX1, wireY0);
2297 t->vertexUV(x + 0.25, y + floating, z + top, wireX0, wireY0);
2298 }
2299 else
2300 {
2301 t->vertexUV(x + 0.5, hoopBottomY, z + bottom, wireX0, wireY1);
2302 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX1, wireY1);
2303 t->vertexUV(x + 0.75, y + floating, z + top, wireX1, wireY0);
2304 t->vertexUV(x + 0.5, hoopBottomY, z + top, wireX0, wireY0);
2305
2306 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX0, wireY1);
2307 t->vertexUV(x + 1, y + floating, z + bottom, wireX1, wireY1);
2308 t->vertexUV(x + 1, y + floating, z + top, wireX1, wireY0);
2309 t->vertexUV(x + 0.75, y + floating, z + top, wireX0, wireY0);
2310 }
2311 }
2312
2313 return true;
2314}
2315
2316bool TileRenderer::tesselateTripwireInWorld(Tile *tt, int x, int y, int z)
2317{
2318 Tesselator *t = Tesselator::getInstance();
2319 Icon *tex = getTexture(tt, 0);
2320 int data = level->getData(x, y, z);
2321 bool attached = (data & TripWireTile::MASK_ATTACHED) == TripWireTile::MASK_ATTACHED;
2322 bool suspended = (data & TripWireTile::MASK_SUSPENDED) == TripWireTile::MASK_SUSPENDED;
2323
2324 if (hasFixedTexture()) tex = fixedTexture;
2325
2326 float brightness;
2327 if (SharedConstants::TEXTURE_LIGHTING)
2328 {
2329 t->tex2(tt->getLightColor(level, x, y, z));
2330 }
2331 brightness = tt->getBrightness(level, x, y, z) * 0.75f;
2332 t->color(brightness, brightness, brightness);
2333
2334 double wireX0 = tex->getU0();
2335 double wireY0 = tex->getV(attached ? 2 : 0);
2336 double wireX1 = tex->getU1();
2337 double wireY1 = tex->getV(attached ? 4 : 2);
2338 double floating = (suspended ? 3.5f : 1.5f) / 16.0;
2339
2340 bool w = TripWireTile::shouldConnectTo(level, x, y, z, data, Direction::WEST);
2341 bool e = TripWireTile::shouldConnectTo(level, x, y, z, data, Direction::EAST);
2342 bool n = TripWireTile::shouldConnectTo(level, x, y, z, data, Direction::NORTH);
2343 bool s = TripWireTile::shouldConnectTo(level, x, y, z, data, Direction::SOUTH);
2344
2345 float width = 0.5f / 16.0f;
2346 float top = 0.5f - (width / 2);
2347 float bottom = top + width;
2348
2349 if (!n && !e && !s && !w)
2350 {
2351 n = true;
2352 s = true;
2353 }
2354
2355 if (n)
2356 {
2357 t->vertexUV(x + top, y + floating, z + 0.25, wireX0, wireY0);
2358 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX0, wireY1);
2359 t->vertexUV(x + bottom, y + floating, z, wireX1, wireY1);
2360 t->vertexUV(x + top, y + floating, z, wireX1, wireY0);
2361
2362 t->vertexUV(x + top, y + floating, z, wireX1, wireY0);
2363 t->vertexUV(x + bottom, y + floating, z, wireX1, wireY1);
2364 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX0, wireY1);
2365 t->vertexUV(x + top, y + floating, z + 0.25, wireX0, wireY0);
2366 }
2367 if (n || (s && !e && !w))
2368 {
2369 t->vertexUV(x + top, y + floating, z + 0.5, wireX0, wireY0);
2370 t->vertexUV(x + bottom, y + floating, z + 0.5, wireX0, wireY1);
2371 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX1, wireY1);
2372 t->vertexUV(x + top, y + floating, z + 0.25, wireX1, wireY0);
2373
2374 t->vertexUV(x + top, y + floating, z + 0.25, wireX1, wireY0);
2375 t->vertexUV(x + bottom, y + floating, z + 0.25, wireX1, wireY1);
2376 t->vertexUV(x + bottom, y + floating, z + 0.5, wireX0, wireY1);
2377 t->vertexUV(x + top, y + floating, z + 0.5, wireX0, wireY0);
2378 }
2379 if (s || (n && !e && !w))
2380 {
2381 t->vertexUV(x + top, y + floating, z + 0.75, wireX0, wireY0);
2382 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX0, wireY1);
2383 t->vertexUV(x + bottom, y + floating, z + 0.5, wireX1, wireY1);
2384 t->vertexUV(x + top, y + floating, z + 0.5, wireX1, wireY0);
2385
2386 t->vertexUV(x + top, y + floating, z + 0.5, wireX1, wireY0);
2387 t->vertexUV(x + bottom, y + floating, z + 0.5, wireX1, wireY1);
2388 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX0, wireY1);
2389 t->vertexUV(x + top, y + floating, z + 0.75, wireX0, wireY0);
2390 }
2391 if (s)
2392 {
2393 t->vertexUV(x + top, y + floating, z + 1, wireX0, wireY0);
2394 t->vertexUV(x + bottom, y + floating, z + 1, wireX0, wireY1);
2395 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX1, wireY1);
2396 t->vertexUV(x + top, y + floating, z + 0.75, wireX1, wireY0);
2397
2398 t->vertexUV(x + top, y + floating, z + 0.75, wireX1, wireY0);
2399 t->vertexUV(x + bottom, y + floating, z + 0.75, wireX1, wireY1);
2400 t->vertexUV(x + bottom, y + floating, z + 1, wireX0, wireY1);
2401 t->vertexUV(x + top, y + floating, z + 1, wireX0, wireY0);
2402 }
2403
2404 if (w)
2405 {
2406 t->vertexUV(x, y + floating, z + bottom, wireX0, wireY1);
2407 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX1, wireY1);
2408 t->vertexUV(x + 0.25, y + floating, z + top, wireX1, wireY0);
2409 t->vertexUV(x, y + floating, z + top, wireX0, wireY0);
2410
2411 t->vertexUV(x, y + floating, z + top, wireX0, wireY0);
2412 t->vertexUV(x + 0.25, y + floating, z + top, wireX1, wireY0);
2413 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX1, wireY1);
2414 t->vertexUV(x, y + floating, z + bottom, wireX0, wireY1);
2415 }
2416 if (w || (e && !n && !s))
2417 {
2418 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX0, wireY1);
2419 t->vertexUV(x + 0.5, y + floating, z + bottom, wireX1, wireY1);
2420 t->vertexUV(x + 0.5, y + floating, z + top, wireX1, wireY0);
2421 t->vertexUV(x + 0.25, y + floating, z + top, wireX0, wireY0);
2422
2423 t->vertexUV(x + 0.25, y + floating, z + top, wireX0, wireY0);
2424 t->vertexUV(x + 0.5, y + floating, z + top, wireX1, wireY0);
2425 t->vertexUV(x + 0.5, y + floating, z + bottom, wireX1, wireY1);
2426 t->vertexUV(x + 0.25, y + floating, z + bottom, wireX0, wireY1);
2427 }
2428 if (e || (w && !n && !s))
2429 {
2430 t->vertexUV(x + 0.5, y + floating, z + bottom, wireX0, wireY1);
2431 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX1, wireY1);
2432 t->vertexUV(x + 0.75, y + floating, z + top, wireX1, wireY0);
2433 t->vertexUV(x + 0.5, y + floating, z + top, wireX0, wireY0);
2434
2435 t->vertexUV(x + 0.5, y + floating, z + top, wireX0, wireY0);
2436 t->vertexUV(x + 0.75, y + floating, z + top, wireX1, wireY0);
2437 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX1, wireY1);
2438 t->vertexUV(x + 0.5, y + floating, z + bottom, wireX0, wireY1);
2439 }
2440 if (e)
2441 {
2442 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX0, wireY1);
2443 t->vertexUV(x + 1, y + floating, z + bottom, wireX1, wireY1);
2444 t->vertexUV(x + 1, y + floating, z + top, wireX1, wireY0);
2445 t->vertexUV(x + 0.75, y + floating, z + top, wireX0, wireY0);
2446
2447 t->vertexUV(x + 0.75, y + floating, z + top, wireX0, wireY0);
2448 t->vertexUV(x + 1, y + floating, z + top, wireX1, wireY0);
2449 t->vertexUV(x + 1, y + floating, z + bottom, wireX1, wireY1);
2450 t->vertexUV(x + 0.75, y + floating, z + bottom, wireX0, wireY1);
2451 }
2452
2453 return true;
2454}
2455
2456bool TileRenderer::tesselateFireInWorld( FireTile* tt, int x, int y, int z )
2457{
2458 Tesselator* t = Tesselator::getInstance();
2459
2460 Icon *firstTex = tt->getTextureLayer(0);
2461 Icon *secondTex = tt->getTextureLayer(1);
2462 Icon *tex = firstTex;
2463
2464 if (hasFixedTexture()) tex = fixedTexture;
2465
2466 if ( SharedConstants::TEXTURE_LIGHTING )
2467 {
2468 t->color( 1.0f, 1.0f, 1.0f );
2469 t->tex2( getLightColor(tt, level, x, y, z ) );
2470 }
2471 else
2472 {
2473 float br = tt->getBrightness( level, x, y, z );
2474 t->color( br, br, br );
2475 }
2476 float u0 = tex->getU0(true);
2477 float v0 = tex->getV0(true);
2478 float u1 = tex->getU1(true);
2479 float v1 = tex->getV1(true);
2480 float h = 1.4f;
2481
2482 if ( level->isTopSolidBlocking( x, y - 1, z ) || Tile::fire->canBurn( level, x, y - 1, z ) )
2483 {
2484 float x0 = x + 0.5f + 0.2f;
2485 float x1 = x + 0.5f - 0.2f;
2486 float z0 = z + 0.5f + 0.2f;
2487 float z1 = z + 0.5f - 0.2f;
2488
2489 float x0_ = x + 0.5f - 0.3f;
2490 float x1_ = x + 0.5f + 0.3f;
2491 float z0_ = z + 0.5f - 0.3f;
2492 float z1_ = z + 0.5f + 0.3f;
2493
2494 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z + 1 ), ( float )( u1 ), ( float )( v0 ) );
2495 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z + 1 ), ( float )( u1 ), ( float )( v1 ) );
2496 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z + 0 ), ( float )( u0 ), ( float )( v1 ) );
2497 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z + 0 ), ( float )( u0 ), ( float )( v0 ) );
2498
2499 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z + 0 ), ( float )( u1 ), ( float )( v0 ) );
2500 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z + 0 ), ( float )( u1 ), ( float )( v1 ) );
2501 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z + 1 ), ( float )( u0 ), ( float )( v1 ) );
2502 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z + 1 ), ( float )( u0 ), ( float )( v0 ) );
2503
2504 tex = secondTex;
2505 u0 = tex->getU0(true);
2506 v0 = tex->getV0(true);
2507 u1 = tex->getU1(true);
2508 v1 = tex->getV1(true);
2509
2510 t->vertexUV( ( float )( x + 1 ), ( float )( y + h ), ( float )( z1_ ), ( float )( u1 ), ( float )( v0 ) );
2511 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
2512 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
2513 t->vertexUV( ( float )( x + 0 ), ( float )( y + h ), ( float )( z1_ ), ( float )( u0 ), ( float )( v0 ) );
2514
2515 t->vertexUV( ( float )( x + 0 ), ( float )( y + h ), ( float )( z0_ ), ( float )( u1 ), ( float )( v0 ) );
2516 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
2517 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
2518 t->vertexUV( ( float )( x + 1 ), ( float )( y + h ), ( float )( z0_ ), ( float )( u0 ), ( float )( v0 ) );
2519
2520 x0 = x + 0.5f - 0.5f;
2521 x1 = x + 0.5f + 0.5f;
2522 z0 = z + 0.5f - 0.5f;
2523 z1 = z + 0.5f + 0.5f;
2524
2525 x0_ = x + 0.5f - 0.4f;
2526 x1_ = x + 0.5f + 0.4f;
2527 z0_ = z + 0.5f - 0.4f;
2528 z1_ = z + 0.5f + 0.4f;
2529
2530 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z + 0 ), ( float )( u0 ), ( float )( v0 ) );
2531 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z + 0 ), ( float )( u0 ), ( float )( v1 ) );
2532 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z + 1 ), ( float )( u1 ), ( float )( v1 ) );
2533 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z + 1 ), ( float )( u1 ), ( float )( v0 ) );
2534
2535 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z + 1 ), ( float )( u0 ), ( float )( v0 ) );
2536 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z + 1 ), ( float )( u0 ), ( float )( v1 ) );
2537 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z + 0 ), ( float )( u1 ), ( float )( v1 ) );
2538 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z + 0 ), ( float )( u1 ), ( float )( v0 ) );
2539
2540 tex = firstTex;
2541 u0 = tex->getU0(true);
2542 v0 = tex->getV0(true);
2543 u1 = tex->getU1(true);
2544 v1 = tex->getV1(true);
2545
2546 t->vertexUV( ( float )( x + 0 ), ( float )( y + h ), ( float )( z1_ ), ( float )( u0 ), ( float )( v0 ) );
2547 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
2548 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
2549 t->vertexUV( ( float )( x + 1 ), ( float )( y + h ), ( float )( z1_ ), ( float )( u1 ), ( float )( v0 ) );
2550
2551 t->vertexUV( ( float )( x + 1 ), ( float )( y + h ), ( float )( z0_ ), ( float )( u0 ), ( float )( v0 ) );
2552 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
2553 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
2554 t->vertexUV( ( float )( x + 0 ), ( float )( y + h ), ( float )( z0_ ), ( float )( u1 ), ( float )( v0 ) );
2555 }
2556 else
2557 {
2558 float r = 0.2f;
2559 float yo = 1 / 16.0f;
2560 if ( ( ( x + y + z ) & 1 ) == 1 )
2561 {
2562 tex = secondTex;
2563 u0 = tex->getU0(true);
2564 v0 = tex->getV0(true);
2565 u1 = tex->getU1(true);
2566 v1 = tex->getV1(true);
2567 }
2568 if ( ( ( x / 2 + y / 2 + z / 2 ) & 1 ) == 1 )
2569 {
2570 float tmp = u1;
2571 u1 = u0;
2572 u0 = tmp;
2573 }
2574 if ( Tile::fire->canBurn( level, x - 1, y, z ) )
2575 {
2576 t->vertexUV( ( float )( x + r ), ( float )( y + h + yo ), ( float )( z +
2577 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2578 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2579 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2580 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2581 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2582 t->vertexUV( ( float )( x + r ), ( float )( y + h + yo ), ( float )( z +
2583 0.0f ), ( float )( u0 ), ( float )( v0 ) );
2584
2585 t->vertexUV( ( float )( x + r ), ( float )( y + h + yo ), ( float )( z +
2586 0.0f ), ( float )( u0 ), ( float )( v0 ) );
2587 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2588 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2589 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2590 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2591 t->vertexUV( ( float )( x + r ), ( float )( y + h + yo ), ( float )( z +
2592 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2593 }
2594 if ( Tile::fire->canBurn( level, x + 1, y, z ) )
2595 {
2596 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + h + yo ), ( float )( z +
2597 0.0f ), ( float )( u0 ), ( float )( v0 ) );
2598 t->vertexUV( ( float )( x + 1 - 0 ), ( float )( y + 0 + yo ), ( float )( z +
2599 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2600 t->vertexUV( ( float )( x + 1 - 0 ), ( float )( y + 0 + yo ), ( float )( z +
2601 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2602 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + h + yo ), ( float )( z +
2603 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2604
2605 t->vertexUV( ( float )( x + 1.0f - r ), ( float )( y + h + yo ), ( float )( z +
2606 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2607 t->vertexUV( ( float )( x + 1.0f - 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2608 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2609 t->vertexUV( ( float )( x + 1.0f - 0 ), ( float )( y + 0.0f + yo ), ( float )( z +
2610 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2611 t->vertexUV( ( float )( x + 1.0f - r ), ( float )( y + h + yo ), ( float )( z +
2612 0.0f ), ( float )( u0 ), ( float )( v0 ) );
2613 }
2614 if ( Tile::fire->canBurn( level, x, y, z - 1 ) )
2615 {
2616 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h + yo ), ( float )( z +
2617 r ), ( float )( u1 ), ( float )( v0 ) );
2618 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2619 0.0f ), ( float )( u1 ), ( float )( v1 ) );
2620 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2621 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2622 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h + yo ), ( float )( z +
2623 r ), ( float )( u0 ), ( float )( v0 ) );
2624
2625 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h + yo ), ( float )( z +
2626 r ), ( float )( u0 ), ( float )( v0 ) );
2627 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2628 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2629 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z +
2630 0.0f ), ( float )( u1 ), ( float )( v1 ) );
2631 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h + yo ), ( float )( z +
2632 r ), ( float )( u1 ), ( float )( v0 ) );
2633 }
2634 if ( Tile::fire->canBurn( level, x, y, z + 1 ) )
2635 {
2636 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h + yo ), ( float )( z + 1.0f -
2637 r ), ( float )( u0 ), ( float )( v0 ) );
2638 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + 0.0f + yo ), ( float )( z + 1.0f -
2639 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2640 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z + 1.0f -
2641 0.0f ), ( float )( u1 ), ( float )( v1 ) );
2642 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h + yo ), ( float )( z + 1.0f -
2643 r ), ( float )( u1 ), ( float )( v0 ) );
2644
2645 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h + yo ), ( float )( z + 1.0f -
2646 r ), ( float )( u1 ), ( float )( v0 ) );
2647 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + 0.0f + yo ), ( float )( z + 1.0f -
2648 0.0f ), ( float )( u1 ), ( float )( v1 ) );
2649 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + 0.0f + yo ), ( float )( z + 1.0f -
2650 0.0f ), ( float )( u0 ), ( float )( v1 ) );
2651 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h + yo ), ( float )( z + 1.0f -
2652 r ), ( float )( u0 ), ( float )( v0 ) );
2653 }
2654 if ( Tile::fire->canBurn( level, x, y + 1.0f, z ) )
2655 {
2656 double x0 = x + 0.5f + 0.5f;
2657 double x1 = x + 0.5f - 0.5f;
2658 double z0 = z + 0.5f + 0.5f;
2659 double z1 = z + 0.5f - 0.5f;
2660
2661 double x0_ = x + 0.5f - 0.5f;
2662 double x1_ = x + 0.5f + 0.5f;
2663 double z0_ = z + 0.5f - 0.5f;
2664 double z1_ = z + 0.5f + 0.5f;
2665
2666 tex = firstTex;
2667 u0 = tex->getU0(true);
2668 v0 = tex->getV0(true);
2669 u1 = tex->getU1(true);
2670 v1 = tex->getV1(true);
2671
2672 y += 1;
2673 h = -0.2f;
2674
2675 if ( ( ( x + y + z ) & 1 ) == 0 )
2676 {
2677 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z +
2678 0 ), ( float )( u1 ), ( float )( v0 ) );
2679 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z +
2680 0 ), ( float )( u1 ), ( float )( v1 ) );
2681 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z +
2682 1 ), ( float )( u0 ), ( float )( v1 ) );
2683 t->vertexUV( ( float )( x0_ ), ( float )( y + h ), ( float )( z +
2684 1 ), ( float )( u0 ), ( float )( v0 ) );
2685
2686 tex = secondTex;
2687 u0 = tex->getU0(true);
2688 v0 = tex->getV0(true);
2689 u1 = tex->getU1(true);
2690 v1 = tex->getV1(true);
2691
2692 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z +
2693 1.0f ), ( float )( u1 ), ( float )( v0 ) );
2694 t->vertexUV( ( float )( x1 ), ( float )( y + 0.0f ), ( float )( z +
2695 1.0f ), ( float )( u1 ), ( float )( v1 ) );
2696 t->vertexUV( ( float )( x1 ), ( float )( y + 0.0f ), ( float )( z +
2697 0 ), ( float )( u0 ), ( float )( v1 ) );
2698 t->vertexUV( ( float )( x1_ ), ( float )( y + h ), ( float )( z +
2699 0 ), ( float )( u0 ), ( float )( v0 ) );
2700 }
2701 else
2702 {
2703 t->vertexUV( ( float )( x + 0.0f ), ( float )( y +
2704 h ), ( float )( z1_ ), ( float )( u1 ), ( float )( v0 ) );
2705 t->vertexUV( ( float )( x + 0.0f ), ( float )( y +
2706 0.0f ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
2707 t->vertexUV( ( float )( x + 1.0f ), ( float )( y +
2708 0.0f ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
2709 t->vertexUV( ( float )( x + 1.0f ), ( float )( y +
2710 h ), ( float )( z1_ ), ( float )( u0 ), ( float )( v0 ) );
2711
2712 tex = secondTex;
2713 u0 = tex->getU0(true);
2714 v0 = tex->getV0(true);
2715 u1 = tex->getU1(true);
2716 v1 = tex->getV1(true);
2717
2718 t->vertexUV( ( float )( x + 1.0f ), ( float )( y +
2719 h ), ( float )( z0_ ), ( float )( u1 ), ( float )( v0 ) );
2720 t->vertexUV( ( float )( x + 1.0f ), ( float )( y +
2721 0.0f ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
2722 t->vertexUV( ( float )( x + 0.0f ), ( float )( y +
2723 0.0f ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
2724 t->vertexUV( ( float )( x + 0.0f ), ( float )( y +
2725 h ), ( float )( z0_ ), ( float )( u0 ), ( float )( v0 ) );
2726 }
2727 }
2728 }
2729
2730 return true;
2731
2732}
2733
2734bool TileRenderer::tesselateDustInWorld( Tile* tt, int x, int y, int z )
2735{
2736 Tesselator* t = Tesselator::getInstance();
2737
2738 int data = level->getData( x, y, z );
2739 Icon *crossTexture = RedStoneDustTile::getTexture(RedStoneDustTile::TEXTURE_CROSS);
2740 Icon *lineTexture = RedStoneDustTile::getTexture(RedStoneDustTile::TEXTURE_LINE);
2741 Icon *crossTextureOverlay = RedStoneDustTile::getTexture(RedStoneDustTile::TEXTURE_CROSS_OVERLAY);
2742 Icon *lineTextureOverlay = RedStoneDustTile::getTexture(RedStoneDustTile::TEXTURE_LINE_OVERLAY);
2743
2744 float br;
2745 if ( SharedConstants::TEXTURE_LIGHTING )
2746 {
2747 t->tex2( getLightColor(tt, level, x, y, z ) );
2748 br = 1;
2749 }
2750 else
2751 {
2752 br = tt->getBrightness( level, x, y, z );
2753 }
2754 // 4J Stu - not used any more
2755 //float pow = ( data / 15.0f );
2756 //float red = pow * 0.6f + 0.4f;
2757 //if ( data == 0 ) red = 0.3f;
2758
2759 //float green = pow * pow * 0.7f - 0.5f;
2760 //float blue = pow * pow * 0.6f - 0.7f;
2761 //if ( green < 0 ) green = 0;
2762 //if ( blue < 0 ) blue = 0;
2763
2764 unsigned int colour = 0;
2765 if(data == 0)
2766 {
2767 colour = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Tile_RedstoneDustUnlit );
2768 }
2769 else
2770 {
2771 unsigned int minColour = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Tile_RedstoneDustLitMin );
2772 unsigned int maxColour = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Tile_RedstoneDustLitMax );
2773
2774 byte redComponent = ((minColour>>16)&0xFF) + (( (maxColour>>16)&0xFF - (minColour>>16)&0xFF)*( (data-1)/14.0f));
2775 byte greenComponent = ((minColour>>8)&0xFF) + (( (maxColour>>8)&0xFF - (minColour>>8)&0xFF)*( (data-1)/14.0f));
2776 byte blueComponent = ((minColour)&0xFF) + (( (maxColour)&0xFF - (minColour)&0xFF)*( (data-1)/14.0f));
2777
2778 colour = redComponent<<16 | greenComponent<<8 | blueComponent;
2779 }
2780
2781 float red = ((colour>>16)&0xFF)/255.0f;
2782 float green = ((colour>>8)&0xFF)/255.0f;
2783 float blue = (colour&0xFF)/255.0f;
2784
2785 if ( SharedConstants::TEXTURE_LIGHTING )
2786 {
2787 t->color( red, green, blue );
2788 }
2789 else
2790 {
2791 t->color( br * red, br * green, br * blue );
2792 }
2793 const float dustOffset = 0.25f / 16.0f;
2794 const float overlayOffset = 0.25f / 16.0f;
2795
2796 bool w = RedStoneDustTile::shouldConnectTo( level, x - 1, y, z, Direction::WEST )
2797 || ( !level->isSolidBlockingTile( x - 1, y, z ) && RedStoneDustTile::shouldConnectTo( level, x - 1, y - 1, z,
2798 Direction::UNDEFINED ) );
2799 bool e = RedStoneDustTile::shouldConnectTo( level, x + 1, y, z, Direction::EAST )
2800 || ( !level->isSolidBlockingTile( x + 1, y, z ) && RedStoneDustTile::shouldConnectTo( level, x + 1, y - 1, z,
2801 Direction::UNDEFINED ) );
2802 bool n = RedStoneDustTile::shouldConnectTo( level, x, y, z - 1, Direction::NORTH )
2803 || ( !level->isSolidBlockingTile( x, y, z - 1 ) && RedStoneDustTile::shouldConnectTo( level, x, y - 1, z - 1,
2804 Direction::UNDEFINED ) );
2805 bool s = RedStoneDustTile::shouldConnectTo( level, x, y, z + 1, Direction::SOUTH )
2806 || ( !level->isSolidBlockingTile( x, y, z + 1 ) && RedStoneDustTile::shouldConnectTo( level, x, y - 1, z + 1,
2807 Direction::UNDEFINED ) );
2808 if ( !level->isSolidBlockingTile( x, y + 1, z ) )
2809 {
2810 if ( level->isSolidBlockingTile( x - 1, y, z ) && RedStoneDustTile::shouldConnectTo( level, x - 1, y + 1, z,
2811 Direction::UNDEFINED ) ) w
2812 = true;
2813 if ( level->isSolidBlockingTile( x + 1, y, z ) && RedStoneDustTile::shouldConnectTo( level, x + 1, y + 1, z,
2814 Direction::UNDEFINED ) ) e
2815 = true;
2816 if ( level->isSolidBlockingTile( x, y, z - 1 ) && RedStoneDustTile::shouldConnectTo( level, x, y + 1, z - 1,
2817 Direction::UNDEFINED ) ) n
2818 = true;
2819 if ( level->isSolidBlockingTile( x, y, z + 1 ) && RedStoneDustTile::shouldConnectTo( level, x, y + 1, z + 1,
2820 Direction::UNDEFINED ) ) s
2821 = true;
2822 }
2823 float x0 = ( float )( x + 0.0f );
2824 float x1 = ( float )( x + 1.0f );
2825 float z0 = ( float )( z + 0.0f );
2826 float z1 = ( float )( z + 1.0f );
2827
2828 int pic = 0;
2829 if ( ( w || e ) && ( !n && !s ) ) pic = 1;
2830 if ( ( n || s ) && ( !e && !w ) ) pic = 2;
2831
2832 if ( pic == 0 )
2833 {
2834 // if ( e || n || s || w )
2835 int u0 = 0;
2836 int v0 = 0;
2837 int u1 = SharedConstants::WORLD_RESOLUTION;
2838 int v1 = SharedConstants::WORLD_RESOLUTION;
2839
2840 int cutDistance = 5;
2841 if (!w) x0 += cutDistance / (float) SharedConstants::WORLD_RESOLUTION;
2842 if (!w) u0 += cutDistance;
2843 if (!e) x1 -= cutDistance / (float) SharedConstants::WORLD_RESOLUTION;
2844 if (!e) u1 -= cutDistance;
2845 if (!n) z0 += cutDistance / (float) SharedConstants::WORLD_RESOLUTION;
2846 if (!n) v0 += cutDistance;
2847 if (!s) z1 -= cutDistance / (float) SharedConstants::WORLD_RESOLUTION;
2848 if (!s) v1 -= cutDistance;
2849 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z1 ), crossTexture->getU(u1, true), crossTexture->getV(v1) );
2850 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z0 ), crossTexture->getU(u1, true), crossTexture->getV(v0) );
2851 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z0 ), crossTexture->getU(u0, true), crossTexture->getV(v0) );
2852 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z1 ), crossTexture->getU(u0, true), crossTexture->getV(v1) );
2853
2854 t->color( br, br, br );
2855 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z1 ), crossTextureOverlay->getU(u1, true), crossTextureOverlay->getV(v1, true) );
2856 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z0 ), crossTextureOverlay->getU(u1, true), crossTextureOverlay->getV(v0, true) );
2857 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z0 ), crossTextureOverlay->getU(u0, true), crossTextureOverlay->getV(v0, true) );
2858 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z1 ), crossTextureOverlay->getU(u0, true), crossTextureOverlay->getV(v1, true) );
2859 }
2860 else if ( pic == 1 )
2861 {
2862 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z1 ), lineTexture->getU1(true), lineTexture->getV1(true) );
2863 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z0 ), lineTexture->getU1(true), lineTexture->getV0(true) );
2864 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z0 ), lineTexture->getU0(true), lineTexture->getV0(true) );
2865 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z1 ), lineTexture->getU0(true), lineTexture->getV1(true) );
2866
2867 t->color( br, br, br );
2868 t->vertexUV( ( float )( x1 ), ( float )( y + overlayOffset ), ( float )( z1 ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV1(true) );
2869 t->vertexUV( ( float )( x1 ), ( float )( y + overlayOffset ), ( float )( z0 ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV0(true) );
2870 t->vertexUV( ( float )( x0 ), ( float )( y + overlayOffset ), ( float )( z0 ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV0(true) );
2871 t->vertexUV( ( float )( x0 ), ( float )( y + overlayOffset ), ( float )( z1 ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV1(true) );
2872 }
2873 else
2874 {
2875 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z1 ), lineTexture->getU1(true), lineTexture->getV1(true) );
2876 t->vertexUV( ( float )( x1 ), ( float )( y + dustOffset ), ( float )( z0 ), lineTexture->getU0(true), lineTexture->getV1(true) );
2877 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z0 ), lineTexture->getU0(true), lineTexture->getV0(true) );
2878 t->vertexUV( ( float )( x0 ), ( float )( y + dustOffset ), ( float )( z1 ), lineTexture->getU1(true), lineTexture->getV0(true) );
2879
2880 t->color( br, br, br );
2881 t->vertexUV( ( float )( x1 ), ( float )( y + overlayOffset ), ( float )( z1 ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV1(true) );
2882 t->vertexUV( ( float )( x1 ), ( float )( y + overlayOffset ), ( float )( z0 ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV1(true) );
2883 t->vertexUV( ( float )( x0 ), ( float )( y + overlayOffset ), ( float )( z0 ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV0(true) );
2884 t->vertexUV( ( float )( x0 ), ( float )( y + overlayOffset ), ( float )( z1 ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV0(true) );
2885 }
2886
2887 if ( !level->isSolidBlockingTile( x, y + 1, z ) )
2888 {
2889 const float yStretch = .35f / 16.0f;
2890
2891 if ( level->isSolidBlockingTile( x - 1, y, z ) && level->getTile( x - 1, y + 1, z ) == Tile::redStoneDust_Id )
2892 {
2893 t->color( br * red, br * green, br * blue );
2894 t->vertexUV( ( float )( x + dustOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 1 ), lineTexture->getU1(true), lineTexture->getV0(true) );
2895 t->vertexUV( ( float )( x + dustOffset ), ( float )( y + 0 ), ( float )( z + 1 ), lineTexture->getU0(true), lineTexture->getV0(true) );
2896 t->vertexUV( ( float )( x + dustOffset ), ( float )( y + 0 ), ( float )( z + 0 ), lineTexture->getU0(true), lineTexture->getV1(true) );
2897 t->vertexUV( ( float )( x + dustOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 0 ), lineTexture->getU1(true), lineTexture->getV1(true) );
2898
2899 t->color( br, br, br );
2900 t->vertexUV( ( float )( x + overlayOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 1 ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV0(true) );
2901 t->vertexUV( ( float )( x + overlayOffset ), ( float )( y + 0 ), ( float )( z + 1 ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV0(true) );
2902 t->vertexUV( ( float )( x + overlayOffset ), ( float )( y + 0 ), ( float )( z + 0 ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV1(true) );
2903 t->vertexUV( ( float )( x + overlayOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 0 ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV1(true) );
2904 }
2905 if ( level->isSolidBlockingTile( x + 1, y, z ) && level->getTile( x + 1, y + 1, z ) == Tile::redStoneDust_Id )
2906 {
2907 t->color( br * red, br * green, br * blue );
2908 t->vertexUV( ( float )( x + 1 - dustOffset ), ( float )( y + 0 ), ( float )( z + 1 ), lineTexture->getU0(true), lineTexture->getV1(true) );
2909 t->vertexUV( ( float )( x + 1 - dustOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 1 ), lineTexture->getU1(true), lineTexture->getV1(true) );
2910 t->vertexUV( ( float )( x + 1 - dustOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 0 ), lineTexture->getU1(true), lineTexture->getV0(true) );
2911 t->vertexUV( ( float )( x + 1 - dustOffset ), ( float )( y + 0 ), ( float )( z + 0 ), lineTexture->getU0(true), lineTexture->getV0(true) );
2912
2913 t->color( br, br, br );
2914 t->vertexUV( ( float )( x + 1 - overlayOffset ), ( float )( y + 0 ), ( float )( z + 1 ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV1(true) );
2915 t->vertexUV( ( float )( x + 1 - overlayOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 1 ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV1(true) );
2916 t->vertexUV( ( float )( x + 1 - overlayOffset ), ( float )( y + 1 + yStretch ), ( float )( z + 0 ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV0(true) );
2917 t->vertexUV( ( float )( x + 1 - overlayOffset ), ( float )( y + 0 ), ( float )( z + 0 ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV0(true) );
2918 }
2919 if ( level->isSolidBlockingTile( x, y, z - 1 ) && level->getTile( x, y + 1, z - 1 ) == Tile::redStoneDust_Id )
2920 {
2921 t->color( br * red, br * green, br * blue );
2922 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z + dustOffset ), lineTexture->getU0(true), lineTexture->getV1(true) );
2923 t->vertexUV( ( float )( x + 1 ), ( float )( y + 1 + yStretch ), ( float )( z + dustOffset ), lineTexture->getU1(true), lineTexture->getV1(true) );
2924 t->vertexUV( ( float )( x + 0 ), ( float )( y + 1 + yStretch ), ( float )( z + dustOffset ), lineTexture->getU1(true), lineTexture->getV0(true) );
2925 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z + dustOffset ), lineTexture->getU0(true), lineTexture->getV0(true) );
2926
2927 t->color( br, br, br );
2928 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z + overlayOffset ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV1(true) );
2929 t->vertexUV( ( float )( x + 1 ), ( float )( y + 1 + yStretch ), ( float )( z + overlayOffset ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV1(true) );
2930 t->vertexUV( ( float )( x + 0 ), ( float )( y + 1 + yStretch ), ( float )( z + overlayOffset ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV0(true) );
2931 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z + overlayOffset ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV0(true) );
2932 }
2933 if ( level->isSolidBlockingTile( x, y, z + 1 ) && level->getTile( x, y + 1, z + 1 ) == Tile::redStoneDust_Id )
2934 {
2935 t->color( br * red, br * green, br * blue );
2936 t->vertexUV( ( float )( x + 1 ), ( float )( y + 1 + yStretch ), ( float )( z + 1 - dustOffset ), lineTexture->getU1(true), lineTexture->getV0(true) );
2937 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z + 1 - dustOffset ), lineTexture->getU0(true), lineTexture->getV0(true) );
2938 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z + 1 - dustOffset ), lineTexture->getU0(true), lineTexture->getV1(true) );
2939 t->vertexUV( ( float )( x + 0 ), ( float )( y + 1 + yStretch ), ( float )( z + 1 - dustOffset ), lineTexture->getU1(true), lineTexture->getV1(true) );
2940
2941 t->color( br, br, br );
2942 t->vertexUV( ( float )( x + 1 ), ( float )( y + 1 + yStretch ), ( float )( z + 1 - overlayOffset ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV0(true) );
2943 t->vertexUV( ( float )( x + 1 ), ( float )( y + 0 ), ( float )( z + 1 - overlayOffset ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV0(true) );
2944 t->vertexUV( ( float )( x + 0 ), ( float )( y + 0 ), ( float )( z + 1 - overlayOffset ), lineTextureOverlay->getU0(true), lineTextureOverlay->getV1(true) );
2945 t->vertexUV( ( float )( x + 0 ), ( float )( y + 1 + yStretch ), ( float )( z + 1 - overlayOffset ), lineTextureOverlay->getU1(true), lineTextureOverlay->getV1(true) );
2946 }
2947 }
2948
2949
2950 return true;
2951
2952}
2953
2954bool TileRenderer::tesselateRailInWorld( RailTile* tt, int x, int y, int z )
2955{
2956 Tesselator* t = Tesselator::getInstance();
2957 int data = level->getData( x, y, z );
2958
2959 Icon *tex = getTexture(tt, 0, data);
2960 if (hasFixedTexture()) tex = fixedTexture;
2961
2962 if ( tt->isUsesDataBit() )
2963 {
2964 data &= RailTile::RAIL_DIRECTION_MASK;
2965 }
2966
2967 if ( SharedConstants::TEXTURE_LIGHTING )
2968 {
2969 t->tex2( getLightColor(tt, level, x, y, z ) );
2970 t->color( 1.0f, 1.0f, 1.0f );
2971 }
2972 else
2973 {
2974 float br = tt->getBrightness( level, x, y, z );
2975 t->color( br, br, br );
2976 }
2977
2978 float u0 = tex->getU0(true);
2979 float v0 = tex->getV0(true);
2980 float u1 = tex->getU1(true);
2981 float v1 = tex->getV1(true);
2982
2983 float r = 1 / 16.0f;
2984
2985 float x0 = ( float )( x + 1 );
2986 float x1 = ( float )( x + 1 );
2987 float x2 = ( float )( x + 0 );
2988 float x3 = ( float )( x + 0 );
2989
2990 float z0 = ( float )( z + 0 );
2991 float z1 = ( float )( z + 1 );
2992 float z2 = ( float )( z + 1 );
2993 float z3 = ( float )( z + 0 );
2994
2995 float y0 = ( float )( y + r );
2996 float y1 = ( float )( y + r );
2997 float y2 = ( float )( y + r );
2998 float y3 = ( float )( y + r );
2999
3000 if ( data == 1 || data == 2 || data == 3 || data == 7 )
3001 {
3002 x0 = x3 = ( float )( x + 1 );
3003 x1 = x2 = ( float )( x + 0 );
3004 z0 = z1 = ( float )( z + 1 );
3005 z2 = z3 = ( float )( z + 0 );
3006 }
3007 else if ( data == 8 )
3008 {
3009 x0 = x1 = ( float )( x + 0 );
3010 x2 = x3 = ( float )( x + 1 );
3011 z0 = z3 = ( float )( z + 1 );
3012 z1 = z2 = ( float )( z + 0 );
3013 }
3014 else if ( data == 9 )
3015 {
3016 x0 = x3 = ( float )( x + 0 );
3017 x1 = x2 = ( float )( x + 1 );
3018 z0 = z1 = ( float )( z + 0 );
3019 z2 = z3 = ( float )( z + 1 );
3020 }
3021
3022 if ( data == 2 || data == 4 )
3023 {
3024 y0 += 1;
3025 y3 += 1;
3026 }
3027 else if ( data == 3 || data == 5 )
3028 {
3029 y1 += 1;
3030 y2 += 1;
3031 }
3032
3033 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3034 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
3035 t->vertexUV( ( float )( x2 ), ( float )( y2 ), ( float )( z2 ), ( float )( u0 ), ( float )( v1 ) );
3036 t->vertexUV( ( float )( x3 ), ( float )( y3 ), ( float )( z3 ), ( float )( u0 ), ( float )( v0 ) );
3037
3038 t->vertexUV( ( float )( x3 ), ( float )( y3 ), ( float )( z3 ), ( float )( u0 ), ( float )( v0 ) );
3039 t->vertexUV( ( float )( x2 ), ( float )( y2 ), ( float )( z2 ), ( float )( u0 ), ( float )( v1 ) );
3040 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
3041 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
3042
3043 return true;
3044
3045}
3046
3047bool TileRenderer::tesselateLadderInWorld( Tile* tt, int x, int y, int z )
3048{
3049 Tesselator* t = Tesselator::getInstance();
3050
3051 Icon *tex = getTexture(tt, 0);
3052
3053 if (hasFixedTexture()) tex = fixedTexture;
3054
3055 if ( SharedConstants::TEXTURE_LIGHTING )
3056 {
3057 t->tex2( getLightColor(tt, level, x, y, z ) );
3058 float br = 1;
3059 t->color( br, br, br );
3060 }
3061 else
3062 {
3063 float br = tt->getBrightness( level, x, y, z );
3064 t->color( br, br, br );
3065 }
3066 float u0 = tex->getU0(true);
3067 float v0 = tex->getV0(true);
3068 float u1 = tex->getU1(true);
3069 float v1 = tex->getV1(true);
3070
3071 int face = level->getData( x, y, z );
3072
3073 float o = 0 / 16.0f;
3074 float r = 0.05f;
3075 if ( face == 5 )
3076 {
3077 t->vertexUV( ( float )( x + r ), ( float )( y + 1 + o ), ( float )( z + 1 +
3078 o ), ( float )( u0 ), ( float )( v0 ) );
3079 t->vertexUV( ( float )( x + r ), ( float )( y + 0 - o ), ( float )( z + 1 +
3080 o ), ( float )( u0 ), ( float )( v1 ) );
3081 t->vertexUV( ( float )( x + r ), ( float )( y + 0 - o ), ( float )( z + 0 -
3082 o ), ( float )( u1 ), ( float )( v1 ) );
3083 t->vertexUV( ( float )( x + r ), ( float )( y + 1 + o ), ( float )( z + 0 -
3084 o ), ( float )( u1 ), ( float )( v0 ) );
3085 }
3086 if ( face == 4 )
3087 {
3088 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + 0 - o ), ( float )( z + 1 +
3089 o ), ( float )( u1 ), ( float )( v1 ) );
3090 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + 1 + o ), ( float )( z + 1 +
3091 o ), ( float )( u1 ), ( float )( v0 ) );
3092 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + 1 + o ), ( float )( z + 0 -
3093 o ), ( float )( u0 ), ( float )( v0 ) );
3094 t->vertexUV( ( float )( x + 1 - r ), ( float )( y + 0 - o ), ( float )( z + 0 -
3095 o ), ( float )( u0 ), ( float )( v1 ) );
3096 }
3097 if ( face == 3 )
3098 {
3099 t->vertexUV( ( float )( x + 1 + o ), ( float )( y + 0 - o ), ( float )( z +
3100 r ), ( float )( u1 ), ( float )( v1 ) );
3101 t->vertexUV( ( float )( x + 1 + o ), ( float )( y + 1 + o ), ( float )( z +
3102 r ), ( float )( u1 ), ( float )( v0 ) );
3103 t->vertexUV( ( float )( x + 0 - o ), ( float )( y + 1 + o ), ( float )( z +
3104 r ), ( float )( u0 ), ( float )( v0 ) );
3105 t->vertexUV( ( float )( x + 0 - o ), ( float )( y + 0 - o ), ( float )( z +
3106 r ), ( float )( u0 ), ( float )( v1 ) );
3107 }
3108 if ( face == 2 )
3109 {
3110 t->vertexUV( ( float )( x + 1 + o ), ( float )( y + 1 + o ), ( float )( z + 1 -
3111 r ), ( float )( u0 ), ( float )( v0 ) );
3112 t->vertexUV( ( float )( x + 1 + o ), ( float )( y + 0 - o ), ( float )( z + 1 -
3113 r ), ( float )( u0 ), ( float )( v1 ) );
3114 t->vertexUV( ( float )( x + 0 - o ), ( float )( y + 0 - o ), ( float )( z + 1 -
3115 r ), ( float )( u1 ), ( float )( v1 ) );
3116 t->vertexUV( ( float )( x + 0 - o ), ( float )( y + 1 + o ), ( float )( z + 1 -
3117 r ), ( float )( u1 ), ( float )( v0 ) );
3118 }
3119
3120 return true;
3121
3122}
3123
3124bool TileRenderer::tesselateVineInWorld( Tile* tt, int x, int y, int z )
3125{
3126 Tesselator* t = Tesselator::getInstance();
3127
3128 Icon *tex = getTexture(tt, 0);
3129
3130 if (hasFixedTexture()) tex = fixedTexture;
3131
3132
3133 float br = 1;
3134 if ( SharedConstants::TEXTURE_LIGHTING )
3135 {
3136 t->tex2( getLightColor(tt, level, x, y, z ) );
3137 }
3138 else
3139 {
3140 br = tt->getBrightness( level, x, y, z );
3141 }
3142 {
3143 int col = tt->getColor( level, x, y, z );
3144 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
3145 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
3146 float b = ( ( col )& 0xff ) / 255.0f;
3147
3148 t->color( br * r, br * g, br * b );
3149 }
3150
3151 float u0 = tex->getU0(true);
3152 float v0 = tex->getV0(true);
3153 float u1 = tex->getU1(true);
3154 float v1 = tex->getV1(true);
3155
3156 float r = 0.05f;
3157 int facings = level->getData( x, y, z );
3158
3159 if ( ( facings & VineTile::VINE_WEST ) != 0 )
3160 {
3161 t->vertexUV( x + r, y + 1, z + 1, u0, v0 );
3162 t->vertexUV( x + r, y + 0, z + 1, u0, v1 );
3163 t->vertexUV( x + r, y + 0, z + 0, u1, v1 );
3164 t->vertexUV( x + r, y + 1, z + 0, u1, v0 );
3165
3166 t->vertexUV( x + r, y + 1, z + 0, u1, v0 );
3167 t->vertexUV( x + r, y + 0, z + 0, u1, v1 );
3168 t->vertexUV( x + r, y + 0, z + 1, u0, v1 );
3169 t->vertexUV( x + r, y + 1, z + 1, u0, v0 );
3170 }
3171 if ( ( facings & VineTile::VINE_EAST ) != 0 )
3172 {
3173 t->vertexUV( x + 1 - r, y + 0, z + 1, u1, v1 );
3174 t->vertexUV( x + 1 - r, y + 1, z + 1, u1, v0 );
3175 t->vertexUV( x + 1 - r, y + 1, z + 0, u0, v0 );
3176 t->vertexUV( x + 1 - r, y + 0, z + 0, u0, v1 );
3177
3178 t->vertexUV( x + 1 - r, y + 0, z + 0, u0, v1 );
3179 t->vertexUV( x + 1 - r, y + 1, z + 0, u0, v0 );
3180 t->vertexUV( x + 1 - r, y + 1, z + 1, u1, v0 );
3181 t->vertexUV( x + 1 - r, y + 0, z + 1, u1, v1 );
3182 }
3183 if ( ( facings & VineTile::VINE_NORTH ) != 0 )
3184 {
3185 t->vertexUV( x + 1, y + 0, z + r, u1, v1 );
3186 t->vertexUV( x + 1, y + 1, z + r, u1, v0 );
3187 t->vertexUV( x + 0, y + 1, z + r, u0, v0 );
3188 t->vertexUV( x + 0, y + 0, z + r, u0, v1 );
3189
3190 t->vertexUV( x + 0, y + 0, z + r, u0, v1 );
3191 t->vertexUV( x + 0, y + 1, z + r, u0, v0 );
3192 t->vertexUV( x + 1, y + 1, z + r, u1, v0 );
3193 t->vertexUV( x + 1, y + 0, z + r, u1, v1 );
3194 }
3195 if ( ( facings & VineTile::VINE_SOUTH ) != 0 )
3196 {
3197 t->vertexUV( x + 1, y + 1, z + 1 - r, u0, v0 );
3198 t->vertexUV( x + 1, y + 0, z + 1 - r, u0, v1 );
3199 t->vertexUV( x + 0, y + 0, z + 1 - r, u1, v1 );
3200 t->vertexUV( x + 0, y + 1, z + 1 - r, u1, v0 );
3201
3202 t->vertexUV( x + 0, y + 1, z + 1 - r, u1, v0 );
3203 t->vertexUV( x + 0, y + 0, z + 1 - r, u1, v1 );
3204 t->vertexUV( x + 1, y + 0, z + 1 - r, u0, v1 );
3205 t->vertexUV( x + 1, y + 1, z + 1 - r, u0, v0 );
3206 }
3207 if ( level->isSolidBlockingTile( x, y + 1, z ) )
3208 {
3209 t->vertexUV( x + 1, y + 1 - r, z + 0, u0, v0 );
3210 t->vertexUV( x + 1, y + 1 - r, z + 1, u0, v1 );
3211 t->vertexUV( x + 0, y + 1 - r, z + 1, u1, v1 );
3212 t->vertexUV( x + 0, y + 1 - r, z + 0, u1, v0 );
3213 }
3214
3215 return true;
3216}
3217
3218bool TileRenderer::tesselateThinPaneInWorld(Tile *tt, int x, int y, int z)
3219{
3220 int depth = level->getMaxBuildHeight();
3221 Tesselator *t = Tesselator::getInstance();
3222
3223 t->tex2(tt->getLightColor(level, x, y, z));
3224 int col = tt->getColor(level, x, y, z);
3225 float r = ((col >> 16) & 0xff) / 255.0f;
3226 float g = ((col >> 8) & 0xff) / 255.0f;
3227 float b = ((col) & 0xff) / 255.0f;
3228
3229 if (GameRenderer::anaglyph3d)
3230 {
3231 float cr = (r * 30 + g * 59 + b * 11) / 100;
3232 float cg = (r * 30 + g * 70) / (100);
3233 float cb = (r * 30 + b * 70) / (100);
3234
3235 r = cr;
3236 g = cg;
3237 b = cb;
3238 }
3239 t->color(r, g, b);
3240
3241 Icon *tex;
3242 Icon *edgeTex;
3243
3244 bool stained = dynamic_cast<StainedGlassPaneBlock *>(tt) != NULL;
3245 if (hasFixedTexture())
3246 {
3247 tex = fixedTexture;
3248 edgeTex = fixedTexture;
3249 }
3250 else
3251 {
3252 int data = level->getData(x, y, z);
3253 tex = getTexture(tt, 0, data);
3254 edgeTex = (stained) ? ((StainedGlassPaneBlock *) tt)->getEdgeTexture(data) : ((ThinFenceTile *) tt)->getEdgeTexture();
3255 }
3256
3257 double u0 = tex->getU0();
3258 double iu0 = tex->getU(7);
3259 double iu1 = tex->getU(9);
3260 double u1 = tex->getU1();
3261 double v0 = tex->getV0();
3262 double v1 = tex->getV1();
3263
3264 double eiu0 = edgeTex->getU(7);
3265 double eiu1 = edgeTex->getU(9);
3266 double ev0 = edgeTex->getV0();
3267 double ev1 = edgeTex->getV1();
3268 double eiv0 = edgeTex->getV(7);
3269 double eiv1 = edgeTex->getV(9);
3270
3271 double x0 = x;
3272 double x1 = x + 1;
3273 double z0 = z;
3274 double z1 = z + 1;
3275 double ix0 = x + .5 - 1.0 / 16.0;
3276 double ix1 = x + .5 + 1.0 / 16.0;
3277 double iz0 = z + .5 - 1.0 / 16.0;
3278 double iz1 = z + .5 + 1.0 / 16.0;
3279
3280 bool n = (stained) ? ((StainedGlassPaneBlock *)tt)->attachsTo(level->getTile(x, y, z - 1)) : ((ThinFenceTile *)tt)->attachsTo(level->getTile(x, y, z - 1));
3281 bool s = (stained) ? ((StainedGlassPaneBlock *)tt)->attachsTo(level->getTile(x, y, z + 1)) : ((ThinFenceTile *)tt)->attachsTo(level->getTile(x, y, z + 1));
3282 bool w = (stained) ? ((StainedGlassPaneBlock *)tt)->attachsTo(level->getTile(x - 1, y, z)) : ((ThinFenceTile *)tt)->attachsTo(level->getTile(x - 1, y, z));
3283 bool e = (stained) ? ((StainedGlassPaneBlock *)tt)->attachsTo(level->getTile(x + 1, y, z)) : ((ThinFenceTile *)tt)->attachsTo(level->getTile(x + 1, y, z));
3284
3285 double noZFightingOffset = 0.001;
3286 double yt = 1.0 - noZFightingOffset;
3287 double yb = 0.0 + noZFightingOffset;
3288
3289 bool none = !(n || s || w || e);
3290
3291 if (w || none)
3292 {
3293 if (w && e)
3294 {
3295 if (!n)
3296 {
3297 t->vertexUV(x1, y + yt, iz0, u1, v0);
3298 t->vertexUV(x1, y + yb, iz0, u1, v1);
3299 t->vertexUV(x0, y + yb, iz0, u0, v1);
3300 t->vertexUV(x0, y + yt, iz0, u0, v0);
3301 }
3302 else
3303 {
3304 t->vertexUV(ix0, y + yt, iz0, iu0, v0);
3305 t->vertexUV(ix0, y + yb, iz0, iu0, v1);
3306 t->vertexUV( x0, y + yb, iz0, u0, v1);
3307 t->vertexUV( x0, y + yt, iz0, u0, v0);
3308
3309 t->vertexUV( x1, y + yt, iz0, u1, v0);
3310 t->vertexUV( x1, y + yb, iz0, u1, v1);
3311 t->vertexUV(ix1, y + yb, iz0, iu1, v1);
3312 t->vertexUV(ix1, y + yt, iz0, iu1, v0);
3313 }
3314 if (!s)
3315 {
3316 t->vertexUV(x0, y + yt, iz1, u0, v0);
3317 t->vertexUV(x0, y + yb, iz1, u0, v1);
3318 t->vertexUV(x1, y + yb, iz1, u1, v1);
3319 t->vertexUV(x1, y + yt, iz1, u1, v0);
3320 }
3321 else
3322 {
3323 t->vertexUV( x0, y + yt, iz1, u0, v0);
3324 t->vertexUV( x0, y + yb, iz1, u0, v1);
3325 t->vertexUV(ix0, y + yb, iz1, iu0, v1);
3326 t->vertexUV(ix0, y + yt, iz1, iu0, v0);
3327
3328 t->vertexUV(ix1, y + yt, iz1, iu1, v0);
3329 t->vertexUV(ix1, y + yb, iz1, iu1, v1);
3330 t->vertexUV( x1, y + yb, iz1, u1, v1);
3331 t->vertexUV( x1, y + yt, iz1, u1, v0);
3332 }
3333
3334 t->vertexUV(x0, y + yt, iz1, eiu1, ev0);
3335 t->vertexUV(x1, y + yt, iz1, eiu1, ev1);
3336 t->vertexUV(x1, y + yt, iz0, eiu0, ev1);
3337 t->vertexUV(x0, y + yt, iz0, eiu0, ev0);
3338
3339 t->vertexUV(x1, y + yb, iz1, eiu0, ev1);
3340 t->vertexUV(x0, y + yb, iz1, eiu0, ev0);
3341 t->vertexUV(x0, y + yb, iz0, eiu1, ev0);
3342 t->vertexUV(x1, y + yb, iz0, eiu1, ev1);
3343 }
3344 else
3345 {
3346 if (!(n || none))
3347 {
3348 t->vertexUV(ix1, y + yt, iz0, iu1, v0);
3349 t->vertexUV(ix1, y + yb, iz0, iu1, v1);
3350 t->vertexUV( x0, y + yb, iz0, u0, v1);
3351 t->vertexUV( x0, y + yt, iz0, u0, v0);
3352 }
3353 else
3354 {
3355 t->vertexUV(ix0, y + yt, iz0, iu0, v0);
3356 t->vertexUV(ix0, y + yb, iz0, iu0, v1);
3357 t->vertexUV( x0, y + yb, iz0, u0, v1);
3358 t->vertexUV( x0, y + yt, iz0, u0, v0);
3359 }
3360 if (!(s || none))
3361 {
3362 t->vertexUV( x0, y + yt, iz1, u0, v0);
3363 t->vertexUV( x0, y + yb, iz1, u0, v1);
3364 t->vertexUV(ix1, y + yb, iz1, iu1, v1);
3365 t->vertexUV(ix1, y + yt, iz1, iu1, v0);
3366 }
3367 else
3368 {
3369 t->vertexUV( x0, y + yt, iz1, u0, v0);
3370 t->vertexUV( x0, y + yb, iz1, u0, v1);
3371 t->vertexUV(ix0, y + yb, iz1, iu0, v1);
3372 t->vertexUV(ix0, y + yt, iz1, iu0, v0);
3373 }
3374
3375 t->vertexUV( x0, y + yt, iz1, eiu1, ev0);
3376 t->vertexUV(ix0, y + yt, iz1, eiu1, eiv0);
3377 t->vertexUV(ix0, y + yt, iz0, eiu0, eiv0);
3378 t->vertexUV( x0, y + yt, iz0, eiu0, ev0);
3379
3380 t->vertexUV(ix0, y + yb, iz1, eiu0, eiv0);
3381 t->vertexUV( x0, y + yb, iz1, eiu0, ev0);
3382 t->vertexUV( x0, y + yb, iz0, eiu1, ev0);
3383 t->vertexUV(ix0, y + yb, iz0, eiu1, eiv0);
3384 }
3385 }
3386 else if (!(n || s))
3387 {
3388 t->vertexUV(ix0, y + yt, iz0, iu0, v0);
3389 t->vertexUV(ix0, y + yb, iz0, iu0, v1);
3390 t->vertexUV(ix0, y + yb, iz1, iu1, v1);
3391 t->vertexUV(ix0, y + yt, iz1, iu1, v0);
3392 }
3393
3394 if ((e || none) && !w)
3395 {
3396 if (!(s || none))
3397 {
3398 t->vertexUV(ix0, y + yt, iz1, iu0, v0);
3399 t->vertexUV(ix0, y + yb, iz1, iu0, v1);
3400 t->vertexUV( x1, y + yb, iz1, u1, v1);
3401 t->vertexUV( x1, y + yt, iz1, u1, v0);
3402 }
3403 else
3404 {
3405 t->vertexUV(ix1, y + yt, iz1, iu1, v0);
3406 t->vertexUV(ix1, y + yb, iz1, iu1, v1);
3407 t->vertexUV( x1, y + yb, iz1, u1, v1);
3408 t->vertexUV( x1, y + yt, iz1, u1, v0);
3409 }
3410 if (!(n || none))
3411 {
3412 t->vertexUV( x1, y + yt, iz0, u1, v0);
3413 t->vertexUV( x1, y + yb, iz0, u1, v1);
3414 t->vertexUV(ix0, y + yb, iz0, iu0, v1);
3415 t->vertexUV(ix0, y + yt, iz0, iu0, v0);
3416 }
3417 else
3418 {
3419 t->vertexUV( x1, y + yt, iz0, u1, v0);
3420 t->vertexUV( x1, y + yb, iz0, u1, v1);
3421 t->vertexUV(ix1, y + yb, iz0, iu1, v1);
3422 t->vertexUV(ix1, y + yt, iz0, iu1, v0);
3423 }
3424
3425 t->vertexUV(ix1, y + yt, iz1, eiu1, eiv1);
3426 t->vertexUV( x1, y + yt, iz1, eiu1, ev0);
3427 t->vertexUV( x1, y + yt, iz0, eiu0, ev0);
3428 t->vertexUV(ix1, y + yt, iz0, eiu0, eiv1);
3429
3430 t->vertexUV( x1, y + yb, iz1, eiu0, ev1);
3431 t->vertexUV(ix1, y + yb, iz1, eiu0, eiv1);
3432 t->vertexUV(ix1, y + yb, iz0, eiu1, eiv1);
3433 t->vertexUV( x1, y + yb, iz0, eiu1, ev1);
3434 }
3435 else if (!(e || n || s))
3436 {
3437 t->vertexUV(ix1, y + yt, iz1, iu0, v0);
3438 t->vertexUV(ix1, y + yb, iz1, iu0, v1);
3439 t->vertexUV(ix1, y + yb, iz0, iu1, v1);
3440 t->vertexUV(ix1, y + yt, iz0, iu1, v0);
3441 }
3442
3443 if (n || none)
3444 {
3445 if (n && s)
3446 {
3447 if (!w)
3448 {
3449 t->vertexUV(ix0, y + yt, z0, u0, v0);
3450 t->vertexUV(ix0, y + yb, z0, u0, v1);
3451 t->vertexUV(ix0, y + yb, z1, u1, v1);
3452 t->vertexUV(ix0, y + yt, z1, u1, v0);
3453 }
3454 else
3455 {
3456 t->vertexUV(ix0, y + yt, z0, u0, v0);
3457 t->vertexUV(ix0, y + yb, z0, u0, v1);
3458 t->vertexUV(ix0, y + yb, iz0, iu0, v1);
3459 t->vertexUV(ix0, y + yt, iz0, iu0, v0);
3460
3461 t->vertexUV(ix0, y + yt, iz1, iu1, v0);
3462 t->vertexUV(ix0, y + yb, iz1, iu1, v1);
3463 t->vertexUV(ix0, y + yb, z1, u1, v1);
3464 t->vertexUV(ix0, y + yt, z1, u1, v0);
3465 }
3466 if (!e)
3467 {
3468 t->vertexUV(ix1, y + yt, z1, u1, v0);
3469 t->vertexUV(ix1, y + yb, z1, u1, v1);
3470 t->vertexUV(ix1, y + yb, z0, u0, v1);
3471 t->vertexUV(ix1, y + yt, z0, u0, v0);
3472 }
3473 else
3474 {
3475 t->vertexUV(ix1, y + yt, iz0, iu0, v0);
3476 t->vertexUV(ix1, y + yb, iz0, iu0, v1);
3477 t->vertexUV(ix1, y + yb, z0, u0, v1);
3478 t->vertexUV(ix1, y + yt, z0, u0, v0);
3479
3480 t->vertexUV(ix1, y + yt, z1, u1, v0);
3481 t->vertexUV(ix1, y + yb, z1, u1, v1);
3482 t->vertexUV(ix1, y + yb, iz1, iu1, v1);
3483 t->vertexUV(ix1, y + yt, iz1, iu1, v0);
3484 }
3485
3486 t->vertexUV(ix1, y + yt, z0, eiu1, ev0);
3487 t->vertexUV(ix0, y + yt, z0, eiu0, ev0);
3488 t->vertexUV(ix0, y + yt, z1, eiu0, ev1);
3489 t->vertexUV(ix1, y + yt, z1, eiu1, ev1);
3490
3491 t->vertexUV(ix0, y + yb, z0, eiu0, ev0);
3492 t->vertexUV(ix1, y + yb, z0, eiu1, ev0);
3493 t->vertexUV(ix1, y + yb, z1, eiu1, ev1);
3494 t->vertexUV(ix0, y + yb, z1, eiu0, ev1);
3495 }
3496 else
3497 {
3498 if (!(w || none))
3499 {
3500 t->vertexUV(ix0, y + yt, z0, u0, v0);
3501 t->vertexUV(ix0, y + yb, z0, u0, v1);
3502 t->vertexUV(ix0, y + yb, iz1, iu1, v1);
3503 t->vertexUV(ix0, y + yt, iz1, iu1, v0);
3504 }
3505 else
3506 {
3507 t->vertexUV(ix0, y + yt, z0, u0, v0);
3508 t->vertexUV(ix0, y + yb, z0, u0, v1);
3509 t->vertexUV(ix0, y + yb, iz0, iu0, v1);
3510 t->vertexUV(ix0, y + yt, iz0, iu0, v0);
3511 }
3512 if (!(e || none))
3513 {
3514 t->vertexUV(ix1, y + yt, iz1, iu1, v0);
3515 t->vertexUV(ix1, y + yb, iz1, iu1, v1);
3516 t->vertexUV(ix1, y + yb, z0, u0, v1);
3517 t->vertexUV(ix1, y + yt, z0, u0, v0);
3518 }
3519 else
3520 {
3521 t->vertexUV(ix1, y + yt, iz0, iu0, v0);
3522 t->vertexUV(ix1, y + yb, iz0, iu0, v1);
3523 t->vertexUV(ix1, y + yb, z0, u0, v1);
3524 t->vertexUV(ix1, y + yt, z0, u0, v0);
3525 }
3526
3527 t->vertexUV(ix1, y + yt, z0, eiu1, ev0);
3528 t->vertexUV(ix0, y + yt, z0, eiu0, ev0);
3529 t->vertexUV(ix0, y + yt, iz0, eiu0, eiv0);
3530 t->vertexUV(ix1, y + yt, iz0, eiu1, eiv0);
3531
3532 t->vertexUV(ix0, y + yb, z0, eiu0, ev0);
3533 t->vertexUV(ix1, y + yb, z0, eiu1, ev0);
3534 t->vertexUV(ix1, y + yb, iz0, eiu1, eiv0);
3535 t->vertexUV(ix0, y + yb, iz0, eiu0, eiv0);
3536 }
3537 }
3538 else if (!(e || w))
3539 {
3540 t->vertexUV(ix1, y + yt, iz0, iu1, v0);
3541 t->vertexUV(ix1, y + yb, iz0, iu1, v1);
3542 t->vertexUV(ix0, y + yb, iz0, iu0, v1);
3543 t->vertexUV(ix0, y + yt, iz0, iu0, v0);
3544 }
3545
3546 if ((s || none) && !n)
3547 {
3548 if (!(w || none))
3549 {
3550 t->vertexUV(ix0, y + yt, iz0, iu0, v0);
3551 t->vertexUV(ix0, y + yb, iz0, iu0, v1);
3552 t->vertexUV(ix0, y + yb, z1, u1, v1);
3553 t->vertexUV(ix0, y + yt, z1, u1, v0);
3554 }
3555 else
3556 {
3557 t->vertexUV(ix0, y + yt, iz1, iu1, v0);
3558 t->vertexUV(ix0, y + yb, iz1, iu1, v1);
3559 t->vertexUV(ix0, y + yb, z1, u1, v1);
3560 t->vertexUV(ix0, y + yt, z1, u1, v0);
3561 }
3562 if (!(e || none))
3563 {
3564 t->vertexUV(ix1, y + yt, z1, u1, v0);
3565 t->vertexUV(ix1, y + yb, z1, u1, v1);
3566 t->vertexUV(ix1, y + yb, iz0, iu0, v1);
3567 t->vertexUV(ix1, y + yt, iz0, iu0, v0);
3568 }
3569 else
3570 {
3571 t->vertexUV(ix1, y + yt, z1, u1, v0);
3572 t->vertexUV(ix1, y + yb, z1, u1, v1);
3573 t->vertexUV(ix1, y + yb, iz1, iu1, v1);
3574 t->vertexUV(ix1, y + yt, iz1, iu1, v0);
3575 }
3576
3577 t->vertexUV(ix1, y + yt, iz1, eiu1, eiv1);
3578 t->vertexUV(ix0, y + yt, iz1, eiu0, eiv1);
3579 t->vertexUV(ix0, y + yt, z1, eiu0, ev1);
3580 t->vertexUV(ix1, y + yt, z1, eiu1, ev1);
3581
3582 t->vertexUV(ix0, y + yb, iz1, eiu0, eiv1);
3583 t->vertexUV(ix1, y + yb, iz1, eiu1, eiv1);
3584 t->vertexUV(ix1, y + yb, z1, eiu1, ev1);
3585 t->vertexUV(ix0, y + yb, z1, eiu0, ev1);
3586 }
3587 else if (!(s || e || w))
3588 {
3589 t->vertexUV(ix0, y + yt, iz1, iu0, v0);
3590 t->vertexUV(ix0, y + yb, iz1, iu0, v1);
3591 t->vertexUV(ix1, y + yb, iz1, iu1, v1);
3592 t->vertexUV(ix1, y + yt, iz1, iu1, v0);
3593 }
3594
3595 t->vertexUV(ix1, y + yt, iz0, eiu1, eiv0);
3596 t->vertexUV(ix0, y + yt, iz0, eiu0, eiv0);
3597 t->vertexUV(ix0, y + yt, iz1, eiu0, eiv1);
3598 t->vertexUV(ix1, y + yt, iz1, eiu1, eiv1);
3599
3600 t->vertexUV(ix0, y + yb, iz0, eiu0, eiv0);
3601 t->vertexUV(ix1, y + yb, iz0, eiu1, eiv0);
3602 t->vertexUV(ix1, y + yb, iz1, eiu1, eiv1);
3603 t->vertexUV(ix0, y + yb, iz1, eiu0, eiv1);
3604
3605 if (none)
3606 {
3607 t->vertexUV(x0, y + yt, iz0, iu0, v0);
3608 t->vertexUV(x0, y + yb, iz0, iu0, v1);
3609 t->vertexUV(x0, y + yb, iz1, iu1, v1);
3610 t->vertexUV(x0, y + yt, iz1, iu1, v0);
3611
3612 t->vertexUV(x1, y + yt, iz1, iu0, v0);
3613 t->vertexUV(x1, y + yb, iz1, iu0, v1);
3614 t->vertexUV(x1, y + yb, iz0, iu1, v1);
3615 t->vertexUV(x1, y + yt, iz0, iu1, v0);
3616
3617 t->vertexUV(ix1, y + yt, z0, iu1, v0);
3618 t->vertexUV(ix1, y + yb, z0, iu1, v1);
3619 t->vertexUV(ix0, y + yb, z0, iu0, v1);
3620 t->vertexUV(ix0, y + yt, z0, iu0, v0);
3621
3622 t->vertexUV(ix0, y + yt, z1, iu0, v0);
3623 t->vertexUV(ix0, y + yb, z1, iu0, v1);
3624 t->vertexUV(ix1, y + yb, z1, iu1, v1);
3625 t->vertexUV(ix1, y + yt, z1, iu1, v0);
3626 }
3627 return true;
3628}
3629
3630bool TileRenderer::tesselateThinFenceInWorld( ThinFenceTile* tt, int x, int y, int z )
3631{
3632 int depth = level->getMaxBuildHeight();
3633 Tesselator* t = Tesselator::getInstance();
3634
3635 float br;
3636 if ( SharedConstants::TEXTURE_LIGHTING )
3637 {
3638 t->tex2( getLightColor(tt, level, x, y, z ) );
3639 br = 1;
3640 }
3641 else
3642 {
3643 br = tt->getBrightness( level, x, y, z );
3644 }
3645 int col = tt->getColor( level, x, y, z );
3646 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
3647 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
3648 float b = ( ( col )& 0xff ) / 255.0f;
3649
3650 if ( GameRenderer::anaglyph3d )
3651 {
3652 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
3653 float cg = ( r * 30 + g * 70 ) / ( 100 );
3654 float cb = ( r * 30 + b * 70 ) / ( 100 );
3655
3656 r = cr;
3657 g = cg;
3658 b = cb;
3659 }
3660 t->color( br * r, br * g, br * b );
3661
3662 Icon *tex;
3663 Icon *edgeTex;
3664
3665 if ( hasFixedTexture() )
3666 {
3667 tex = fixedTexture;
3668 edgeTex = fixedTexture;
3669 }
3670 else
3671 {
3672 int data = level->getData( x, y, z );
3673 tex = getTexture( tt, 0, data );
3674 edgeTex = tt->getEdgeTexture();
3675 }
3676
3677 int xt = tex->getX();
3678 int yt = tex->getY();
3679 float u0 = tex->getU0(true);
3680 float u1 = tex->getU(8, true);
3681 float u2 = tex->getU1(true);
3682 float v0 = tex->getV0(true);
3683 float v2 = tex->getV1(true);
3684
3685 int xet = edgeTex->getX();
3686 int yet = edgeTex->getY();
3687
3688 float iu0 = edgeTex->getU(7, true);
3689 float iu1 = edgeTex->getU(9, true);
3690 float iv0 = edgeTex->getV0(true);
3691 float iv1 = edgeTex->getV(8, true);
3692 float iv2 = edgeTex->getV1(true);
3693
3694 float x0 = (float)x;
3695 float x1 = x + 0.5f;
3696 float x2 = x + 1.0f;
3697 float z0 = (float)z;
3698 float z1 = z + 0.5f;
3699 float z2 = z + 1.0f;
3700 float ix0 = x + 0.5f - 1.0f / 16.0f;
3701 float ix1 = x + 0.5f + 1.0f / 16.0f;
3702 float iz0 = z + 0.5f - 1.0f / 16.0f;
3703 float iz1 = z + 0.5f + 1.0f / 16.0f;
3704
3705 bool n = tt->attachsTo( level->getTile( x, y, z - 1 ) );
3706 bool s = tt->attachsTo( level->getTile( x, y, z + 1 ) );
3707 bool w = tt->attachsTo( level->getTile( x - 1, y, z ) );
3708 bool e = tt->attachsTo( level->getTile( x + 1, y, z ) );
3709
3710 bool up = tt->shouldRenderFace( level, x, y + 1, z, Facing::UP );
3711 bool down = tt->shouldRenderFace( level, x, y - 1, z, Facing::DOWN );
3712
3713 const float noZFightingOffset = 0.01f;
3714 const float noZFightingOffsetB = 0.005;
3715
3716 if ( ( w && e ) || ( !w && !e && !n && !s ) )
3717 {
3718 t->vertexUV( x0, y + 1, z1, u0, v0 );
3719 t->vertexUV( x0, y + 0, z1, u0, v2 );
3720 t->vertexUV( x2, y + 0, z1, u2, v2 );
3721 t->vertexUV( x2, y + 1, z1, u2, v0 );
3722
3723 t->vertexUV( x2, y + 1, z1, u0, v0 );
3724 t->vertexUV( x2, y + 0, z1, u0, v2 );
3725 t->vertexUV( x0, y + 0, z1, u2, v2 );
3726 t->vertexUV( x0, y + 1, z1, u2, v0 );
3727
3728 if ( up )
3729 {
3730 // small edge texture
3731 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3732 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3733 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3734 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3735
3736 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3737 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3738 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3739 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3740 }
3741 else
3742 {
3743 if ( y < ( depth - 1 ) && level->isEmptyTile( x - 1, y + 1, z ) )
3744 {
3745 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3746 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3747 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3748 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3749
3750 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3751 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3752 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3753 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3754 }
3755 if ( y < ( depth - 1 ) && level->isEmptyTile( x + 1, y + 1, z ) )
3756 {
3757 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3758 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3759 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3760 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3761
3762 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3763 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3764 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3765 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3766 }
3767 }
3768 if ( down )
3769 {
3770 // small edge texture
3771 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv2 );
3772 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv0 );
3773 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv0 );
3774 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv2 );
3775
3776 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv2 );
3777 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv0 );
3778 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv0 );
3779 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv2 );
3780 }
3781 else
3782 {
3783 if ( y > 1 && level->isEmptyTile( x - 1, y - 1, z ) )
3784 {
3785 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv1 );
3786 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv2 );
3787 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv2 );
3788 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv1 );
3789
3790 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv1 );
3791 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv2 );
3792 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv2 );
3793 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv1 );
3794 }
3795 if ( y > 1 && level->isEmptyTile( x + 1, y - 1, z ) )
3796 {
3797 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv0 );
3798 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv1 );
3799 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv1 );
3800 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv0 );
3801
3802 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv0 );
3803 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv1 );
3804 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv1 );
3805 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv0 );
3806 }
3807 }
3808 }
3809 else if ( w && !e )
3810 {
3811 // half-step towards west
3812 t->vertexUV( x0, y + 1, z1, u0, v0 );
3813 t->vertexUV( x0, y + 0, z1, u0, v2 );
3814 t->vertexUV( x1, y + 0, z1, u1, v2 );
3815 t->vertexUV( x1, y + 1, z1, u1, v0 );
3816
3817 t->vertexUV( x1, y + 1, z1, u0, v0 );
3818 t->vertexUV( x1, y + 0, z1, u0, v2 );
3819 t->vertexUV( x0, y + 0, z1, u1, v2 );
3820 t->vertexUV( x0, y + 1, z1, u1, v0 );
3821
3822 // small edge texture
3823 if ( !s && !n )
3824 {
3825 t->vertexUV( x1, y + 1, iz1, iu0, iv0 );
3826 t->vertexUV( x1, y + 0, iz1, iu0, iv2 );
3827 t->vertexUV( x1, y + 0, iz0, iu1, iv2 );
3828 t->vertexUV( x1, y + 1, iz0, iu1, iv0 );
3829
3830 t->vertexUV( x1, y + 1, iz0, iu0, iv0 );
3831 t->vertexUV( x1, y + 0, iz0, iu0, iv2 );
3832 t->vertexUV( x1, y + 0, iz1, iu1, iv2 );
3833 t->vertexUV( x1, y + 1, iz1, iu1, iv0 );
3834 }
3835
3836 if ( up || ( y < ( depth - 1 ) && level->isEmptyTile( x - 1, y + 1, z ) ) )
3837 {
3838 // small edge texture
3839 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3840 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3841 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3842 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3843
3844 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3845 t->vertexUV( x0, y + 1 + noZFightingOffset, iz1, iu1, iv2 );
3846 t->vertexUV( x0, y + 1 + noZFightingOffset, iz0, iu0, iv2 );
3847 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3848 }
3849 if ( down || ( y > 1 && level->isEmptyTile( x - 1, y - 1, z ) ) )
3850 {
3851 // small edge texture
3852 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv1 );
3853 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv2 );
3854 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv2 );
3855 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv1 );
3856
3857 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv1 );
3858 t->vertexUV( x0, y - noZFightingOffset, iz1, iu1, iv2 );
3859 t->vertexUV( x0, y - noZFightingOffset, iz0, iu0, iv2 );
3860 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv1 );
3861 }
3862
3863 }
3864 else if ( !w && e )
3865 {
3866 // half-step towards east
3867 t->vertexUV( x1, y + 1, z1, u1, v0 );
3868 t->vertexUV( x1, y + 0, z1, u1, v2 );
3869 t->vertexUV( x2, y + 0, z1, u2, v2 );
3870 t->vertexUV( x2, y + 1, z1, u2, v0 );
3871
3872 t->vertexUV( x2, y + 1, z1, u1, v0 );
3873 t->vertexUV( x2, y + 0, z1, u1, v2 );
3874 t->vertexUV( x1, y + 0, z1, u2, v2 );
3875 t->vertexUV( x1, y + 1, z1, u2, v0 );
3876
3877 // small edge texture
3878 if ( !s && !n )
3879 {
3880 t->vertexUV( x1, y + 1, iz0, iu0, iv0 );
3881 t->vertexUV( x1, y + 0, iz0, iu0, iv2 );
3882 t->vertexUV( x1, y + 0, iz1, iu1, iv2 );
3883 t->vertexUV( x1, y + 1, iz1, iu1, iv0 );
3884
3885 t->vertexUV( x1, y + 1, iz1, iu0, iv0 );
3886 t->vertexUV( x1, y + 0, iz1, iu0, iv2 );
3887 t->vertexUV( x1, y + 0, iz0, iu1, iv2 );
3888 t->vertexUV( x1, y + 1, iz0, iu1, iv0 );
3889 }
3890
3891 if ( up || ( y < ( depth - 1 ) && level->isEmptyTile( x + 1, y + 1, z ) ) )
3892 {
3893 // small edge texture
3894 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3895 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3896 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3897 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3898
3899 t->vertexUV( x2, y + 1 + noZFightingOffset, iz1, iu1, iv0 );
3900 t->vertexUV( x1, y + 1 + noZFightingOffset, iz1, iu1, iv1 );
3901 t->vertexUV( x1, y + 1 + noZFightingOffset, iz0, iu0, iv1 );
3902 t->vertexUV( x2, y + 1 + noZFightingOffset, iz0, iu0, iv0 );
3903 }
3904 if ( down || ( y > 1 && level->isEmptyTile( x + 1, y - 1, z ) ) )
3905 {
3906 // small edge texture
3907 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv0 );
3908 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv1 );
3909 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv1 );
3910 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv0 );
3911
3912 t->vertexUV( x2, y - noZFightingOffset, iz1, iu1, iv0 );
3913 t->vertexUV( x1, y - noZFightingOffset, iz1, iu1, iv1 );
3914 t->vertexUV( x1, y - noZFightingOffset, iz0, iu0, iv1 );
3915 t->vertexUV( x2, y - noZFightingOffset, iz0, iu0, iv0 );
3916 }
3917
3918 }
3919
3920 if ( ( n && s ) || ( !w && !e && !n && !s ) )
3921 {
3922 // straight north-south
3923 t->vertexUV( x1, y + 1, z2, u0, v0 );
3924 t->vertexUV( x1, y + 0, z2, u0, v2 );
3925 t->vertexUV( x1, y + 0, z0, u2, v2 );
3926 t->vertexUV( x1, y + 1, z0, u2, v0 );
3927
3928 t->vertexUV( x1, y + 1, z0, u0, v0 );
3929 t->vertexUV( x1, y + 0, z0, u0, v2 );
3930 t->vertexUV( x1, y + 0, z2, u2, v2 );
3931 t->vertexUV( x1, y + 1, z2, u2, v0 );
3932
3933 if ( up )
3934 {
3935 // small edge texture
3936 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv2 );
3937 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu1, iv0 );
3938 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu0, iv0 );
3939 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv2 );
3940
3941 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu1, iv2 );
3942 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv0 );
3943 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv0 );
3944 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu0, iv2 );
3945 }
3946 else
3947 {
3948 if ( y < ( depth - 1 ) && level->isEmptyTile( x, y + 1, z - 1 ) )
3949 {
3950 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu1, iv0 );
3951 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu1, iv1 );
3952 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu0, iv1 );
3953 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu0, iv0 );
3954
3955 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu1, iv0 );
3956 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu1, iv1 );
3957 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu0, iv1 );
3958 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu0, iv0 );
3959 }
3960 if ( y < ( depth - 1 ) && level->isEmptyTile( x, y + 1, z + 1 ) )
3961 {
3962 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu0, iv1 );
3963 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv2 );
3964 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv2 );
3965 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu1, iv1 );
3966
3967 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv1 );
3968 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu0, iv2 );
3969 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu1, iv2 );
3970 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv1 );
3971 }
3972 }
3973 if ( down )
3974 {
3975 // small edge texture
3976 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv2 );
3977 t->vertexUV( ix1, y - noZFightingOffset, z0, iu1, iv0 );
3978 t->vertexUV( ix0, y - noZFightingOffset, z0, iu0, iv0 );
3979 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv2 );
3980
3981 t->vertexUV( ix1, y - noZFightingOffset, z0, iu1, iv2 );
3982 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv0 );
3983 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv0 );
3984 t->vertexUV( ix0, y - noZFightingOffset, z0, iu0, iv2 );
3985 }
3986 else
3987 {
3988 if ( y > 1 && level->isEmptyTile( x, y - 1, z - 1 ) )
3989 {
3990 // north half-step
3991 t->vertexUV( ix0, y - noZFightingOffset, z0, iu1, iv0 );
3992 t->vertexUV( ix0, y - noZFightingOffset, z1, iu1, iv1 );
3993 t->vertexUV( ix1, y - noZFightingOffset, z1, iu0, iv1 );
3994 t->vertexUV( ix1, y - noZFightingOffset, z0, iu0, iv0 );
3995
3996 t->vertexUV( ix0, y - noZFightingOffset, z1, iu1, iv0 );
3997 t->vertexUV( ix0, y - noZFightingOffset, z0, iu1, iv1 );
3998 t->vertexUV( ix1, y - noZFightingOffset, z0, iu0, iv1 );
3999 t->vertexUV( ix1, y - noZFightingOffset, z1, iu0, iv0 );
4000 }
4001 if ( y > 1 && level->isEmptyTile( x, y - 1, z + 1 ) )
4002 {
4003 // south half-step
4004 t->vertexUV( ix0, y - noZFightingOffset, z1, iu0, iv1 );
4005 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv2 );
4006 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv2 );
4007 t->vertexUV( ix1, y - noZFightingOffset, z1, iu1, iv1 );
4008
4009 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv1 );
4010 t->vertexUV( ix0, y - noZFightingOffset, z1, iu0, iv2 );
4011 t->vertexUV( ix1, y - noZFightingOffset, z1, iu1, iv2 );
4012 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv1 );
4013 }
4014 }
4015
4016 }
4017 else if ( n && !s )
4018 {
4019 // half-step towards north
4020 t->vertexUV( x1, y + 1, z0, u0, v0 );
4021 t->vertexUV( x1, y + 0, z0, u0, v2 );
4022 t->vertexUV( x1, y + 0, z1, u1, v2 );
4023 t->vertexUV( x1, y + 1, z1, u1, v0 );
4024
4025 t->vertexUV( x1, y + 1, z1, u0, v0 );
4026 t->vertexUV( x1, y + 0, z1, u0, v2 );
4027 t->vertexUV( x1, y + 0, z0, u1, v2 );
4028 t->vertexUV( x1, y + 1, z0, u1, v0 );
4029
4030 // small edge texture
4031 if ( !e && !w )
4032 {
4033 t->vertexUV( ix0, y + 1, z1, iu0, iv0 );
4034 t->vertexUV( ix0, y + 0, z1, iu0, iv2 );
4035 t->vertexUV( ix1, y + 0, z1, iu1, iv2 );
4036 t->vertexUV( ix1, y + 1, z1, iu1, iv0 );
4037
4038 t->vertexUV( ix1, y + 1, z1, iu0, iv0 );
4039 t->vertexUV( ix1, y + 0, z1, iu0, iv2 );
4040 t->vertexUV( ix0, y + 0, z1, iu1, iv2 );
4041 t->vertexUV( ix0, y + 1, z1, iu1, iv0 );
4042 }
4043
4044 if ( up || ( y < ( depth - 1 ) && level->isEmptyTile( x, y + 1, z - 1 ) ) )
4045 {
4046 // small edge texture
4047 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu1, iv0 );
4048 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu1, iv1 );
4049 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu0, iv1 );
4050 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu0, iv0 );
4051
4052 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu1, iv0 );
4053 t->vertexUV( ix0, y + 1 + noZFightingOffset, z0, iu1, iv1 );
4054 t->vertexUV( ix1, y + 1 + noZFightingOffset, z0, iu0, iv1 );
4055 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu0, iv0 );
4056 }
4057
4058 if ( down || ( y > 1 && level->isEmptyTile( x, y - 1, z - 1 ) ) )
4059 {
4060 // small edge texture
4061 t->vertexUV( ix0, y - noZFightingOffset, z0, iu1, iv0 );
4062 t->vertexUV( ix0, y - noZFightingOffset, z1, iu1, iv1 );
4063 t->vertexUV( ix1, y - noZFightingOffset, z1, iu0, iv1 );
4064 t->vertexUV( ix1, y - noZFightingOffset, z0, iu0, iv0 );
4065
4066 t->vertexUV( ix0, y - noZFightingOffset, z1, iu1, iv0 );
4067 t->vertexUV( ix0, y - noZFightingOffset, z0, iu1, iv1 );
4068 t->vertexUV( ix1, y - noZFightingOffset, z0, iu0, iv1 );
4069 t->vertexUV( ix1, y - noZFightingOffset, z1, iu0, iv0 );
4070 }
4071
4072 }
4073 else if ( !n && s )
4074 {
4075 // half-step towards south
4076 t->vertexUV( x1, y + 1, z1, u1, v0 );
4077 t->vertexUV( x1, y + 0, z1, u1, v2 );
4078 t->vertexUV( x1, y + 0, z2, u2, v2 );
4079 t->vertexUV( x1, y + 1, z2, u2, v0 );
4080
4081 t->vertexUV( x1, y + 1, z2, u1, v0 );
4082 t->vertexUV( x1, y + 0, z2, u1, v2 );
4083 t->vertexUV( x1, y + 0, z1, u2, v2 );
4084 t->vertexUV( x1, y + 1, z1, u2, v0 );
4085
4086 // small edge texture
4087 if ( !e && !w )
4088 {
4089 t->vertexUV( ix1, y + 1, z1, iu0, iv0 );
4090 t->vertexUV( ix1, y + 0, z1, iu0, iv2 );
4091 t->vertexUV( ix0, y + 0, z1, iu1, iv2 );
4092 t->vertexUV( ix0, y + 1, z1, iu1, iv0 );
4093
4094 t->vertexUV( ix0, y + 1, z1, iu0, iv0 );
4095 t->vertexUV( ix0, y + 0, z1, iu0, iv2 );
4096 t->vertexUV( ix1, y + 0, z1, iu1, iv2 );
4097 t->vertexUV( ix1, y + 1, z1, iu1, iv0 );
4098 }
4099
4100 if ( up || ( y < ( depth - 1 ) && level->isEmptyTile( x, y + 1, z + 1 ) ) )
4101 {
4102 // small edge texture
4103 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu0, iv1 );
4104 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv2 );
4105 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv2 );
4106 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu1, iv1 );
4107
4108 t->vertexUV( ix0, y + 1 + noZFightingOffset, z2, iu0, iv1 );
4109 t->vertexUV( ix0, y + 1 + noZFightingOffset, z1, iu0, iv2 );
4110 t->vertexUV( ix1, y + 1 + noZFightingOffset, z1, iu1, iv2 );
4111 t->vertexUV( ix1, y + 1 + noZFightingOffset, z2, iu1, iv1 );
4112 }
4113 if ( down || ( y > 1 && level->isEmptyTile( x, y - 1, z + 1 ) ) )
4114 {
4115 // small edge texture
4116 t->vertexUV( ix0, y - noZFightingOffset, z1, iu0, iv1 );
4117 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv2 );
4118 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv2 );
4119 t->vertexUV( ix1, y - noZFightingOffset, z1, iu1, iv1 );
4120
4121 t->vertexUV( ix0, y - noZFightingOffset, z2, iu0, iv1 );
4122 t->vertexUV( ix0, y - noZFightingOffset, z1, iu0, iv2 );
4123 t->vertexUV( ix1, y - noZFightingOffset, z1, iu1, iv2 );
4124 t->vertexUV( ix1, y - noZFightingOffset, z2, iu1, iv1 );
4125 }
4126
4127 }
4128
4129 return true;
4130}
4131
4132bool TileRenderer::tesselateCrossInWorld( Tile* tt, int x, int y, int z )
4133{
4134 Tesselator* t = Tesselator::getInstance();
4135
4136 float br;
4137 if ( SharedConstants::TEXTURE_LIGHTING )
4138 {
4139 t->tex2( getLightColor(tt, level, x, y, z ) );
4140 br = 1;
4141 }
4142 else
4143 {
4144 br = tt->getBrightness( level, x, y, z );
4145 }
4146
4147 int col = tt->getColor( level, x, y, z );
4148 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
4149 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
4150 float b = ( ( col )& 0xff ) / 255.0f;
4151
4152 if ( GameRenderer::anaglyph3d )
4153 {
4154 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
4155 float cg = ( r * 30 + g * 70 ) / ( 100 );
4156 float cb = ( r * 30 + b * 70 ) / ( 100 );
4157
4158 r = cr;
4159 g = cg;
4160 b = cb;
4161 }
4162 t->color( br * r, br * g, br * b );
4163
4164 float xt = (float)x;
4165 float yt = (float)y;
4166 float zt = (float)z;
4167
4168 if (tt == Tile::tallgrass)
4169 {
4170 __int64 seed = (x * 3129871) ^ (z * 116129781l) ^ (y);
4171 seed = seed * seed * 42317861 + seed * 11;
4172
4173 xt += ((((seed >> 16) & 0xf) / 15.0f) - 0.5f) * 0.5f;
4174 yt += ((((seed >> 20) & 0xf) / 15.0f) - 1.0f) * 0.2f;
4175 zt += ((((seed >> 24) & 0xf) / 15.0f) - 0.5f) * 0.5f;
4176 }
4177
4178 tesselateCrossTexture( tt, level->getData( x, y, z ), xt, yt, zt, 1 );
4179 return true;
4180}
4181
4182bool TileRenderer::tesselateStemInWorld( Tile* _tt, int x, int y, int z )
4183{
4184 StemTile* tt = ( StemTile* )_tt;
4185 Tesselator* t = Tesselator::getInstance();
4186
4187 float br;
4188 if ( SharedConstants::TEXTURE_LIGHTING )
4189 {
4190 t->tex2( getLightColor(tt, level, x, y, z ) );
4191 br = 1;
4192 }
4193 else
4194 {
4195 br = tt->getBrightness( level, x, y, z );
4196 }
4197 int col = tt->getColor( level, x, y, z );
4198 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
4199 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
4200 float b = ( ( col )& 0xff ) / 255.0f;
4201
4202 if ( GameRenderer::anaglyph3d )
4203 {
4204 float cr = ( r * 30.0f + g * 59.0f + b * 11.0f ) / 100.0f;
4205 float cg = ( r * 30.0f + g * 70.0f ) / ( 100.0f );
4206 float cb = ( r * 30.0f + b * 70.0f ) / ( 100.0f );
4207
4208 r = cr;
4209 g = cg;
4210 b = cb;
4211 }
4212 t->color( br * r, br * g, br * b );
4213
4214 tt->updateShape( level, x, y, z );
4215 int dir = tt->getConnectDir( level, x, y, z );
4216 if ( dir < 0 )
4217 {
4218 tesselateStemTexture( tt, level->getData( x, y, z ), tileShapeY1, x, y - 1 / 16.0f, z );
4219 }
4220 else
4221 {
4222 tesselateStemTexture( tt, level->getData( x, y, z ), 0.5f, x, y - 1 / 16.0f, z );
4223 tesselateStemDirTexture( tt, level->getData( x, y, z ), dir, tileShapeY1, x, y - 1 / 16.0f, z );
4224 }
4225 return true;
4226}
4227
4228bool TileRenderer::tesselateRowInWorld( Tile* tt, int x, int y, int z )
4229{
4230 Tesselator* t = Tesselator::getInstance();
4231
4232 if ( SharedConstants::TEXTURE_LIGHTING )
4233 {
4234 t->tex2( getLightColor(tt, level, x, y, z ) );
4235 t->color( 1.0f, 1.0f, 1.0f );
4236 }
4237 else
4238 {
4239 float br = tt->getBrightness( level, x, y, z );
4240 t->color( br, br, br );
4241 }
4242
4243 tesselateRowTexture( tt, level->getData( x, y, z ), x, y - 1.0f / 16.0f, z );
4244 return true;
4245}
4246
4247void TileRenderer::tesselateTorch( Tile* tt, float x, float y, float z, float xxa, float zza, int data )
4248{
4249 Tesselator* t = Tesselator::getInstance();
4250 Icon *tex = getTexture(tt, Facing::DOWN, data);
4251
4252 if (hasFixedTexture()) tex = fixedTexture;
4253 float u0 = tex->getU0(true);
4254 float v0 = tex->getV0(true);
4255 float u1 = tex->getU1(true);
4256 float v1 = tex->getV1(true);
4257
4258 float ut0 = tex->getU(7, true);
4259 float vt0 = tex->getV(6, true);
4260 float ut1 = tex->getU(9, true);
4261 float vt1 = tex->getV(8, true);
4262
4263 float ub0 = tex->getU(7, true);
4264 float vb0 = tex->getV(13, true);
4265 float ub1 = tex->getU(9, true);
4266 float vb1 = tex->getV(15, true);
4267
4268 x += 0.5f;
4269 z += 0.5f;
4270
4271 float x0 = x - 0.5f;
4272 float x1 = x + 0.5f;
4273 float z0 = z - 0.5f;
4274 float z1 = z + 0.5f;
4275 float r = 1 / 16.0f;
4276
4277 float h = 10.0f / 16.0f;
4278 t->vertexUV( ( float )( x + xxa * ( 1 - h ) - r ), ( float )( y + h ), ( float )( z + zza * ( 1 - h ) - r ), ut0, vt0 );
4279 t->vertexUV( ( float )( x + xxa * ( 1 - h ) - r ), ( float )( y + h ), ( float )( z + zza * ( 1 - h ) + r ), ut0, vt1 );
4280 t->vertexUV( ( float )( x + xxa * ( 1 - h ) + r ), ( float )( y + h ), ( float )( z + zza * ( 1 - h ) + r ), ut1, vt1 );
4281 t->vertexUV( ( float )( x + xxa * ( 1 - h ) + r ), ( float )( y + h ), ( float )( z + zza * ( 1 - h ) - r ), ut1, vt0 );
4282
4283 t->vertexUV( (float)(x + r + xxa), (float) y, (float)(z - r + zza), ub1, vb0);
4284 t->vertexUV( (float)(x + r + xxa), (float) y, (float)(z + r + zza), ub1, vb1);
4285 t->vertexUV( (float)(x - r + xxa), (float) y, (float)(z + r + zza), ub0, vb1);
4286 t->vertexUV( (float)(x - r + xxa), (float) y, (float)(z - r + zza), ub0, vb0);
4287
4288 t->vertexUV( ( float )( x - r ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
4289 t->vertexUV( ( float )( x - r + xxa ), ( float )( y + 0 ), ( float )( z0 +
4290 zza ), ( float )( u0 ), ( float )( v1 ) );
4291 t->vertexUV( ( float )( x - r + xxa ), ( float )( y + 0 ), ( float )( z1 +
4292 zza ), ( float )( u1 ), ( float )( v1 ) );
4293 t->vertexUV( ( float )( x - r ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
4294
4295 t->vertexUV( ( float )( x + r ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
4296 t->vertexUV( ( float )( x + xxa + r ), ( float )( y + 0 ), ( float )( z1 +
4297 zza ), ( float )( u0 ), ( float )( v1 ) );
4298 t->vertexUV( ( float )( x + xxa + r ), ( float )( y + 0 ), ( float )( z0 +
4299 zza ), ( float )( u1 ), ( float )( v1 ) );
4300 t->vertexUV( ( float )( x + r ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
4301
4302 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z + r ), ( float )( u0 ), ( float )( v0 ) );
4303 t->vertexUV( ( float )( x0 + xxa ), ( float )( y + 0 ), ( float )( z + r +
4304 zza ), ( float )( u0 ), ( float )( v1 ) );
4305 t->vertexUV( ( float )( x1 + xxa ), ( float )( y + 0 ), ( float )( z + r +
4306 zza ), ( float )( u1 ), ( float )( v1 ) );
4307 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z + r ), ( float )( u1 ), ( float )( v0 ) );
4308
4309 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z - r ), ( float )( u0 ), ( float )( v0 ) );
4310 t->vertexUV( ( float )( x1 + xxa ), ( float )( y + 0 ), ( float )( z - r +
4311 zza ), ( float )( u0 ), ( float )( v1 ) );
4312 t->vertexUV( ( float )( x0 + xxa ), ( float )( y + 0 ), ( float )( z - r +
4313 zza ), ( float )( u1 ), ( float )( v1 ) );
4314 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z - r ), ( float )( u1 ), ( float )( v0 ) );
4315}
4316
4317void TileRenderer::tesselateCrossTexture( Tile* tt, int data, float x, float y, float z, float scale )
4318{
4319 Tesselator* t = Tesselator::getInstance();
4320
4321 Icon *tex = getTexture(tt, 0, data);
4322
4323 if (hasFixedTexture()) tex = fixedTexture;
4324 float u0 = tex->getU0(true);
4325 float v0 = tex->getV0(true);
4326 float u1 = tex->getU1(true);
4327 float v1 = tex->getV1(true);
4328
4329 float width = 0.45 * scale;
4330 float x0 = x + 0.5 - width;
4331 float x1 = x + 0.5 + width;
4332 float z0 = z + 0.5 - width;
4333 float z1 = z + 0.5 + width;
4334
4335 t->vertexUV( ( float )( x0 ), ( float )( y + scale ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
4336 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
4337 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
4338 t->vertexUV( ( float )( x1 ), ( float )( y + scale ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
4339
4340 t->vertexUV( ( float )( x1 ), ( float )( y + scale ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
4341 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
4342 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
4343 t->vertexUV( ( float )( x0 ), ( float )( y + scale ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
4344
4345 t->vertexUV( ( float )( x0 ), ( float )( y + scale ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
4346 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
4347 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
4348 t->vertexUV( ( float )( x1 ), ( float )( y + scale ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
4349
4350 t->vertexUV( ( float )( x1 ), ( float )( y + scale ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
4351 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
4352 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
4353 t->vertexUV( ( float )( x0 ), ( float )( y + scale ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
4354
4355}
4356
4357void TileRenderer::tesselateStemTexture( Tile* tt, int data, float h, float x, float y, float z )
4358{
4359 Tesselator* t = Tesselator::getInstance();
4360
4361 Icon *tex = getTexture(tt, 0, data);
4362
4363 if (hasFixedTexture()) tex = fixedTexture;
4364 float u0 = tex->getU0(true);
4365 float v0 = tex->getV0(true);
4366 float u1 = tex->getU1(true);
4367 float v1 = tex->getV(h * SharedConstants::WORLD_RESOLUTION, true);
4368
4369 float x0 = x + 0.5f - 0.45f;
4370 float x1 = x + 0.5f + 0.45f;
4371 float z0 = z + 0.5f - 0.45f;
4372 float z1 = z + 0.5f + 0.45f;
4373
4374 t->vertexUV( x0, y + h, z0, u0, v0 );
4375 t->vertexUV( x0, y + 0, z0, u0, v1 );
4376 t->vertexUV( x1, y + 0, z1, u1, v1 );
4377 t->vertexUV( x1, y + h, z1, u1, v0 );
4378
4379 t->vertexUV( x1, y + h, z1, u0, v0 );
4380 t->vertexUV( x1, y + 0, z1, u0, v1 );
4381 t->vertexUV( x0, y + 0, z0, u1, v1 );
4382 t->vertexUV( x0, y + h, z0, u1, v0 );
4383
4384 t->vertexUV( x0, y + h, z1, u0, v0 );
4385 t->vertexUV( x0, y + 0, z1, u0, v1 );
4386 t->vertexUV( x1, y + 0, z0, u1, v1 );
4387 t->vertexUV( x1, y + h, z0, u1, v0 );
4388
4389 t->vertexUV( x1, y + h, z0, u0, v0 );
4390 t->vertexUV( x1, y + 0, z0, u0, v1 );
4391 t->vertexUV( x0, y + 0, z1, u1, v1 );
4392 t->vertexUV( x0, y + h, z1, u1, v0 );
4393}
4394
4395bool TileRenderer::tesselateLilypadInWorld(Tile *tt, int x, int y, int z)
4396{
4397 Tesselator *t = Tesselator::getInstance();
4398
4399 Icon *tex = getTexture(tt, Facing::UP);
4400
4401 if (hasFixedTexture()) tex = fixedTexture;
4402 float h = 0.25f / 16.0f;
4403
4404 float u0 = tex->getU0(true);
4405 float v0 = tex->getV0(true);
4406 float u1 = tex->getU1(true);
4407 float v1 = tex->getV1(true);
4408
4409 __int64 seed = (x * 3129871) ^ (z * 116129781l) ^ (y);
4410 seed = seed * seed * 42317861 + seed * 11;
4411
4412 int dir = (int) ((seed >> 16) & 0x3);
4413
4414
4415
4416 t->tex2(getLightColor(tt, level, x, y, z));
4417
4418 float xx = x + 0.5f;
4419 float zz = z + 0.5f;
4420 float c = ((dir & 1) * 0.5f) * (1 - dir / 2 % 2 * 2);
4421 float s = (((dir + 1) & 1) * 0.5f) * (1 - (dir + 1) / 2 % 2 * 2);
4422
4423 t->color(tt->getColor());
4424 t->vertexUV(xx + c - s, y + h, zz + c + s, u0, v0);
4425 t->vertexUV(xx + c + s, y + h, zz - c + s, u1, v0);
4426 t->vertexUV(xx - c + s, y + h, zz - c - s, u1, v1);
4427 t->vertexUV(xx - c - s, y + h, zz + c - s, u0, v1);
4428
4429 t->color((tt->getColor() & 0xfefefe) >> 1);
4430 t->vertexUV(xx - c - s, y + h, zz + c - s, u0, v1);
4431 t->vertexUV(xx - c + s, y + h, zz - c - s, u1, v1);
4432 t->vertexUV(xx + c + s, y + h, zz - c + s, u1, v0);
4433 t->vertexUV(xx + c - s, y + h, zz + c + s, u0, v0);
4434
4435
4436 return true;
4437}
4438
4439void TileRenderer::tesselateStemDirTexture( StemTile* tt, int data, int dir, float h, float x, float y, float z )
4440{
4441 Tesselator* t = Tesselator::getInstance();
4442
4443 Icon *tex = tt->getAngledTexture();
4444
4445 if (hasFixedTexture()) tex = fixedTexture;
4446 float u0 = tex->getU0(true);
4447 float v0 = tex->getV0(true);
4448 float u1 = tex->getU1(true);
4449 float v1 = tex->getV1(true);
4450
4451 float x0 = x + 0.5f - 0.5f;
4452 float x1 = x + 0.5f + 0.5f;
4453 float z0 = z + 0.5f - 0.5f;
4454 float z1 = z + 0.5f + 0.5f;
4455
4456 float xm = x + 0.5f;
4457 float zm = z + 0.5f;
4458
4459 if ( ( dir + 1 ) / 2 % 2 == 1 )
4460 {
4461 float tmp = u1;
4462 u1 = u0;
4463 u0 = tmp;
4464 }
4465
4466 if ( dir < 2 )
4467 {
4468 t->vertexUV( x0, y + h, zm, u0, v0 );
4469 t->vertexUV( x0, y + 0, zm, u0, v1 );
4470 t->vertexUV( x1, y + 0, zm, u1, v1 );
4471 t->vertexUV( x1, y + h, zm, u1, v0 );
4472
4473 t->vertexUV( x1, y + h, zm, u1, v0 );
4474 t->vertexUV( x1, y + 0, zm, u1, v1 );
4475 t->vertexUV( x0, y + 0, zm, u0, v1 );
4476 t->vertexUV( x0, y + h, zm, u0, v0 );
4477 }
4478 else
4479 {
4480 t->vertexUV( xm, y + h, z1, u0, v0 );
4481 t->vertexUV( xm, y + 0, z1, u0, v1 );
4482 t->vertexUV( xm, y + 0, z0, u1, v1 );
4483 t->vertexUV( xm, y + h, z0, u1, v0 );
4484
4485 t->vertexUV( xm, y + h, z0, u1, v0 );
4486 t->vertexUV( xm, y + 0, z0, u1, v1 );
4487 t->vertexUV( xm, y + 0, z1, u0, v1 );
4488 t->vertexUV( xm, y + h, z1, u0, v0 );
4489 }
4490}
4491
4492
4493void TileRenderer::tesselateRowTexture( Tile* tt, int data, float x, float y, float z )
4494{
4495 Tesselator* t = Tesselator::getInstance();
4496
4497 Icon *tex = getTexture(tt, 0, data);
4498
4499 if (hasFixedTexture()) tex = fixedTexture;
4500 float u0 = tex->getU0(true);
4501 float v0 = tex->getV0(true);
4502 float u1 = tex->getU1(true);
4503 float v1 = tex->getV1(true);
4504
4505 float x0 = x + 0.5f - 0.25f;
4506 float x1 = x + 0.5f + 0.25f;
4507 float z0 = z + 0.5f - 0.5f;
4508 float z1 = z + 0.5f + 0.5f;
4509
4510 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
4511 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
4512 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
4513 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
4514
4515 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
4516 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
4517 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
4518 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
4519
4520 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
4521 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
4522 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
4523 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
4524
4525 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
4526 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
4527 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
4528 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
4529
4530 x0 = x + 0.5f - 0.5f;
4531 x1 = x + 0.5f + 0.5f;
4532 z0 = z + 0.5f - 0.25f;
4533 z1 = z + 0.5f + 0.25f;
4534
4535 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
4536 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
4537 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
4538 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
4539
4540 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u0 ), ( float )( v0 ) );
4541 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
4542 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u1 ), ( float )( v1 ) );
4543 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z0 ), ( float )( u1 ), ( float )( v0 ) );
4544
4545 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
4546 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
4547 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
4548 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
4549
4550 t->vertexUV( ( float )( x0 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u0 ), ( float )( v0 ) );
4551 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u0 ), ( float )( v1 ) );
4552 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
4553 t->vertexUV( ( float )( x1 ), ( float )( y + 1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v0 ) );
4554
4555}
4556
4557bool TileRenderer::tesselateWaterInWorld( Tile* tt, int x, int y, int z )
4558{
4559 // 4J Java comment
4560 // TODO: This all needs to change. Somehow.
4561 Tesselator* t = Tesselator::getInstance();
4562
4563 int col = tt->getColor( level, x, y, z );
4564 float r = ( col >> 16 & 0xff ) / 255.0f;
4565 float g = ( col >> 8 & 0xff ) / 255.0f;
4566 float b = ( col & 0xff ) / 255.0f;
4567 bool up = tt->shouldRenderFace( level, x, y + 1, z, 1 );
4568 bool down = tt->shouldRenderFace( level, x, y - 1, z, 0 );
4569 bool dirs[4];
4570 dirs[0] = tt->shouldRenderFace( level, x, y, z - 1, 2 );
4571 dirs[1] = tt->shouldRenderFace( level, x, y, z + 1, 3 );
4572 dirs[2] = tt->shouldRenderFace( level, x - 1, y, z, 4 );
4573 dirs[3] = tt->shouldRenderFace( level, x + 1, y, z, 5 );
4574
4575 if ( !up && !down && !dirs[0] && !dirs[1] && !dirs[2] && !dirs[3] ) return false;
4576
4577 bool changed = false;
4578 float c10 = 0.5f;
4579 float c11 = 1;
4580 float c2 = 0.8f;
4581 float c3 = 0.6f;
4582
4583 double yo0 = 0;
4584 double yo1 = 1;
4585
4586 Material* m = tt->material;
4587 int data = level->getData( x, y, z );
4588
4589 float h0 = getWaterHeight( x, y, z, m );
4590 float h1 = getWaterHeight( x, y, z + 1, m );
4591 float h2 = getWaterHeight( x + 1, y, z + 1, m );
4592 float h3 = getWaterHeight( x + 1, y, z, m );
4593
4594 float offs = 0.001f;
4595 // 4J - added. Farm tiles often found beside water, but they consider themselves non-solid as they only extend up to 15.0f / 16.0f.
4596 // If the max height of this water is below that level, don't bother rendering sides bordering onto farmland.
4597 float maxh = h0;
4598 if ( h1 > maxh ) maxh = h1;
4599 if ( h2 > maxh ) maxh = h2;
4600 if ( h3 > maxh ) maxh = h3;
4601 if ( maxh <= ( 15.0f / 16.0f ) )
4602 {
4603 if ( level->getTile( x, y, z - 1 ) == Tile::farmland_Id )
4604 {
4605 dirs[0] = false;
4606 }
4607 if ( level->getTile( x, y, z + 1 ) == Tile::farmland_Id )
4608 {
4609 dirs[1] = false;
4610 }
4611 if ( level->getTile( x - 1, y, z ) == Tile::farmland_Id )
4612 {
4613 dirs[2] = false;
4614 }
4615 if ( level->getTile( x + 1, y, z ) == Tile::farmland_Id )
4616 {
4617 dirs[3] = false;
4618 }
4619 }
4620
4621 if ( noCulling || up )
4622 {
4623 changed = true;
4624 Icon *tex = getTexture( tt, 1, data );
4625 float angle = ( float )LiquidTile::getSlopeAngle( level, x, y, z, m );
4626 if ( angle > -999 )
4627 {
4628 tex = getTexture( tt, 2, data );
4629 }
4630
4631 h0 -= offs;
4632 h1 -= offs;
4633 h2 -= offs;
4634 h3 -= offs;
4635
4636 float u00, u01, u10, u11;
4637 float v00, v01, v10, v11;
4638 if ( angle < -999 )
4639 {
4640 u00 = tex->getU(0, true);
4641 v00 = tex->getV(0, true);
4642 u01 = u00;
4643 v01 = tex->getV(SharedConstants::WORLD_RESOLUTION, true);
4644 u10 = tex->getU(SharedConstants::WORLD_RESOLUTION, true);
4645 v10 = v01;
4646 u11 = u10;
4647 v11 = v00;
4648 }
4649 else
4650 {
4651 float s = Mth::sin(angle) * .25f;
4652 float c = Mth::cos(angle) * .25f;
4653 float cc = SharedConstants::WORLD_RESOLUTION * .5f;
4654 u00 = tex->getU(cc + (-c - s) * SharedConstants::WORLD_RESOLUTION);
4655 v00 = tex->getV(cc + (-c + s) * SharedConstants::WORLD_RESOLUTION);
4656 u01 = tex->getU(cc + (-c + s) * SharedConstants::WORLD_RESOLUTION);
4657 v01 = tex->getV(cc + (+c + s) * SharedConstants::WORLD_RESOLUTION);
4658 u10 = tex->getU(cc + (+c + s) * SharedConstants::WORLD_RESOLUTION);
4659 v10 = tex->getV(cc + (+c - s) * SharedConstants::WORLD_RESOLUTION);
4660 u11 = tex->getU(cc + (+c - s) * SharedConstants::WORLD_RESOLUTION);
4661 v11 = tex->getV(cc + (-c - s) * SharedConstants::WORLD_RESOLUTION);
4662 }
4663
4664 float br;
4665 if ( SharedConstants::TEXTURE_LIGHTING )
4666 {
4667 t->tex2( getLightColor(tt, level, x, y, z ) );
4668 br = 1;
4669 }
4670 else
4671 {
4672 br = tt->getBrightness( level, x, y, z );
4673 }
4674 t->color( c11 * br * r, c11 * br * g, c11 * br * b );
4675 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h0 ), ( float )( z + 0.0f ), u00, v00 );
4676 t->vertexUV( ( float )( x + 0.0f ), ( float )( y + h1 ), ( float )( z + 1.0f ), u01, v01 );
4677 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h2 ), ( float )( z + 1.0f ), u10, v10 );
4678 t->vertexUV( ( float )( x + 1.0f ), ( float )( y + h3 ), ( float )( z + 0.0f ), u11, v11 );
4679 }
4680
4681 if ( noCulling || down )
4682 {
4683 float br;
4684 if ( SharedConstants::TEXTURE_LIGHTING )
4685 {
4686 t->tex2( getLightColor(tt, level, x, y - 1, z ) );
4687 br = 1;
4688 }
4689 else
4690 {
4691 br = tt->getBrightness( level, x, y - 1, z );
4692 }
4693 t->color( c10 * br, c10 * br, c10 * br );
4694 renderFaceDown( tt, x, y + offs, z, getTexture( tt, 0 ) );
4695 changed = true;
4696 }
4697
4698 for ( int face = 0; face < 4; face++ )
4699 {
4700 int xt = x;
4701 int yt = y;
4702 int zt = z;
4703
4704 if ( face == 0 ) zt--;
4705 if ( face == 1 ) zt++;
4706 if ( face == 2 ) xt--;
4707 if ( face == 3 ) xt++;
4708
4709 Icon *tex = getTexture(tt, face + 2, data);
4710
4711 if ( noCulling || dirs[face] )
4712 {
4713 float hh0;
4714 float hh1;
4715 float x0, z0, x1, z1;
4716 if ( face == 0 )
4717 {
4718 hh0 = ( float )( h0 );
4719 hh1 = ( float )( h3 );
4720 x0 = ( float )( x );
4721 x1 = ( float )( x + 1 );
4722 z0 = ( float )( z + offs);
4723 z1 = ( float )( z + offs);
4724 }
4725 else if ( face == 1 )
4726 {
4727 hh0 = ( float )( h2 );
4728 hh1 = ( float )( h1 );
4729 x0 = ( float )( x + 1 );
4730 x1 = ( float )( x );
4731 z0 = ( float )( z + 1 - offs);
4732 z1 = ( float )( z + 1 - offs);
4733 }
4734 else if ( face == 2 )
4735 {
4736 hh0 = ( float )( h1 );
4737 hh1 = ( float )( h0 );
4738 x0 = ( float )( x + offs);
4739 x1 = ( float )( x + offs);
4740 z0 = ( float )( z + 1 );
4741 z1 = ( float )( z );
4742 }
4743 else
4744 {
4745 hh0 = ( float )( h3 );
4746 hh1 = ( float )( h2 );
4747 x0 = ( float )( x + 1 - offs);
4748 x1 = ( float )( x + 1 - offs);
4749 z0 = ( float )( z );
4750 z1 = ( float )( z + 1 );
4751 }
4752
4753
4754 changed = true;
4755 float u0 = tex->getU(0, true);
4756 float u1 = tex->getU(SharedConstants::WORLD_RESOLUTION * .5f, true);
4757
4758 int yTex = tex->getY();
4759 float v01 = tex->getV((1 - hh0) * SharedConstants::WORLD_RESOLUTION * .5f);
4760 float v02 = tex->getV((1 - hh1) * SharedConstants::WORLD_RESOLUTION * .5f);
4761 float v1 = tex->getV(SharedConstants::WORLD_RESOLUTION * .5f, true);
4762
4763 float br;
4764 if ( SharedConstants::TEXTURE_LIGHTING )
4765 {
4766 t->tex2( getLightColor(tt, level, xt, yt, zt ) );
4767 br = 1;
4768 }
4769 else
4770 {
4771 br = tt->getBrightness( level, xt, yt, zt );
4772 }
4773 if ( face < 2 ) br *= c2;
4774 else
4775 br *= c3;
4776
4777 t->color( c11 * br * r, c11 * br * g, c11 * br * b );
4778 t->vertexUV( ( float )( x0 ), ( float )( y + hh0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v01 ) );
4779 t->vertexUV( ( float )( x1 ), ( float )( y + hh1 ), ( float )( z1 ), ( float )( u1 ), ( float )( v02 ) );
4780 t->vertexUV( ( float )( x1 ), ( float )( y + 0 ), ( float )( z1 ), ( float )( u1 ), ( float )( v1 ) );
4781 t->vertexUV( ( float )( x0 ), ( float )( y + 0 ), ( float )( z0 ), ( float )( u0 ), ( float )( v1 ) );
4782
4783 }
4784
4785 }
4786
4787 tileShapeY0 = yo0;
4788 tileShapeY1 = yo1;
4789
4790 return changed;
4791
4792}
4793
4794float TileRenderer::getWaterHeight( int x, int y, int z, Material* m )
4795{
4796 int count = 0;
4797 float h = 0;
4798 for ( int i = 0; i < 4; i++ )
4799 {
4800 int xx = x - ( i & 1 );
4801 int yy = y;
4802 int zz = z - ( ( i >> 1 ) & 1 );
4803 if ( level->getMaterial( xx, yy + 1, zz ) == m )
4804 {
4805 return 1;
4806 }
4807 Material* tm = level->getMaterial( xx, yy, zz );
4808 if ( tm == m )
4809 {
4810 int d = level->getData( xx, yy, zz );
4811 if ( d >= 8 || d == 0 )
4812 {
4813 h += ( LiquidTile::getHeight( d ) )* 10;
4814 count += 10;
4815 }
4816 h += LiquidTile::getHeight( d );
4817 count++;
4818 }
4819 else if ( !tm->isSolid() )
4820 {
4821 h += 1;
4822 count++;
4823 }
4824 }
4825 return 1 - h / count;
4826}
4827
4828void TileRenderer::renderBlock( Tile* tt, Level* level, int x, int y, int z )
4829{
4830 renderBlock(tt, level, x, y, z, 0);
4831}
4832
4833void TileRenderer::renderBlock(Tile *tt, Level *level, int x, int y, int z, int data)
4834{
4835 float c10 = 0.5f;
4836 float c11 = 1;
4837 float c2 = 0.8f;
4838 float c3 = 0.6f;
4839
4840 Tesselator* t = Tesselator::getInstance();
4841 t->begin();
4842 if ( SharedConstants::TEXTURE_LIGHTING )
4843 {
4844 t->tex2( getLightColor(tt, level, x, y, z ) );
4845 }
4846 float center = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y, z );
4847 float br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y - 1, z );
4848
4849 if ( br < center ) br = center;
4850 t->color( c10 * br, c10 * br, c10 * br );
4851 renderFaceDown( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 0, data ) );
4852
4853 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y + 1, z );
4854 if ( br < center ) br = center;
4855 t->color( c11 * br, c11 * br, c11 * br );
4856 renderFaceUp( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 1, data ) );
4857
4858 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y, z - 1 );
4859 if ( br < center ) br = center;
4860 t->color( c2 * br, c2 * br, c2 * br );
4861 renderNorth( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 2, data ) );
4862
4863 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x, y, z + 1 );
4864 if ( br < center ) br = center;
4865 t->color( c2 * br, c2 * br, c2 * br );
4866 renderSouth( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 3, data ) );
4867
4868 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x - 1, y, z );
4869 if ( br < center ) br = center;
4870 t->color( c3 * br, c3 * br, c3 * br );
4871 renderWest( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 4, data ) );
4872
4873 br = SharedConstants::TEXTURE_LIGHTING ? 1 : tt->getBrightness( level, x + 1, y, z );
4874 if ( br < center ) br = center;
4875 t->color( c3 * br, c3 * br, c3 * br );
4876 renderEast( tt, -0.5f, -0.5f, -0.5f, getTexture( tt, 5, data ) );
4877 t->end();
4878
4879}
4880
4881bool TileRenderer::tesselateBlockInWorld( Tile* tt, int x, int y, int z )
4882{
4883 int col = tt->getColor( level, x, y, z );
4884 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
4885 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
4886 float b = ( ( col )& 0xff ) / 255.0f;
4887
4888 if ( GameRenderer::anaglyph3d )
4889 {
4890 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
4891 float cg = ( r * 30 + g * 70 ) / ( 100 );
4892 float cb = ( r * 30 + b * 70 ) / ( 100 );
4893
4894 r = cr;
4895 g = cg;
4896 b = cb;
4897 }
4898
4899 if ( Tile::lightEmission[tt->id] == 0 )//4J - TODO/remove (Minecraft::useAmbientOcclusion())
4900 {
4901 return tesselateBlockInWorldWithAmbienceOcclusionTexLighting(tt, x, y, z, r, g, b, 0, smoothShapeLighting);
4902 }
4903 else
4904 {
4905 return tesselateBlockInWorld( tt, x, y, z, r, g, b );
4906 }
4907}
4908
4909// AP - added this version to be able to pass the face flags down
4910bool TileRenderer::tesselateBlockInWorld( Tile* tt, int x, int y, int z, int faceFlags )
4911{
4912 int col = tt->getColor( level, x, y, z );
4913 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
4914 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
4915 float b = ( ( col )& 0xff ) / 255.0f;
4916
4917 if ( GameRenderer::anaglyph3d )
4918 {
4919 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
4920 float cg = ( r * 30 + g * 70 ) / ( 100 );
4921 float cb = ( r * 30 + b * 70 ) / ( 100 );
4922
4923 r = cr;
4924 g = cg;
4925 b = cb;
4926 }
4927
4928 if ( Tile::lightEmission[tt->id] == 0 )//4J - TODO/remove (Minecraft::useAmbientOcclusion())
4929 {
4930 return tesselateBlockInWorldWithAmbienceOcclusionTexLighting( tt, x, y, z, r, g, b, faceFlags, smoothShapeLighting );
4931 }
4932 else
4933 {
4934 return tesselateBlockInWorld( tt, x, y, z, r, g, b );
4935 }
4936}
4937
4938bool TileRenderer::tesselateTreeInWorld(Tile *tt, int x, int y, int z)
4939{
4940 int data = level->getData(x, y, z);
4941 int facing = data & TreeTile::MASK_FACING;
4942
4943 if (facing == TreeTile::FACING_X)
4944 {
4945 northFlip = FLIP_CW;
4946 southFlip = FLIP_CW;
4947 upFlip = FLIP_CW;
4948 downFlip = FLIP_CW;
4949 }
4950 else if (facing == TreeTile::FACING_Z)
4951 {
4952 eastFlip = FLIP_CW;
4953 westFlip = FLIP_CW;
4954 }
4955
4956 bool result = tesselateBlockInWorld(tt, x, y, z);
4957
4958 eastFlip = 0;
4959 northFlip = 0;
4960 southFlip = 0;
4961 westFlip = 0;
4962 upFlip = 0;
4963 downFlip = 0;
4964
4965 return result;
4966}
4967
4968bool TileRenderer::tesselateQuartzInWorld(Tile *tt, int x, int y, int z)
4969{
4970 int data = level->getData(x, y, z);
4971
4972 if (data == QuartzBlockTile::TYPE_LINES_X)
4973 {
4974 northFlip = FLIP_CW;
4975 southFlip = FLIP_CW;
4976 upFlip = FLIP_CW;
4977 downFlip = FLIP_CW;
4978 }
4979 else if (data == QuartzBlockTile::TYPE_LINES_Z)
4980 {
4981 eastFlip = FLIP_CW;
4982 westFlip = FLIP_CW;
4983 }
4984
4985 bool result = tesselateBlockInWorld(tt, x, y, z);
4986
4987 eastFlip = 0;
4988 northFlip = 0;
4989 southFlip = 0;
4990 westFlip = 0;
4991 upFlip = 0;
4992 downFlip = 0;
4993
4994 return result;
4995}
4996
4997bool TileRenderer::tesselateCocoaInWorld(CocoaTile *tt, int x, int y, int z)
4998{
4999 Tesselator *t = Tesselator::getInstance();
5000
5001 if (SharedConstants::TEXTURE_LIGHTING)
5002 {
5003 t->tex2(getLightColor(tt, level, x, y, z));
5004 t->color(1.0f, 1.0f, 1.0f);
5005 }
5006 else
5007 {
5008 float br = tt->getBrightness(level, x, y, z);
5009 if (Tile::lightEmission[tt->id] > 0) br = 1.0f;
5010 t->color(br, br, br);
5011 }
5012
5013 int data = level->getData(x, y, z);
5014 int dir = DirectionalTile::getDirection(data);
5015 int age = CocoaTile::getAge(data);
5016 Icon *tex = tt->getTextureForAge(age);
5017
5018 int cocoaWidth = 4 + age * 2;
5019 int cocoaHeight = 5 + age * 2;
5020
5021 double us = 15.0 - cocoaWidth;
5022 double ue = 15.0;
5023 double vs = 4.0;
5024 double ve = 4.0 + cocoaHeight;
5025 double u0 = tex->getU(us, true);
5026 double u1 = tex->getU(ue, true);
5027 double v0 = tex->getV(vs, true);
5028 double v1 = tex->getV(ve, true);
5029
5030
5031 double offX = 0;
5032 double offZ = 0;
5033
5034 switch (dir)
5035 {
5036 case Direction::NORTH:
5037 offX = 8.0 - cocoaWidth / 2;
5038 offZ = 1.0;
5039 break;
5040 case Direction::SOUTH:
5041 offX = 8.0 - cocoaWidth / 2;
5042 offZ = 15.0 - cocoaWidth;
5043 break;
5044 case Direction::EAST:
5045 offX = 15.0 - cocoaWidth;
5046 offZ = 8.0 - cocoaWidth / 2;
5047 break;
5048 case Direction::WEST:
5049 offX = 1.0;
5050 offZ = 8.0 - cocoaWidth / 2;
5051 break;
5052 }
5053
5054 double x0 = x + offX / 16.0;
5055 double x1 = x + (offX + cocoaWidth) / 16.0;
5056 double y0 = y + (12.0 - cocoaHeight) / 16.0;
5057 double y1 = y + 12.0 / 16.0;
5058 double z0 = z + offZ / 16.0;
5059 double z1 = z + (offZ + cocoaWidth) / 16.0;
5060
5061 // west
5062 {
5063 t->vertexUV(x0, y0, z0, u0, v1);
5064 t->vertexUV(x0, y0, z1, u1, v1);
5065 t->vertexUV(x0, y1, z1, u1, v0);
5066 t->vertexUV(x0, y1, z0, u0, v0);
5067 }
5068 // east
5069 {
5070 t->vertexUV(x1, y0, z1, u0, v1);
5071 t->vertexUV(x1, y0, z0, u1, v1);
5072 t->vertexUV(x1, y1, z0, u1, v0);
5073 t->vertexUV(x1, y1, z1, u0, v0);
5074 }
5075 // north
5076 {
5077 t->vertexUV(x1, y0, z0, u0, v1);
5078 t->vertexUV(x0, y0, z0, u1, v1);
5079 t->vertexUV(x0, y1, z0, u1, v0);
5080 t->vertexUV(x1, y1, z0, u0, v0);
5081 }
5082 // south
5083 {
5084 t->vertexUV(x0, y0, z1, u0, v1);
5085 t->vertexUV(x1, y0, z1, u1, v1);
5086 t->vertexUV(x1, y1, z1, u1, v0);
5087 t->vertexUV(x0, y1, z1, u0, v0);
5088 }
5089
5090 int topWidth = cocoaWidth;
5091 if (age >= 2)
5092 {
5093 // special case because the top piece didn't fit
5094 topWidth--;
5095 }
5096
5097 u0 = tex->getU0(true);
5098 u1 = tex->getU(topWidth, true);
5099 v0 = tex->getV0(true);
5100 v1 = tex->getV(topWidth, true);
5101
5102 // top
5103 {
5104 t->vertexUV(x0, y1, z1, u0, v1);
5105 t->vertexUV(x1, y1, z1, u1, v1);
5106 t->vertexUV(x1, y1, z0, u1, v0);
5107 t->vertexUV(x0, y1, z0, u0, v0);
5108 }
5109 // bottom
5110 {
5111 t->vertexUV(x0, y0, z0, u0, v0);
5112 t->vertexUV(x1, y0, z0, u1, v0);
5113 t->vertexUV(x1, y0, z1, u1, v1);
5114 t->vertexUV(x0, y0, z1, u0, v1);
5115 }
5116
5117 // stalk
5118 u0 = tex->getU(12, true);
5119 u1 = tex->getU1(true);
5120 v0 = tex->getV0(true);
5121 v1 = tex->getV(4, true);
5122
5123 offX = 8;
5124 offZ = 0;
5125
5126 switch (dir)
5127 {
5128 case Direction::NORTH:
5129 offX = 8.0;
5130 offZ = 0.0;
5131 break;
5132 case Direction::SOUTH:
5133 offX = 8;
5134 offZ = 12;
5135 {
5136 double temp = u0;
5137 u0 = u1;
5138 u1 = temp;
5139 }
5140 break;
5141 case Direction::EAST:
5142 offX = 12.0;
5143 offZ = 8.0;
5144 {
5145 double temp = u0;
5146 u0 = u1;
5147 u1 = temp;
5148 }
5149 break;
5150 case Direction::WEST:
5151 offX = 0.0;
5152 offZ = 8.0;
5153 break;
5154 }
5155
5156 x0 = x + offX / 16.0;
5157 x1 = x + (offX + 4.0) / 16.0;
5158 y0 = y + 12.0 / 16.0;
5159 y1 = y + 16.0 / 16.0;
5160 z0 = z + offZ / 16.0;
5161 z1 = z + (offZ + 4.0) / 16.0;
5162 if (dir == Direction::NORTH || dir == Direction::SOUTH)
5163 {
5164 // west
5165 {
5166 t->vertexUV(x0, y0, z0, u1, v1);
5167 t->vertexUV(x0, y0, z1, u0, v1);
5168 t->vertexUV(x0, y1, z1, u0, v0);
5169 t->vertexUV(x0, y1, z0, u1, v0);
5170 }
5171 // east
5172 {
5173 t->vertexUV(x0, y0, z1, u0, v1);
5174 t->vertexUV(x0, y0, z0, u1, v1);
5175 t->vertexUV(x0, y1, z0, u1, v0);
5176 t->vertexUV(x0, y1, z1, u0, v0);
5177 }
5178 }
5179 else if (dir == Direction::WEST || dir == Direction::EAST)
5180 {
5181 // north
5182 {
5183 t->vertexUV(x1, y0, z0, u0, v1);
5184 t->vertexUV(x0, y0, z0, u1, v1);
5185 t->vertexUV(x0, y1, z0, u1, v0);
5186 t->vertexUV(x1, y1, z0, u0, v0);
5187 }
5188 // south
5189 {
5190 t->vertexUV(x0, y0, z0, u1, v1);
5191 t->vertexUV(x1, y0, z0, u0, v1);
5192 t->vertexUV(x1, y1, z0, u0, v0);
5193 t->vertexUV(x0, y1, z0, u1, v0);
5194 }
5195 }
5196
5197 return true;
5198}
5199
5200// 4J - brought changes forward from 1.8.2
5201bool TileRenderer::tesselateBlockInWorldWithAmbienceOcclusionTexLighting( Tile* tt, int pX, int pY, int pZ,
5202 float pBaseRed, float pBaseGreen,
5203 float pBaseBlue, int faceFlags, bool smoothShapeLighting )
5204{
5205 // 4J - the texture is (originally) obtained for each face in the block, if those faces are visible. For a lot of blocks,
5206 // the textures don't vary from face to face - this is particularly an issue for leaves as they not only don't vary between faces,
5207 // but they also happen to draw a lot of faces, and the code for determining which texture to use is more complex than in most
5208 // cases. Optimisation here then to store a uniform texture where appropriate (could be extended beyond leaves) that will stop
5209 // any other faces being evaluated.
5210 Icon *uniformTex = NULL;
5211 int id = tt->id;
5212 if( id == Tile::leaves_Id )
5213 {
5214 uniformTex = getTexture(tt, level, pX, pY, pZ, 0);
5215 }
5216 // 4J - added these faceFlags so we can detect whether this block is going to have no visible faces and early out
5217 // the original code checked noCulling and shouldRenderFace directly where faceFlags is used now
5218 // AP - I moved a copy of these face checks to have an even earlier out
5219 // check if the faceFlags have indeed been set
5220 if( faceFlags == 0 )
5221 {
5222 if ( noCulling )
5223 {
5224 faceFlags = 0x3f;
5225 }
5226 else
5227 {
5228 faceFlags |= tt->shouldRenderFace( level, pX, pY - 1, pZ, 0 ) ? 0x01 : 0;
5229 faceFlags |= tt->shouldRenderFace( level, pX, pY + 1, pZ, 1 ) ? 0x02 : 0;
5230 faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ - 1, 2 ) ? 0x04 : 0;
5231 faceFlags |= tt->shouldRenderFace( level, pX, pY, pZ + 1, 3 ) ? 0x08 : 0;
5232 faceFlags |= tt->shouldRenderFace( level, pX - 1, pY, pZ, 4 ) ? 0x10 : 0;
5233 faceFlags |= tt->shouldRenderFace( level, pX + 1, pY, pZ, 5 ) ? 0x20 : 0;
5234 }
5235 if ( faceFlags == 0 )
5236 {
5237 return false;
5238 }
5239 }
5240 // If we are only rendering the bottom face and we're at the bottom of the world, we shouldn't be able to see this - don't render anything
5241 if( ( faceFlags == 1 ) && ( pY == 0 ) )
5242 {
5243 return false;
5244 }
5245
5246 applyAmbienceOcclusion = true;
5247 bool i = false;
5248 float ll1 = 0;
5249 float ll2 = 0;
5250 float ll3 = 0;
5251 float ll4 = 0;
5252
5253 bool tintSides = true;
5254
5255 int centerColor = getLightColor(tt, level, pX, pY, pZ );
5256
5257 Tesselator* t = Tesselator::getInstance();
5258 t->tex2( 0xf000f );
5259
5260 if( uniformTex == NULL )
5261 {
5262 if ( getTexture(tt)->getFlags() == Icon::IS_GRASS_TOP ) tintSides = false;
5263 }
5264 else if (hasFixedTexture())
5265 {
5266 tintSides = false;
5267 }
5268
5269 if ( faceFlags & 0x01 )
5270 {
5271 if ( tileShapeY0 <= 0 ) pY--;
5272
5273 ccxy0 = getLightColor(tt, level, pX - 1, pY, pZ );
5274 cc0yz = getLightColor(tt, level, pX, pY, pZ - 1 );
5275 cc0yZ = getLightColor(tt, level, pX, pY, pZ + 1 );
5276 ccXy0 = getLightColor(tt, level, pX + 1, pY, pZ );
5277
5278 llxy0 = getShadeBrightness(tt, level, pX - 1, pY, pZ );
5279 ll0yz = getShadeBrightness(tt, level, pX, pY, pZ - 1 );
5280 ll0yZ = getShadeBrightness(tt, level, pX, pY, pZ + 1 );
5281 llXy0 = getShadeBrightness(tt, level, pX + 1, pY, pZ );
5282
5283 bool llTransXy0 = Tile::transculent[level->getTile(pX + 1, pY - 1, pZ)];
5284 bool llTransxy0 = Tile::transculent[level->getTile(pX - 1, pY - 1, pZ)];
5285 bool llTrans0yZ = Tile::transculent[level->getTile(pX, pY - 1, pZ + 1)];
5286 bool llTrans0yz = Tile::transculent[level->getTile(pX, pY - 1, pZ - 1)];
5287
5288 if ( llTrans0yz || llTransxy0 )
5289 {
5290 llxyz = getShadeBrightness(tt, level, pX - 1, pY, pZ - 1 );
5291 ccxyz = getLightColor(tt, level, pX - 1, pY, pZ - 1 );
5292 }
5293 else
5294 {
5295 llxyz = llxy0;
5296 ccxyz = ccxy0;
5297 }
5298 if ( llTrans0yZ || llTransxy0 )
5299 {
5300 llxyZ = getShadeBrightness(tt, level, pX - 1, pY, pZ + 1 );
5301 ccxyZ = getLightColor(tt, level, pX - 1, pY, pZ + 1 );
5302 }
5303 else
5304 {
5305 llxyZ = llxy0;
5306 ccxyZ = ccxy0;
5307 }
5308 if ( llTrans0yz || llTransXy0 )
5309 {
5310 llXyz = getShadeBrightness(tt, level, pX + 1, pY, pZ - 1 );
5311 ccXyz = getLightColor(tt, level, pX + 1, pY, pZ - 1 );
5312 }
5313 else
5314 {
5315 llXyz = llXy0;
5316 ccXyz = ccXy0;
5317 }
5318 if ( llTrans0yZ || llTransXy0 )
5319 {
5320 llXyZ = getShadeBrightness(tt, level, pX + 1, pY, pZ + 1 );
5321 ccXyZ = getLightColor(tt, level, pX + 1, pY, pZ + 1 );
5322 }
5323 else
5324 {
5325 llXyZ = llXy0;
5326 ccXyZ = ccXy0;
5327 }
5328
5329 if ( tileShapeY0 <= 0 ) pY++;
5330
5331 int cc0y0 = centerColor;
5332 if (tileShapeY0 <= 0 || !level->isSolidRenderTile(pX, pY - 1, pZ)) cc0y0 = tt->getLightColor(level, pX, pY - 1, pZ);
5333 float ll0y0 = tt->getShadeBrightness(level, pX, pY - 1, pZ);
5334
5335 ll1 = ( llxyZ + llxy0 + ll0yZ + ll0y0 ) / 4.0f;
5336 ll4 = ( ll0yZ + ll0y0 + llXyZ + llXy0 ) / 4.0f;
5337 ll3 = ( ll0y0 + ll0yz + llXy0 + llXyz ) / 4.0f;
5338 ll2 = ( llxy0 + llxyz + ll0y0 + ll0yz ) / 4.0f;
5339
5340 tc1 = blend( ccxyZ, ccxy0, cc0yZ, cc0y0 );
5341 tc4 = blend( cc0yZ, ccXyZ, ccXy0, cc0y0 );
5342 tc3 = blend( cc0yz, ccXy0, ccXyz, cc0y0 );
5343 tc2 = blend( ccxy0, ccxyz, cc0yz, cc0y0 );
5344
5345 if (tintSides)
5346 {
5347 c1r = c2r = c3r = c4r = pBaseRed * 0.5f;
5348 c1g = c2g = c3g = c4g = pBaseGreen * 0.5f;
5349 c1b = c2b = c3b = c4b = pBaseBlue * 0.5f;
5350 }
5351 else
5352 {
5353 c1r = c2r = c3r = c4r = 0.5f;
5354 c1g = c2g = c3g = c4g = 0.5f;
5355 c1b = c2b = c3b = c4b = 0.5f;
5356 }
5357 c1r *= ll1;
5358 c1g *= ll1;
5359 c1b *= ll1;
5360 c2r *= ll2;
5361 c2g *= ll2;
5362 c2b *= ll2;
5363 c3r *= ll3;
5364 c3g *= ll3;
5365 c3b *= ll3;
5366 c4r *= ll4;
5367 c4g *= ll4;
5368 c4b *= ll4;
5369
5370 renderFaceDown( tt, ( double )pX, ( double )pY, ( double )pZ, uniformTex ? uniformTex : getTexture( tt, level, pX, pY, pZ, 0 ) );
5371 i = true;
5372 }
5373 if ( faceFlags & 0x02 )
5374 {
5375 if ( tileShapeY1 >= 1 ) pY++; // 4J - condition brought forward from 1.2.3
5376
5377 ccxY0 = getLightColor(tt, level, pX - 1, pY, pZ );
5378 ccXY0 = getLightColor(tt, level, pX + 1, pY, pZ );
5379 cc0Yz = getLightColor(tt, level, pX, pY, pZ - 1 );
5380 cc0YZ = getLightColor(tt, level, pX, pY, pZ + 1 );
5381
5382 llxY0 = getShadeBrightness(tt, level, pX - 1, pY, pZ );
5383 llXY0 = getShadeBrightness(tt, level, pX + 1, pY, pZ );
5384 ll0Yz = getShadeBrightness(tt, level, pX, pY, pZ - 1 );
5385 ll0YZ = getShadeBrightness(tt, level, pX, pY, pZ + 1 );
5386
5387 bool llTransXY0 = Tile::transculent[level->getTile(pX + 1, pY + 1, pZ)];
5388 bool llTransxY0 = Tile::transculent[level->getTile(pX - 1, pY + 1, pZ)];
5389 bool llTrans0YZ = Tile::transculent[level->getTile(pX, pY + 1, pZ + 1)];
5390 bool llTrans0Yz = Tile::transculent[level->getTile(pX, pY + 1, pZ - 1)];
5391
5392 if ( llTrans0Yz || llTransxY0 )
5393 {
5394 llxYz = getShadeBrightness(tt, level, pX - 1, pY, pZ - 1 );
5395 ccxYz = getLightColor(tt, level, pX - 1, pY, pZ - 1 );
5396 }
5397 else
5398 {
5399 llxYz = llxY0;
5400 ccxYz = ccxY0;
5401 }
5402 if ( llTrans0Yz || llTransXY0 )
5403 {
5404 llXYz = getShadeBrightness(tt, level, pX + 1, pY, pZ - 1 );
5405 ccXYz = getLightColor(tt, level, pX + 1, pY, pZ - 1 );
5406 }
5407 else
5408 {
5409 llXYz = llXY0;
5410 ccXYz = ccXY0;
5411 }
5412 if ( llTrans0YZ || llTransxY0 )
5413 {
5414 llxYZ = getShadeBrightness(tt, level, pX - 1, pY, pZ + 1 );
5415 ccxYZ = getLightColor(tt, level, pX - 1, pY, pZ + 1 );
5416 }
5417 else
5418 {
5419 llxYZ = llxY0;
5420 ccxYZ = ccxY0;
5421 }
5422 if ( llTrans0YZ || llTransXY0 )
5423 {
5424 llXYZ = getShadeBrightness(tt, level, pX + 1, pY, pZ + 1 );
5425 ccXYZ = getLightColor(tt, level, pX + 1, pY, pZ + 1 );
5426 }
5427 else
5428 {
5429 llXYZ = llXY0;
5430 ccXYZ = ccXY0;
5431 }
5432 if ( tileShapeY1 >= 1 ) pY--;
5433
5434 int cc0Y0 = centerColor;
5435 if (tileShapeY1 >= 1 || !level->isSolidRenderTile(pX, pY + 1, pZ)) cc0Y0 = tt->getLightColor(level, pX, pY + 1, pZ);
5436 float ll0Y0 = tt->getShadeBrightness(level, pX, pY + 1, pZ);
5437
5438 ll4 = ( llxYZ + llxY0 + ll0YZ + ll0Y0 ) / 4.0f;
5439 ll1 = ( ll0YZ + ll0Y0 + llXYZ + llXY0 ) / 4.0f;
5440 ll2 = ( ll0Y0 + ll0Yz + llXY0 + llXYz ) / 4.0f;
5441 ll3 = ( llxY0 + llxYz + ll0Y0 + ll0Yz ) / 4.0f;
5442
5443 tc4 = blend( ccxYZ, ccxY0, cc0YZ, cc0Y0 );
5444 tc1 = blend( cc0YZ, ccXYZ, ccXY0, cc0Y0 );
5445 tc2 = blend( cc0Yz, ccXY0, ccXYz, cc0Y0 );
5446 tc3 = blend( ccxY0, ccxYz, cc0Yz, cc0Y0 );
5447
5448 c1r = c2r = c3r = c4r = pBaseRed;
5449 c1g = c2g = c3g = c4g = pBaseGreen;
5450 c1b = c2b = c3b = c4b = pBaseBlue;
5451 c1r *= ll1;
5452 c1g *= ll1;
5453 c1b *= ll1;
5454 c2r *= ll2;
5455 c2g *= ll2;
5456 c2b *= ll2;
5457 c3r *= ll3;
5458 c3g *= ll3;
5459 c3b *= ll3;
5460 c4r *= ll4;
5461 c4g *= ll4;
5462 c4b *= ll4;
5463 renderFaceUp( tt, ( double )pX, ( double )pY, ( double )pZ, uniformTex ? uniformTex : getTexture( tt, level, pX, pY, pZ, 1 ) );
5464 i = true;
5465 }
5466 if ( faceFlags & 0x04 )
5467 {
5468 if ( tileShapeZ0 <= 0 ) pZ--; // 4J - condition brought forward from 1.2.3
5469 llx0z = getShadeBrightness(tt, level, pX - 1, pY, pZ );
5470 ll0yz = getShadeBrightness(tt, level, pX, pY - 1, pZ );
5471 ll0Yz = getShadeBrightness(tt, level, pX, pY + 1, pZ );
5472 llX0z = getShadeBrightness(tt, level, pX + 1, pY, pZ );
5473
5474 ccx0z = getLightColor(tt, level, pX - 1, pY, pZ );
5475 cc0yz = getLightColor(tt, level, pX, pY - 1, pZ );
5476 cc0Yz = getLightColor(tt, level, pX, pY + 1, pZ );
5477 ccX0z = getLightColor(tt, level, pX + 1, pY, pZ );
5478
5479 bool llTransX0z = Tile::transculent[level->getTile(pX + 1, pY, pZ - 1)];
5480 bool llTransx0z = Tile::transculent[level->getTile(pX - 1, pY, pZ - 1)];
5481 bool llTrans0Yz = Tile::transculent[level->getTile(pX, pY + 1, pZ - 1)];
5482 bool llTrans0yz = Tile::transculent[level->getTile(pX, pY - 1, pZ - 1)];
5483
5484 if ( llTransx0z || llTrans0yz )
5485 {
5486 llxyz = getShadeBrightness(tt, level, pX - 1, pY - 1, pZ );
5487 ccxyz = getLightColor(tt, level, pX - 1, pY - 1, pZ );
5488 }
5489 else
5490 {
5491 llxyz = llx0z;
5492 ccxyz = ccx0z;
5493 }
5494 if ( llTransx0z || llTrans0Yz )
5495 {
5496 llxYz = getShadeBrightness(tt, level, pX - 1, pY + 1, pZ );
5497 ccxYz = getLightColor(tt, level, pX - 1, pY + 1, pZ );
5498 }
5499 else
5500 {
5501 llxYz = llx0z;
5502 ccxYz = ccx0z;
5503 }
5504 if ( llTransX0z || llTrans0yz )
5505 {
5506 llXyz = getShadeBrightness(tt, level, pX + 1, pY - 1, pZ );
5507 ccXyz = getLightColor(tt, level, pX + 1, pY - 1, pZ );
5508 }
5509 else
5510 {
5511 llXyz = llX0z;
5512 ccXyz = ccX0z;
5513 }
5514 if ( llTransX0z || llTrans0Yz )
5515 {
5516 llXYz = getShadeBrightness(tt, level, pX + 1, pY + 1, pZ );
5517 ccXYz = getLightColor(tt, level, pX + 1, pY + 1, pZ );
5518 }
5519 else
5520 {
5521 llXYz = llX0z;
5522 ccXYz = ccX0z;
5523 }
5524 if ( tileShapeZ0 <= 0 ) pZ++;
5525
5526 int cc00z = centerColor;
5527 if (tileShapeZ0 <= 0 || !level->isSolidRenderTile(pX, pY, pZ - 1)) cc00z = tt->getLightColor(level, pX, pY, pZ - 1);
5528 float ll00z = tt->getShadeBrightness(level, pX, pY, pZ - 1);
5529
5530 {
5531 if(smoothShapeLighting) // MGH - unifying tesselateBlockInWorldWithAmbienceOcclusionTexLighting and tesselateBlockInWorldWithAmbienceOcclusionTexLighting2
5532 {
5533 float _ll1 = (llx0z + llxYz + ll00z + ll0Yz) / 4.0f;
5534 float _ll2 = (ll00z + ll0Yz + llX0z + llXYz) / 4.0f;
5535 float _ll3 = (ll0yz + ll00z + llXyz + llX0z) / 4.0f;
5536 float _ll4 = (llxyz + llx0z + ll0yz + ll00z) / 4.0f;
5537 ll1 = (float) (_ll1 * tileShapeY1 * (1.0 - tileShapeX0) + _ll2 * tileShapeY0 * tileShapeX0 + _ll3 * (1.0 - tileShapeY1) * tileShapeX0 + _ll4 * (1.0 - tileShapeY1)
5538 * (1.0 - tileShapeX0));
5539 ll2 = (float) (_ll1 * tileShapeY1 * (1.0 - tileShapeX1) + _ll2 * tileShapeY1 * tileShapeX1 + _ll3 * (1.0 - tileShapeY1) * tileShapeX1 + _ll4 * (1.0 - tileShapeY1)
5540 * (1.0 - tileShapeX1));
5541 ll3 = (float) (_ll1 * tileShapeY0 * (1.0 - tileShapeX1) + _ll2 * tileShapeY0 * tileShapeX1 + _ll3 * (1.0 - tileShapeY0) * tileShapeX1 + _ll4 * (1.0 - tileShapeY0)
5542 * (1.0 - tileShapeX1));
5543 ll4 = (float) (_ll1 * tileShapeY0 * (1.0 - tileShapeX0) + _ll2 * tileShapeY0 * tileShapeX0 + _ll3 * (1.0 - tileShapeY0) * tileShapeX0 + _ll4 * (1.0 - tileShapeY0)
5544 * (1.0 - tileShapeX0));
5545
5546 int _tc1 = blend(ccx0z, ccxYz, cc0Yz, cc00z);
5547 int _tc2 = blend(cc0Yz, ccX0z, ccXYz, cc00z);
5548 int _tc3 = blend(cc0yz, ccXyz, ccX0z, cc00z);
5549 int _tc4 = blend(ccxyz, ccx0z, cc0yz, cc00z);
5550 tc1 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * (1.0 - tileShapeX0), tileShapeY1 * tileShapeX0, (1.0 - tileShapeY1) * tileShapeX0, (1.0 - tileShapeY1) * (1.0 - tileShapeX0));
5551 tc2 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * (1.0 - tileShapeX1), tileShapeY1 * tileShapeX1, (1.0 - tileShapeY1) * tileShapeX1, (1.0 - tileShapeY1) * (1.0 - tileShapeX1));
5552 tc3 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * (1.0 - tileShapeX1), tileShapeY0 * tileShapeX1, (1.0 - tileShapeY0) * tileShapeX1, (1.0 - tileShapeY0) * (1.0 - tileShapeX1));
5553 tc4 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * (1.0 - tileShapeX0), tileShapeY0 * tileShapeX0, (1.0 - tileShapeY0) * tileShapeX0, (1.0 - tileShapeY0) * (1.0 - tileShapeX0));
5554
5555 }
5556 else
5557 {
5558 ll1 = ( llx0z + llxYz + ll00z + ll0Yz ) / 4.0f;
5559 ll2 = ( ll00z + ll0Yz + llX0z + llXYz ) / 4.0f;
5560 ll3 = ( ll0yz + ll00z + llXyz + llX0z ) / 4.0f;
5561 ll4 = ( llxyz + llx0z + ll0yz + ll00z ) / 4.0f;
5562
5563 tc1 = blend( ccx0z, ccxYz, cc0Yz, cc00z );
5564 tc2 = blend( cc0Yz, ccX0z, ccXYz, cc00z );
5565 tc3 = blend( cc0yz, ccXyz, ccX0z, cc00z );
5566 tc4 = blend( ccxyz, ccx0z, cc0yz, cc00z );
5567
5568 }
5569 }
5570
5571 if (tintSides)
5572 {
5573 c1r = c2r = c3r = c4r = pBaseRed * 0.8f;
5574 c1g = c2g = c3g = c4g = pBaseGreen * 0.8f;
5575 c1b = c2b = c3b = c4b = pBaseBlue * 0.8f;
5576 }
5577 else
5578 {
5579 c1r = c2r = c3r = c4r = 0.8f;
5580 c1g = c2g = c3g = c4g = 0.8f;
5581 c1b = c2b = c3b = c4b = 0.8f;
5582 }
5583 c1r *= ll1;
5584 c1g *= ll1;
5585 c1b *= ll1;
5586 c2r *= ll2;
5587 c2g *= ll2;
5588 c2b *= ll2;
5589 c3r *= ll3;
5590 c3g *= ll3;
5591 c3b *= ll3;
5592 c4r *= ll4;
5593 c4g *= ll4;
5594 c4b *= ll4;
5595
5596 Icon *tex = uniformTex ? uniformTex : getTexture(tt, level, pX, pY, pZ, 2);
5597 renderNorth( tt, ( double )pX, ( double )pY, ( double )pZ, tex );
5598
5599 if ( fancy && (tex->getFlags() == Icon::IS_GRASS_SIDE) && !hasFixedTexture() )
5600 {
5601 c1r *= pBaseRed;
5602 c2r *= pBaseRed;
5603 c3r *= pBaseRed;
5604 c4r *= pBaseRed;
5605 c1g *= pBaseGreen;
5606 c2g *= pBaseGreen;
5607 c3g *= pBaseGreen;
5608 c4g *= pBaseGreen;
5609 c1b *= pBaseBlue;
5610 c2b *= pBaseBlue;
5611 c3b *= pBaseBlue;
5612 c4b *= pBaseBlue;
5613 bool prev = t->setMipmapEnable( false ); // 4J added - this is rendering the little bit of grass at the top of the side of dirt, don't mipmap it
5614 renderNorth( tt, ( double )pX, ( double )pY, ( double )pZ, GrassTile::getSideTextureOverlay() );
5615 t->setMipmapEnable( prev );
5616 }
5617
5618 i = true;
5619 }
5620 if ( faceFlags & 0x08 )
5621 {
5622 if ( tileShapeZ1 >= 1 ) pZ++;
5623
5624 llx0Z = getShadeBrightness(tt, level, pX - 1, pY, pZ );
5625 llX0Z = getShadeBrightness(tt, level, pX + 1, pY, pZ );
5626 ll0yZ = getShadeBrightness(tt, level, pX, pY - 1, pZ );
5627 ll0YZ = getShadeBrightness(tt, level, pX, pY + 1, pZ );
5628
5629 ccx0Z = getLightColor(tt, level, pX - 1, pY, pZ );
5630 ccX0Z = getLightColor(tt, level, pX + 1, pY, pZ );
5631 cc0yZ = getLightColor(tt, level, pX, pY - 1, pZ );
5632 cc0YZ = getLightColor(tt, level, pX, pY + 1, pZ );
5633
5634 bool llTransX0Z = Tile::transculent[level->getTile(pX + 1, pY, pZ + 1)];
5635 bool llTransx0Z = Tile::transculent[level->getTile(pX - 1, pY, pZ + 1)];
5636 bool llTrans0YZ = Tile::transculent[level->getTile(pX, pY + 1, pZ + 1)];
5637 bool llTrans0yZ = Tile::transculent[level->getTile(pX, pY - 1, pZ + 1)];
5638
5639 if ( llTransx0Z || llTrans0yZ )
5640 {
5641 llxyZ = getShadeBrightness(tt, level, pX - 1, pY - 1, pZ );
5642 ccxyZ = getLightColor(tt, level, pX - 1, pY - 1, pZ );
5643 }
5644 else
5645 {
5646 llxyZ = llx0Z;
5647 ccxyZ = ccx0Z;
5648 }
5649 if ( llTransx0Z || llTrans0YZ )
5650 {
5651 llxYZ = getShadeBrightness(tt, level, pX - 1, pY + 1, pZ );
5652 ccxYZ = getLightColor(tt, level, pX - 1, pY + 1, pZ );
5653 }
5654 else
5655 {
5656 llxYZ = llx0Z;
5657 ccxYZ = ccx0Z;
5658 }
5659 if ( llTransX0Z || llTrans0yZ )
5660 {
5661 llXyZ = getShadeBrightness(tt, level, pX + 1, pY - 1, pZ );
5662 ccXyZ = getLightColor(tt, level, pX + 1, pY - 1, pZ );
5663 }
5664 else
5665 {
5666 llXyZ = llX0Z;
5667 ccXyZ = ccX0Z;
5668 }
5669 if ( llTransX0Z || llTrans0YZ )
5670 {
5671 llXYZ = getShadeBrightness(tt, level, pX + 1, pY + 1, pZ );
5672 ccXYZ = getLightColor(tt, level, pX + 1, pY + 1, pZ );
5673 }
5674 else
5675 {
5676 llXYZ = llX0Z;
5677 ccXYZ = ccX0Z;
5678 }
5679 if ( tileShapeZ1 >= 1 ) pZ--;
5680
5681 int cc00Z = centerColor;
5682 if (tileShapeZ1 >= 1 || !level->isSolidRenderTile(pX, pY, pZ + 1)) cc00Z = tt->getLightColor(level, pX, pY, pZ + 1);
5683 float ll00Z = tt->getShadeBrightness(level, pX, pY, pZ + 1);
5684
5685 {
5686 if(smoothShapeLighting) // MGH - unifying tesselateBlockInWorldWithAmbienceOcclusionTexLighting and tesselateBlockInWorldWithAmbienceOcclusionTexLighting2
5687 {
5688 float _ll1 = (llx0Z + llxYZ + ll00Z + ll0YZ) / 4.0f;
5689 float _ll4 = (ll00Z + ll0YZ + llX0Z + llXYZ) / 4.0f;
5690 float _ll3 = (ll0yZ + ll00Z + llXyZ + llX0Z) / 4.0f;
5691 float _ll2 = (llxyZ + llx0Z + ll0yZ + ll00Z) / 4.0f;
5692 ll1 = (float) (_ll1 * tileShapeY1 * (1.0 - tileShapeX0) + _ll4 * tileShapeY1 * tileShapeX0 + _ll3 * (1.0 - tileShapeY1) * tileShapeX0 + _ll2 * (1.0 - tileShapeY1)
5693 * (1.0 - tileShapeX0));
5694 ll2 = (float) (_ll1 * tileShapeY0 * (1.0 - tileShapeX0) + _ll4 * tileShapeY0 * tileShapeX0 + _ll3 * (1.0 - tileShapeY0) * tileShapeX0 + _ll2 * (1.0 - tileShapeY0)
5695 * (1.0 - tileShapeX0));
5696 ll3 = (float) (_ll1 * tileShapeY0 * (1.0 - tileShapeX1) + _ll4 * tileShapeY0 * tileShapeX1 + _ll3 * (1.0 - tileShapeY0) * tileShapeX1 + _ll2 * (1.0 - tileShapeY0)
5697 * (1.0 - tileShapeX1));
5698 ll4 = (float) (_ll1 * tileShapeY1 * (1.0 - tileShapeX1) + _ll4 * tileShapeY1 * tileShapeX1 + _ll3 * (1.0 - tileShapeY1) * tileShapeX1 + _ll2 * (1.0 - tileShapeY1)
5699 * (1.0 - tileShapeX1));
5700
5701 int _tc1 = blend(ccx0Z, ccxYZ, cc0YZ, cc00Z);
5702 int _tc4 = blend(cc0YZ, ccX0Z, ccXYZ, cc00Z);
5703 int _tc3 = blend(cc0yZ, ccXyZ, ccX0Z, cc00Z);
5704 int _tc2 = blend(ccxyZ, ccx0Z, cc0yZ, cc00Z);
5705 tc1 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * (1.0 - tileShapeX0), (1.0 - tileShapeY1) * (1.0 - tileShapeX0), (1.0 - tileShapeY1) * tileShapeX0, tileShapeY1 * tileShapeX0);
5706 tc2 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * (1.0 - tileShapeX0), (1.0 - tileShapeY0) * (1.0 - tileShapeX0), (1.0 - tileShapeY0) * tileShapeX0, tileShapeY0 * tileShapeX0);
5707 tc3 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * (1.0 - tileShapeX1), (1.0 - tileShapeY0) * (1.0 - tileShapeX1), (1.0 - tileShapeY0) * tileShapeX1, tileShapeY0 * tileShapeX1);
5708 tc4 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * (1.0 - tileShapeX1), (1.0 - tileShapeY1) * (1.0 - tileShapeX1), (1.0 - tileShapeY1) * tileShapeX1, tileShapeY1 * tileShapeX1);
5709 }
5710 else
5711 {
5712 ll1 = ( llx0Z + llxYZ + ll00Z + ll0YZ ) / 4.0f;
5713 ll4 = ( ll00Z + ll0YZ + llX0Z + llXYZ ) / 4.0f;
5714 ll3 = ( ll0yZ + ll00Z + llXyZ + llX0Z ) / 4.0f;
5715 ll2 = ( llxyZ + llx0Z + ll0yZ + ll00Z ) / 4.0f;
5716
5717 tc1 = blend( ccx0Z, ccxYZ, cc0YZ, cc00Z );
5718 tc4 = blend( cc0YZ, ccX0Z, ccXYZ, cc00Z );
5719 tc3 = blend( cc0yZ, ccXyZ, ccX0Z, cc00Z );
5720 tc2 = blend( ccxyZ, ccx0Z, cc0yZ, cc00Z );
5721 }
5722 }
5723
5724 if (tintSides)
5725 {
5726 c1r = c2r = c3r = c4r = pBaseRed * 0.8f;
5727 c1g = c2g = c3g = c4g = pBaseGreen * 0.8f;
5728 c1b = c2b = c3b = c4b = pBaseBlue * 0.8f;
5729 }
5730 else
5731 {
5732 c1r = c2r = c3r = c4r = 0.8f;
5733 c1g = c2g = c3g = c4g = 0.8f;
5734 c1b = c2b = c3b = c4b = 0.8f;
5735 }
5736 c1r *= ll1;
5737 c1g *= ll1;
5738 c1b *= ll1;
5739 c2r *= ll2;
5740 c2g *= ll2;
5741 c2b *= ll2;
5742 c3r *= ll3;
5743 c3g *= ll3;
5744 c3b *= ll3;
5745 c4r *= ll4;
5746 c4g *= ll4;
5747 c4b *= ll4;
5748
5749 Icon *tex = uniformTex ? uniformTex : getTexture(tt, level, pX, pY, pZ, 3);
5750 renderSouth( tt, ( double )pX, ( double )pY, ( double )pZ, tex );
5751 if ( fancy && (tex->getFlags() == Icon::IS_GRASS_SIDE) && !hasFixedTexture() )
5752 {
5753 c1r *= pBaseRed;
5754 c2r *= pBaseRed;
5755 c3r *= pBaseRed;
5756 c4r *= pBaseRed;
5757 c1g *= pBaseGreen;
5758 c2g *= pBaseGreen;
5759 c3g *= pBaseGreen;
5760 c4g *= pBaseGreen;
5761 c1b *= pBaseBlue;
5762 c2b *= pBaseBlue;
5763 c3b *= pBaseBlue;
5764 c4b *= pBaseBlue;
5765 bool prev = t->setMipmapEnable( false ); // 4J added - this is rendering the little bit of grass at the top of the side of dirt, don't mipmap it
5766 renderSouth( tt, ( double )pX, ( double )pY, ( double )pZ, GrassTile::getSideTextureOverlay() );
5767 t->setMipmapEnable( prev );
5768 }
5769
5770 i = true;
5771 }
5772 if ( faceFlags & 0x10 ) // ((noCulling) || (tt->shouldRenderFace(level, pX - 1, pY, pZ, 4)))
5773 {
5774 if ( tileShapeX0 <= 0 ) pX--; // 4J - condition brought forward from 1.2.3
5775 llxy0 = getShadeBrightness(tt, level, pX, pY - 1, pZ );
5776 llx0z = getShadeBrightness(tt, level, pX, pY, pZ - 1 );
5777 llx0Z = getShadeBrightness(tt, level, pX, pY, pZ + 1 );
5778 llxY0 = getShadeBrightness(tt, level, pX, pY + 1, pZ );
5779
5780 ccxy0 = getLightColor(tt, level, pX, pY - 1, pZ );
5781 ccx0z = getLightColor(tt, level, pX, pY, pZ - 1 );
5782 ccx0Z = getLightColor(tt, level, pX, pY, pZ + 1 );
5783 ccxY0 = getLightColor(tt, level, pX, pY + 1, pZ );
5784
5785 bool llTransxY0 = Tile::transculent[level->getTile(pX - 1, pY + 1, pZ)];
5786 bool llTransxy0 = Tile::transculent[level->getTile(pX - 1, pY - 1, pZ)];
5787 bool llTransx0z = Tile::transculent[level->getTile(pX - 1, pY, pZ - 1)];
5788 bool llTransx0Z = Tile::transculent[level->getTile(pX - 1, pY, pZ + 1)];
5789
5790 if ( llTransx0z || llTransxy0 )
5791 {
5792 llxyz = getShadeBrightness(tt, level, pX, pY - 1, pZ - 1 );
5793 ccxyz = getLightColor(tt, level, pX, pY - 1, pZ - 1 );
5794 }
5795 else
5796 {
5797 llxyz = llx0z;
5798 ccxyz = ccx0z;
5799 }
5800 if ( llTransx0Z || llTransxy0 )
5801 {
5802 llxyZ = getShadeBrightness(tt, level, pX, pY - 1, pZ + 1 );
5803 ccxyZ = getLightColor(tt, level, pX, pY - 1, pZ + 1 );
5804 }
5805 else
5806 {
5807 llxyZ = llx0Z;
5808 ccxyZ = ccx0Z;
5809 }
5810 if ( llTransx0z || llTransxY0 )
5811 {
5812 llxYz = getShadeBrightness(tt, level, pX, pY + 1, pZ - 1 );
5813 ccxYz = getLightColor(tt, level, pX, pY + 1, pZ - 1 );
5814 }
5815 else
5816 {
5817 llxYz = llx0z;
5818 ccxYz = ccx0z;
5819 }
5820 if ( llTransx0Z || llTransxY0 )
5821 {
5822 llxYZ = getShadeBrightness(tt, level, pX, pY + 1, pZ + 1 );
5823 ccxYZ = getLightColor(tt, level, pX, pY + 1, pZ + 1 );
5824 }
5825 else
5826 {
5827 llxYZ = llx0Z;
5828 ccxYZ = ccx0Z;
5829 }
5830 if ( tileShapeX0 <= 0 ) pX++; // 4J - condition brought forward from 1.2.3
5831
5832 int ccx00 = centerColor;
5833 if (tileShapeX0 <= 0 || !level->isSolidRenderTile(pX - 1, pY, pZ)) ccx00 = tt->getLightColor(level, pX - 1, pY, pZ);
5834 float llx00 = tt->getShadeBrightness(level, pX - 1, pY, pZ);
5835
5836 {
5837 if(smoothShapeLighting) // MGH - unifying tesselateBlockInWorldWithAmbienceOcclusionTexLighting and tesselateBlockInWorldWithAmbienceOcclusionTexLighting2
5838 {
5839 float _ll4 = (llxy0 + llxyZ + llx00 + llx0Z) / 4.0f;
5840 float _ll1 = (llx00 + llx0Z + llxY0 + llxYZ) / 4.0f;
5841 float _ll2 = (llx0z + llx00 + llxYz + llxY0) / 4.0f;
5842 float _ll3 = (llxyz + llxy0 + llx0z + llx00) / 4.0f;
5843 ll1 = (float) (_ll1 * tileShapeY1 * tileShapeZ1 + _ll2 * tileShapeY1 * (1.0 - tileShapeZ1) + _ll3 * (1.0 - tileShapeY1) * (1.0 - tileShapeZ1) + _ll4 * (1.0 - tileShapeY1)
5844 * tileShapeZ1);
5845 ll2 = (float) (_ll1 * tileShapeY1 * tileShapeZ0 + _ll2 * tileShapeY1 * (1.0 - tileShapeZ0) + _ll3 * (1.0 - tileShapeY1) * (1.0 - tileShapeZ0) + _ll4 * (1.0 - tileShapeY1)
5846 * tileShapeZ0);
5847 ll3 = (float) (_ll1 * tileShapeY0 * tileShapeZ0 + _ll2 * tileShapeY0 * (1.0 - tileShapeZ0) + _ll3 * (1.0 - tileShapeY0) * (1.0 - tileShapeZ0) + _ll4 * (1.0 - tileShapeY0)
5848 * tileShapeZ0);
5849 ll4 = (float) (_ll1 * tileShapeY0 * tileShapeZ1 + _ll2 * tileShapeY0 * (1.0 - tileShapeZ1) + _ll3 * (1.0 - tileShapeY0) * (1.0 - tileShapeZ1) + _ll4 * (1.0 - tileShapeY0)
5850 * tileShapeZ1);
5851
5852 int _tc4 = blend(ccxy0, ccxyZ, ccx0Z, ccx00);
5853 int _tc1 = blend(ccx0Z, ccxY0, ccxYZ, ccx00);
5854 int _tc2 = blend(ccx0z, ccxYz, ccxY0, ccx00);
5855 int _tc3 = blend(ccxyz, ccxy0, ccx0z, ccx00);
5856 tc1 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * tileShapeZ1, tileShapeY1 * (1.0 - tileShapeZ1), (1.0 - tileShapeY1) * (1.0 - tileShapeZ1), (1.0 - tileShapeY1) * tileShapeZ1);
5857 tc2 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY1 * tileShapeZ0, tileShapeY1 * (1.0 - tileShapeZ0), (1.0 - tileShapeY1) * (1.0 - tileShapeZ0), (1.0 - tileShapeY1) * tileShapeZ0);
5858 tc3 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * tileShapeZ0, tileShapeY0 * (1.0 - tileShapeZ0), (1.0 - tileShapeY0) * (1.0 - tileShapeZ0), (1.0 - tileShapeY0) * tileShapeZ0);
5859 tc4 = blend(_tc1, _tc2, _tc3, _tc4, tileShapeY0 * tileShapeZ1, tileShapeY0 * (1.0 - tileShapeZ1), (1.0 - tileShapeY0) * (1.0 - tileShapeZ1), (1.0 - tileShapeY0) * tileShapeZ1);
5860 }
5861 else
5862 {
5863 ll4 = ( llxy0 + llxyZ + llx00 + llx0Z ) / 4.0f;
5864 ll1 = ( llx00 + llx0Z + llxY0 + llxYZ ) / 4.0f;
5865 ll2 = ( llx0z + llx00 + llxYz + llxY0 ) / 4.0f;
5866 ll3 = ( llxyz + llxy0 + llx0z + llx00 ) / 4.0f;
5867
5868 tc4 = blend( ccxy0, ccxyZ, ccx0Z, ccx00 );
5869 tc1 = blend( ccx0Z, ccxY0, ccxYZ, ccx00 );
5870 tc2 = blend( ccx0z, ccxYz, ccxY0, ccx00 );
5871 tc3 = blend( ccxyz, ccxy0, ccx0z, ccx00 );
5872 }
5873 }
5874
5875 if (tintSides)
5876 {
5877 c1r = c2r = c3r = c4r = pBaseRed * 0.6f;
5878 c1g = c2g = c3g = c4g = pBaseGreen * 0.6f;
5879 c1b = c2b = c3b = c4b = pBaseBlue * 0.6f;
5880 }
5881 else
5882 {
5883 c1r = c2r = c3r = c4r = 0.6f;
5884 c1g = c2g = c3g = c4g = 0.6f;
5885 c1b = c2b = c3b = c4b = 0.6f;
5886 }
5887
5888 c1r *= ll1;
5889 c1g *= ll1;
5890 c1b *= ll1;
5891 c2r *= ll2;
5892 c2g *= ll2;
5893 c2b *= ll2;
5894 c3r *= ll3;
5895 c3g *= ll3;
5896 c3b *= ll3;
5897 c4r *= ll4;
5898 c4g *= ll4;
5899 c4b *= ll4;
5900 Icon *tex = uniformTex ? uniformTex : getTexture(tt, level, pX, pY, pZ, 4);
5901 renderWest( tt, ( double )pX, ( double )pY, ( double )pZ, tex );
5902 if ( fancy && (tex->getFlags() == Icon::IS_GRASS_SIDE) && !hasFixedTexture() )
5903 {
5904 c1r *= pBaseRed;
5905 c2r *= pBaseRed;
5906 c3r *= pBaseRed;
5907 c4r *= pBaseRed;
5908 c1g *= pBaseGreen;
5909 c2g *= pBaseGreen;
5910 c3g *= pBaseGreen;
5911 c4g *= pBaseGreen;
5912 c1b *= pBaseBlue;
5913 c2b *= pBaseBlue;
5914 c3b *= pBaseBlue;
5915 c4b *= pBaseBlue;
5916 bool prev = t->setMipmapEnable( false ); // 4J added - this is rendering the little bit of grass at the top of the side of dirt, don't mipmap it
5917 renderWest( tt, ( double )pX, ( double )pY, ( double )pZ, GrassTile::getSideTextureOverlay() );
5918 t->setMipmapEnable( prev );
5919 }
5920
5921 i = true;
5922 }
5923 if ( faceFlags & 0x20 ) // ((noCulling) || (tt->shouldRenderFace(level, pX + 1, pY, pZ, 5)))
5924 {
5925 if ( tileShapeX1 >= 1 ) pX++;
5926 llXy0 = getShadeBrightness(tt, level, pX, pY - 1, pZ );
5927 llX0z = getShadeBrightness(tt, level, pX, pY, pZ - 1 );
5928 llX0Z = getShadeBrightness(tt, level, pX, pY, pZ + 1 );
5929 llXY0 = getShadeBrightness(tt, level, pX, pY + 1, pZ );
5930
5931 ccXy0 = getLightColor(tt, level, pX, pY - 1, pZ );
5932 ccX0z = getLightColor(tt, level, pX, pY, pZ - 1 );
5933 ccX0Z = getLightColor(tt, level, pX, pY, pZ + 1 );
5934 ccXY0 = getLightColor(tt, level, pX, pY + 1, pZ );
5935
5936 bool llTransXY0 = Tile::transculent[level->getTile(pX + 1, pY + 1, pZ)];
5937 bool llTransXy0 = Tile::transculent[level->getTile(pX + 1, pY - 1, pZ)];
5938 bool llTransX0Z = Tile::transculent[level->getTile(pX + 1, pY, pZ + 1)];
5939 bool llTransX0z = Tile::transculent[level->getTile(pX + 1, pY, pZ - 1)];
5940
5941 if ( llTransXy0 || llTransX0z )
5942 {
5943 llXyz = getShadeBrightness(tt, level, pX, pY - 1, pZ - 1 );
5944 ccXyz = getLightColor(tt, level, pX, pY - 1, pZ - 1 );
5945 }
5946 else
5947 {
5948 llXyz = llX0z;
5949 ccXyz = ccX0z;
5950 }
5951 if ( llTransXy0 || llTransX0Z )
5952 {
5953 llXyZ = getShadeBrightness(tt, level, pX, pY - 1, pZ + 1 );
5954 ccXyZ = getLightColor(tt, level, pX, pY - 1, pZ + 1 );
5955 }
5956 else
5957 {
5958 llXyZ = llX0Z;
5959 ccXyZ = ccX0Z;
5960 }
5961 if ( llTransXY0 || llTransX0z )
5962 {
5963 llXYz = getShadeBrightness(tt, level, pX, pY + 1, pZ - 1 );
5964 ccXYz = getLightColor(tt, level, pX, pY + 1, pZ - 1 );
5965 }
5966 else
5967 {
5968 llXYz = llX0z;
5969 ccXYz = ccX0z;
5970 }
5971 if ( llTransXY0 || llTransX0Z )
5972 {
5973 llXYZ = getShadeBrightness(tt, level, pX, pY + 1, pZ + 1 );
5974 ccXYZ = getLightColor(tt, level, pX, pY + 1, pZ + 1 );
5975 }
5976 else
5977 {
5978 llXYZ = llX0Z;
5979 ccXYZ = ccX0Z;
5980 }
5981 if ( tileShapeX1 >= 1 ) pX--; // 4J - condition brought forward from 1.2.3
5982
5983 int ccX00 = centerColor;
5984 if (tileShapeX1 >= 1 || !level->isSolidRenderTile(pX + 1, pY, pZ)) ccX00 = tt->getLightColor(level, pX + 1, pY, pZ);
5985 float llX00 = tt->getShadeBrightness(level, pX + 1, pY, pZ);
5986
5987 {
5988 if(smoothShapeLighting) // MGH - unifying tesselateBlockInWorldWithAmbienceOcclusionTexLighting and tesselateBlockInWorldWithAmbienceOcclusionTexLighting2
5989 {
5990 float _ll1 = (llXy0 + llXyZ + llX00 + llX0Z) / 4.0f;
5991 float _ll2 = (llXyz + llXy0 + llX0z + llX00) / 4.0f;
5992 float _ll3 = (llX0z + llX00 + llXYz + llXY0) / 4.0f;
5993 float _ll4 = (llX00 + llX0Z + llXY0 + llXYZ) / 4.0f;
5994 ll1 = (float) (_ll1 * (1.0 - tileShapeY0) * tileShapeZ1 + _ll2 * (1.0 - tileShapeY0) * (1.0 - tileShapeZ1) + _ll3 * tileShapeY0 * (1.0 - tileShapeZ1) + _ll4 * tileShapeY0
5995 * tileShapeZ1);
5996 ll2 = (float) (_ll1 * (1.0 - tileShapeY0) * tileShapeZ0 + _ll2 * (1.0 - tileShapeY0) * (1.0 - tileShapeZ0) + _ll3 * tileShapeY0 * (1.0 - tileShapeZ0) + _ll4 * tileShapeY0
5997 * tileShapeZ0);
5998 ll3 = (float) (_ll1 * (1.0 - tileShapeY1) * tileShapeZ0 + _ll2 * (1.0 - tileShapeY1) * (1.0 - tileShapeZ0) + _ll3 * tileShapeY1 * (1.0 - tileShapeZ0) + _ll4 * tileShapeY1
5999 * tileShapeZ0);
6000 ll4 = (float) (_ll1 * (1.0 - tileShapeY1) * tileShapeZ1 + _ll2 * (1.0 - tileShapeY1) * (1.0 - tileShapeZ1) + _ll3 * tileShapeY1 * (1.0 - tileShapeZ1) + _ll4 * tileShapeY1
6001 * tileShapeZ1);
6002
6003 int _tc1 = blend(ccXy0, ccXyZ, ccX0Z, ccX00);
6004 int _tc4 = blend(ccX0Z, ccXY0, ccXYZ, ccX00);
6005 int _tc3 = blend(ccX0z, ccXYz, ccXY0, ccX00);
6006 int _tc2 = blend(ccXyz, ccXy0, ccX0z, ccX00);
6007 tc1 = blend(_tc1, _tc2, _tc3, _tc4, (1.0 - tileShapeY0) * tileShapeZ1, (1.0 - tileShapeY0) * (1.0 - tileShapeZ1), tileShapeY0 * (1.0 - tileShapeZ1), tileShapeY0 * tileShapeZ1);
6008 tc2 = blend(_tc1, _tc2, _tc3, _tc4, (1.0 - tileShapeY0) * tileShapeZ0, (1.0 - tileShapeY0) * (1.0 - tileShapeZ0), tileShapeY0 * (1.0 - tileShapeZ0), tileShapeY0 * tileShapeZ0);
6009 tc3 = blend(_tc1, _tc2, _tc3, _tc4, (1.0 - tileShapeY1) * tileShapeZ0, (1.0 - tileShapeY1) * (1.0 - tileShapeZ0), tileShapeY1 * (1.0 - tileShapeZ0), tileShapeY1 * tileShapeZ0);
6010 tc4 = blend(_tc1, _tc2, _tc3, _tc4, (1.0 - tileShapeY1) * tileShapeZ1, (1.0 - tileShapeY1) * (1.0 - tileShapeZ1), tileShapeY1 * (1.0 - tileShapeZ1), tileShapeY1 * tileShapeZ1);
6011 }
6012 else
6013 {
6014 ll1 = (llXy0 + llXyZ + llX00 + llX0Z) / 4.0f;
6015 ll2 = (llXyz + llXy0 + llX0z + llX00) / 4.0f;
6016 ll3 = (llX0z + llX00 + llXYz + llXY0) / 4.0f;
6017 ll4 = (llX00 + llX0Z + llXY0 + llXYZ) / 4.0f;
6018
6019 tc1 = blend(ccXy0, ccXyZ, ccX0Z, ccX00);
6020 tc4 = blend(ccX0Z, ccXY0, ccXYZ, ccX00);
6021 tc3 = blend(ccX0z, ccXYz, ccXY0, ccX00);
6022 tc2 = blend(ccXyz, ccXy0, ccX0z, ccX00);
6023 }
6024 }
6025 if (tintSides)
6026 {
6027 c1r = c2r = c3r = c4r = pBaseRed * 0.6f;
6028 c1g = c2g = c3g = c4g = pBaseGreen * 0.6f;
6029 c1b = c2b = c3b = c4b = pBaseBlue * 0.6f;
6030 }
6031 else
6032 {
6033 c1r = c2r = c3r = c4r = 0.6f;
6034 c1g = c2g = c3g = c4g = 0.6f;
6035 c1b = c2b = c3b = c4b = 0.6f;
6036 }
6037 c1r *= ll1;
6038 c1g *= ll1;
6039 c1b *= ll1;
6040 c2r *= ll2;
6041 c2g *= ll2;
6042 c2b *= ll2;
6043 c3r *= ll3;
6044 c3g *= ll3;
6045 c3b *= ll3;
6046 c4r *= ll4;
6047 c4g *= ll4;
6048 c4b *= ll4;
6049
6050 Icon *tex = getTexture(tt, level, pX, pY, pZ, 5);
6051 renderEast(tt, (double) pX, (double) pY, (double) pZ, tex);
6052 if (fancy && (tex->getFlags() == Icon::IS_GRASS_SIDE) && !hasFixedTexture())
6053 {
6054 c1r *= pBaseRed;
6055 c2r *= pBaseRed;
6056 c3r *= pBaseRed;
6057 c4r *= pBaseRed;
6058 c1g *= pBaseGreen;
6059 c2g *= pBaseGreen;
6060 c3g *= pBaseGreen;
6061 c4g *= pBaseGreen;
6062 c1b *= pBaseBlue;
6063 c2b *= pBaseBlue;
6064 c3b *= pBaseBlue;
6065 c4b *= pBaseBlue;
6066 renderEast(tt, (double) pX, (double) pY, (double) pZ, GrassTile::getSideTextureOverlay());
6067 }
6068 i = true;
6069 }
6070 applyAmbienceOcclusion = false;
6071
6072 return true;
6073}
6074
6075
6076// 4J - brought forward from 1.8.2
6077int TileRenderer::blend( int a, int b, int c, int def )
6078{
6079 if ( a == 0 ) a = def;
6080 if ( b == 0 ) b = def;
6081 if ( c == 0 ) c = def;
6082 return ( ( a + b + c + def ) >> 2 ) & 0xff00ff;
6083}
6084
6085int TileRenderer::blend(int a, int b, int c, int d, double fa, double fb, double fc, double fd)
6086{
6087
6088 int top = (int) ((double) ((a >> 16) & 0xff) * fa + (double) ((b >> 16) & 0xff) * fb + (double) ((c >> 16) & 0xff) * fc + (double) ((d >> 16) & 0xff) * fd) & 0xff;
6089 int bottom = (int) ((double) (a & 0xff) * fa + (double) (b & 0xff) * fb + (double) (c & 0xff) * fc + (double) (d & 0xff) * fd) & 0xff;
6090 return (top << 16) | bottom;
6091}
6092
6093bool TileRenderer::tesselateBlockInWorld( Tile* tt, int x, int y, int z, float r, float g, float b )
6094{
6095 applyAmbienceOcclusion = false;
6096
6097 Tesselator* t = Tesselator::getInstance();
6098
6099 bool changed = false;
6100 float c10 = 0.5f;
6101 float c11 = 1;
6102 float c2 = 0.8f;
6103 float c3 = 0.6f;
6104
6105 float r11 = c11 * r;
6106 float g11 = c11 * g;
6107 float b11 = c11 * b;
6108
6109 float r10 = c10;
6110 float r2 = c2;
6111 float r3 = c3;
6112
6113 float g10 = c10;
6114 float g2 = c2;
6115 float g3 = c3;
6116
6117 float b10 = c10;
6118 float b2 = c2;
6119 float b3 = c3;
6120
6121 if ( tt != Tile::grass )
6122 {
6123 r10 *= r;
6124 r2 *= r;
6125 r3 *= r;
6126
6127 g10 *= g;
6128 g2 *= g;
6129 g3 *= g;
6130
6131 b10 *= b;
6132 b2 *= b;
6133 b3 *= b;
6134 }
6135
6136 int centerColor = 0;
6137 float centerBrightness = 0.0f;
6138 if ( SharedConstants::TEXTURE_LIGHTING )
6139 {
6140 centerColor = getLightColor(tt, level, x, y, z );
6141 }
6142 else
6143 {
6144 centerBrightness = tt->getBrightness( level, x, y, z );
6145 }
6146
6147 if ( noCulling || tt->shouldRenderFace( level, x, y - 1, z, Facing::DOWN ) )
6148 {
6149 if ( SharedConstants::TEXTURE_LIGHTING )
6150 {
6151 t->tex2( tileShapeY0 > 0 ? centerColor : getLightColor(tt, level, x, y - 1, z ) );
6152 t->color( r10, g10, b10 );
6153 }
6154 else
6155 {
6156 float br = tt->getBrightness( level, x, y - 1, z );
6157 t->color( r10 * br, g10 * br, b10 * br );
6158 }
6159 renderFaceDown( tt, x, y, z, getTexture(tt, level, x, y, z, 0 ) );
6160 changed = true;
6161 }
6162
6163 if ( noCulling || tt->shouldRenderFace( level, x, y + 1, z, Facing::UP ) )
6164 {
6165 if ( SharedConstants::TEXTURE_LIGHTING )
6166 {
6167 t->tex2( tileShapeY1 < 1 ? centerColor : getLightColor(tt, level, x, y + 1, z ) );
6168 t->color( r11, g11, b11 );
6169 }
6170 else
6171 {
6172 float br = tt->getBrightness( level, x, y + 1, z );
6173 if ( tileShapeY1 != 1 && !tt->material->isLiquid() ) br = centerBrightness;
6174 t->color( r11 * br, g11 * br, b11 * br );
6175 }
6176 renderFaceUp( tt, x, y, z, getTexture(tt, level, x, y, z, 1 ) );
6177 changed = true;
6178 }
6179
6180 if ( noCulling || tt->shouldRenderFace( level, x, y, z - 1, Facing::NORTH ) )
6181 {
6182 if ( SharedConstants::TEXTURE_LIGHTING )
6183 {
6184 t->tex2( tileShapeZ0 > 0 ? centerColor : getLightColor(tt, level, x, y, z - 1 ) );
6185 t->color( r2, g2, b2 );
6186 }
6187 else
6188 {
6189 float br = tt->getBrightness( level, x, y, z - 1 );
6190 if ( tileShapeZ0 > 0 ) br = centerBrightness;
6191 t->color( r2 * br, g2 * br, b2 * br );
6192 }
6193
6194 Icon *tex = getTexture(tt, level, x, y, z, 2);
6195 renderNorth( tt, x, y, z, tex );
6196 if ( fancy && (tex->getFlags() == Icon::IS_GRASS_SIDE) && !hasFixedTexture() )
6197 {
6198 t->color( r2 * r, g2 * g, b2 * b );
6199 renderNorth( tt, x, y, z, GrassTile::getSideTextureOverlay() );
6200 }
6201 changed = true;
6202 }
6203
6204 if ( noCulling || tt->shouldRenderFace( level, x, y, z + 1, Facing::SOUTH ) )
6205 {
6206 if ( SharedConstants::TEXTURE_LIGHTING )
6207 {
6208 t->tex2( tileShapeZ1 < 1 ? centerColor : getLightColor(tt, level, x, y, z + 1 ) );
6209 t->color( r2, g2, b2 );
6210 }
6211 else
6212 {
6213 float br = tt->getBrightness( level, x, y, z + 1 );
6214 if ( tileShapeZ1 < 1 ) br = centerBrightness;
6215 t->color( r2 * br, g2 * br, b2 * br );
6216 }
6217 Icon *tex = getTexture(tt, level, x, y, z, 3);
6218 renderSouth( tt, x, y, z, tex );
6219 if ( fancy && (tex->getFlags() == Icon::IS_GRASS_SIDE) && !hasFixedTexture() )
6220 {
6221 t->color( r2 * r, g2 * g, b2 * b );
6222 renderSouth( tt, x, y, z, GrassTile::getSideTextureOverlay() );
6223 }
6224 changed = true;
6225 }
6226
6227 if ( noCulling || tt->shouldRenderFace( level, x - 1, y, z, Facing::WEST ) )
6228 {
6229 if ( SharedConstants::TEXTURE_LIGHTING )
6230 {
6231 t->tex2( tileShapeX0 > 0 ? centerColor : getLightColor(tt, level, x - 1, y, z ) );
6232 t->color( r3, g3, b3 );
6233 }
6234 else
6235 {
6236 float br = tt->getBrightness( level, x - 1, y, z );
6237 if ( tileShapeX0 > 0 ) br = centerBrightness;
6238 t->color( r3 * br, g3 * br, b3 * br );
6239 }
6240 Icon *tex = getTexture(tt, level, x, y, z, 4);
6241 renderWest( tt, x, y, z, tex );
6242 if ( fancy && (tex->getFlags() == Icon::IS_GRASS_SIDE) && !hasFixedTexture() )
6243 {
6244 t->color( r3 * r, g3 * g, b3 * b );
6245 renderWest( tt, x, y, z, GrassTile::getSideTextureOverlay() );
6246 }
6247 changed = true;
6248 }
6249
6250 if ( noCulling || tt->shouldRenderFace( level, x + 1, y, z, Facing::EAST ) )
6251 {
6252 if ( SharedConstants::TEXTURE_LIGHTING )
6253 {
6254 t->tex2( tileShapeX1 < 1 ? centerColor : getLightColor(tt, level, x + 1, y, z ) );
6255 t->color( r3, g3, b3 );
6256 }
6257 else
6258 {
6259 float br = tt->getBrightness( level, x + 1, y, z );
6260 if ( tileShapeX1 < 1 ) br = centerBrightness;
6261 t->color( r3 * br, g3 * br, b3 * br );
6262 }
6263 Icon *tex = getTexture(tt, level, x, y, z, 5);
6264 renderEast( tt, x, y, z, tex );
6265 if ( fancy && (tex->getFlags() == Icon::IS_GRASS_SIDE) && !hasFixedTexture() )
6266 {
6267 t->color( r3 * r, g3 * g, b3 * b );
6268 renderEast( tt, x, y, z, GrassTile::getSideTextureOverlay() );
6269 }
6270 changed = true;
6271 }
6272
6273 return changed;
6274
6275}
6276
6277bool TileRenderer::tesselateBeaconInWorld(Tile *tt, int x, int y, int z)
6278{
6279 float obsHeight = 3.0f / 16.0f;
6280
6281 setFixedTexture(getTexture(Tile::glass));
6282 setShape(0, 0, 0, 1, 1, 1);
6283 tesselateBlockInWorld(tt, x, y, z);
6284
6285 // Force drawing of all faces else the inner-block of the beacon gets culled.
6286 noCulling = true;
6287 setFixedTexture(getTexture(Tile::obsidian));
6288 setShape(2.0f / 16.0f, 0.1f / 16.0f, 2.0f / 16.0f, 14.0f / 16.0f, obsHeight, 14.0f / 16.0f);
6289 tesselateBlockInWorld(tt, x, y, z);
6290
6291 setFixedTexture(getTexture(Tile::beacon));
6292 setShape(3.0f / 16.0f, obsHeight, 3.0f / 16.0f, 13.0f / 16.0f, 14.0f / 16.0f, 13.0f / 16.0f);
6293 tesselateBlockInWorld(tt, x, y, z);
6294 noCulling = false;
6295
6296 clearFixedTexture();
6297
6298 return true;
6299}
6300
6301bool TileRenderer::tesselateCactusInWorld( Tile* tt, int x, int y, int z )
6302{
6303 int col = tt->getColor( level, x, y, z );
6304 float r = ( ( col >> 16 ) & 0xff ) / 255.0f;
6305 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
6306 float b = ( ( col )& 0xff ) / 255.0f;
6307
6308 if ( GameRenderer::anaglyph3d )
6309 {
6310 float cr = ( r * 30 + g * 59 + b * 11 ) / 100;
6311 float cg = ( r * 30 + g * 70 ) / ( 100 );
6312 float cb = ( r * 30 + b * 70 ) / ( 100 );
6313
6314 r = cr;
6315 g = cg;
6316 b = cb;
6317 }
6318
6319 return tesselateCactusInWorld( tt, x, y, z, r, g, b );
6320}
6321
6322bool TileRenderer::tesselateCactusInWorld( Tile* tt, int x, int y, int z, float r, float g, float b )
6323{
6324 Tesselator* t = Tesselator::getInstance();
6325
6326 bool changed = false;
6327 float c10 = 0.5f;
6328 float c11 = 1;
6329 float c2 = 0.8f;
6330 float c3 = 0.6f;
6331
6332 float r10 = c10 * r;
6333 float r11 = c11 * r;
6334 float r2 = c2 * r;
6335 float r3 = c3 * r;
6336
6337 float g10 = c10 * g;
6338 float g11 = c11 * g;
6339 float g2 = c2 * g;
6340 float g3 = c3 * g;
6341
6342 float b10 = c10 * b;
6343 float b11 = c11 * b;
6344 float b2 = c2 * b;
6345 float b3 = c3 * b;
6346
6347 float faceOffset = 1 / 16.0f;
6348
6349 int centerColor = tt->getLightColor(level, x, y, z);
6350
6351 if (noCulling || tt->shouldRenderFace(level, x, y - 1, z, 0)) {
6352 t->tex2(tileShapeY0 > 0 ? centerColor : tt->getLightColor(level, x, y - 1, z));
6353 t->color(r10, g10, b10);
6354 renderFaceDown(tt, x, y, z, getTexture(tt, level, x, y, z, 0));
6355 }
6356
6357 if (noCulling || tt->shouldRenderFace(level, x, y + 1, z, 1)) {
6358 t->tex2(tileShapeY1 < 1 ? centerColor : tt->getLightColor(level, x, y + 1, z));
6359 t->color(r11, g11, b11);
6360 renderFaceUp(tt, x, y, z, getTexture(tt, level, x, y, z, 1));
6361 }
6362
6363 // North/South
6364 t->tex2(centerColor);
6365 t->color(r2, g2, b2);
6366 t->addOffset(0, 0, faceOffset);
6367 renderNorth(tt, x, y, z, getTexture(tt, level, x, y, z, 2));
6368 t->addOffset(0, 0, -faceOffset);
6369
6370 t->addOffset(0, 0, -faceOffset);
6371 renderSouth(tt, x, y, z, getTexture(tt, level, x, y, z, 3));
6372 t->addOffset(0, 0, faceOffset);
6373
6374 // West/East
6375 t->color(r3, g3, b3);
6376 t->addOffset(faceOffset, 0, 0);
6377 renderWest(tt, x, y, z, getTexture(tt, level, x, y, z, 4));
6378 t->addOffset(-faceOffset, 0, 0);
6379
6380 t->addOffset(-faceOffset, 0, 0);
6381 renderEast(tt, x, y, z, getTexture(tt, level, x, y, z, 5));
6382 t->addOffset(faceOffset, 0, 0);
6383
6384 return true;
6385}
6386
6387bool TileRenderer::tesselateFenceInWorld( FenceTile* tt, int x, int y, int z )
6388{
6389 bool changed = false;
6390
6391 float a = 6 / 16.0f;
6392 float b = 10 / 16.0f;
6393
6394 setShape( a, 0, a, b, 1, b );
6395 tesselateBlockInWorld( tt, x, y, z );
6396 changed = true;
6397
6398 bool vertical = false;
6399 bool horizontal = false;
6400
6401 if (tt->connectsTo(level, x - 1, y, z) || tt->connectsTo(level, x + 1, y, z)) vertical = true;
6402 if (tt->connectsTo(level, x, y, z - 1) || tt->connectsTo(level, x, y, z + 1)) horizontal = true;
6403
6404 bool l = tt->connectsTo(level, x - 1, y, z);
6405 bool r = tt->connectsTo(level, x + 1, y, z);
6406 bool u = tt->connectsTo(level, x, y, z - 1);
6407 bool d = tt->connectsTo(level, x, y, z + 1);
6408
6409 if ( !vertical && !horizontal ) vertical = true;
6410
6411 a = 7 / 16.0f;
6412 b = 9 / 16.0f;
6413 float h0 = 12 / 16.0f;
6414 float h1 = 15 / 16.0f;
6415
6416 float x0 = l ? 0 : a;
6417 float x1 = r ? 1 : b;
6418 float z0 = u ? 0 : a;
6419 float z1 = d ? 1 : b;
6420 if ( vertical )
6421 {
6422 setShape( x0, h0, a, x1, h1, b );
6423 tesselateBlockInWorld( tt, x, y, z );
6424 changed = true;
6425 }
6426 if ( horizontal )
6427 {
6428 setShape( a, h0, z0, b, h1, z1 );
6429 tesselateBlockInWorld( tt, x, y, z );
6430 changed = true;
6431 }
6432
6433 h0 = 6 / 16.0f;
6434 h1 = 9 / 16.0f;
6435 if ( vertical )
6436 {
6437 setShape( x0, h0, a, x1, h1, b );
6438 tesselateBlockInWorld( tt, x, y, z );
6439 changed = true;
6440 }
6441 if ( horizontal )
6442 {
6443 setShape( a, h0, z0, b, h1, z1 );
6444 tesselateBlockInWorld( tt, x, y, z );
6445 changed = true;
6446 }
6447
6448 tt->updateShape(level, x, y, z);
6449
6450 return changed;
6451}
6452
6453bool TileRenderer::tesselateWallInWorld(WallTile *tt, int x, int y, int z)
6454{
6455 bool w = tt->connectsTo(level, x - 1, y, z);
6456 bool e = tt->connectsTo(level, x + 1, y, z);
6457 bool n = tt->connectsTo(level, x, y, z - 1);
6458 bool s = tt->connectsTo(level, x, y, z + 1);
6459
6460 bool vertical = (n && s && !w && !e);
6461 bool horizontal = (!n && !s && w && e);
6462 bool emptyAbove = level->isEmptyTile(x, y + 1, z);
6463
6464 if ((!vertical && !horizontal) || !emptyAbove)
6465 {
6466 // center post
6467 setShape(.5f - WallTile::POST_WIDTH, 0, .5f - WallTile::POST_WIDTH, .5f + WallTile::POST_WIDTH, WallTile::POST_HEIGHT, .5f + WallTile::POST_WIDTH);
6468 tesselateBlockInWorld(tt, x, y, z);
6469
6470 if (w)
6471 {
6472 setShape(0, 0, .5f - WallTile::WALL_WIDTH, .5f - WallTile::POST_WIDTH, WallTile::WALL_HEIGHT, .5f + WallTile::WALL_WIDTH);
6473 tesselateBlockInWorld(tt, x, y, z);
6474 }
6475 if (e)
6476 {
6477 setShape(.5f + WallTile::POST_WIDTH, 0, .5f - WallTile::WALL_WIDTH, 1, WallTile::WALL_HEIGHT, .5f + WallTile::WALL_WIDTH);
6478 tesselateBlockInWorld(tt, x, y, z);
6479 }
6480 if (n)
6481 {
6482 setShape(.5f - WallTile::WALL_WIDTH, 0, 0, .5f + WallTile::WALL_WIDTH, WallTile::WALL_HEIGHT, .5f - WallTile::POST_WIDTH);
6483 tesselateBlockInWorld(tt, x, y, z);
6484 }
6485 if (s)
6486 {
6487 setShape(.5f - WallTile::WALL_WIDTH, 0, .5f + WallTile::POST_WIDTH, .5f + WallTile::WALL_WIDTH, WallTile::WALL_HEIGHT, 1);
6488 tesselateBlockInWorld(tt, x, y, z);
6489 }
6490 }
6491 else if (vertical)
6492 {
6493 // north-south wall
6494 setShape(.5f - WallTile::WALL_WIDTH, 0, 0, .5f + WallTile::WALL_WIDTH, WallTile::WALL_HEIGHT, 1);
6495 tesselateBlockInWorld(tt, x, y, z);
6496 }
6497 else
6498 {
6499 // west-east wall
6500 setShape(0, 0, .5f - WallTile::WALL_WIDTH, 1, WallTile::WALL_HEIGHT, .5f + WallTile::WALL_WIDTH);
6501 tesselateBlockInWorld(tt, x, y, z);
6502 }
6503
6504 tt->updateShape(level, x, y, z);
6505 return true;
6506}
6507
6508bool TileRenderer::tesselateEggInWorld(EggTile *tt, int x, int y, int z)
6509{
6510 bool changed = false;
6511
6512 int y0 = 0;
6513 for (int i = 0; i < 8; i++)
6514 {
6515 int ww = 0;
6516 int hh = 1;
6517 if (i == 0) ww = 2;
6518 if (i == 1) ww = 3;
6519 if (i == 2) ww = 4;
6520 if (i == 3)
6521 {
6522 ww = 5;
6523 hh = 2;
6524 }
6525 if (i == 4)
6526 {
6527 ww = 6;
6528 hh = 3;
6529 }
6530 if (i == 5)
6531 {
6532 ww = 7;
6533 hh = 5;
6534 }
6535 if (i == 6)
6536 {
6537 ww = 6;
6538 hh = 2;
6539 }
6540 if (i == 7) ww = 3;
6541 float w = ww / 16.0f;
6542 float yy1 = 1 - (y0 / 16.0f);
6543 float yy0 = 1 - ((y0 + hh) / 16.0f);
6544 y0 += hh;
6545 setShape(0.5f - w, yy0, 0.5f - w, 0.5f + w, yy1, 0.5f + w);
6546 tesselateBlockInWorld(tt, x, y, z);
6547 }
6548 changed = true;
6549
6550 setShape(0, 0, 0, 1, 1, 1);
6551
6552 return changed;
6553}
6554
6555bool TileRenderer::tesselateFenceGateInWorld(FenceGateTile *tt, int x, int y, int z)
6556{
6557 bool changed = true;
6558
6559 int data = level->getData(x, y, z);
6560 bool isOpen = FenceGateTile::isOpen(data);
6561 int direction = DirectionalTile::getDirection(data);
6562
6563 float h00 = 6 / 16.0f;
6564 float h01 = 9 / 16.0f;
6565 float h10 = 12 / 16.0f;
6566 float h11 = 15 / 16.0f;
6567 float h20 = 5 / 16.0f;
6568 float h21 = 16 / 16.0f;
6569
6570 if (((direction == Direction::NORTH || direction == Direction::SOUTH) && level->getTile(x - 1, y, z) == Tile::cobbleWall_Id && level->getTile(x + 1, y, z) == Tile::cobbleWall_Id)
6571 || ((direction == Direction::EAST || direction == Direction::WEST) && level->getTile(x, y, z - 1) == Tile::cobbleWall_Id && level->getTile(x, y, z + 1) == Tile::cobbleWall_Id))
6572 {
6573 h00 -= 3.0f / 16.0f;
6574 h01 -= 3.0f / 16.0f;
6575 h10 -= 3.0f / 16.0f;
6576 h11 -= 3.0f / 16.0f;
6577 h20 -= 3.0f / 16.0f;
6578 h21 -= 3.0f / 16.0f;
6579 }
6580
6581 noCulling = true;
6582
6583 // edge sticks
6584 if (direction == Direction::EAST || direction == Direction::WEST)
6585 {
6586 upFlip = FLIP_CW;
6587 float x0 = 7 / 16.0f;
6588 float x1 = 9 / 16.0f;
6589 float z0 = 0 / 16.0f;
6590 float z1 = 2 / 16.0f;
6591 setShape(x0, h20, z0, x1, h21, z1);
6592 tesselateBlockInWorld(tt, x, y, z);
6593
6594 z0 = 14 / 16.0f;
6595 z1 = 16 / 16.0f;
6596 setShape(x0, h20, z0, x1, h21, z1);
6597 tesselateBlockInWorld(tt, x, y, z);
6598 upFlip = FLIP_NONE;
6599 }
6600 else
6601 {
6602 float x0 = 0 / 16.0f;
6603 float x1 = 2 / 16.0f;
6604 float z0 = 7 / 16.0f;
6605 float z1 = 9 / 16.0f;
6606 setShape(x0, h20, z0, x1, h21, z1);
6607 tesselateBlockInWorld(tt, x, y, z);
6608
6609 x0 = 14 / 16.0f;
6610 x1 = 16 / 16.0f;
6611 setShape(x0, h20, z0, x1, h21, z1);
6612 tesselateBlockInWorld(tt, x, y, z);
6613 }
6614 if (isOpen)
6615 {
6616 if (direction == Direction::NORTH || direction == Direction::SOUTH)
6617 {
6618 upFlip = FLIP_CW;
6619 }
6620 if (direction == Direction::EAST)
6621 {
6622
6623 const float z00 = 0 / 16.0f;
6624 const float z01 = 2 / 16.0f;
6625 const float z10 = 14 / 16.0f;
6626 const float z11 = 16 / 16.0f;
6627
6628 const float x0 = 9 / 16.0f;
6629 const float x1 = 13 / 16.0f;
6630 const float x2 = 15 / 16.0f;
6631
6632 setShape(x1, h00, z00, x2, h11, z01);
6633 tesselateBlockInWorld(tt, x, y, z);
6634 setShape(x1, h00, z10, x2, h11, z11);
6635 tesselateBlockInWorld(tt, x, y, z);
6636
6637 setShape(x0, h00, z00, x1, h01, z01);
6638 tesselateBlockInWorld(tt, x, y, z);
6639 setShape(x0, h00, z10, x1, h01, z11);
6640 tesselateBlockInWorld(tt, x, y, z);
6641
6642 setShape(x0, h10, z00, x1, h11, z01);
6643 tesselateBlockInWorld(tt, x, y, z);
6644 setShape(x0, h10, z10, x1, h11, z11);
6645 tesselateBlockInWorld(tt, x, y, z);
6646 }
6647 else if (direction == Direction::WEST)
6648 {
6649 const float z00 = 0 / 16.0f;
6650 const float z01 = 2 / 16.0f;
6651 const float z10 = 14 / 16.0f;
6652 const float z11 = 16 / 16.0f;
6653
6654 const float x0 = 1 / 16.0f;
6655 const float x1 = 3 / 16.0f;
6656 const float x2 = 7 / 16.0f;
6657
6658 setShape(x0, h00, z00, x1, h11, z01);
6659 tesselateBlockInWorld(tt, x, y, z);
6660 setShape(x0, h00, z10, x1, h11, z11);
6661 tesselateBlockInWorld(tt, x, y, z);
6662
6663 setShape(x1, h00, z00, x2, h01, z01);
6664 tesselateBlockInWorld(tt, x, y, z);
6665 setShape(x1, h00, z10, x2, h01, z11);
6666 tesselateBlockInWorld(tt, x, y, z);
6667
6668 setShape(x1, h10, z00, x2, h11, z01);
6669 tesselateBlockInWorld(tt, x, y, z);
6670 setShape(x1, h10, z10, x2, h11, z11);
6671 tesselateBlockInWorld(tt, x, y, z);
6672 }
6673 else if (direction == Direction::SOUTH)
6674 {
6675
6676 const float x00 = 0 / 16.0f;
6677 const float x01 = 2 / 16.0f;
6678 const float x10 = 14 / 16.0f;
6679 const float x11 = 16 / 16.0f;
6680
6681 const float z0 = 9 / 16.0f;
6682 const float z1 = 13 / 16.0f;
6683 const float z2 = 15 / 16.0f;
6684
6685 setShape(x00, h00, z1, x01, h11, z2);
6686 tesselateBlockInWorld(tt, x, y, z);
6687 setShape(x10, h00, z1, x11, h11, z2);
6688 tesselateBlockInWorld(tt, x, y, z);
6689
6690 setShape(x00, h00, z0, x01, h01, z1);
6691 tesselateBlockInWorld(tt, x, y, z);
6692 setShape(x10, h00, z0, x11, h01, z1);
6693 tesselateBlockInWorld(tt, x, y, z);
6694
6695 setShape(x00, h10, z0, x01, h11, z1);
6696 tesselateBlockInWorld(tt, x, y, z);
6697 setShape(x10, h10, z0, x11, h11, z1);
6698 tesselateBlockInWorld(tt, x, y, z);
6699 }
6700 else if (direction == Direction::NORTH)
6701 {
6702 const float x00 = 0 / 16.0f;
6703 const float x01 = 2 / 16.0f;
6704 const float x10 = 14 / 16.0f;
6705 const float x11 = 16 / 16.0f;
6706
6707 const float z0 = 1 / 16.0f;
6708 const float z1 = 3 / 16.0f;
6709 const float z2 = 7 / 16.0f;
6710
6711 setShape(x00, h00, z0, x01, h11, z1);
6712 tesselateBlockInWorld(tt, x, y, z);
6713 setShape(x10, h00, z0, x11, h11, z1);
6714 tesselateBlockInWorld(tt, x, y, z);
6715
6716 setShape(x00, h00, z1, x01, h01, z2);
6717 tesselateBlockInWorld(tt, x, y, z);
6718 setShape(x10, h00, z1, x11, h01, z2);
6719 tesselateBlockInWorld(tt, x, y, z);
6720
6721 setShape(x00, h10, z1, x01, h11, z2);
6722 tesselateBlockInWorld(tt, x, y, z);
6723 setShape(x10, h10, z1, x11, h11, z2);
6724 tesselateBlockInWorld(tt, x, y, z);
6725 }
6726 }
6727 else
6728 {
6729 if (direction == Direction::EAST || direction == Direction::WEST)
6730 {
6731 upFlip = FLIP_CW;
6732 float x0 = 7 / 16.0f;
6733 float x1 = 9 / 16.0f;
6734 float z0 = 6 / 16.0f;
6735 float z1 = 8 / 16.0f;
6736 setShape(x0, h00, z0, x1, h11, z1);
6737 tesselateBlockInWorld(tt, x, y, z);
6738 z0 = 8 / 16.0f;
6739 z1 = 10 / 16.0f;
6740 setShape(x0, h00, z0, x1, h11, z1);
6741 tesselateBlockInWorld(tt, x, y, z);
6742 z0 = 10 / 16.0f;
6743 z1 = 14 / 16.0f;
6744 setShape(x0, h00, z0, x1, h01, z1);
6745 tesselateBlockInWorld(tt, x, y, z);
6746 setShape(x0, h10, z0, x1, h11, z1);
6747 tesselateBlockInWorld(tt, x, y, z);
6748 z0 = 2 / 16.0f;
6749 z1 = 6 / 16.0f;
6750 setShape(x0, h00, z0, x1, h01, z1);
6751 tesselateBlockInWorld(tt, x, y, z);
6752 setShape(x0, h10, z0, x1, h11, z1);
6753 tesselateBlockInWorld(tt, x, y, z);
6754 }
6755 else
6756 {
6757 float x0 = 6 / 16.0f;
6758 float x1 = 8 / 16.0f;
6759 float z0 = 7 / 16.0f;
6760 float z1 = 9 / 16.0f;
6761 setShape(x0, h00, z0, x1, h11, z1);
6762 tesselateBlockInWorld(tt, x, y, z);
6763 x0 = 8 / 16.0f;
6764 x1 = 10 / 16.0f;
6765 setShape(x0, h00, z0, x1, h11, z1);
6766 tesselateBlockInWorld(tt, x, y, z);
6767 x0 = 10 / 16.0f;
6768 x1 = 14 / 16.0f;
6769 setShape(x0, h00, z0, x1, h01, z1);
6770 tesselateBlockInWorld(tt, x, y, z);
6771 setShape(x0, h10, z0, x1, h11, z1);
6772 tesselateBlockInWorld(tt, x, y, z);
6773 x0 = 2 / 16.0f;
6774 x1 = 6 / 16.0f;
6775 setShape(x0, h00, z0, x1, h01, z1);
6776 tesselateBlockInWorld(tt, x, y, z);
6777 setShape(x0, h10, z0, x1, h11, z1);
6778 tesselateBlockInWorld(tt, x, y, z);
6779
6780 }
6781 }
6782 noCulling = false;
6783 upFlip = FLIP_NONE;
6784
6785 setShape(0, 0, 0, 1, 1, 1);
6786
6787 return changed;
6788}
6789
6790bool TileRenderer::tesselateHopperInWorld(Tile *tt, int x, int y, int z)
6791{
6792 Tesselator *t = Tesselator::getInstance();
6793
6794 float br;
6795 if (SharedConstants::TEXTURE_LIGHTING)
6796 {
6797 t->tex2(tt->getLightColor(level, x, y, z));
6798 br = 1;
6799 }
6800 else
6801 {
6802 br = tt->getBrightness(level, x, y, z);
6803 }
6804 int col = tt->getColor(level, x, y, z);
6805 float r = ((col >> 16) & 0xff) / 255.0f;
6806 float g = ((col >> 8) & 0xff) / 255.0f;
6807 float b = ((col) & 0xff) / 255.0f;
6808
6809 if (GameRenderer::anaglyph3d)
6810 {
6811 float cr = (r * 30 + g * 59 + b * 11) / 100;
6812 float cg = (r * 30 + g * 70) / (100);
6813 float cb = (r * 30 + b * 70) / (100);
6814
6815 r = cr;
6816 g = cg;
6817 b = cb;
6818 }
6819 t->color(br * r, br * g, br * b);
6820
6821 return tesselateHopperInWorld(tt, x, y, z, level->getData(x, y, z), false);
6822}
6823
6824bool TileRenderer::tesselateHopperInWorld(Tile *tt, int x, int y, int z, int data, bool render)
6825{
6826 Tesselator *t = Tesselator::getInstance();
6827 int facing = HopperTile::getAttachedFace(data);
6828
6829 // bounding box first
6830 double bottom = 10.0 / 16.0;
6831 setShape(0, bottom, 0, 1, 1, 1);
6832
6833 if (render)
6834 {
6835 t->begin();
6836 t->normal(0, -1, 0);
6837 renderFaceDown(tt, 0, 0, 0, getTexture(tt, 0, data));
6838 t->end();
6839
6840 t->begin();
6841 t->normal(0, 1, 0);
6842 renderFaceUp(tt, 0, 0, 0, getTexture(tt, 1, data));
6843 t->end();
6844
6845 t->begin();
6846 t->normal(0, 0, -1);
6847 renderNorth(tt, 0, 0, 0, getTexture(tt, 2, data));
6848 t->end();
6849
6850 t->begin();
6851 t->normal(0, 0, 1);
6852 renderSouth(tt, 0, 0, 0, getTexture(tt, 3, data));
6853 t->end();
6854
6855 t->begin();
6856 t->normal(-1, 0, 0);
6857 renderWest(tt, 0, 0, 0, getTexture(tt, 4, data));
6858 t->end();
6859
6860 t->begin();
6861 t->normal(1, 0, 0);
6862 renderEast(tt, 0, 0, 0, getTexture(tt, 5, data));
6863 t->end();
6864 }
6865 else
6866 {
6867 tesselateBlockInWorld(tt, x, y, z);
6868 }
6869
6870 if (!render)
6871 {
6872 float br;
6873 if (SharedConstants::TEXTURE_LIGHTING)
6874 {
6875 t->tex2(tt->getLightColor(level, x, y, z));
6876 br = 1;
6877 }
6878 else
6879 {
6880 br = tt->getBrightness(level, x, y, z);
6881 }
6882 int col = tt->getColor(level, x, y, z);
6883 float r = ((col >> 16) & 0xff) / 255.0f;
6884 float g = ((col >> 8) & 0xff) / 255.0f;
6885 float b = ((col) & 0xff) / 255.0f;
6886
6887 if (GameRenderer::anaglyph3d) {
6888 float cr = (r * 30 + g * 59 + b * 11) / 100;
6889 float cg = (r * 30 + g * 70) / (100);
6890 float cb = (r * 30 + b * 70) / (100);
6891
6892 r = cr;
6893 g = cg;
6894 b = cb;
6895 }
6896 t->color(br * r, br * g, br * b);
6897 }
6898
6899 // render inside
6900 Icon *hopperTex = HopperTile::getTexture(HopperTile::TEXTURE_OUTSIDE);
6901 Icon *bottomTex = HopperTile::getTexture(HopperTile::TEXTURE_INSIDE);
6902 float cWidth = 2.0f / 16.0f;
6903
6904 if (render)
6905 {
6906 t->begin();
6907 t->normal(1, 0, 0);
6908 renderEast(tt, -1.0f + cWidth, 0, 0, hopperTex);
6909 t->end();
6910
6911 t->begin();
6912 t->normal(-1, 0, 0);
6913 renderWest(tt, 1.0f - cWidth, 0, 0, hopperTex);
6914 t->end();
6915
6916 t->begin();
6917 t->normal(0, 0, 1);
6918 renderSouth(tt, 0, 0, -1.0f + cWidth, hopperTex);
6919 t->end();
6920
6921 t->begin();
6922 t->normal(0, 0, -1);
6923 renderNorth(tt, 0, 0, 1.0f - cWidth, hopperTex);
6924 t->end();
6925
6926 t->begin();
6927 t->normal(0, 1, 0);
6928 renderFaceUp(tt, 0, -1.0f + bottom, 0, bottomTex);
6929 t->end();
6930 }
6931 else
6932 {
6933 renderEast(tt, x - 1.0f + cWidth, y, z, hopperTex);
6934 renderWest(tt, x + 1.0f - cWidth, y, z, hopperTex);
6935 renderSouth(tt, x, y, z - 1.0f + cWidth, hopperTex);
6936 renderNorth(tt, x, y, z + 1.0f - cWidth, hopperTex);
6937 renderFaceUp(tt, x, y - 1.0f + bottom, z, bottomTex);
6938 }
6939
6940 // render bottom box
6941 setFixedTexture(hopperTex);
6942 double inset = 4.0 / 16.0;
6943 double lboxy0 = 4.0 / 16.0;
6944 double lboxy1 = bottom;
6945 setShape(inset, lboxy0, inset, 1.0 - inset, lboxy1 - .002, 1.0 - inset);
6946
6947 if (render)
6948 {
6949 t->begin();
6950 t->normal(1, 0, 0);
6951 renderEast(tt, 0, 0, 0, hopperTex);
6952 t->end();
6953
6954 t->begin();
6955 t->normal(-1, 0, 0);
6956 renderWest(tt, 0, 0, 0, hopperTex);
6957 t->end();
6958
6959 t->begin();
6960 t->normal(0, 0, 1);
6961 renderSouth(tt, 0, 0, 0, hopperTex);
6962 t->end();
6963
6964 t->begin();
6965 t->normal(0, 0, -1);
6966 renderNorth(tt, 0, 0, 0, hopperTex);
6967 t->end();
6968
6969 t->begin();
6970 t->normal(0, 1, 0);
6971 renderFaceUp(tt, 0, 0, 0, hopperTex);
6972 t->end();
6973
6974 t->begin();
6975 t->normal(0, -1, 0);
6976 renderFaceDown(tt, 0, 0, 0, hopperTex);
6977 t->end();
6978 }
6979 else
6980 {
6981 tesselateBlockInWorld(tt, x, y, z);
6982 }
6983
6984 if (!render)
6985 {
6986 // render pipe
6987 double pipe = 6.0 / 16.0;
6988 double pipeW = 4.0 / 16.0;
6989 setFixedTexture(hopperTex);
6990
6991 // down
6992 if (facing == Facing::DOWN)
6993 {
6994 setShape(pipe, 0, pipe, 1.0 - pipe, 4.0 / 16.0, 1.0 - pipe);
6995 tesselateBlockInWorld(tt, x, y, z);
6996 }
6997 // north
6998 if (facing == Facing::NORTH)
6999 {
7000 setShape(pipe, lboxy0, 0, 1.0 - pipe, lboxy0 + pipeW, inset);
7001 tesselateBlockInWorld(tt, x, y, z);
7002 }
7003 // south
7004 if (facing == Facing::SOUTH)
7005 {
7006 setShape(pipe, lboxy0, 1.0 - inset, 1.0 - pipe, lboxy0 + pipeW, 1.0);
7007 tesselateBlockInWorld(tt, x, y, z);
7008 }
7009 // west
7010 if (facing == Facing::WEST)
7011 {
7012 setShape(0, lboxy0, pipe, inset, lboxy0 + pipeW, 1.0 - pipe);
7013 tesselateBlockInWorld(tt, x, y, z);
7014 }
7015 // east
7016 if (facing == Facing::EAST)
7017 {
7018 setShape(1.0 - inset, lboxy0, pipe, 1.0, lboxy0 + pipeW, 1.0 - pipe);
7019 tesselateBlockInWorld(tt, x, y, z);
7020 }
7021 }
7022
7023 clearFixedTexture();
7024
7025 return true;
7026
7027}
7028
7029bool TileRenderer::tesselateStairsInWorld( StairTile* tt, int x, int y, int z )
7030{
7031 tt->setBaseShape(level, x, y, z);
7032 setShape(tt);
7033 tesselateBlockInWorld(tt, x, y, z);
7034
7035 bool checkInnerPiece = tt->setStepShape(level, x, y, z);
7036 setShape(tt);
7037 tesselateBlockInWorld(tt, x, y, z);
7038
7039 if (checkInnerPiece)
7040 {
7041 if (tt->setInnerPieceShape(level, x, y, z))
7042 {
7043 setShape(tt);
7044 tesselateBlockInWorld(tt, x, y, z);
7045 }
7046 }
7047 return true;
7048}
7049
7050bool TileRenderer::tesselateDoorInWorld( Tile* tt, int x, int y, int z )
7051{
7052 Tesselator* t = Tesselator::getInstance();
7053
7054 // skip rendering if the other half of the door is missing,
7055 // to avoid rendering doors that are about to be removed
7056 int data = level->getData(x, y, z);
7057 if ((data & DoorTile::UPPER_BIT) != 0)
7058 {
7059 if (level->getTile(x, y - 1, z) != tt->id)
7060 {
7061 return false;
7062 }
7063 }
7064 else {
7065 if (level->getTile(x, y + 1, z) != tt->id)
7066 {
7067 return false;
7068 }
7069 }
7070
7071 bool changed = false;
7072 float c10 = 0.5f;
7073 float c11 = 1;
7074 float c2 = 0.8f;
7075 float c3 = 0.6f;
7076
7077 int centerColor = 0;
7078 float centerBrightness = 0.0f;
7079
7080 if ( SharedConstants::TEXTURE_LIGHTING )
7081 {
7082 centerColor = getLightColor(tt, level, x, y, z );
7083 }
7084 else
7085 {
7086 centerBrightness = tt->getBrightness( level, x, y, z );
7087 }
7088
7089
7090 if ( SharedConstants::TEXTURE_LIGHTING )
7091 {
7092 t->tex2( tileShapeY0 > 0 ? centerColor : getLightColor(tt, level, x, y - 1, z ) );
7093 t->color( c10, c10, c10 );
7094 }
7095 else
7096 {
7097 float br = tt->getBrightness( level, x, y - 1, z );
7098 if ( tileShapeY0 > 0 ) br = centerBrightness;
7099 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
7100 t->color( c10 * br, c10 * br, c10 * br );
7101 }
7102 renderFaceDown( tt, x, y, z, getTexture(tt, level, x, y, z, 0 ) );
7103 changed = true;
7104
7105 if ( SharedConstants::TEXTURE_LIGHTING )
7106 {
7107 t->tex2( tileShapeY1 < 1 ? centerColor : getLightColor(tt, level, x, y + 1, z ) );
7108 t->color( c11, c11, c11 );
7109 }
7110 else
7111 {
7112 float br = tt->getBrightness( level, x, y + 1, z );
7113 if ( tileShapeY1 < 1 ) br = centerBrightness;
7114 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
7115 t->color( c11 * br, c11 * br, c11 * br );
7116 }
7117 renderFaceUp( tt, x, y, z, getTexture(tt, level, x, y, z, 1 ) );
7118 changed = true;
7119
7120 {
7121 if ( SharedConstants::TEXTURE_LIGHTING )
7122 {
7123 t->tex2( tileShapeZ0 > 0 ? centerColor : getLightColor(tt, level, x, y, z - 1 ) );
7124 t->color( c2, c2, c2 );
7125 }
7126 else
7127 {
7128 float br = tt->getBrightness( level, x, y, z - 1 );
7129 if ( tileShapeZ0 > 0 ) br = centerBrightness;
7130 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
7131 t->color( c2 * br, c2 * br, c2 * br );
7132 }
7133 Icon *tex = getTexture(tt, level, x, y, z, 2 );
7134 renderNorth( tt, x, y, z, tex );
7135 changed = true;
7136 xFlipTexture = false;
7137 }
7138 {
7139 if ( SharedConstants::TEXTURE_LIGHTING )
7140 {
7141 t->tex2( tileShapeZ1 < 1 ? centerColor : getLightColor(tt, level, x, y, z + 1 ) );
7142 t->color( c2, c2, c2 );
7143 }
7144 else
7145 {
7146 float br = tt->getBrightness( level, x, y, z + 1 );
7147 if ( tileShapeZ1 < 1 ) br = centerBrightness;
7148 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
7149 t->color( c2 * br, c2 * br, c2 * br );
7150 }
7151 Icon *tex = getTexture( tt, level, x, y, z, 3 );
7152 renderSouth( tt, x, y, z, tex );
7153 changed = true;
7154 xFlipTexture = false;
7155 }
7156 {
7157 if ( SharedConstants::TEXTURE_LIGHTING )
7158 {
7159 t->tex2( tileShapeX0 > 0 ? centerColor : getLightColor(tt, level, x - 1, y, z ) );
7160 t->color( c3, c3, c3 );
7161 }
7162 else
7163 {
7164 float br = tt->getBrightness( level, x - 1, y, z );
7165 if ( tileShapeX0 > 0 ) br = centerBrightness;
7166 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
7167 t->color( c3 * br, c3 * br, c3 * br );
7168 }
7169 Icon *tex = getTexture(tt, level, x, y, z, 4 );
7170 renderWest( tt, x, y, z, tex );
7171 changed = true;
7172 xFlipTexture = false;
7173 }
7174 {
7175 if ( SharedConstants::TEXTURE_LIGHTING )
7176 {
7177 t->tex2( tileShapeX1 < 1 ? centerColor : getLightColor(tt, level, x + 1, y, z ) );
7178 t->color( c3, c3, c3 );
7179 }
7180 else
7181 {
7182 float br = tt->getBrightness( level, x + 1, y, z );
7183 if ( tileShapeX1 < 1 ) br = centerBrightness;
7184 if ( Tile::lightEmission[tt->id] > 0 ) br = 1.0f;
7185 t->color( c3 * br, c3 * br, c3 * br );
7186 }
7187 Icon *tex = getTexture(tt, level, x, y, z, 5 );
7188 renderEast( tt, x, y, z, tex );
7189 changed = true;
7190 xFlipTexture = false;
7191 }
7192 return changed;
7193}
7194
7195void TileRenderer::renderFaceDown( Tile* tt, double x, double y, double z, Icon *tex )
7196{
7197 Tesselator* t = Tesselator::getInstance();
7198
7199 if (hasFixedTexture()) tex = fixedTexture;
7200 float u00 = tex->getU(tileShapeX0 * 16.0f, true);
7201 float u11 = tex->getU(tileShapeX1 * 16.0f, true);
7202 float v00 = tex->getV(tileShapeZ0 * 16.0f, true);
7203 float v11 = tex->getV(tileShapeZ1 * 16.0f, true);
7204
7205 if ( tileShapeX0 < 0 || tileShapeX1 > 1 )
7206 {
7207 u00 = tex->getU0(true);
7208 u11 = tex->getU1(true);
7209 }
7210 if ( tileShapeZ0 < 0 || tileShapeZ1 > 1 )
7211 {
7212 v00 = tex->getV0(true);
7213 v11 = tex->getV1(true);
7214 }
7215
7216 double u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7217 if ( downFlip == FLIP_CCW )
7218 {
7219 u00 = tex->getU(tileShapeZ0 * 16.0f, true);
7220 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f, true);
7221 u11 = tex->getU(tileShapeZ1 * 16.0f, true);
7222 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f, true);
7223
7224 u01 = u11;
7225 u10 = u00;
7226 v01 = v00;
7227 v10 = v11;
7228 u01 = u00;
7229 u10 = u11;
7230 v00 = v11;
7231 v11 = v01;
7232 }
7233 else if ( downFlip == FLIP_CW )
7234 {
7235 // reshape
7236 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f, true);
7237 v00 = tex->getV(tileShapeX0 * 16.0f, true);
7238 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f, true);
7239 v11 = tex->getV(tileShapeX1 * 16.0f, true);
7240
7241 // rotate
7242 u01 = u11;
7243 u10 = u00;
7244 v01 = v00;
7245 v10 = v11;
7246 u00 = u01;
7247 u11 = u10;
7248 v01 = v11;
7249 v10 = v00;
7250 }
7251 else if ( downFlip == FLIP_180 )
7252 {
7253 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f, true);
7254 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f, true);
7255 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f, true);
7256 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f, true);
7257
7258 u01 = u11;
7259 u10 = u00;
7260 v01 = v00;
7261 v10 = v11;
7262 }
7263
7264 double x0 = x + tileShapeX0;
7265 double x1 = x + tileShapeX1;
7266 double y0 = y + tileShapeY0;
7267 double z0 = z + tileShapeZ0;
7268 double z1 = z + tileShapeZ1;
7269
7270 if ( applyAmbienceOcclusion )
7271 {
7272#ifdef __PSVITA__
7273 if( t->getCompactVertices() )
7274 {
7275 t->tileQuad(( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ), c1r, c1g, c1b, tc1,
7276 ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ), c2r, c2g, c2b, tc2,
7277 ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ), c3r, c3g, c3b, tc3,
7278 ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ), c4r, c4g, c4b, tc4);
7279 return;
7280 }
7281#endif
7282
7283 t->color( c1r, c1g, c1b );
7284 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7285 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7286 t->color( c2r, c2g, c2b );
7287 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7288 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7289 t->color( c3r, c3g, c3b );
7290 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7291 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7292 t->color( c4r, c4g, c4b );
7293 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7294 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7295 }
7296 else
7297 {
7298 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7299 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7300 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7301 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7302 }
7303}
7304
7305void TileRenderer::renderFaceUp( Tile* tt, double x, double y, double z, Icon *tex )
7306{
7307 Tesselator* t = Tesselator::getInstance();
7308
7309 if (hasFixedTexture()) tex = fixedTexture;
7310 float u00 = tex->getU(tileShapeX0 * 16.0f, true);
7311 float u11 = tex->getU(tileShapeX1 * 16.0f, true);
7312 float v00 = tex->getV(tileShapeZ0 * 16.0f, true);
7313 float v11 = tex->getV(tileShapeZ1 * 16.0f, true);
7314
7315 if ( tileShapeX0 < 0 || tileShapeX1 > 1 )
7316 {
7317 u00 = tex->getU0(true);
7318 u11 = tex->getU1(true);
7319 }
7320 if ( tileShapeZ0 < 0 || tileShapeZ1 > 1 )
7321 {
7322 v00 = tex->getV0(true);
7323 v11 = tex->getV1(true);
7324 }
7325
7326 float u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7327
7328 if ( upFlip == FLIP_CW )
7329 {
7330 u00 = tex->getU(tileShapeZ0 * 16.0f, true);
7331 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f, true);
7332 u11 = tex->getU(tileShapeZ1 * 16.0f, true);
7333 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f, true);
7334
7335 u01 = u11;
7336 u10 = u00;
7337 v01 = v00;
7338 v10 = v11;
7339 u01 = u00;
7340 u10 = u11;
7341 v00 = v11;
7342 v11 = v01;
7343 }
7344 else if ( upFlip == FLIP_CCW )
7345 {
7346 // reshape
7347 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f, true);
7348 v00 = tex->getV(tileShapeX0 * 16.0f, true);
7349 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f, true);
7350 v11 = tex->getV(tileShapeX1 * 16.0f, true);
7351
7352 // rotate
7353 u01 = u11;
7354 u10 = u00;
7355 v01 = v00;
7356 v10 = v11;
7357 u00 = u01;
7358 u11 = u10;
7359 v01 = v11;
7360 v10 = v00;
7361 }
7362 else if ( upFlip == FLIP_180 )
7363 {
7364 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f, true);
7365 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f, true);
7366 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f, true);
7367 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f, true);
7368
7369 u01 = u11;
7370 u10 = u00;
7371 v01 = v00;
7372 v10 = v11;
7373 }
7374
7375
7376 double x0 = x + tileShapeX0;
7377 double x1 = x + tileShapeX1;
7378 double y1 = y + tileShapeY1;
7379 double z0 = z + tileShapeZ0;
7380 double z1 = z + tileShapeZ1;
7381
7382 if ( applyAmbienceOcclusion )
7383 {
7384#ifdef __PSVITA__
7385 if( t->getCompactVertices() )
7386 {
7387 t->tileQuad(( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ), c1r, c1g, c1b, tc1,
7388 ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ), c2r, c2g, c2b, tc2,
7389 ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ), c3r, c3g, c3b, tc3,
7390 ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ), c4r, c4g, c4b, tc4);
7391 return;
7392 }
7393#endif
7394
7395 t->color( c1r, c1g, c1b );
7396 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7397 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7398 t->color( c2r, c2g, c2b );
7399 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7400 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7401 t->color( c3r, c3g, c3b );
7402 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7403 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7404 t->color( c4r, c4g, c4b );
7405 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7406 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7407 }
7408 else
7409 {
7410 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7411 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7412 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7413 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7414 }
7415
7416}
7417
7418void TileRenderer::renderNorth( Tile* tt, double x, double y, double z, Icon *tex )
7419{
7420 Tesselator* t = Tesselator::getInstance();
7421
7422 if (hasFixedTexture()) tex = fixedTexture;
7423 double u00 = tex->getU(tileShapeX0 * 16.0f, true);
7424 double u11 = tex->getU(tileShapeX1 * 16.0f, true);
7425 double v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f, true);
7426 double v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f, true);
7427 if ( xFlipTexture )
7428 {
7429 double tmp = u00;
7430 u00 = u11;
7431 u11 = tmp;
7432 }
7433
7434 if ( tileShapeX0 < 0 || tileShapeX1 > 1 )
7435 {
7436 u00 = tex->getU0(true);
7437 u11 = tex->getU1(true);
7438 }
7439 if ( tileShapeY0 < 0 || tileShapeY1 > 1 )
7440 {
7441 v00 = tex->getV0(true);
7442 v11 = tex->getV1(true);
7443 }
7444
7445 double u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7446
7447 if ( northFlip == FLIP_CCW )
7448 {
7449 u00 = tex->getU(tileShapeY0 * 16.0f, true);
7450 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f, true);
7451 u11 = tex->getU(tileShapeY1 * 16.0f, true);
7452 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f, true);
7453
7454 u01 = u11;
7455 u10 = u00;
7456 v01 = v00;
7457 v10 = v11;
7458 u01 = u00;
7459 u10 = u11;
7460 v00 = v11;
7461 v11 = v01;
7462 }
7463 else if ( northFlip == FLIP_CW )
7464 {
7465 // reshape
7466 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f, true);
7467 v00 = tex->getV(tileShapeX1 * 16.0f, true);
7468 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f, true);
7469 v11 = tex->getV(tileShapeX0 * 16.0f, true);
7470
7471 // rotate
7472 u01 = u11;
7473 u10 = u00;
7474 v01 = v00;
7475 v10 = v11;
7476 u00 = u01;
7477 u11 = u10;
7478 v01 = v11;
7479 v10 = v00;
7480 }
7481 else if ( northFlip == FLIP_180 )
7482 {
7483 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f, true);
7484 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f, true);
7485 v00 = tex->getV(tileShapeY1 * 16.0f, true);
7486 v11 = tex->getV(tileShapeY0 * 16.0f, true);
7487
7488 u01 = u11;
7489 u10 = u00;
7490 v01 = v00;
7491 v10 = v11;
7492 }
7493
7494
7495 double x0 = x + tileShapeX0;
7496 double x1 = x + tileShapeX1;
7497 double y0 = y + tileShapeY0;
7498 double y1 = y + tileShapeY1;
7499 double z0 = z + tileShapeZ0;
7500
7501 if ( applyAmbienceOcclusion )
7502 {
7503#ifdef __PSVITA__
7504 if( t->getCompactVertices() )
7505 {
7506 t->tileQuad(( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ), c1r, c1g, c1b, tc1,
7507 ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ), c2r, c2g, c2b, tc2,
7508 ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ), c3r, c3g, c3b, tc3,
7509 ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ), c4r, c4g, c4b, tc4);
7510 return;
7511 }
7512#endif
7513
7514 t->color( c1r, c1g, c1b );
7515 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7516 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7517 t->color( c2r, c2g, c2b );
7518 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7519 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7520 t->color( c3r, c3g, c3b );
7521 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7522 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ) );
7523 t->color( c4r, c4g, c4b );
7524 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7525 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ) );
7526 }
7527 else
7528 {
7529 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7530 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7531 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ) );
7532 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ) );
7533 }
7534
7535}
7536
7537void TileRenderer::renderSouth( Tile* tt, double x, double y, double z, Icon *tex )
7538{
7539 Tesselator* t = Tesselator::getInstance();
7540
7541 if (hasFixedTexture()) tex = fixedTexture;
7542 double u00 = tex->getU(tileShapeX0 * 16.0f, true);
7543 double u11 = tex->getU(tileShapeX1 * 16.0f, true);
7544 double v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f, true);
7545 double v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f, true);
7546 if ( xFlipTexture )
7547 {
7548 double tmp = u00;
7549 u00 = u11;
7550 u11 = tmp;
7551 }
7552
7553 if ( tileShapeX0 < 0 || tileShapeX1 > 1 )
7554 {
7555 u00 = tex->getU0(true);
7556 u11 = tex->getU1(true);
7557 }
7558 if ( tileShapeY0 < 0 || tileShapeY1 > 1 )
7559 {
7560 v00 = tex->getV0(true);
7561 v11 = tex->getV1(true);
7562 }
7563
7564 double u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7565
7566 if ( southFlip == FLIP_CW )
7567 {
7568 u00 = tex->getU(tileShapeY0 * 16.0f, true);
7569 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f, true);
7570 u11 = tex->getU(tileShapeY1 * 16.0f, true);
7571 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f, true);
7572
7573 u01 = u11;
7574 u10 = u00;
7575 v01 = v00;
7576 v10 = v11;
7577 u01 = u00;
7578 u10 = u11;
7579 v00 = v11;
7580 v11 = v01;
7581 }
7582 else if ( southFlip == FLIP_CCW )
7583 {
7584 // reshape
7585 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f, true);
7586 v00 = tex->getV(tileShapeX0 * 16.0f, true);
7587 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f, true);
7588 v11 = tex->getV(tileShapeX1 * 16.0f, true);
7589
7590 // rotate
7591 u01 = u11;
7592 u10 = u00;
7593 v01 = v00;
7594 v10 = v11;
7595 u00 = u01;
7596 u11 = u10;
7597 v01 = v11;
7598 v10 = v00;
7599 }
7600 else if ( southFlip == FLIP_180 )
7601 {
7602 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX0 * 16.0f, true);
7603 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeX1 * 16.0f, true);
7604 v00 = tex->getV(tileShapeY1 * 16.0f, true);
7605 v11 = tex->getV(tileShapeY0 * 16.0f, true);
7606
7607 u01 = u11;
7608 u10 = u00;
7609 v01 = v00;
7610 v10 = v11;
7611 }
7612
7613
7614 double x0 = x + tileShapeX0;
7615 double x1 = x + tileShapeX1;
7616 double y0 = y + tileShapeY0;
7617 double y1 = y + tileShapeY1;
7618 double z1 = z + tileShapeZ1;
7619
7620 if ( applyAmbienceOcclusion )
7621 {
7622#ifdef __PSVITA__
7623 if( t->getCompactVertices() )
7624 {
7625 t->tileQuad(( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ), c1r, c1g, c1b, tc1,
7626 ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ), c2r, c2g, c2b, tc2,
7627 ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ), c3r, c3g, c3b, tc3,
7628 ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ), c4r, c4g, c4b, tc4);
7629 return;
7630 }
7631#endif
7632
7633 t->color( c1r, c1g, c1b );
7634 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7635 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ) );
7636 t->color( c2r, c2g, c2b );
7637 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7638 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7639 t->color( c3r, c3g, c3b );
7640 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7641 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7642 t->color( c4r, c4g, c4b );
7643 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7644 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ) );
7645 }
7646 else
7647 {
7648 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ) );
7649 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7650 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7651 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ) );
7652 }
7653
7654}
7655
7656void TileRenderer::renderWest( Tile* tt, double x, double y, double z, Icon *tex )
7657{
7658 Tesselator* t = Tesselator::getInstance();
7659
7660 if (hasFixedTexture()) tex = fixedTexture;
7661 double u00 = tex->getU(tileShapeZ0 * 16.0f, true);
7662 double u11 = tex->getU(tileShapeZ1 * 16.0f, true);
7663 double v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f, true);
7664 double v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f, true);
7665 if ( xFlipTexture )
7666 {
7667 double tmp = u00;
7668 u00 = u11;
7669 u11 = tmp;
7670 }
7671
7672 if ( tileShapeZ0 < 0 || tileShapeZ1 > 1 )
7673 {
7674 u00 = tex->getU0(true);
7675 u11 = tex->getU1(true);
7676 }
7677 if ( tileShapeY0 < 0 || tileShapeY1 > 1 )
7678 {
7679 v00 = tex->getV0(true);
7680 v11 = tex->getV1(true);
7681 }
7682
7683 double u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7684
7685 if ( westFlip == FLIP_CW )
7686 {
7687 u00 = tex->getU(tileShapeY0 * 16.0f, true);
7688 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f, true);
7689 u11 = tex->getU(tileShapeY1 * 16.0f, true);
7690 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f, true);
7691
7692 u01 = u11;
7693 u10 = u00;
7694 v01 = v00;
7695 v10 = v11;
7696 u01 = u00;
7697 u10 = u11;
7698 v00 = v11;
7699 v11 = v01;
7700 }
7701 else if ( westFlip == FLIP_CCW )
7702 {
7703 // reshape
7704 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f, true);
7705 v00 = tex->getV(tileShapeZ0 * 16.0f, true);
7706 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f, true);
7707 v11 = tex->getV(tileShapeZ1 * 16.0f, true);
7708
7709 // rotate
7710 u01 = u11;
7711 u10 = u00;
7712 v01 = v00;
7713 v10 = v11;
7714 u00 = u01;
7715 u11 = u10;
7716 v01 = v11;
7717 v10 = v00;
7718 }
7719 else if ( westFlip == FLIP_180 )
7720 {
7721 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f, true);
7722 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f, true);
7723 v00 = tex->getV(tileShapeY1 * 16.0f, true);
7724 v11 = tex->getV(tileShapeY0 * 16.0f, true);
7725
7726 u01 = u11;
7727 u10 = u00;
7728 v01 = v00;
7729 v10 = v11;
7730 }
7731
7732 double x0 = x + tileShapeX0;
7733 double y0 = y + tileShapeY0;
7734 double y1 = y + tileShapeY1;
7735 double z0 = z + tileShapeZ0;
7736 double z1 = z + tileShapeZ1;
7737
7738 if ( applyAmbienceOcclusion )
7739 {
7740#ifdef __PSVITA__
7741 if( t->getCompactVertices() )
7742 {
7743 t->tileQuad(( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ), c1r, c1g, c1b, tc1,
7744 ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ), c2r, c2g, c2b, tc2,
7745 ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ), c3r, c3g, c3b, tc3,
7746 ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ), c4r, c4g, c4b, tc4);
7747 return;
7748 }
7749#endif
7750
7751 t->color( c1r, c1g, c1b );
7752 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7753 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ) );
7754 t->color( c2r, c2g, c2b );
7755 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7756 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7757 t->color( c3r, c3g, c3b );
7758 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7759 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ) );
7760 t->color( c4r, c4g, c4b );
7761 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7762 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7763 }
7764 else
7765 {
7766 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z1 ), ( float )( u01 ), ( float )( v01 ) );
7767 t->vertexUV( ( float )( x0 ), ( float )( y1 ), ( float )( z0 ), ( float )( u00 ), ( float )( v00 ) );
7768 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z0 ), ( float )( u10 ), ( float )( v10 ) );
7769 t->vertexUV( ( float )( x0 ), ( float )( y0 ), ( float )( z1 ), ( float )( u11 ), ( float )( v11 ) );
7770 }
7771
7772}
7773
7774void TileRenderer::renderEast( Tile* tt, double x, double y, double z, Icon *tex )
7775{
7776 Tesselator* t = Tesselator::getInstance();
7777
7778 if (hasFixedTexture()) tex = fixedTexture;
7779 double u00 = tex->getU(tileShapeZ0 * 16.0f, true);
7780 double u11 = tex->getU(tileShapeZ1 * 16.0f, true);
7781 double v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f, true);
7782 double v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f, true);
7783 if ( xFlipTexture )
7784 {
7785 double tmp = u00;
7786 u00 = u11;
7787 u11 = tmp;
7788 }
7789
7790 if ( tileShapeZ0 < 0 || tileShapeZ1 > 1 )
7791 {
7792 u00 = tex->getU0(true);
7793 u11 = tex->getU1(true);
7794 }
7795 if ( tileShapeY0 < 0 || tileShapeY1 > 1 )
7796 {
7797 v00 = tex->getV0(true);
7798 v11 = tex->getV1(true);
7799 }
7800
7801 double u01 = u11, u10 = u00, v01 = v00, v10 = v11;
7802
7803 if ( eastFlip == FLIP_CCW )
7804 {
7805 u00 = tex->getU(tileShapeY0 * 16.0f, true);
7806 v00 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f, true);
7807 u11 = tex->getU(tileShapeY1 * 16.0f, true);
7808 v11 = tex->getV(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f, true);
7809
7810 u01 = u11;
7811 u10 = u00;
7812 v01 = v00;
7813 v10 = v11;
7814 u01 = u00;
7815 u10 = u11;
7816 v00 = v11;
7817 v11 = v01;
7818 }
7819 else if ( eastFlip == FLIP_CW )
7820 {
7821 // reshape
7822 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY1 * 16.0f, true);
7823 v00 = tex->getV(tileShapeZ1 * 16.0f, true);
7824 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeY0 * 16.0f, true);
7825 v11 = tex->getV(tileShapeZ0 * 16.0f, true);
7826
7827 // rotate
7828 u01 = u11;
7829 u10 = u00;
7830 v01 = v00;
7831 v10 = v11;
7832 u00 = u01;
7833 u11 = u10;
7834 v01 = v11;
7835 v10 = v00;
7836 }
7837 else if ( eastFlip == FLIP_180 )
7838 {
7839 u00 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ0 * 16.0f, true);
7840 u11 = tex->getU(SharedConstants::WORLD_RESOLUTION - tileShapeZ1 * 16.0f, true);
7841 v00 = tex->getV(tileShapeY1 * 16.0f, true);
7842 v11 = tex->getV(tileShapeY0 * 16.0f, true);
7843
7844 u01 = u11;
7845 u10 = u00;
7846 v01 = v00;
7847 v10 = v11;
7848 }
7849
7850 double x1 = x + tileShapeX1;
7851 double y0 = y + tileShapeY0;
7852 double y1 = y + tileShapeY1;
7853 double z0 = z + tileShapeZ0;
7854 double z1 = z + tileShapeZ1;
7855
7856 if ( applyAmbienceOcclusion )
7857 {
7858#ifdef __PSVITA__
7859 if( t->getCompactVertices() )
7860 {
7861 t->tileQuad(( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ), c1r, c1g, c1b, tc1,
7862 ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ), c2r, c2g, c2b, tc2,
7863 ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ), c3r, c3g, c3b, tc3,
7864 ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ), c4r, c4g, c4b, tc4);
7865 return;
7866 }
7867#endif
7868
7869 t->color( c1r, c1g, c1b );
7870 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc1 );
7871 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7872 t->color( c2r, c2g, c2b );
7873 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc2 );
7874 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ) );
7875 t->color( c3r, c3g, c3b );
7876 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc3 );
7877 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7878 t->color( c4r, c4g, c4b );
7879 if ( SharedConstants::TEXTURE_LIGHTING ) t->tex2( tc4 );
7880 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ) );
7881 }
7882 else
7883 {
7884 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z1 ), ( float )( u10 ), ( float )( v10 ) );
7885 t->vertexUV( ( float )( x1 ), ( float )( y0 ), ( float )( z0 ), ( float )( u11 ), ( float )( v11 ) );
7886 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z0 ), ( float )( u01 ), ( float )( v01 ) );
7887 t->vertexUV( ( float )( x1 ), ( float )( y1 ), ( float )( z1 ), ( float )( u00 ), ( float )( v00 ) );
7888 }
7889
7890}
7891
7892void TileRenderer::renderCube( Tile* tile, float alpha )
7893{
7894 int shape = tile->getRenderShape();
7895 Tesselator* t = Tesselator::getInstance();
7896
7897 if ( shape == Tile::SHAPE_BLOCK )
7898 {
7899 tile->updateDefaultShape();
7900 glTranslatef( -0.5f, -0.5f, -0.5f );
7901 float c10 = 0.5f;
7902 float c11 = 1;
7903 float c2 = 0.8f;
7904 float c3 = 0.6f;
7905
7906 t->begin();
7907 t->color( c11, c11, c11, alpha );
7908 renderFaceDown( tile, 0, 0, 0,getTexture(tile, 0 ) );
7909 t->color( c10, c10, c10, alpha );
7910 renderFaceUp( tile, 0, 0, 0, getTexture(tile, 1 ) );
7911 t->color( c2, c2, c2, alpha );
7912 renderNorth( tile, 0, 0, 0, getTexture(tile, 2 ) );
7913 renderSouth( tile, 0, 0, 0, getTexture(tile, 3 ) );
7914 t->color( c3, c3, c3, alpha );
7915 renderWest( tile, 0, 0, 0, getTexture(tile, 4 ) );
7916 renderEast( tile, 0, 0, 0, getTexture(tile, 5 ) );
7917
7918 t->end();
7919
7920 glTranslatef( 0.5f, 0.5f, 0.5f );
7921 }
7922
7923}
7924
7925void TileRenderer::renderTile( Tile* tile, int data, float brightness, float fAlpha, bool useCompiled )
7926{
7927 Tesselator* t = Tesselator::getInstance();
7928
7929 bool isGrass = tile->id == Tile::grass_Id;
7930
7931 if (tile == Tile::dispenser || tile == Tile::furnace || tile == Tile::dropper)
7932 {
7933 data = 3;
7934 }
7935
7936 if ( setColor )
7937 {
7938 int col = tile->getColor( data );
7939 if (isGrass)
7940 {
7941 col = 0xffffff;
7942 }
7943 float red = ( ( col >> 16 ) & 0xff ) / 255.0f;
7944 float g = ( ( col >> 8 ) & 0xff ) / 255.0f;
7945 float b = ( ( col )& 0xff ) / 255.0f;
7946
7947 glColor4f( red * brightness, g * brightness, b * brightness, fAlpha );
7948 }
7949
7950 int shape = tile->getRenderShape();
7951 setShape(tile);
7952
7953 t->setMipmapEnable( Tile::mipmapEnable[tile->id] ); // 4J added
7954
7955 if ( shape == Tile::SHAPE_BLOCK || shape == Tile::SHAPE_TREE || shape == Tile::SHAPE_QUARTZ || shape == Tile::SHAPE_PISTON_BASE || shape == Tile::SHAPE_PORTAL_FRAME )
7956 {
7957 if ( shape == Tile::SHAPE_PISTON_BASE )
7958 {
7959 data = Facing::UP;
7960 }
7961
7962 tile->updateDefaultShape();
7963 setShape(tile);
7964 glRotatef(90, 0, 1, 0);
7965
7966 glTranslatef( -0.5f, -0.5f, -0.5f );
7967 t->begin();
7968 t->normal( 0, -1, 0 );
7969 renderFaceDown( tile, 0, 0, 0, getTexture(tile, 0, data ) );
7970 t->end();
7971
7972 if (isGrass && setColor)
7973 {
7974 int col = tile->getColor(data);
7975 float red = ((col >> 16) & 0xff) / 255.0f;
7976 float g = ((col >> 8) & 0xff) / 255.0f;
7977 float b = ((col) & 0xff) / 255.0f;
7978
7979 glColor4f(red * brightness, g * brightness, b * brightness, fAlpha);
7980 }
7981
7982 t->begin();
7983 t->normal( 0, 1, 0 );
7984 renderFaceUp( tile, 0, 0, 0, getTexture(tile, 1, data ) );
7985 t->end();
7986
7987 if (isGrass && setColor)
7988 {
7989 glColor4f(brightness, brightness, brightness, fAlpha);
7990 }
7991
7992 t->begin();
7993 t->normal( 0, 0, -1 );
7994 renderNorth( tile, 0, 0, 0, getTexture(tile, 2, data ) );
7995 t->end();
7996
7997 if (isGrass && setColor)
7998 {
7999 int col = tile->getColor(data);
8000 float red = ((col >> 16) & 0xff) / 255.0f;
8001 float g = ((col >> 8) & 0xff) / 255.0f;
8002 float b = ((col) & 0xff) / 255.0f;
8003
8004 glColor4f(red * brightness, g * brightness, b * brightness, fAlpha);
8005
8006 t->begin();
8007 t->normal( 0, 0, -1 );
8008 renderNorth( tile, 0, 0, 0, GrassTile::getSideTextureOverlay() );
8009 t->end();
8010
8011 glColor4f(brightness, brightness, brightness, fAlpha);
8012 }
8013
8014 t->begin();
8015 t->normal( 0, 0, 1 );
8016 renderSouth( tile, 0, 0, 0, getTexture(tile, 3, data ) );
8017 t->end();
8018
8019 if (isGrass && setColor)
8020 {
8021 int col = tile->getColor(data);
8022 float red = ((col >> 16) & 0xff) / 255.0f;
8023 float g = ((col >> 8) & 0xff) / 255.0f;
8024 float b = ((col) & 0xff) / 255.0f;
8025
8026 glColor4f(red * brightness, g * brightness, b * brightness, fAlpha);
8027
8028 t->begin();
8029 t->normal( 0, 0, 1 );
8030 renderSouth( tile, 0, 0, 0, GrassTile::getSideTextureOverlay() );
8031 t->end();
8032
8033 glColor4f(brightness, brightness, brightness, fAlpha);
8034 }
8035
8036 t->begin();
8037 t->normal( -1, 0, 0 );
8038 renderWest( tile, 0, 0, 0, getTexture(tile, 4, data ) );
8039 t->end();
8040
8041 if (isGrass && setColor)
8042 {
8043 int col = tile->getColor(data);
8044 float red = ((col >> 16) & 0xff) / 255.0f;
8045 float g = ((col >> 8) & 0xff) / 255.0f;
8046 float b = ((col) & 0xff) / 255.0f;
8047
8048 glColor4f(red * brightness, g * brightness, b * brightness, fAlpha);
8049
8050 t->begin();
8051 t->normal( -1, 0, 0 );
8052 renderWest( tile, 0, 0, 0, GrassTile::getSideTextureOverlay() );
8053 t->end();
8054
8055 glColor4f(brightness, brightness, brightness, fAlpha);
8056 }
8057
8058 t->begin();
8059 t->normal( 1, 0, 0 );
8060 renderEast( tile, 0, 0, 0, getTexture(tile, 5, data ) );
8061 t->end();
8062
8063 if (isGrass && setColor)
8064 {
8065 int col = tile->getColor(data);
8066 float red = ((col >> 16) & 0xff) / 255.0f;
8067 float g = ((col >> 8) & 0xff) / 255.0f;
8068 float b = ((col) & 0xff) / 255.0f;
8069
8070 glColor4f(red * brightness, g * brightness, b * brightness, fAlpha);
8071
8072 t->begin();
8073 t->normal( 1, 0, 0 );
8074 renderEast( tile, 0, 0, 0, GrassTile::getSideTextureOverlay() );
8075 t->end();
8076
8077 glColor4f(brightness, brightness, brightness, fAlpha);
8078 }
8079
8080 glTranslatef( 0.5f, 0.5f, 0.5f );
8081 }
8082 else if ( shape == Tile::SHAPE_CROSS_TEXTURE )
8083 {
8084 t->begin();
8085 t->normal( 0, -1, 0 );
8086 tesselateCrossTexture( tile, data, -0.5f, -0.5f, -0.5f, 1 );
8087 t->end();
8088 }
8089 else if (shape == Tile::SHAPE_STEM)
8090 {
8091 t->begin();
8092 t->normal(0, -1, 0);
8093 tile->updateDefaultShape();
8094 tesselateStemTexture(tile, data, tileShapeY1, -0.5f, -0.5f, -0.5f);
8095 t->end();
8096 }
8097 else if (shape == Tile::SHAPE_LILYPAD)
8098 {
8099 t->begin();
8100 t->normal(0, -1, 0);
8101 tile->updateDefaultShape();
8102 t->end();
8103 }
8104 else if ( shape == Tile::SHAPE_CACTUS )
8105 {
8106 tile->updateDefaultShape();
8107 glTranslatef( -0.5f, -0.5f, -0.5f );
8108 float s = 1 / 16.0f;
8109 t->begin();
8110 t->normal( 0, -1, 0 );
8111 renderFaceDown( tile, 0, 0, 0, getTexture(tile, 0 ) );
8112 t->end();
8113
8114 t->begin();
8115 t->normal( 0, 1, 0 );
8116 renderFaceUp( tile, 0, 0, 0, getTexture(tile, 1 ) );
8117 t->end();
8118
8119 t->begin();
8120 t->normal( 0, 0, -1 );
8121 t->addOffset( 0, 0, s );
8122 renderNorth( tile, 0, 0, 0, getTexture(tile, 2 ) );
8123 t->addOffset( 0, 0, -s );
8124 t->end();
8125
8126 t->begin();
8127 t->normal( 0, 0, 1 );
8128 t->addOffset( 0, 0, -s );
8129 renderSouth( tile, 0, 0, 0, getTexture(tile, 3 ) );
8130 t->addOffset( 0, 0, s );
8131 t->end();
8132
8133 t->begin();
8134 t->normal( -1, 0, 0 );
8135 t->addOffset( s, 0, 0 );
8136 renderWest( tile, 0, 0, 0, getTexture(tile, 4 ) );
8137 t->addOffset( -s, 0, 0 );
8138 t->end();
8139
8140 t->begin();
8141 t->normal( 1, 0, 0 );
8142 t->addOffset( -s, 0, 0 );
8143 renderEast( tile, 0, 0, 0, getTexture(tile, 5 ) );
8144 t->addOffset( s, 0, 0 );
8145 t->end();
8146
8147 glTranslatef( 0.5f, 0.5f, 0.5f );
8148 }
8149 else if (shape == Tile::SHAPE_ENTITYTILE_ANIMATED)
8150 {
8151 glRotatef(90, 0, 1, 0);
8152 glTranslatef(-0.5f, -0.5f, -0.5f);
8153 EntityTileRenderer::instance->render(tile, data, brightness, fAlpha, setColor, useCompiled);
8154 glEnable(GL_RESCALE_NORMAL);
8155 }
8156 else if ( shape == Tile::SHAPE_ROWS )
8157 {
8158 t->begin();
8159 t->normal( 0, -1, 0 );
8160 tesselateRowTexture( tile, data, -0.5f, -0.5f, -0.5f );
8161 t->end();
8162 }
8163 else if ( shape == Tile::SHAPE_TORCH )
8164 {
8165 t->begin();
8166 t->normal( 0, -1, 0 );
8167 tesselateTorch( tile, -0.5f, -0.5f, -0.5f, 0, 0, 0 );
8168 t->end();
8169 }
8170 else if ( shape == Tile::SHAPE_STAIRS )
8171 {
8172 for ( int i = 0; i < 2; i++ )
8173 {
8174 if ( i == 0 ) setShape( 0, 0, 0, 1, 1, 0.5f );
8175 if ( i == 1 ) setShape( 0, 0, 0.5f, 1, 0.5f, 1 );
8176
8177 glTranslatef( -0.5f, -0.5f, -0.5f );
8178 t->begin();
8179 t->normal( 0, -1, 0 );
8180 renderFaceDown( tile, 0, 0, 0, getTexture(tile, 0 ) );
8181 t->end();
8182
8183 t->begin();
8184 t->normal( 0, 1, 0 );
8185 renderFaceUp( tile, 0, 0, 0, getTexture(tile, 1 ) );
8186 t->end();
8187
8188 t->begin();
8189 t->normal( 0, 0, -1 );
8190 renderNorth( tile, 0, 0, 0, getTexture(tile, 2 ) );
8191 t->end();
8192
8193 t->begin();
8194 t->normal( 0, 0, 1 );
8195 renderSouth( tile, 0, 0, 0, getTexture(tile, 3 ) );
8196 t->end();
8197
8198 t->begin();
8199 t->normal( -1, 0, 0 );
8200 renderWest( tile, 0, 0, 0, getTexture(tile, 4 ) );
8201 t->end();
8202
8203 t->begin();
8204 t->normal( 1, 0, 0 );
8205 renderEast( tile, 0, 0, 0, getTexture(tile, 5 ) );
8206 t->end();
8207
8208 glTranslatef( 0.5f, 0.5f, 0.5f );
8209 }
8210 }
8211 else if (shape == Tile::SHAPE_EGG)
8212 {
8213 int y0 = 0;
8214 glTranslatef(-0.5f, -0.5f, -0.5f);
8215 t->begin();
8216 for (int i = 0; i < 8; i++)
8217 {
8218 int ww = 0;
8219 int hh = 1;
8220 if (i == 0) ww = 2;
8221 if (i == 1) ww = 3;
8222 if (i == 2) ww = 4;
8223 if (i == 3)
8224 {
8225 ww = 5;
8226 hh = 2;
8227 }
8228 if (i == 4)
8229 {
8230 ww = 6;
8231 hh = 3;
8232 }
8233 if (i == 5)
8234 {
8235 ww = 7;
8236 hh = 5;
8237 }
8238 if (i == 6)
8239 {
8240 ww = 6;
8241 hh = 2;
8242 }
8243 if (i == 7) ww = 3;
8244 float w = ww / 16.0f;
8245 float yy1 = 1 - (y0 / 16.0f);
8246 float yy0 = 1 - ((y0 + hh) / 16.0f);
8247 y0 += hh;
8248 setShape(0.5f - w, yy0, 0.5f - w, 0.5f + w, yy1, 0.5f + w);
8249 t->normal(0, -1, 0);
8250 renderFaceDown(tile, 0, 0, 0, getTexture(tile,0));
8251 t->normal(0, 1, 0);
8252 renderFaceUp(tile, 0, 0, 0, getTexture(tile,1));
8253 t->normal(0, 0, -1);
8254 renderNorth(tile, 0, 0, 0, getTexture(tile,2));
8255 t->normal(0, 0, 1);
8256 renderSouth(tile, 0, 0, 0, getTexture(tile,3));
8257 t->normal(-1, 0, 0);
8258 renderWest(tile, 0, 0, 0, getTexture(tile,4));
8259 t->normal(1, 0, 0);
8260 renderEast(tile, 0, 0, 0, getTexture(tile,5));
8261 }
8262 t->end();
8263 glTranslatef(0.5f, 0.5f, 0.5f);
8264 setShape(0, 0, 0, 1, 1, 1);
8265 }
8266
8267 else if ( shape == Tile::SHAPE_FENCE )
8268 {
8269 for ( int i = 0; i < 4; i++ )
8270 {
8271 float w = 2 / 16.0f;
8272 if ( i == 0 ) setShape( 0.5f - w, 0, 0, 0.5f + w, 1, w * 2 );
8273 if ( i == 1 ) setShape( 0.5f - w, 0, 1 - w * 2, 0.5f + w, 1, 1 );
8274 w = 1 / 16.0f;
8275 if ( i == 2 ) setShape( 0.5f - w, 1 - w * 3, -w * 2, 0.5f + w, 1 - w, 1 + w * 2 );
8276 if ( i == 3 ) setShape( 0.5f - w, 0.5f - w * 3, -w * 2, 0.5f + w, 0.5f - w, 1 + w * 2 );
8277
8278 glTranslatef( -0.5f, -0.5f, -0.5f );
8279 t->begin();
8280 t->normal( 0, -1, 0 );
8281 renderFaceDown( tile, 0, 0, 0, getTexture(tile, 0 ) );
8282 t->end();
8283
8284 t->begin();
8285 t->normal( 0, 1, 0 );
8286 renderFaceUp( tile, 0, 0, 0, getTexture(tile, 1 ) );
8287 t->end();
8288
8289 t->begin();
8290 t->normal( 0, 0, -1 );
8291 renderNorth( tile, 0, 0, 0, getTexture(tile, 2 ) );
8292 t->end();
8293
8294 t->begin();
8295 t->normal( 0, 0, 1 );
8296 renderSouth( tile, 0, 0, 0, getTexture(tile, 3 ) );
8297 t->end();
8298
8299 t->begin();
8300 t->normal( -1, 0, 0 );
8301 renderWest( tile, 0, 0, 0, getTexture(tile, 4 ) );
8302 t->end();
8303
8304 t->begin();
8305 t->normal( 1, 0, 0 );
8306 renderEast( tile, 0, 0, 0, getTexture(tile, 5 ) );
8307 t->end();
8308
8309 glTranslatef( 0.5f, 0.5f, 0.5f );
8310 }
8311 setShape( 0, 0, 0, 1, 1, 1 );
8312 }
8313 else if (shape == Tile::SHAPE_FENCE_GATE)
8314 {
8315 for (int i = 0; i < 3; i++)
8316 {
8317 float w = 1 / 16.0f;
8318 if (i == 0) setShape(0.5f - w, .3f, 0, 0.5f + w, 1, w * 2);
8319 if (i == 1) setShape(0.5f - w, .3f, 1 - w * 2, 0.5f + w, 1, 1);
8320 w = 1 / 16.0f;
8321 if (i == 2) setShape(0.5f - w, .5f, 0, 0.5f + w, 1 - w, 1);
8322
8323 glTranslatef(-0.5f, -0.5f, -0.5f);
8324 t->begin();
8325 t->normal(0, -1, 0);
8326 renderFaceDown(tile, 0, 0, 0, getTexture(tile,0));
8327 t->end();
8328
8329 t->begin();
8330 t->normal(0, 1, 0);
8331 renderFaceUp(tile, 0, 0, 0, getTexture(tile,1));
8332 t->end();
8333
8334 t->begin();
8335 t->normal(0, 0, -1);
8336 renderNorth(tile, 0, 0, 0, getTexture(tile,2));
8337 t->end();
8338
8339 t->begin();
8340 t->normal(0, 0, 1);
8341 renderSouth(tile, 0, 0, 0, getTexture(tile,3));
8342 t->end();
8343
8344 t->begin();
8345 t->normal(-1, 0, 0);
8346 renderWest(tile, 0, 0, 0, getTexture(tile,4));
8347 t->end();
8348
8349 t->begin();
8350 t->normal(1, 0, 0);
8351 renderEast(tile, 0, 0, 0, getTexture(tile,5));
8352 t->end();
8353
8354 glTranslatef(0.5f, 0.5f, 0.5f);
8355 }
8356 }
8357 else if (shape == Tile::SHAPE_WALL)
8358 {
8359 for (int i = 0; i < 2; i++)
8360 {
8361 if (i == 0) setShape(0, 0, .5f - WallTile::WALL_WIDTH, 1, WallTile::WALL_HEIGHT, .5f + WallTile::WALL_WIDTH);
8362 if (i == 1) setShape(.5f - WallTile::POST_WIDTH, 0, .5f - WallTile::POST_WIDTH, .5f + WallTile::POST_WIDTH, WallTile::POST_HEIGHT, .5f + WallTile::POST_WIDTH);
8363
8364 glTranslatef(-0.5f, -0.5f, -0.5f);
8365 t->begin();
8366 t->normal(0, -1, 0);
8367 renderFaceDown(tile, 0, 0, 0, tile->getTexture(0, data));
8368 t->end();
8369
8370 t->begin();
8371 t->normal(0, 1, 0);
8372 renderFaceUp(tile, 0, 0, 0, tile->getTexture(1, data));
8373 t->end();
8374
8375 t->begin();
8376 t->normal(0, 0, -1);
8377 renderNorth(tile, 0, 0, 0, tile->getTexture(2, data));
8378 t->end();
8379
8380 t->begin();
8381 t->normal(0, 0, 1);
8382 renderSouth(tile, 0, 0, 0, tile->getTexture(3, data));
8383 t->end();
8384
8385 t->begin();
8386 t->normal(-1, 0, 0);
8387 renderWest(tile, 0, 0, 0, tile->getTexture(4, data));
8388 t->end();
8389
8390 t->begin();
8391 t->normal(1, 0, 0);
8392 renderEast(tile, 0, 0, 0, tile->getTexture(5, data));
8393 t->end();
8394
8395 glTranslatef(0.5f, 0.5f, 0.5f);
8396 }
8397 setShape(0, 0, 0, 1, 1, 1);
8398 }
8399 else if (shape == Tile::SHAPE_ANVIL)
8400 {
8401 glTranslatef(-0.5f, -0.5f, -0.5f);
8402 tesselateAnvilInWorld((AnvilTile *) tile, 0, 0, 0, data << 2, true);
8403 glTranslatef(0.5f, 0.5f, 0.5f);
8404 }
8405 else if ( shape == Tile::SHAPE_PORTAL_FRAME )
8406 {
8407 // 4J added
8408 setShape(0, 0, 0, 1, 13.0f / 16.0f, 1);
8409
8410 glTranslatef( -0.5f, -0.5f, -0.5f );
8411 t->begin();
8412 t->normal( 0, -1, 0 );
8413 renderFaceDown( tile, 0, 0, 0, getTexture(tile, 0, 0 ) );
8414 t->end();
8415
8416 t->begin();
8417 t->normal( 0, 1, 0 );
8418 renderFaceUp( tile, 0, 0, 0, getTexture(tile, 1, 0 ) );
8419 t->end();
8420
8421 t->begin();
8422 t->normal( 0, 0, -1 );
8423 renderNorth( tile, 0, 0, 0, getTexture(tile, 2, 0 ) );
8424 t->end();
8425
8426 t->begin();
8427 t->normal( 0, 0, 1 );
8428 renderSouth( tile, 0, 0, 0, getTexture(tile, 3, 0 ) );
8429 t->end();
8430
8431 t->begin();
8432 t->normal( -1, 0, 0 );
8433 renderWest( tile, 0, 0, 0, getTexture(tile, 4, 0 ) );
8434 t->end();
8435
8436 t->begin();
8437 t->normal( 1, 0, 0 );
8438 renderEast( tile, 0, 0, 0, getTexture(tile, 5, 0 ) );
8439 t->end();
8440
8441 glTranslatef( 0.5f, 0.5f, 0.5f );
8442
8443 tile->updateDefaultShape();
8444
8445 }
8446 else if (shape == Tile::SHAPE_BEACON)
8447 {
8448 for (int i = 0; i < 3; i++)
8449 {
8450 if (i == 0)
8451 {
8452 setShape(2.0f / 16.0f, 0, 2.0f / 16.0f, 14.0f / 16.0f, 3.0f / 16.0f, 14.0f / 16.0f);
8453 setFixedTexture(getTexture(Tile::obsidian));
8454 }
8455 else if (i == 1)
8456 {
8457 setShape(3.0f / 16.0f, 3.0f / 16.0f, 3.0f / 16.0f, 13.0f / 16.0f, 14.0f / 16.0f, 13.0f / 16.0f);
8458 setFixedTexture(getTexture(Tile::beacon));
8459 }
8460 else if (i == 2)
8461 {
8462 setShape(0, 0, 0, 1, 1, 1);
8463 setFixedTexture(getTexture(Tile::glass));
8464 }
8465
8466 glTranslatef(-0.5f, -0.5f, -0.5f);
8467 t->begin();
8468 t->normal(0, -1, 0);
8469 renderFaceDown(tile, 0, 0, 0, getTexture(tile, 0, data));
8470 t->end();
8471
8472 t->begin();
8473 t->normal(0, 1, 0);
8474 renderFaceUp(tile, 0, 0, 0, getTexture(tile, 1, data));
8475 t->end();
8476
8477 t->begin();
8478 t->normal(0, 0, -1);
8479 renderNorth(tile, 0, 0, 0, getTexture(tile, 2, data));
8480 t->end();
8481
8482 t->begin();
8483 t->normal(0, 0, 1);
8484 renderSouth(tile, 0, 0, 0, getTexture(tile, 3, data));
8485 t->end();
8486
8487 t->begin();
8488 t->normal(-1, 0, 0);
8489 renderWest(tile, 0, 0, 0, getTexture(tile, 4, data));
8490 t->end();
8491
8492 t->begin();
8493 t->normal(1, 0, 0);
8494 renderEast(tile, 0, 0, 0, getTexture(tile, 5, data));
8495 t->end();
8496
8497 glTranslatef(0.5f, 0.5f, 0.5f);
8498 }
8499 setShape(0, 0, 0, 1, 1, 1);
8500 clearFixedTexture();
8501 }
8502 else if (shape == Tile::SHAPE_HOPPER)
8503 {
8504 glTranslatef(-0.5f, -0.5f, -0.5f);
8505 tesselateHopperInWorld(tile, 0, 0, 0, 0, true);
8506 glTranslatef(0.5f, 0.5f, 0.5f);
8507 }
8508
8509 t->setMipmapEnable( true ); // 4J added
8510}
8511
8512bool TileRenderer::canRender( int renderShape )
8513{
8514 if ( renderShape == Tile::SHAPE_BLOCK ) return true;
8515 if ( renderShape == Tile::SHAPE_TREE ) return true;
8516 if ( renderShape == Tile::SHAPE_QUARTZ) return true;
8517 if ( renderShape == Tile::SHAPE_CACTUS ) return true;
8518 if ( renderShape == Tile::SHAPE_STAIRS ) return true;
8519 if ( renderShape == Tile::SHAPE_FENCE ) return true;
8520 if ( renderShape == Tile::SHAPE_EGG) return true;
8521 if ( renderShape == Tile::SHAPE_ENTITYTILE_ANIMATED) return true;
8522 if ( renderShape == Tile::SHAPE_FENCE_GATE) return true;
8523 if ( renderShape == Tile::SHAPE_PISTON_BASE ) return true;
8524 if ( renderShape == Tile::SHAPE_PORTAL_FRAME ) return true;
8525 if ( renderShape == Tile::SHAPE_WALL) return true;
8526 if ( renderShape == Tile::SHAPE_BEACON) return true;
8527 if ( renderShape == Tile::SHAPE_ANVIL) return true;
8528 return false;
8529}
8530
8531Icon *TileRenderer::getTexture(Tile *tile, LevelSource *level, int x, int y, int z, int face)
8532{
8533 return getTextureOrMissing(tile->getTexture(level, x, y, z, face));
8534}
8535
8536Icon *TileRenderer::getTexture(Tile *tile, int face, int data)
8537{
8538 return getTextureOrMissing(tile->getTexture(face, data));
8539}
8540
8541Icon *TileRenderer::getTexture(Tile *tile, int face)
8542{
8543 return getTextureOrMissing(tile->getTexture(face));
8544}
8545
8546Icon *TileRenderer::getTexture(Tile *tile)
8547{
8548 return getTextureOrMissing(tile->getTexture(Facing::UP));
8549}
8550
8551Icon *TileRenderer::getTextureOrMissing(Icon *icon)
8552{
8553 if (icon == NULL) return minecraft->textures->getMissingIcon(Icon::TYPE_TERRAIN);
8554
8555#ifdef __PSVITA__
8556 // AP - alpha cut out is expensive on vita. Pass on the Alpha Cut out flag to the tesselator
8557 Tesselator* t = Tesselator::getInstance();
8558 t->setAlphaCutOut( icon->getFlags() & Icon::IS_ALPHA_CUT_OUT );
8559#endif
8560
8561 return icon;
8562}