@@ -69,6 +69,7 @@ static bool loadRegion(const char* file, const bool mustExist, int &loadedChunks
69
69
static bool loadTerrainRegion (const char *fromPath, int &loadedChunks);
70
70
static bool scanWorldDirectoryRegion (const char *fromPath);
71
71
static inline void assignBlock (const uint8_t &source, uint8_t * &dest, int &x, int &y, int &z, uint8_t * &justData);
72
+ static inline void lightCave (const int x, const int y, const int z, const int offsetx, const int offsetz);
72
73
73
74
int getWorldFormat (const char *worldPath)
74
75
{
@@ -461,58 +462,7 @@ static bool loadChunk(const char *streamOrFile, const size_t streamLen)
461
462
if (block == TORCH) {
462
463
// In underground mode, the lightmap is also used, but the values are calculated manually, to only show
463
464
// caves the players have discovered yet. It's not perfect of course, but works ok.
464
- for (int ty = int (y) - 9 ; ty < int (y) + 9 ; ty+=2 ) { // The trick here is to only take into account
465
- const int oty = ty - (int )g_MapminY;
466
- if (oty < 0 ) {
467
- continue ; // areas around torches.
468
- }
469
- if (oty >= int (g_MapsizeY)) {
470
- break ;
471
- }
472
- for (int tz = int (z) - 18 + offsetz; tz < int (z) + 18 + offsetz; ++tz) {
473
- if (tz < CHUNKSIZE_Z) {
474
- continue ;
475
- }
476
- for (int tx = int (x) - 18 + offsetx; tx < int (x) + 18 + offsetx; ++tx) {
477
- if (tx < CHUNKSIZE_X) {
478
- continue ;
479
- }
480
- if (g_Orientation == East) {
481
- if (tx >= int (g_MapsizeZ)-CHUNKSIZE_Z) {
482
- break ;
483
- }
484
- if (tz >= int (g_MapsizeX)-CHUNKSIZE_X) {
485
- break ;
486
- }
487
- SETLIGHTEAST (tx, oty, tz) = 0xFF ;
488
- } else if (g_Orientation == North) {
489
- if (tx >= int (g_MapsizeX)-CHUNKSIZE_X) {
490
- break ;
491
- }
492
- if (tz >= int (g_MapsizeZ)-CHUNKSIZE_Z) {
493
- break ;
494
- }
495
- SETLIGHTNORTH (tx, oty, tz) = 0xFF ;
496
- } else if (g_Orientation == South) {
497
- if (tx >= int (g_MapsizeX)-CHUNKSIZE_X) {
498
- break ;
499
- }
500
- if (tz >= int (g_MapsizeZ)-CHUNKSIZE_Z) {
501
- break ;
502
- }
503
- SETLIGHTSOUTH (tx, oty, tz) = 0xFF ;
504
- } else {
505
- if (tx >= int (g_MapsizeZ)-CHUNKSIZE_Z) {
506
- break ;
507
- }
508
- if (tz >= int (g_MapsizeX)-CHUNKSIZE_X) {
509
- break ;
510
- }
511
- SETLIGHTWEST (tx , oty, tz) = 0xFF ;
512
- }
513
- }
514
- }
515
- }
465
+ lightCave (x, y, z, offsetx, offsetz);
516
466
}
517
467
} else if (g_Skylight && y % 2 == 0 && y >= g_MapminY) { // copy light info too. Only every other time, since light info is 4 bits
518
468
const uint8_t &light = lightdata[(y / 2 ) + (z + (x * CHUNKSIZE_Z)) * (CHUNKSIZE_Y / 2 )];
@@ -626,7 +576,12 @@ static bool loadAnvilChunk(NBT_Tag * const level, const int32_t chunkX, const in
626
576
uint8_t &block = blockdata[x + (z + (y * CHUNKSIZE_Z)) * CHUNKSIZE_X];
627
577
assignBlock (block, targetBlock, x, y, z, justData);
628
578
// Light
629
- if (g_Skylight && (y & 1 ) == 0 ) {
579
+ if (g_Underground) {
580
+ if (y < g_MapminY) continue ;
581
+ if (block == TORCH) {
582
+ lightCave (x, y, z, offsetx, offsetz);
583
+ }
584
+ } else if (g_Skylight && (y & 1 ) == 0 ) {
630
585
const uint8_t highlight = ((lightdata[(x + (z + ((y + 1 ) * CHUNKSIZE_Z)) * CHUNKSIZE_X) / 2 ] >> ((x & 1 ) * 4 )) & 0x0F );
631
586
const uint8_t lowlight = ((lightdata[(x + (z + (y * CHUNKSIZE_Z)) * CHUNKSIZE_X) / 2 ] >> ((x & 1 ) * 4 )) & 0x0F );
632
587
uint8_t highsky = ((skydata[(x + (z + ((y + 1 ) * CHUNKSIZE_Z)) * CHUNKSIZE_X) / 2 ] >> ((x & 1 ) * 4 )) & 0x0F );
@@ -1061,13 +1016,13 @@ static inline void assignBlock(const uint8_t &block, uint8_t* &targetBlock, int
1061
1016
uint8_t col = (justData[(x + (z + (y * CHUNKSIZE_Z)) * CHUNKSIZE_X) / 2 ] >> ((x % 2 ) * 4 )) & 0xF ;
1062
1017
if (block == LEAVES) {
1063
1018
if ((col & 0x3 ) != 0 ) { // Map to pine or birch
1064
- *targetBlock++ = 230 + (( col & 0x3 ) - 1 ) % 2 + 1 ;
1019
+ *targetBlock++ = 228 + (col & 0x3 );
1065
1020
} else {
1066
1021
*targetBlock++ = block;
1067
1022
}
1068
1023
} else if (block == LOG) {
1069
1024
if (col != 0 ) { // Map to pine or birch
1070
- *targetBlock++ = 237 + col;
1025
+ *targetBlock++ = 236 + ( col & 0x3 ) ;
1071
1026
} else {
1072
1027
*targetBlock++ = block;
1073
1028
}
@@ -1079,7 +1034,7 @@ static inline void assignBlock(const uint8_t &block, uint8_t* &targetBlock, int
1079
1034
}
1080
1035
} else if (block == STEP) {
1081
1036
if (col != 0 ) {
1082
- *targetBlock++ = 232 + col;
1037
+ *targetBlock++ = 231 + col;
1083
1038
} else {
1084
1039
*targetBlock++ = block;
1085
1040
}
@@ -1098,3 +1053,96 @@ static inline void assignBlock(const uint8_t &block, uint8_t* &targetBlock, int
1098
1053
*targetBlock++ = block;
1099
1054
}
1100
1055
}
1056
+
1057
+ static inline void lightCave (const int x, const int y, const int z, const int offsetx, const int offsetz)
1058
+ {
1059
+ for (int ty = int (y) - 9 ; ty < int (y) + 9 ; ty+=2 ) { // The trick here is to only take into account
1060
+ const int oty = ty - g_MapminY;
1061
+ if (oty < 0 ) {
1062
+ continue ; // areas around torches.
1063
+ }
1064
+ if (oty >= int (g_MapsizeY)) {
1065
+ break ;
1066
+ }
1067
+ for (int tz = int (z) - 18 + offsetz; tz < int (z) + 18 + offsetz; ++tz) {
1068
+ if (tz < CHUNKSIZE_Z) {
1069
+ continue ;
1070
+ }
1071
+ for (int tx = int (x) - 18 + offsetx; tx < int (x) + 18 + offsetx; ++tx) {
1072
+ if (tx < CHUNKSIZE_X) {
1073
+ continue ;
1074
+ }
1075
+ if (g_Orientation == East) {
1076
+ if (tx >= int (g_MapsizeZ)-CHUNKSIZE_Z) {
1077
+ break ;
1078
+ }
1079
+ if (tz >= int (g_MapsizeX)-CHUNKSIZE_X) {
1080
+ break ;
1081
+ }
1082
+ SETLIGHTEAST (tx, oty, tz) = 0xFF ;
1083
+ } else if (g_Orientation == North) {
1084
+ if (tx >= int (g_MapsizeX)-CHUNKSIZE_X) {
1085
+ break ;
1086
+ }
1087
+ if (tz >= int (g_MapsizeZ)-CHUNKSIZE_Z) {
1088
+ break ;
1089
+ }
1090
+ SETLIGHTNORTH (tx, oty, tz) = 0xFF ;
1091
+ } else if (g_Orientation == South) {
1092
+ if (tx >= int (g_MapsizeX)-CHUNKSIZE_X) {
1093
+ break ;
1094
+ }
1095
+ if (tz >= int (g_MapsizeZ)-CHUNKSIZE_Z) {
1096
+ break ;
1097
+ }
1098
+ SETLIGHTSOUTH (tx, oty, tz) = 0xFF ;
1099
+ } else {
1100
+ if (tx >= int (g_MapsizeZ)-CHUNKSIZE_Z) {
1101
+ break ;
1102
+ }
1103
+ if (tz >= int (g_MapsizeX)-CHUNKSIZE_X) {
1104
+ break ;
1105
+ }
1106
+ SETLIGHTWEST (tx , oty, tz) = 0xFF ;
1107
+ }
1108
+ }
1109
+ }
1110
+ }
1111
+ }
1112
+
1113
+ void uncoverNether ()
1114
+ {
1115
+ const int cap = (g_MapsizeY - g_MapminY) - 57 ;
1116
+ const int to = (g_MapsizeY - g_MapminY) - 52 ;
1117
+ printf (" Uncovering Nether...\n " );
1118
+ for (size_t x = CHUNKSIZE_X; x < g_MapsizeX - CHUNKSIZE_X; ++x) {
1119
+ printProgress (x - CHUNKSIZE_X, g_MapsizeX);
1120
+ for (size_t z = CHUNKSIZE_Z; z < g_MapsizeZ - CHUNKSIZE_Z; ++z) {
1121
+ // Remove blocks on top, otherwise there is not much to see here
1122
+ int massive = 0 ;
1123
+ uint8_t *bp = g_Terrain + ((z + (x * g_MapsizeZ) + 1 ) * g_MapsizeY) - 1 ;
1124
+ int i;
1125
+ for (i = 0 ; i < to; ++i) { // Go down 74 blocks from the ceiling to see if there is anything except solid
1126
+ if (massive && (*bp == AIR || *bp == LAVA || *bp == STAT_LAVA)) {
1127
+ if (--massive == 0 ) {
1128
+ break ; // Ignore caves that are only 2 blocks high
1129
+ }
1130
+ }
1131
+ if (*bp != AIR && *bp != LAVA && *bp != STAT_LAVA) {
1132
+ massive = 3 ;
1133
+ }
1134
+ --bp;
1135
+ }
1136
+ // So there was some cave or anything before going down 70 blocks, everything above will get removed
1137
+ // If not, only 45 blocks starting at the ceiling will be removed
1138
+ if (i > cap) {
1139
+ i = cap - 25 ; // TODO: Make this configurable
1140
+ }
1141
+ bp = g_Terrain + ((z + (x * g_MapsizeZ) + 1 ) * g_MapsizeY) - 1 ;
1142
+ for (int j = 0 ; j < i; ++j) {
1143
+ *bp-- = AIR;
1144
+ }
1145
+ }
1146
+ }
1147
+ printProgress (10 , 10 );
1148
+ }
0 commit comments