diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp index c4111da11..da54f7194 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp @@ -194,14 +194,15 @@ void ConsoleSchematicFile::save_tags(DataOutputStream *dos) __int64 ConsoleSchematicFile::applyBlocksAndData(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot) { int xStart = std::max(destinationBox->x0, (double)chunk->x*16); - int xEnd = std::min(destinationBox->x1, (double)((xStart>>4)<<4) + 16); + // 4jcraft added cast to u + int xEnd = std::min(destinationBox->x1, (double)((unsigned) (xStart>>4)<<4) + 16); int yStart = destinationBox->y0; int yEnd = destinationBox->y1; if(yEnd > Level::maxBuildHeight) yEnd = Level::maxBuildHeight; int zStart = std::max(destinationBox->z0, (double)chunk->z*16); - int zEnd = std::min(destinationBox->z1, (double)((zStart>>4)<<4) + 16); + int zEnd = std::min(destinationBox->z1, (double)(((unsigned) zStart>>4)<<4) + 16); #ifdef _DEBUG app.DebugPrintf("Range is (%d,%d,%d) to (%d,%d,%d)\n",xStart,yStart,zStart,xEnd-1,yEnd-1,zEnd-1); @@ -333,14 +334,14 @@ __int64 ConsoleSchematicFile::applyBlocksAndData(LevelChunk *chunk, AABB *chunkB __int64 ConsoleSchematicFile::applyLighting(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot) { int xStart = std::max(destinationBox->x0, (double)chunk->x*16); - int xEnd = std::min(destinationBox->x1, (double)((xStart>>4)<<4) + 16); + int xEnd = std::min(destinationBox->x1, (double)(((unsigned) xStart>>4)<<4) + 16); int yStart = destinationBox->y0; int yEnd = destinationBox->y1; if(yEnd > Level::maxBuildHeight) yEnd = Level::maxBuildHeight; int zStart = std::max(destinationBox->z0, (double)chunk->z*16); - int zEnd = std::min(destinationBox->z1, (double)((zStart>>4)<<4) + 16); + int zEnd = std::min(destinationBox->z1, (double)(((unsigned) zStart>>4)<<4) + 16); int rowBlocksIncluded = (yEnd-yStart)*(zEnd-zStart); int blocksIncluded = (xEnd-xStart)*rowBlocksIncluded; diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp b/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp index b6bf2a390..b7f0bcaf0 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp @@ -244,8 +244,8 @@ void LevelGenerationOptions::processSchematics(LevelChunk *chunk) rule->processSchematic(chunkBox, chunk); } - int cx = (chunk->x << 4); - int cz = (chunk->z << 4); + int cx = ((unsigned)chunk->x << 4); + int cz = ((unsigned)chunk->z << 4); for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ ) { @@ -511,4 +511,4 @@ bool LevelGenerationOptions::getuseFlatWorld() { return m_useFlatWorld; } bool LevelGenerationOptions::requiresGameRules() { return m_bRequiresGameRules; } void LevelGenerationOptions::setRequiredGameRules(LevelRuleset *rules) { m_requiredGameRules = rules; m_bRequiresGameRules = true; } -LevelRuleset *LevelGenerationOptions::getRequiredGameRules() { return m_requiredGameRules; } \ No newline at end of file +LevelRuleset *LevelGenerationOptions::getRequiredGameRules() { return m_requiredGameRules; } diff --git a/Minecraft.World/IO/Files/ConsoleSaveFileSplit.cpp b/Minecraft.World/IO/Files/ConsoleSaveFileSplit.cpp index 5b088f628..645d2c13e 100644 --- a/Minecraft.World/IO/Files/ConsoleSaveFileSplit.cpp +++ b/Minecraft.World/IO/Files/ConsoleSaveFileSplit.cpp @@ -1221,7 +1221,7 @@ bool ConsoleSaveFileSplit::GetNumericIdentifierFromName(const std::wstring &file swscanf_s(body, L"%d.%d.mcr", &x, &z ); // Pack full id - id |= ( ( x << 8 ) & 0x0000ff00 ); + id |= ( ( (unsigned int) x << 8 ) & 0x0000ff00 ); id |= ( z & 0x000000ff ); *idOut = id; diff --git a/Minecraft.World/Level/LevelChunk.cpp b/Minecraft.World/Level/LevelChunk.cpp index 2658be342..cc0aa626e 100644 --- a/Minecraft.World/Level/LevelChunk.cpp +++ b/Minecraft.World/Level/LevelChunk.cpp @@ -459,7 +459,7 @@ bool LevelChunk::isAt(int x, int z) int LevelChunk::getHeightmap(int x, int z) { - return heightmap[z << 4 | x] & 0xff; + return heightmap[(unsigned) z << 4 | x] & 0xff; } int LevelChunk::getHighestSectionPosition() @@ -492,12 +492,12 @@ void LevelChunk::recalcHeightmapOnly() for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) { - rainHeights[x + (z << 4)] = 255; // 4J - changed from int to unsigned char & this special value changed from -999 to 255 + rainHeights[x + ((unsigned) z << 4)] = 255; // 4J - changed from int to unsigned char & this special value changed from -999 to 255 int y = Level::maxBuildHeight - 1; // int p = x << level->depthBitsPlusFour | z << level->depthBits; // 4J - removed #ifdef __PSVITA__ - int Index = ( x << 11 ) + ( z << 7 ); + int Index = ( (unsigned) x << 11 ) + ( (unsigned) z << 7 ); int offset = Level::COMPRESSED_CHUNK_SECTION_TILES; y = 127; while (y > 0 && Tile::lightBlock[blockData[Index + offset + (y - 1)]] == 0) // 4J - was blocks->get() was blocks[p + y - 1] @@ -525,7 +525,7 @@ void LevelChunk::recalcHeightmapOnly() blocks = (y-1) >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT?upperBlocks : lowerBlocks; } #endif - heightmap[z << 4 | x] = (uint8_t) y; + heightmap[(unsigned) z << 4 | x] = (uint8_t) y; if (y < min) min = y; } @@ -553,7 +553,7 @@ void LevelChunk::recalcHeightmap() // int p = x << level->depthBitsPlusFour | z << level->depthBits; // 4J - removed #ifdef __PSVITA__ - int Index = ( x << 11 ) + ( z << 7 ); + int Index = ( (unsigned) x << 11 ) + ( (unsigned) z << 7 ); int offset = Level::COMPRESSED_CHUNK_SECTION_TILES; y = 127; while (y > 0 && Tile::lightBlock[blockData[Index + offset + (y - 1)]] == 0) // 4J - was blocks->get() was blocks[p + y - 1] @@ -581,7 +581,7 @@ void LevelChunk::recalcHeightmap() blocks = (y-1) >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT?upperBlocks : lowerBlocks; } #endif - heightmap[z << 4 | x] = (uint8_t) y; + heightmap[(unsigned) z << 4 | x] = (uint8_t) y; if (y < min) min = y; if (!level->dimension->hasCeiling) @@ -788,7 +788,7 @@ void LevelChunk::lightGap(int x, int z, int y1, int y2) void LevelChunk::recalcHeight(int x, int yStart, int z) { - int yOld = heightmap[z << 4 | x] & 0xff; + int yOld = heightmap[(unsigned) z << 4 | x] & 0xff; int y = yOld; if (yStart > yOld) y = yStart; @@ -803,7 +803,7 @@ void LevelChunk::recalcHeight(int x, int yStart, int z) if (y == yOld) return; // level->lightColumnChanged(x, z, y, yOld); // 4J - this call moved below & corrected - see comment further down - heightmap[z << 4 | x] = (uint8_t) y; + heightmap[(unsigned) z << 4 | x] = (uint8_t) y; if (y < minHeight) { @@ -815,7 +815,7 @@ void LevelChunk::recalcHeight(int x, int yStart, int z) for (int _x = 0; _x < 16; _x++) for (int _z = 0; _z < 16; _z++) { - if ((heightmap[_z << 4 | _x] & 0xff) < min) min = (heightmap[_z << 4 | _x] & 0xff); + if ((heightmap[(unsigned) _z << 4 | _x] & 0xff) < min) min = (heightmap[(unsigned) _z << 4 | _x] & 0xff); } this->minHeight = min; } @@ -865,7 +865,7 @@ void LevelChunk::recalcHeight(int x, int yStart, int z) level->lightColumnChanged(xOffs, zOffs, y, yOld); // 4J - lighting changes brought forward from 1.8.2 - int height = heightmap[z << 4 | x]; + int height = heightmap[(unsigned) z << 4 | x]; int y1 = yOld; int y2 = height; if (y2 < y1) @@ -913,7 +913,7 @@ bool LevelChunk::setTileAndData(int x, int y, int z, int _tile, int _data) uint8_t tile = (uint8_t) _tile; // Optimisation brought forward from 1.8.2, change from int to unsigned char & this special value changed from -999 to 255 - int slot = z << 4 | x; + int slot = (unsigned) z << 4 | x; if (y >= ((int)rainHeights[slot]) - 1) { @@ -1246,7 +1246,7 @@ void LevelChunk::removeEntity(std::shared_ptr e, int yc) bool LevelChunk::isSkyLit(int x, int y, int z) { - return y >= (heightmap[z << 4 | x] & 0xff); + return y >= (heightmap[(unsigned) z << 4 | x] & 0xff); } void LevelChunk::skyBrightnessChanged() @@ -1979,12 +1979,13 @@ bool LevelChunk::isYSpaceEmpty(int y1, int y2) Biome *LevelChunk::getBiome(int x, int z, BiomeSource *biomeSource) { - int value = biomes[(z << 4) | x] & 0xff; + int value = biomes[((unsigned) z << 4) | x] & 0xff; if (value == 0xff) { - Biome *biome = biomeSource->getBiome((this->x << 4) + x, (this->z << 4) + z); + // 4jcraft added casts to u + Biome *biome = biomeSource->getBiome(((unsigned) this->x << 4) + x, ((unsigned) this->z << 4) + z); value = biome->id; - biomes[(z << 4) | x] = (uint8_t) (value & 0xff); + biomes[((unsigned) z << 4) | x] = (uint8_t) (value & 0xff); } if (Biome::biomes[value] == NULL) { @@ -2007,7 +2008,7 @@ void LevelChunk::setBiomes(byteArray biomes) // 4J - optimisation brought forward from 1.8.2 int LevelChunk::getTopRainBlock(int x, int z) { - int slot = x | (z << 4); + int slot = x | ((unsigned) z << 4); int h = rainHeights[slot]; if (h == 255) diff --git a/Minecraft.World/Level/RandomLevelSource.cpp b/Minecraft.World/Level/RandomLevelSource.cpp index e7f055b13..b18278516 100644 --- a/Minecraft.World/Level/RandomLevelSource.cpp +++ b/Minecraft.World/Level/RandomLevelSource.cpp @@ -144,7 +144,7 @@ void RandomLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks) for (int x = 0; x < CHUNK_WIDTH; x++) { - int offs = (x + xc * CHUNK_WIDTH) << Level::genDepthBitsPlusFour | (0 + zc * CHUNK_WIDTH) << Level::genDepthBits | (yc * CHUNK_HEIGHT + y); + int offs = (unsigned) (x + (unsigned) xc * CHUNK_WIDTH) << Level::genDepthBitsPlusFour | ((unsigned) zc * CHUNK_WIDTH) << Level::genDepthBits | (yc * CHUNK_HEIGHT + y); int step = 1 << Level::genDepthBits; offs -= step; double zStep = 1 / (double) CHUNK_WIDTH; @@ -654,7 +654,8 @@ void RandomLevelSource::postProcess(ChunkSource *parent, int xt, int zt) pprandom->setSeed(level->getSeed()); __int64 xScale = pprandom->nextLong() / 2 * 2 + 1; __int64 zScale = pprandom->nextLong() / 2 * 2 + 1; - pprandom->setSeed(((xt * xScale) + (zt * zScale)) ^ level->getSeed()); + // 4jcraft added casts to u, holy moly, the getSeed is 64 bit and the result is 32... + pprandom->setSeed((((uint64_t)(int64_t)xt * (uint64_t)(int64_t)xScale) + ((uint64_t)(int64_t)zt * (uint64_t)(int64_t)zScale)) ^ level->getSeed()); bool hasVillage = false; diff --git a/Minecraft.World/Level/Storage/McRegionChunkStorage.cpp b/Minecraft.World/Level/Storage/McRegionChunkStorage.cpp index b13f1c221..e31fab3c5 100644 --- a/Minecraft.World/Level/Storage/McRegionChunkStorage.cpp +++ b/Minecraft.World/Level/Storage/McRegionChunkStorage.cpp @@ -78,7 +78,9 @@ LevelChunk *McRegionChunkStorage::load(Level *level, int x, int z) // If we can't find the chunk in the save file, then we should remove any entities we might have for that chunk if(regionChunkInputStream == NULL) { - __int64 index = ((__int64)(x) << 32) | (((__int64)(z))&0x00000000FFFFFFFF); + // 4jcraft fixed cast from int to int64 and taking the mask of the upper bits + // and cast to unsigned + __int64 index = ((uint64_t)(uint32_t)(x) << 32) | (((uint64_t)(uint32_t)(z))); AUTO_VAR(it, m_entityData.find(index)); if(it != m_entityData.end()) diff --git a/Minecraft.World/Util/Random.cpp b/Minecraft.World/Util/Random.cpp index 00c4403aa..10f58d938 100644 --- a/Minecraft.World/Util/Random.cpp +++ b/Minecraft.World/Util/Random.cpp @@ -88,7 +88,8 @@ int Random::nextInt(int n) if ((n & -n) == n) // i.e., n is a power of 2 - return (int)(((__int64)next(31) * n) >> 31); // 4J Stu - Made __int64 instead of long + // 4jcraft added casts to unsigned + return (unsigned int)(((__uint64)next(31) * n) >> 31); // 4J Stu - Made __int64 instead of long int bits, val; do @@ -106,7 +107,8 @@ float Random::nextFloat() __int64 Random::nextLong() { - return ((__int64)next(32) << 32) + next(32); + // 4jcraft added casts to unsigned + return (__uint64)((__uint64)next(32) << 32) + next(32); } bool Random::nextBoolean() diff --git a/Minecraft.World/WorldGen/Biomes/BiomeCache.cpp b/Minecraft.World/WorldGen/Biomes/BiomeCache.cpp index 3fc2d7bc5..0e6f91eb0 100644 --- a/Minecraft.World/WorldGen/Biomes/BiomeCache.cpp +++ b/Minecraft.World/WorldGen/Biomes/BiomeCache.cpp @@ -18,7 +18,8 @@ BiomeCache::Block::Block(int x, int z, BiomeCache *parent) // parent->source->getTemperatureBlock(temps, x << ZONE_SIZE_BITS, z << ZONE_SIZE_BITS, ZONE_SIZE, ZONE_SIZE); // parent->source->getDownfallBlock(downfall, x << ZONE_SIZE_BITS, z << ZONE_SIZE_BITS, ZONE_SIZE, ZONE_SIZE); // parent->source->getBiomeBlock(biomes, x << ZONE_SIZE_BITS, z << ZONE_SIZE_BITS, ZONE_SIZE, ZONE_SIZE, false); - parent->source->getBiomeIndexBlock(biomeIndices, x << ZONE_SIZE_BITS, z << ZONE_SIZE_BITS, ZONE_SIZE, ZONE_SIZE, false); + // 4jcraft added cast to unsigned + parent->source->getBiomeIndexBlock(biomeIndices, (unsigned) x << ZONE_SIZE_BITS, (unsigned) z << ZONE_SIZE_BITS, ZONE_SIZE, ZONE_SIZE, false); } @@ -162,4 +163,4 @@ BiomeArray BiomeCache::getBiomeBlockAt(int x, int z) byteArray BiomeCache::getBiomeIndexBlockAt(int x, int z) { return getBlockAt(x, z)->biomeIndices; -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Features/LargeFeature.cpp b/Minecraft.World/WorldGen/Features/LargeFeature.cpp index e1cda1982..187ec5dd1 100644 --- a/Minecraft.World/WorldGen/Features/LargeFeature.cpp +++ b/Minecraft.World/WorldGen/Features/LargeFeature.cpp @@ -28,10 +28,10 @@ void LargeFeature::apply(ChunkSource *ChunkSource, Level *level, int xOffs, int { for (int z = zOffs - r; z <= zOffs + r; z++) { - __int64 xx = x * xScale; - __int64 zz = z * zScale; + __int64 xx = (uint64_t) x * xScale; + __int64 zz = (uint64_t) z * zScale; random->setSeed(xx ^ zz ^ level->getSeed()); addFeature(level, x, z, xOffs, zOffs, blocks); } } -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Features/StrongholdFeature.cpp b/Minecraft.World/WorldGen/Features/StrongholdFeature.cpp index 52ee3d0c3..1c6a69d51 100644 --- a/Minecraft.World/WorldGen/Features/StrongholdFeature.cpp +++ b/Minecraft.World/WorldGen/Features/StrongholdFeature.cpp @@ -98,7 +98,7 @@ bool StrongholdFeature::isFeatureChunk(int x, int z,bool bIsSuperflat) int selectedX = (int) (Math::round(cos(angle) * dist)); int selectedZ = (int) (Math::round(sin(angle) * dist)); - TilePos *position = level->getBiomeSource()->findBiome((selectedX << 4) + 8, (selectedZ << 4) + 8, 7 << 4, allowedBiomes, &random); + TilePos *position = level->getBiomeSource()->findBiome(((unsigned int) selectedX << 4) + 8, ((unsigned int) selectedZ << 4) + 8, 7 << 4, allowedBiomes, &random); if (position != NULL) { selectedX = position->x >> 4; @@ -221,4 +221,4 @@ StrongholdFeature::StrongholdStart::StrongholdStart(Level *level, Random *random calculateBoundingBox(); moveBelowSeaLevel(level, random, 10); -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Features/StructureFeature.cpp b/Minecraft.World/WorldGen/Features/StructureFeature.cpp index 2f274e691..dfb98b0c6 100644 --- a/Minecraft.World/WorldGen/Features/StructureFeature.cpp +++ b/Minecraft.World/WorldGen/Features/StructureFeature.cpp @@ -42,8 +42,8 @@ bool StructureFeature::postProcess(Level *level, Random *random, int chunkX, int // Normal feature generation offsets generation by half a chunk to ensure that it can generate the entire feature in chunks already created // Structure features don't need this, as the PlaceBlock function only places blocks inside the BoundingBox specified, and parts // of a struture piece can be added in more than one post-process call - int cx = (chunkX << 4); // + 8; - int cz = (chunkZ << 4); // + 8; + int cx = ((unsigned) chunkX << 4); // + 8; + int cz = ((unsigned)chunkZ << 4); // + 8; bool intersection = false; for( AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end(); it++ ) diff --git a/Minecraft.World/WorldGen/Features/VillageFeature.cpp b/Minecraft.World/WorldGen/Features/VillageFeature.cpp index 7d9dd0ea6..ab3755071 100644 --- a/Minecraft.World/WorldGen/Features/VillageFeature.cpp +++ b/Minecraft.World/WorldGen/Features/VillageFeature.cpp @@ -91,7 +91,8 @@ VillageFeature::VillageStart::VillageStart(Level *level, Random *random, int chu std::list *pieceSet = VillagePieces::createPieceSet(random, villageSizeModifier); - VillagePieces::StartPiece *startRoom = new VillagePieces::StartPiece(level->getBiomeSource(), 0, random, (chunkX << 4) + 2, (chunkZ << 4) + 2, pieceSet, villageSizeModifier, level); + // 4jcraft added casts to u + VillagePieces::StartPiece *startRoom = new VillagePieces::StartPiece(level->getBiomeSource(), 0, random, ((unsigned) chunkX << 4) + 2, ((unsigned) chunkZ << 4) + 2, pieceSet, villageSizeModifier, level); pieces.push_back(startRoom); startRoom->addChildren(startRoom, &pieces, random); diff --git a/Minecraft.World/WorldGen/Layers/FuzzyZoomLayer.cpp b/Minecraft.World/WorldGen/Layers/FuzzyZoomLayer.cpp index 9b117e887..70fb06100 100644 --- a/Minecraft.World/WorldGen/Layers/FuzzyZoomLayer.cpp +++ b/Minecraft.World/WorldGen/Layers/FuzzyZoomLayer.cpp @@ -15,17 +15,18 @@ intArray FuzzyZoomLayer::getArea(int xo, int yo, int w, int h) int ph = (h >> 1) + 3; intArray p = parent->getArea(px, py, pw, ph); + // 4jcraft added casts to unsigned to prevent shift of neg value intArray tmp = IntCache::allocate((pw * 2) * (ph * 2)); - int ww = (pw << 1); + int ww = ((unsigned int) pw << 1); for (int y = 0; y < ph - 1; y++) { - int ry = y << 1; + int ry = (unsigned int) y << 1; int pp = ry * ww; int ul = p[(0 + 0) + (y + 0) * pw]; int dl = p[(0 + 0) + (y + 1) * pw]; for (int x = 0; x < pw - 1; x++) { - initRandom((x + px) << 1, (y + py) << 1); + initRandom((unsigned int) (x + px) << 1, (unsigned int) (y + py) << 1); int ur = p[(x + 1) + (y + 0) * pw]; int dr = p[(x + 1) + (y + 1) * pw]; @@ -41,7 +42,7 @@ intArray FuzzyZoomLayer::getArea(int xo, int yo, int w, int h) intArray result = IntCache::allocate(w * h); for (int y = 0; y < h; y++) { - System::arraycopy(tmp, (y + (yo & 1)) * (pw << 1) + (xo & 1), &result, y * w, w); + System::arraycopy(tmp, (y + (yo & 1)) * ((unsigned int) pw << 1) + (xo & 1), &result, y * w, w); } return result; @@ -69,4 +70,4 @@ std::shared_ptrFuzzyZoomLayer::zoom(__int64 seed, std::shared_ptrs result = std::shared_ptr(new FuzzyZoomLayer(seed + i, result)); } return result; -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Layers/Layer.cpp b/Minecraft.World/WorldGen/Layers/Layer.cpp index 286fd3827..454ec8d5f 100644 --- a/Minecraft.World/WorldGen/Layers/Layer.cpp +++ b/Minecraft.World/WorldGen/Layers/Layer.cpp @@ -111,7 +111,7 @@ Layer::Layer(__int64 seedMixup) { parent = nullptr; - // 4jcraft added all those calls abecause of signed int overflow + // 4jcraft added casts to prevent signed int overflow this->seedMixup = seedMixup; this->seedMixup *= (uint64_t) this->seedMixup * 6364136223846793005l + 1442695040888963407l; this->seedMixup = (uint64_t) this->seedMixup + seedMixup; @@ -125,7 +125,7 @@ void Layer::init(__int64 seed) { this->seed = seed; if (parent != NULL) parent->init(seed); - // 4jcraft added all those calls abecause of signed int overflow + // 4jcraft added casts to prevent signed int overflow this->seed *= (uint64_t) this->seed * 6364136223846793005l + 1442695040888963407l; this->seed = (uint64_t) this->seed + seedMixup; this->seed *= (uint64_t) this->seed * 6364136223846793005l + 1442695040888963407l; @@ -137,7 +137,7 @@ void Layer::init(__int64 seed) void Layer::initRandom(__int64 x, __int64 y) { rval = seed; - // 4jcraft added all those calls abecause of signed int overflow + // 4jcraft added casts to prevent signed int overflow rval *= (uint64_t) rval * 6364136223846793005l + 1442695040888963407l; rval += (uint64_t) x; rval *= (uint64_t) rval * 6364136223846793005l + 1442695040888963407l; @@ -196,7 +196,8 @@ int Layer::nextRandom(int max) #endif if (result < 0) result += max; - rval *= rval * 6364136223846793005l + 1442695040888963407l; - rval += seed; + // 4jcraft added cast to unsigned + rval *= (uint64_t) rval * 6364136223846793005l + 1442695040888963407l; + rval += (uint64_t) seed; return result; } diff --git a/Minecraft.World/WorldGen/Layers/VoronoiZoom.cpp b/Minecraft.World/WorldGen/Layers/VoronoiZoom.cpp index 7c0e57a7c..85154ecd4 100644 --- a/Minecraft.World/WorldGen/Layers/VoronoiZoom.cpp +++ b/Minecraft.World/WorldGen/Layers/VoronoiZoom.cpp @@ -19,8 +19,9 @@ intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) int ph = (h >> bits) + 3; intArray p = parent->getArea(px, py, pw, ph); - int ww = pw << bits; - int hh = ph << bits; + // 4jcraft added all those casts to unsigned + int ww = (unsigned) pw << bits; + int hh = (unsigned) ph << bits; intArray tmp = IntCache::allocate(ww * hh); for (int y = 0; y < ph - 1; y++) { @@ -29,16 +30,16 @@ intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) for (int x = 0; x < pw - 1; x++) { double s = ss * 0.9; - initRandom((x + px) << bits, (y + py) << bits); + initRandom((unsigned) (x + px) << bits, (unsigned) (y + py) << bits); double x0 = (nextRandom(1024) / 1024.0 - 0.5) * s; double y0 = (nextRandom(1024) / 1024.0 - 0.5) * s; - initRandom((x + px + 1) << bits, (y + py) << bits); + initRandom((unsigned) (x + px + 1) << bits, (unsigned) (y + py) << bits); double x1 = (nextRandom(1024) / 1024.0 - 0.5) * s + ss; double y1 = (nextRandom(1024) / 1024.0 - 0.5) * s; - initRandom((x + px) << bits, (y + py + 1) << bits); + initRandom((unsigned) (x + px) << bits, (unsigned) (y + py + 1) << bits); double x2 = (nextRandom(1024) / 1024.0 - 0.5) * s; double y2 = (nextRandom(1024) / 1024.0 - 0.5) * s + ss; - initRandom((x + px + 1) << bits, (y + py + 1) << bits); + initRandom((unsigned) (x + px + 1) << bits, (unsigned) (y + py + 1) << bits); double x3 = (nextRandom(1024) / 1024.0 - 0.5) * s + ss; double y3 = (nextRandom(1024) / 1024.0 - 0.5) * s + ss; @@ -47,7 +48,7 @@ intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) for (int yy = 0; yy < ss; yy++) { - int pp = ((y << bits) + yy) * ww + ((x << bits)); + int pp = ((unsigned) (y << bits) + yy) * ww + ((unsigned) (x << bits)); for (int xx = 0; xx < ss; xx++) { double d0 = ((yy - y0) * (yy - y0) + (xx - x0) * (xx - x0)); @@ -81,7 +82,7 @@ intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) intArray result = IntCache::allocate(w * h); for (int y = 0; y < h; y++) { - System::arraycopy(tmp, (y + (yo & (ss - 1))) * (pw << bits) + (xo & (ss - 1)), &result, y * w, w); + System::arraycopy(tmp, (y + (yo & (ss - 1))) * ((unsigned) pw << bits) + (xo & (ss - 1)), &result, y * w, w); } return result; } @@ -119,4 +120,4 @@ int VoronoiZoom::random(int a, int b, int c, int d) if (s == 1) return b; if (s == 2) return c; return d; -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Layers/ZoomLayer.cpp b/Minecraft.World/WorldGen/Layers/ZoomLayer.cpp index b0e5d6d79..3f7cbf5f9 100644 --- a/Minecraft.World/WorldGen/Layers/ZoomLayer.cpp +++ b/Minecraft.World/WorldGen/Layers/ZoomLayer.cpp @@ -16,16 +16,17 @@ intArray ZoomLayer::getArea(int xo, int yo, int w, int h) intArray p = parent->getArea(px, py, pw, ph); intArray tmp = IntCache::allocate((pw * 2) * (ph * 2)); - int ww = (pw << 1); + // 4jcraft added casts to unsigned + int ww = ((unsigned int) pw << 1); for (int y = 0; y < ph - 1; y++) { - int ry = y << 1; + int ry = (unsigned int) y << 1; int pp = ry * ww; int ul = p[(0 + 0) + (y + 0) * pw]; int dl = p[(0 + 0) + (y + 1) * pw]; for (int x = 0; x < pw - 1; x++) { - initRandom((x + px) << 1, (y + py) << 1); + initRandom((unsigned int) (x + px) << 1, (unsigned int) (y + py) << 1); int ur = p[(x + 1) + (y + 0) * pw]; int dr = p[(x + 1) + (y + 1) * pw]; @@ -41,7 +42,7 @@ intArray ZoomLayer::getArea(int xo, int yo, int w, int h) intArray result = IntCache::allocate(w * h); for (int y = 0; y < h; y++) { - System::arraycopy(tmp, (y + (yo & 1)) * (pw << 1) + (xo & 1), &result, y * w, w); + System::arraycopy(tmp, (y + (yo & 1)) * (unsigned int) (pw << 1) + (xo & 1), &result, y * w, w); } return result; } @@ -89,4 +90,4 @@ std::shared_ptrZoomLayer::zoom(__int64 seed, std::shared_ptr sup, result = std::shared_ptr(new ZoomLayer(seed + i, result)); } return result; -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Structures/MineShaftStart.cpp b/Minecraft.World/WorldGen/Structures/MineShaftStart.cpp index f15f0b952..8e905916d 100644 --- a/Minecraft.World/WorldGen/Structures/MineShaftStart.cpp +++ b/Minecraft.World/WorldGen/Structures/MineShaftStart.cpp @@ -3,10 +3,11 @@ MineShaftStart::MineShaftStart(Level *level, Random *random, int chunkX, int chunkZ) { - MineShaftPieces::MineShaftRoom *mineShaftRoom = new MineShaftPieces::MineShaftRoom(0, random, (chunkX << 4) + 2, (chunkZ << 4) + 2); + // 4jcraft added to unsigned + MineShaftPieces::MineShaftRoom *mineShaftRoom = new MineShaftPieces::MineShaftRoom(0, random, ((unsigned) chunkX << 4) + 2, ((unsigned) chunkZ << 4) + 2); pieces.push_back(mineShaftRoom); mineShaftRoom->addChildren(mineShaftRoom, &pieces, random); calculateBoundingBox(); moveBelowSeaLevel(level, random, 10); -} \ No newline at end of file +}