diff --git a/Minecraft.World/AddIslandLayer.cpp b/Minecraft.World/AddIslandLayer.cpp index 5edee3c4..37e05822 100644 --- a/Minecraft.World/AddIslandLayer.cpp +++ b/Minecraft.World/AddIslandLayer.cpp @@ -14,7 +14,7 @@ intArray AddIslandLayer::getArea(int xo, int yo, int w, int h) int pw = w + 2; int ph = h + 2; intArray p = parent->getArea(px, py, pw, ph); - + PIXBeginNamedEvent(0.0, "AddIslandLayer::getArea"); intArray result = IntCache::allocate(w * h); for (int y = 0; y < h; y++) { @@ -40,7 +40,7 @@ intArray AddIslandLayer::getArea(int xo, int yo, int w, int h) } else { - if (swap == Biome::iceFlats->id) result[x + y * w] = Biome::frozenOcean->id; + if (swap == 4) result[x + y * w] = Biome::frozenOcean->id; else result[x + y * w] = 0; } } @@ -48,7 +48,7 @@ intArray AddIslandLayer::getArea(int xo, int yo, int w, int h) { if (nextRandom(5) == 0) { - if (c == Biome::iceFlats->id) result[x + y * w] = Biome::frozenOcean->id; + if (c == 4) result[x + y * w] = Biome::frozenOcean->id; else result[x + y * w] = 0; } else result[x + y * w] = c; @@ -59,6 +59,6 @@ intArray AddIslandLayer::getArea(int xo, int yo, int w, int h) } } } - + PIXEndNamedEvent(); return result; } \ No newline at end of file diff --git a/Minecraft.World/AddSnowLayer.cpp b/Minecraft.World/AddSnowLayer.cpp index 252dbd50..6b41b8ae 100644 --- a/Minecraft.World/AddSnowLayer.cpp +++ b/Minecraft.World/AddSnowLayer.cpp @@ -28,8 +28,9 @@ intArray AddSnowLayer::getArea(int xo, int yo, int w, int h) } else { - int r = nextRandom(5); - if (r == 0) r = Biome::iceFlats->id; + int r = nextRandom(6); + if (r == 0) r = 4; + else if (r <= 1) r = 3; else r = 1; result[x + y * w] = r; } diff --git a/Minecraft.World/Biome.cpp b/Minecraft.World/Biome.cpp index 3c0e4b2c..1d036950 100644 --- a/Minecraft.World/Biome.cpp +++ b/Minecraft.World/Biome.cpp @@ -130,13 +130,21 @@ void Biome::staticCtor() Biome::mesaPlateau = (new MesaBiome(39, true, false))->setColor(0xca5936)->setName(L"Mesa Plateau")->setDepthAndScale(1.5f, 0.025f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Mesa, eMinecraftColour_Foliage_Mesa, eMinecraftColour_Water_Mesa, eMinecraftColour_Sky_Desert); Biome::sunflowersPlains = (new PlainsBiome(129,true))->setColor(0x8db360)->setName(L"Sunflowers Plains")->setTemperatureAndDownfall(0.8f, 0.4f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Plains, eMinecraftColour_Foliage_Plains, eMinecraftColour_Water_Plains,eMinecraftColour_Sky_Plains); - Biome::extremeHillsM = static_cast(Biome::biomes[3])->createMutatedBiome(131); + Biome::extremeHillsM = static_cast(Biome::biomes[3])->createMutatedBiome(131)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_ExtremeHills, eMinecraftColour_Foliage_ExtremeHills, eMinecraftColour_Water_ExtremeHills,eMinecraftColour_Sky_ExtremeHills); Biome::flowerForest = (new ForestBiome(132, 1))->setColor(0x056621)->setName(L"Flower Forest")->setTemperatureAndDownfall(0.7f, 0.8f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Forest, eMinecraftColour_Foliage_Forest, eMinecraftColour_Water_Forest,eMinecraftColour_Sky_Forest); + Biome::desertM = (new DesertBiome(130))->setColor(0xFA9418)->setName(L"Desert M")->setNoRain()->setTemperatureAndDownfall(2, 0)->setDepthAndScale(0.225f, 0.25f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Desert, eMinecraftColour_Foliage_Desert, eMinecraftColour_Water_Desert,eMinecraftColour_Sky_Desert); + Biome::taigaM = (new TaigaBiome(133))->setColor(0x0b6659)->setName(L"Taiga M")->setLeafColor(0x4EBA31)->setTemperatureAndDownfall(0.25f, 0.8f)->setDepthAndScale(0.3f, 0.4f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Taiga, eMinecraftColour_Foliage_Taiga, eMinecraftColour_Water_Taiga,eMinecraftColour_Sky_Taiga); + Biome::swamplandM = (new SwampBiome(134))->setColor(0x07F9B2)->setName(L"Swampland M")->setLeafColor(0x8BAF48)->setDepthAndScale(-0.1f, 0.3f)->setTemperatureAndDownfall(0.8f, 0.9f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Swampland, eMinecraftColour_Foliage_Swampland, eMinecraftColour_Water_Swampland,eMinecraftColour_Sky_Swampland); Biome::iceSpikes = (new IceBiome(140,true))->setColor(0xffffff)->setName(L"Ice Spikes")->setSnowCovered()->setTemperatureAndDownfall(0, 0.5f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_IcePlains, eMinecraftColour_Foliage_IcePlains, eMinecraftColour_Water_IcePlains,eMinecraftColour_Sky_IcePlains); + Biome::jungleM = (new JungleBiome(149, false))->setColor(0x537b09)->setName(L"Jungle M")->setLeafColor(0x537b09)->setTemperatureAndDownfall(1.2f, 0.9f)->setDepthAndScale(0.2f, 0.4f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Jungle, eMinecraftColour_Foliage_Jungle, eMinecraftColour_Water_Jungle,eMinecraftColour_Sky_Jungle); + Biome::jungleEdgeM = (new JungleBiome(151, true))->setColor(0x6458135)->setName(L"Jungle Edge M")->setLeafColor(0x5470985)->setTemperatureAndDownfall(0.95F, 0.8F); Biome::birchForestM=(new ForestBiome::MutatedBirchForestBiome(155, biomes[27]))->setColor(0x47875a)->setName(L"Birch Forest M")->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Forest, eMinecraftColour_Foliage_Birch, eMinecraftColour_Water_Forest, eMinecraftColour_Sky_Forest); Biome::birchForestHillsM=(new ForestBiome::MutatedBirchForestBiome(156, biomes[28]))->setColor(0x47875a)->setName(L"Birch Forest Hills M")->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_ForestHills, eMinecraftColour_Foliage_Birch, eMinecraftColour_Water_Forest, eMinecraftColour_Sky_ForestHills); Biome::roofedForestM=(new ForestBiome::MutatedForestBiome(157, biomes[29]))->setColor(0x177a35)->setName(L"Roofed Forest M")->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_RoofedForest, eMinecraftColour_Foliage_RoofedForest, eMinecraftColour_Water_Forest, eMinecraftColour_Sky_Forest); - Biome::extremeHills_plusM = static_cast(Biome::biomes[34])->createMutatedBiome(162); + Biome::coldTaigaM = (new TaigaBiome(158))->setColor(0x0b6659)->setName(L"Cold Taiga M")->setLeafColor(0x4EBA31)->setSnowCovered()->setTemperatureAndDownfall(-0.5f, 0.4f)->setDepthAndScale(0.3f, 0.4f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Taiga, eMinecraftColour_Foliage_Taiga, eMinecraftColour_Water_Taiga,eMinecraftColour_Sky_Taiga); + Biome::redwoodTaiga = (new TaigaBiome(160, 1))->setColor(0x0b6659)->setName(L"Mega Spruce Taiga")->setLeafColor(0x4EBA31)->setTemperatureAndDownfall(0.3f, 0.8f)->setDepthAndScale(0.2f, 0.2f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Taiga, eMinecraftColour_Foliage_Taiga, eMinecraftColour_Water_Taiga,eMinecraftColour_Sky_Taiga); + Biome::redwoodTaigaHills = (new TaigaBiome(161, 2))->setColor(0x0b6659)->setName(L"Mega Spruce Taiga Hills")->setLeafColor(0x4EBA31)->setTemperatureAndDownfall(0.3f, 0.8f)->setDepthAndScale(0.2f, 0.2f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Taiga, eMinecraftColour_Foliage_Taiga, eMinecraftColour_Water_Taiga,eMinecraftColour_Sky_Taiga); + Biome::extremeHills_plusM = static_cast(Biome::biomes[34])->createMutatedBiome(162)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_ExtremeHills,eMinecraftColour_Foliage_ExtremeHills,eMinecraftColour_Water_ExtremeHills, eMinecraftColour_Sky_ExtremeHills); Biome::savannaM = (new MutatedSavannaBiome(163, biomes[35]))->setColor(0xe5da87)->setName(L"Savanna M")->setNoRain()->setTemperatureAndDownfall(1.1f, 0.0f)->setDepthAndScale(0.35f, 1.3f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Savanna, eMinecraftColour_Foliage_Savanna, eMinecraftColour_Sky_Desert, eMinecraftColour_Sky_Desert); Biome::savannaPlateauM = (new MutatedSavannaBiome(164, biomes[36]))->setColor(0xd1c890)->setName(L"Savanna Plateau M")->setNoRain()->setTemperatureAndDownfall(1.0f, 0.0f)->setDepthAndScale(1.05f, 1.2125f)->setLeafFoliageWaterSkyColor(eMinecraftColour_Grass_Savanna, eMinecraftColour_Foliage_Savanna, eMinecraftColour_Sky_Desert, eMinecraftColour_Sky_Desert); @@ -384,18 +392,17 @@ float Biome::getTemperature(int x, int y, int z) void Biome::buildSurfaceAtDefault(Level *level, Random *random, byte* chunkBlocks, int x, int z, double noiseVal) { - byte topState = this->topMaterial; + byte topState = this->topMaterial; byte topStateData = this->topMaterialData; - byte fillerState = this->material; + byte fillerState = this->material; byte fillerStateData = this->materialData; - int runDepth = -1; + int runDepth = -1; int noiseDepth = (int)(noiseVal / 3.0 + 3.0 + random->nextDouble() * 0.25); int localX = x & 15; int localZ = z & 15; - - const int SEA_LEVEL = 63; + const int SEA_LEVEL = 63; for (int y = 127; y >= 0; --y) { @@ -409,26 +416,26 @@ void Biome::buildSurfaceAtDefault(Level *level, Random *random, byte* chunkBlock byte currentBlockId = chunkBlocks[index]; - if (currentBlockId == 0) + if (currentBlockId == 0) { runDepth = -1; } else if (currentBlockId == static_cast(Tile::stone_Id)) { - if (runDepth == -1) + if (runDepth == -1) { if (noiseDepth <= 0) { - topState = 0; + topState = 0; topStateData = 0; - fillerState = static_cast(Tile::stone_Id); + fillerState = static_cast(Tile::stone_Id); fillerStateData = 0; } - else if (y < 6) + else if (y >= SEA_LEVEL - 7 - noiseDepth && y < SEA_LEVEL - 1) { - topState = this->topMaterial; + topState = this->topMaterial; topStateData = this->topMaterialData; - fillerState = this->material; + fillerState = this->material; fillerStateData = this->materialData; } @@ -446,17 +453,16 @@ void Biome::buildSurfaceAtDefault(Level *level, Random *random, byte* chunkBlock if (y >= SEA_LEVEL - 1) { chunkBlocks[index] = topState; - } - else if (y < SEA_LEVEL - 7 - noiseDepth) + else if (y < SEA_LEVEL - 7 - noiseDepth) { - topState = 0; + topState = 0; topStateData = 0; - fillerState = static_cast(Tile::stone_Id); + fillerState = static_cast(Tile::stone_Id); fillerStateData = 0; chunkBlocks[index] = static_cast(Tile::gravel_Id); } - else + else { chunkBlocks[index] = fillerState; } @@ -468,10 +474,17 @@ void Biome::buildSurfaceAtDefault(Level *level, Random *random, byte* chunkBlock if (runDepth == 0 && fillerState == static_cast(Tile::sand_Id)) { - runDepth = random->nextInt(4) + (y > 0 ? y : 0); - - fillerState = static_cast(Tile::sandStone_Id); - fillerStateData = 0; + runDepth = random->nextInt(4); + if (fillerStateData == 1) + { + fillerState = static_cast(Tile::red_sandstone_Id); + fillerStateData = 0; + } + else + { + fillerState = static_cast(Tile::sandStone_Id); + fillerStateData = 0; + } } } } diff --git a/Minecraft.World/Biome.h b/Minecraft.World/Biome.h index ed6e766f..f33792cd 100644 --- a/Minecraft.World/Biome.h +++ b/Minecraft.World/Biome.h @@ -227,6 +227,6 @@ public: virtual int getGrassColor() const; virtual Feature *getFlowerFeature(Random *random, int x, int y, int z); virtual int getRandomDoublePlantType(Random *random); - Biome* getBiome(uint32_t id); - Biome* getBiome(uint32_t id, Biome* fallback); + static Biome* getBiome(uint32_t id); + static Biome* getBiome(uint32_t id, Biome* fallback); }; \ No newline at end of file diff --git a/Minecraft.World/BiomeInitLayer.cpp b/Minecraft.World/BiomeInitLayer.cpp index 8616725f..c9389419 100644 --- a/Minecraft.World/BiomeInitLayer.cpp +++ b/Minecraft.World/BiomeInitLayer.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "net.minecraft.world.level.biome.h" #include "net.minecraft.world.level.newbiome.layer.h" #include "net.minecraft.world.level.h" @@ -90,66 +90,80 @@ intArray BiomeInitLayer::getArea(int xo, int yo, int w, int h) { initRandom(x + xo, y + yo); - int val = b[x + y * w]; - int v18 = (val >> 8) & 0xF; - int v19 = val & 0xFFFFF0FF; + int val = b[x + y * w]; + + int v18 = (val >> 8) & 0xF; + + int v19 = val & 0xFFFFF0FF; + if (customSettings && customSettings->biome >= 0) { result[x + y * w] = customSettings->biome; continue; } + if (isOcean(v19) || v19 == Biome::mushroomIsland->id) { result[x + y * w] = v19; continue; } + if (v19 == 1) { if (v18 <= 0) { + result[x + y * w] = desertBiomes[nextRandom(desertBiomes.length)]->id; } - else if (nextRandom(3)) + else if (nextRandom(3) != 0) { result[x + y * w] = Biome::mesaPlateauF->id; } else { - result[x + y * w] = Biome::plains->id; + result[x + y * w] = Biome::mesaPlateau->id; } } + else if (v19 == 2) { if (v18 <= 0) { + result[x + y * w] = warmBiomes[nextRandom(warmBiomes.length)]->id; } else { + result[x + y * w] = Biome::jungle->id; } } + else if (v19 == 3) { if (v18 <= 0) { + result[x + y * w] = coolBiomes[nextRandom(coolBiomes.length)]->id; } else { + result[x + y * w] = Biome::megaTaiga->id; } } + else if (v19 == 4) { result[x + y * w] = icyBiomes[nextRandom(icyBiomes.length)]->id; } else { - result[x + y * w] = v19; + + result[x + y * w] = v19; } } } diff --git a/Minecraft.World/DeepOceanLayer.cpp b/Minecraft.World/DeepOceanLayer.cpp index 6e9ded7b..782baf27 100644 --- a/Minecraft.World/DeepOceanLayer.cpp +++ b/Minecraft.World/DeepOceanLayer.cpp @@ -15,6 +15,7 @@ intArray DeepOceanLayer::getArea(int xo, int yo, int w, int h) int k = w + 2; int l = h + 2; intArray aint = this->parent->getArea(i, j, k, l); + PIXBeginNamedEvent(0.0, "AddDeepOceanLayer::getArea"); intArray aint1 = IntCache::allocate(w * h); for (int i1 = 0; i1 < h; ++i1) @@ -58,6 +59,6 @@ intArray DeepOceanLayer::getArea(int xo, int yo, int w, int h) } } } - + PIXEndNamedEvent(); return aint1; } diff --git a/Minecraft.World/ExtremeHillsBiome.cpp b/Minecraft.World/ExtremeHillsBiome.cpp index 2e517ad2..87be6845 100644 --- a/Minecraft.World/ExtremeHillsBiome.cpp +++ b/Minecraft.World/ExtremeHillsBiome.cpp @@ -105,6 +105,7 @@ Biome* ExtremeHillsBiome::mutateHills(Biome* baseBiome) this->setName(baseBiome->m_name + L" M"); this->setDepthAndScale(baseBiome->depth, baseBiome->scale); this->setTemperatureAndDownfall(baseBiome->temperature, baseBiome->downfall); + this->setWaterSkyColor(baseBiome->getWaterColor(), baseBiome->getSkyColor()); return this; } diff --git a/Minecraft.World/Layer.cpp b/Minecraft.World/Layer.cpp index 8998cb4b..52010d59 100644 --- a/Minecraft.World/Layer.cpp +++ b/Minecraft.World/Layer.cpp @@ -1,207 +1,249 @@ - #include "stdafx.h" - #include "net.minecraft.world.level.newbiome.layer.h" - #include "RiverInitLayer.h" - #include "RareBiomeSpotLayer.h" - #include "net.minecraft.world.level.h" - #include "BiomeOverrideLayer.h" - #include "CustomizableSourceSettings.h" +#include "stdafx.h" +#include "net.minecraft.world.level.newbiome.layer.h" +#include "RiverInitLayer.h" +#include "RareBiomeSpotLayer.h" +#include "net.minecraft.world.level.h" +#include "BiomeOverrideLayer.h" +#include "CustomizableSourceSettings.h" - #ifdef __PSVITA__ - // AP - this is used to perform fast 64bit divides of known values - #include "../Minecraft.Client/PSVita/PSVitaExtras/libdivide.h" +#ifdef __PSVITA__ +#include "../Minecraft.Client/PSVita/PSVitaExtras/libdivide.h" #include +libdivide::divider fast_d2(2); +libdivide::divider fast_d3(3); +libdivide::divider fast_d4(4); +libdivide::divider fast_d5(5); +libdivide::divider fast_d6(6); +libdivide::divider fast_d7(7); +libdivide::divider fast_d10(10); +#endif - libdivide::divider fast_d2(2); - libdivide::divider fast_d3(3); - libdivide::divider fast_d4(4); - libdivide::divider fast_d5(5); - libdivide::divider fast_d6(6); - libdivide::divider fast_d7(7); - libdivide::divider fast_d10(10); - #endif - -LayerArray Layer::getDefaultLayers(int64_t seed, LevelType* levelType, void* superflatConfig) { - - +LayerArray Layer::getDefaultLayers(int64_t seed, LevelType* levelType, void* superflatConfig) +{ shared_ptr islandLayer = std::make_shared(seed, 1); islandLayer = std::make_shared(seed, islandLayer, 0x7D0); islandLayer = std::make_shared(seed, islandLayer, 1); - islandLayer = std::make_shared(seed, islandLayer, 0x7D1); + islandLayer = std::make_shared(seed, islandLayer, 0x7D1); islandLayer = std::make_shared(seed, islandLayer, 2); - islandLayer = std::make_shared(seed, islandLayer, 0x32); - islandLayer = std::make_shared(seed, islandLayer, 0x46); + islandLayer = std::make_shared(seed, islandLayer, 0x32); + islandLayer = std::make_shared(seed, islandLayer, 0x46); islandLayer = std::make_shared(seed, islandLayer, 2); islandLayer = std::make_shared(seed, islandLayer, 2); islandLayer = std::make_shared(seed, islandLayer, 3); - islandLayer = std::make_shared(seed, islandLayer, 2, 0); - islandLayer = std::make_shared(seed, islandLayer, 2, 1); + islandLayer = std::make_shared(seed, islandLayer, 2, 0); + islandLayer = std::make_shared(seed, islandLayer, 2, 1); islandLayer = std::make_shared(seed, islandLayer, 3, 2); - islandLayer = std::make_shared(seed, islandLayer, 0x7D2); - islandLayer = std::make_shared(seed, islandLayer, 0x7D3); + islandLayer = std::make_shared(seed, islandLayer, 0x7D2); + islandLayer = std::make_shared(seed, islandLayer, 0x7D3); islandLayer = std::make_shared(seed, islandLayer, 4); - islandLayer = std::make_shared(seed, islandLayer, 5); + + + islandLayer = std::make_shared(seed, islandLayer, 4); - shared_ptr baseLayer = ZoomLayer::zoom(seed, islandLayer, 0x3E8, 0); + shared_ptr baseLayer = ZoomLayer::zoom(seed, islandLayer, 0x3E8, 0); + int zoomLevel = 4; int riverZoomCount = 4; - - if (levelType == LevelType::lvl_customized && superflatConfig != nullptr) { + + if (levelType == LevelType::lvl_customized && superflatConfig != nullptr) + { auto settings = CustomizableSourceSettings::Builder::build( CustomizableSourceSettings::Builder::fromString(superflatConfig)); + zoomLevel = settings->getBiomeSize(); riverZoomCount = settings->getRiverSize(); - } - - if (levelType == LevelType::lvl_largeBiomes) { - zoomLevel = 6; + } - - shared_ptr riverInit = make_shared(seed, baseLayer, 0x64); - - - shared_ptr hillsNoise = ZoomLayer::zoom(seed, riverInit, 0x3E8, 2); - - + if (levelType == LevelType::lvl_largeBiomes) + zoomLevel = 6; + + + shared_ptr riverInit = make_shared(seed, baseLayer, 0x64); + + shared_ptr hillsNoise = ZoomLayer::zoom(seed, riverInit, 0x3E8, 2); + shared_ptr riverLayerFinal = ZoomLayer::zoom(seed, riverInit, 0x3E8, 2); riverLayerFinal = ZoomLayer::zoom(seed, riverLayerFinal, 0x3E8, riverZoomCount); - riverLayerFinal = make_shared(seed, riverLayerFinal, 1); riverLayerFinal = make_shared(seed, riverLayerFinal, 0x3E8); - - - shared_ptr biomeLayer = make_shared(seed, baseLayer, 0xC8, levelType, superflatConfig); + + shared_ptr biomeLayer = make_shared(seed, baseLayer, 0xC8, levelType, superflatConfig); biomeLayer = ZoomLayer::zoom(seed, biomeLayer, 0x3E8, 2); biomeLayer = make_shared(seed, biomeLayer, 0x3E8); biomeLayer = make_shared(seed, biomeLayer, hillsNoise, 0x3E8); - biomeLayer = make_shared(seed, biomeLayer, 0x3E9); + biomeLayer = make_shared(seed, biomeLayer, 0x3E9); - - for (int i = 0; i < zoomLevel; ++i) { + for (int i = 0; i < zoomLevel; ++i) + { biomeLayer = make_shared(seed, biomeLayer, 0x3E8 + i); - - if (i == 0) { + + if (i == 0) + { biomeLayer = make_shared(seed, biomeLayer, 3); + biomeLayer = make_shared(seed, biomeLayer, 5); } - - if (i == 1 || zoomLevel == 1) { + + + if (zoomLevel == 1||i == 1) + { + biomeLayer = make_shared(seed, biomeLayer, 5); biomeLayer = make_shared(seed, biomeLayer, 0x3E8); } } biomeLayer = make_shared(seed, biomeLayer, 0x3E8); - - shared_ptr mixed = make_shared(seed, biomeLayer, riverLayerFinal, 0x64); - shared_ptr voronoi = make_shared(seed, mixed, 0xA); + shared_ptr mixed = make_shared(seed, biomeLayer, riverLayerFinal, 0x64); + shared_ptr voronoi = make_shared(seed, mixed, 0xA); mixed->init(seed); voronoi->init(seed); LayerArray result(3, false); - result[0] = mixed; - result[1] = voronoi; - result[2] = mixed; + result[0] = mixed; + result[1] = voronoi; + result[2] = mixed; return result; } - Layer::Layer(int64_t seedMixup) - { - parent = nullptr; +Layer::Layer(int64_t seedMixup) +{ + parent = nullptr; - this->seedMixup = seedMixup; - this->seedMixup *= this->seedMixup * 6364136223846793005l + 1442695040888963407l; - this->seedMixup += seedMixup; - this->seedMixup *= this->seedMixup * 6364136223846793005l + 1442695040888963407l; - this->seedMixup += seedMixup; - this->seedMixup *= this->seedMixup * 6364136223846793005l + 1442695040888963407l; - this->seedMixup += seedMixup; - } + this->seedMixup = seedMixup; + this->seedMixup *= this->seedMixup * 6364136223846793005l + 1442695040888963407l; + this->seedMixup += seedMixup; + this->seedMixup *= this->seedMixup * 6364136223846793005l + 1442695040888963407l; + this->seedMixup += seedMixup; + this->seedMixup *= this->seedMixup * 6364136223846793005l + 1442695040888963407l; + this->seedMixup += seedMixup; +} +void Layer::initRandom(int64_t x, int64_t y) +{ + rval = seed; + rval *= rval * 6364136223846793005L + 1442695040888963407L; + rval += x; + rval *= rval * 6364136223846793005L + 1442695040888963407L; + rval += y; + rval *= rval * 6364136223846793005L + 1442695040888963407L; + rval += x; + rval *= rval * 6364136223846793005L + 1442695040888963407L; + rval += y; +} +int Layer::nextRandom(int max) +{ +#ifdef __PSVITA__ + int result; + long long temp = rval; + temp >>= 24; + if (max == 2) + result = temp - (temp / fast_d2) * 2; + else if (max == 3) + result = temp - (temp / fast_d3) * 3; + else if (max == 4) + result = temp - (temp / fast_d4) * 4; + else if (max == 5) + result = temp - (temp / fast_d5) * 5; + else if (max == 6) + result = temp - (temp / fast_d6) * 6; + else if (max == 7) + result = temp - (temp / fast_d7) * 7; + else if (max == 10) + result = temp - (temp / fast_d10) * 10; + else + result = temp - (temp / max) * max; +#else + int result = static_cast((rval >> 24) % max); +#endif + if (result < 0) result += max; + rval *= rval * 6364136223846793005L + 1442695040888963407L; + rval += seed; + return result; +} - void Layer::initRandom(int64_t x, int64_t y) - { - rval = seed; - rval *= rval * 6364136223846793005l + 1442695040888963407l; - rval += x; - rval *= rval * 6364136223846793005l + 1442695040888963407l; - rval += y; - rval *= rval * 6364136223846793005l + 1442695040888963407l; - rval += x; - rval *= rval * 6364136223846793005l + 1442695040888963407l; - rval += y; - } - - int Layer::nextRandom(int max) - { - #ifdef __PSVITA__ - // AP - 64bit mods are very slow on Vita. Replaced with a divide/mult for general case and a fast divide library for specific numbers - // todo - this can sometimes yield a different number to the original. There's a strange bug sometimes with Vita where if the line - // "result = (int) ((rval >> 24) % max);" is done twice in a row 'result' will not be the same. Need to speak to Sony about that - // Also need to compare level against a different platform using the same seed - int result; - long long temp = rval; - temp >>= 24; - if( max == 2 ) - { - result = temp-(temp/fast_d2)*2; - } - else if( max == 3 ) - { - result = temp-(temp/fast_d3)*3; - } - else if( max == 4 ) - { - result = temp-(temp/fast_d4)*4; - } - else if( max == 5 ) - { - result = temp-(temp/fast_d5)*5; - } - else if( max == 6 ) - { - result = temp-(temp/fast_d6)*6; - } - else if( max == 7 ) - { - result = temp-(temp/fast_d7)*7; - } - else if( max == 10 ) - { - result = temp-(temp/fast_d10)*10; - } - else - { - result = temp-(temp/max)*max; - } - #else - - int result = static_cast((rval >> 24) % max); - #endif - - if (result < 0) result += max; - rval *= rval * 6364136223846793005l + 1442695040888963407l; - rval += seed; - return result; - } - -void Layer::init(int64_t seed) +void Layer::init(int64_t seed) { this->seed = seed; if (parent != nullptr) parent->init(seed); - this->seed *= this->seed * 6364136223846793005LL + 1442695040888963407LL; + this->seed *= this->seed * 6364136223846793005L + 1442695040888963407L; this->seed += seedMixup; - this->seed *= this->seed * 6364136223846793005LL + 1442695040888963407LL; + this->seed *= this->seed * 6364136223846793005L + 1442695040888963407L; this->seed += seedMixup; - this->seed *= this->seed * 6364136223846793005LL + 1442695040888963407LL; + this->seed *= this->seed * 6364136223846793005L + 1442695040888963407L; this->seed += seedMixup; } + bool Layer::isOcean(int biomeId) { - return biomeId == Biome::ocean->id || - biomeId == Biome::deepOcean->id || + return biomeId == Biome::ocean->id || + biomeId == Biome::deepOcean->id || biomeId == Biome::frozenOcean->id; +} + + +bool Layer::isSame(int biomeIdA, int biomeIdB) { + if (biomeIdA == biomeIdB) { + return true; + } else { + Biome* biome = Biome::getBiome(biomeIdA); + Biome* biome2 = Biome::getBiome(biomeIdB); + if (biome != nullptr && biome2 != nullptr) { + if (biome != Biome::mesaPlateauF && biome != Biome::mesaPlateau) { + return biome == biome2 || biome->getBaseBiomeId() == biome2->getBaseBiomeId(); + } else { + return biome2 == Biome::mesaPlateauF || biome2 == Biome::mesaPlateau; + } + } else { + return false; + } + } +} + + +int Layer::random(int i, int j, int k, int l) { + int random = nextRandom(4); + + int ret = (random != 2 ? i : k); + if (random == 3) + ret = l; + if (random == 1) + ret = j; + return ret; +} + +int Layer::random(int i, int j) { + if (nextRandom(2)) { + return j; + } + + return i; +} + +int Layer::modeOrRandom(int i, int j, int k, int l) { + if (j == k && k == l) { + return j; + } else if (i == j && i == k) { + return i; + } else if (i == j && i == l) { + return i; + } else if (i == k && i == l) { + return i; + } else if (i == j && k != l) { + return i; + } else if (i == k && j != l) { + return i; + } else if (i == l && j != k) { + return i; + } else if (j == k && i != l) { + return j; + } else if (j == l && i != k) { + return j; + } else { + return k == l && i != j ? k : random(i, j, k, l); + } } \ No newline at end of file diff --git a/Minecraft.World/Layer.h b/Minecraft.World/Layer.h index 71a1aba0..cfc3cf28 100644 --- a/Minecraft.World/Layer.h +++ b/Minecraft.World/Layer.h @@ -27,11 +27,14 @@ public: virtual void init(int64_t seed); bool isOcean(int biomeId); + bool isSame(int biomeIdA, int biomeIdB); virtual void initRandom(int64_t x, int64_t y); protected: int nextRandom(int max); - + int random(int i, int j, int k, int l); + int random(int i, int j); + int modeOrRandom(int i, int j, int k, int l); public: virtual intArray getArea(int xo, int yo, int w, int h) = 0; }; \ No newline at end of file diff --git a/Minecraft.World/Level.cpp b/Minecraft.World/Level.cpp index 19126b24..730362e2 100644 --- a/Minecraft.World/Level.cpp +++ b/Minecraft.World/Level.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "System.h" #include "BasicTypeContainers.h" #include "File.h" @@ -4798,4 +4798,24 @@ bool Level::canCreateMore(eINSTANCEOF type, ESPAWN_TYPE spawnType) } // 4J: Interpret 0 as no limit return max == 0 || count < max; +} + + +BlockPos Level::getHeightmapPos(int x, int z) +{ + + if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || + x >= MAX_LEVEL_SIZE || z >= MAX_LEVEL_SIZE) + { + return BlockPos(x, 64, z); + } + + if (hasChunk(x >> 4, z >> 4)) + { + LevelChunk* lc = getChunk(x >> 4, z >> 4); + int y = lc->getHeightmap(x & 0xF, z & 0xF); + return BlockPos(x, y, z); + } + + return BlockPos(x, 0, z); } \ No newline at end of file diff --git a/Minecraft.World/Level.h b/Minecraft.World/Level.h index 0d96a297..4a6686fd 100644 --- a/Minecraft.World/Level.h +++ b/Minecraft.World/Level.h @@ -209,7 +209,7 @@ public: bool reallyHasChunkAt(int x, int y, int z); // 4J added bool reallyHasChunksAt(int x, int y, int z, int r); // 4J added bool reallyHasChunksAt(int x0, int y0, int z0, int x1, int y1, int z1); // 4J added - + BlockPos getHeightmapPos(int x, int z); public: bool hasChunk(int x, int z); bool reallyHasChunk(int x, int z ); // 4J added diff --git a/Minecraft.World/RareBiomeLayer.cpp b/Minecraft.World/RareBiomeLayer.cpp index f7499d5b..2efdb10d 100644 --- a/Minecraft.World/RareBiomeLayer.cpp +++ b/Minecraft.World/RareBiomeLayer.cpp @@ -22,14 +22,29 @@ intArray RareBiomeLayer::getArea(int xo, int yo, int w, int h) if (this->nextRandom(57) == 0) { - if (k == Biome::plains->id) - { - aint1[j + i * w] = Biome::plains->id + 128; - } - else - { - aint1[j + i * w] = k; - } + int mutated = k; + if (k == Biome::plains->id) mutated = Biome::sunflowersPlains->id; // 1 -> 129 + else if (k == Biome::desert->id) mutated = Biome::desertM->id; // 2 -> 130 + else if (k == Biome::extremeHills->id) mutated = Biome::extremeHillsM->id; // 3 -> 131 + else if (k == Biome::forest->id) mutated = Biome::flowerForest->id; // 4 -> 132 + else if (k == Biome::taiga->id) mutated = Biome::taigaM->id; // 5 -> 133 + else if (k == Biome::swampland->id) mutated = Biome::swamplandM->id; // 6 -> 134 + else if (k == Biome::iceFlats->id) mutated = Biome::iceSpikes->id; // 12 -> 140 + else if (k == Biome::jungle->id) mutated = Biome::jungleM->id; // 21 -> 149 + else if (k == Biome::jungleEdge->id) mutated = Biome::jungleEdgeM->id; // 23 -> 151 + else if (k == Biome::birchForest->id) mutated = Biome::birchForestM->id; // 27 -> 155 + else if (k == Biome::birchForestHills->id) mutated = Biome::birchForestHillsM->id; // 28 -> 156 + else if (k == Biome::roofedForest->id) mutated = Biome::roofedForestM->id; // 29 -> 157 + else if (k == Biome::coldTaiga->id) mutated = Biome::coldTaigaM->id; // 30 -> 158 + else if (k == Biome::megaTaiga->id) mutated = Biome::redwoodTaiga->id; // 32 -> 160 + else if (k == Biome::megaTaigaHills->id) mutated = Biome::redwoodTaigaHills->id; // 33 -> 161 + else if (k == Biome::extremeHills_plus->id) mutated = Biome::extremeHills_plusM->id; // 34 -> 162 + else if (k == Biome::savanna->id) mutated = Biome::savannaM->id; // 35 -> 163 + else if (k == Biome::savannaPlateau->id) mutated = Biome::savannaPlateauM->id; // 36 -> 164 + else if (k == Biome::mesa->id) mutated = Biome::mesaBryce->id; // 37 -> 165 + else if (k == Biome::mesaPlateauF->id) mutated = Biome::mesaPlateauFM->id; // 38 -> 166 + else if (k == Biome::mesaPlateau->id) mutated = Biome::mesaPlateauM->id; // 39 -> 167 + aint1[j + i * w] = mutated; } else { @@ -39,4 +54,4 @@ intArray RareBiomeLayer::getArea(int xo, int yo, int w, int h) } return aint1; -} +} \ No newline at end of file diff --git a/Minecraft.World/RareBiomeSpotLayer.cpp b/Minecraft.World/RareBiomeSpotLayer.cpp index 57885546..fbbc0113 100644 --- a/Minecraft.World/RareBiomeSpotLayer.cpp +++ b/Minecraft.World/RareBiomeSpotLayer.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "RareBiomeSpotLayer.h" #include "IntCache.h" +#include "net.minecraft.world.level.biome.h" RareBiomeSpotLayer::RareBiomeSpotLayer(int64_t seed, std::shared_ptr parent, int64_t seedMixup) : Layer(seedMixup) { @@ -9,6 +10,22 @@ RareBiomeSpotLayer::RareBiomeSpotLayer(int64_t seed, std::shared_ptr pare intArray RareBiomeSpotLayer::getArea(int xo, int yo, int w, int h) { - - return parent->getArea(xo, yo, w, h); + intArray b = parent->getArea(xo, yo, w, h); + intArray result = IntCache::allocate(w * h); + + for (int y = 0; y < h; y++) + { + for (int x = 0; x < w; x++) + { + initRandom(x + xo, y + yo); + int biomeId = b[x + y * w]; + + if (nextRandom(57) == 0 && biomeId == Biome::plains->id) + result[x + y * w] = biomeId + 128; + else + result[x + y * w] = biomeId; + } + } + + return result; } diff --git a/Minecraft.World/RegionHillsLayer.cpp b/Minecraft.World/RegionHillsLayer.cpp index bc7e2498..81b3a49e 100644 --- a/Minecraft.World/RegionHillsLayer.cpp +++ b/Minecraft.World/RegionHillsLayer.cpp @@ -55,8 +55,14 @@ intArray RegionHillsLayer::getArea(int xo, int yo, int w, int h) if (riverNoise != nullptr && k != 0 && l >= 2 && (l - 2) % 29 == 1 && k < 128) { - - result[x + y * w] = k; + if (Biome::biomes[k + 128] != nullptr) + { + result[x + y * w] = k + 128; + } + else + { + result[x + y * w] = k; + } } else if (nextRandom(3) != 0 && !flag) { @@ -135,6 +141,18 @@ intArray RegionHillsLayer::getArea(int xo, int yo, int w, int h) + if (flag && i1 != k) + { + if (Biome::biomes[i1 + 128] != nullptr) + { + i1 += 128; + } + else + { + i1 = k; + } + } + if (i1 == k) { result[x + y * w] = k; diff --git a/Minecraft.World/RiverMixerLayer.cpp b/Minecraft.World/RiverMixerLayer.cpp index e27894a3..a6dda05c 100644 --- a/Minecraft.World/RiverMixerLayer.cpp +++ b/Minecraft.World/RiverMixerLayer.cpp @@ -23,18 +23,20 @@ intArray RiverMixerLayer::getArea(int xo, int yo, int w, int h) intArray result = IntCache::allocate(w * h); for (int i = 0; i < w * h; i++) { - if (b[i] == Biome::ocean->id || b[i] == Biome::deepOcean->id) + if (b[i] == Biome::ocean->id || b[i] == Biome::deepOcean->id || b[i] == Biome::frozenOcean->id) { result[i] = b[i]; - } else { if (r[i] >= 0) { - if (b[i] == Biome::iceFlats->id) result[i] = Biome::frozenRiver->id; - else if (b[i] == Biome::mushroomIsland->id || b[i] == Biome::mushroomIslandShore->id) result[i] = Biome::mushroomIsland->id; // 4J - don't make mushroom island shores as we don't have any island left once we do this as our islands are small (this used to change to mushroomIslandShore) - else result[i] = r[i]; + if (b[i] == Biome::iceFlats->id || b[i] == Biome::iceSpikes->id || b[i] == Biome::coldTaiga->id || b[i] == Biome::coldTaigaHills->id) + result[i] = Biome::frozenRiver->id; + else if (b[i] == Biome::mushroomIsland->id || b[i] == Biome::mushroomIslandShore->id) + result[i] = Biome::mushroomIsland->id; // 4J - don't make mushroom island shores as we don't have any island left once we do this as our islands are small (this used to change to mushroomIslandShore) + else + result[i] = r[i]; } else { diff --git a/Minecraft.World/SavannaBiome.cpp b/Minecraft.World/SavannaBiome.cpp index 422388c8..37122a41 100644 --- a/Minecraft.World/SavannaBiome.cpp +++ b/Minecraft.World/SavannaBiome.cpp @@ -1,61 +1,55 @@ -#include "stdafx.h" +#include "stdafx.h" #include "net.minecraft.world.level.levelgen.feature.h" #include "net.minecraft.world.level.biome.h" #include "net.minecraft.world.entity.animal.h" #include "net.minecraft.world.entity.h" #include "SavannaBiome.h" -#include "SavannaTreeFeature.h" +#include "SavannaTreeFeature.h" #include "DoublePlantFeature.h" #include "TallGrass2.h" #include "Level.h" #include "Random.h" + SavannaBiome::SavannaBiome(int id) : Biome(id) { - friendlies.push_back(new MobSpawnerData(eTYPE_HORSE, 1, 2, 6)); - - decorator->treeCount = 1; + decorator->treeCount = 1; decorator->flowerCount = 4; - decorator->grassCount = 20; - + decorator->grassCount = 20; } -Feature *SavannaBiome::getTreeFeature(Random *random) +Feature* SavannaBiome::getTreeFeature(Random* random) { - - if (random->nextInt(5) > 0) + if (random->nextInt(5) <= 0) { - return new SavannaTreeFeature(false); + return new TreeFeature(false); } - - - return new TreeFeature(false); + return new SavannaTreeFeature(false); } int SavannaBiome::getGrassColor() const { - return 0xBFB755; + return 0xBFB755; } int SavannaBiome::getFolageColor() const { - return 0xAEA42A; + return 0xAEA42A; } -Feature *SavannaBiome::getFlowerFeature(Random *random, int x, int y, int z) +Feature* SavannaBiome::getFlowerFeature(Random* random, int x, int y, int z) { - - return nullptr; + return nullptr; } -int SavannaBiome::getRandomDoublePlantType(Random *random) +int SavannaBiome::getRandomDoublePlantType(Random* random) { - return 0; + return 0; } -void SavannaBiome::decorate(Level *level, Random *random, int xo, int zo) +void SavannaBiome::decorate(Level* level, Random* random, int xo, int zo) { DOUBLE_PLANT_GENERATOR->setPlantType(TallGrass2::TALL_GRASS); @@ -63,51 +57,68 @@ void SavannaBiome::decorate(Level *level, Random *random, int xo, int zo) { int x = xo + random->nextInt(16) + 8; int z = zo + random->nextInt(16) + 8; - int y = random->nextInt(level->getHeightmap(x, z) + 32); + int surfaceY = level->getHeightmapPos(x, z).getY(); + int y = random->nextInt(surfaceY + 32); DOUBLE_PLANT_GENERATOR->place(level, random, x, y, z); } Biome::decorate(level, random, xo, zo); } -MutatedSavannaBiome::MutatedSavannaBiome(int id, Biome* baseBiome) : MutatedBiome(id, baseBiome) +Biome* SavannaBiome::createMutatedCopy(int newId) { - decorator->treeCount = 2; - decorator->flowerCount = 2; - decorator->grassCount = 5; + MutatedSavannaBiome* mutated = new MutatedSavannaBiome(newId, this); + + + mutated->scale = (this->scale + 1.0f) * 0.5f; + mutated->depth = (this->depth * 0.5f) + 0.3f; + mutated->temperature = (this->temperature * 0.5f) + 1.2f; + + return mutated; } -void MutatedSavannaBiome::buildSurfaceAtDefault(Level *level, Random *random, byte* chunkBlocks, int x, int z, double noiseVal) + +MutatedSavannaBiome::MutatedSavannaBiome(int id, Biome* baseBiome) + : MutatedBiome(id, baseBiome) { - topMaterial = static_cast(Tile::grass_Id); - material = static_cast(Tile::dirt_Id); + decorator->treeCount = 2; + decorator->flowerCount = 2; + decorator->grassCount = 5; +} + +void MutatedSavannaBiome::buildSurfaceAtDefault(Level* level, Random* random, + byte* chunkBlocks, + int x, int z, double noiseVal) +{ + + topMaterial = static_cast(Tile::grass_Id); + topMaterialData = 0; + material = static_cast(Tile::dirt_Id); + materialData = 0; if (noiseVal > 1.75) { - topMaterial = static_cast(Tile::stone_Id); + + topMaterial = static_cast(Tile::stone_Id); topMaterialData = 0; - material = static_cast(Tile::stone_Id); - materialData = 0; + material = static_cast(Tile::stone_Id); + materialData = 0; } else if (noiseVal > -0.5) { - topMaterial = static_cast(Tile::dirt_Id); - topMaterialData = 0; - material = static_cast(Tile::dirt_Id); - materialData = 0; - } - else - { - topMaterial = static_cast(Tile::grass_Id); - topMaterialData = 0; - material = static_cast(Tile::dirt_Id); - materialData = 0; + + topMaterial = static_cast(Tile::dirt_Id); + topMaterialData = 1; + material = static_cast(Tile::dirt_Id); + materialData = 0; } + Biome::buildSurfaceAtDefault(level, random, chunkBlocks, x, z, noiseVal); } -void MutatedSavannaBiome::decorate(Level *level, Random *random, int xo, int zo) +void MutatedSavannaBiome::decorate(Level* level, Random* random, int xo, int zo) { - MutatedBiome::decorate(level, random, xo, zo); -} + + decorator->decorate(level, random, xo, zo); +} \ No newline at end of file diff --git a/Minecraft.World/SavannaBiome.h b/Minecraft.World/SavannaBiome.h index 9aea9d0f..66c21310 100644 --- a/Minecraft.World/SavannaBiome.h +++ b/Minecraft.World/SavannaBiome.h @@ -1,3 +1,4 @@ + #pragma once #include "Biome.h" #include "MutatedBiome.h" @@ -6,21 +7,21 @@ class SavannaBiome : public Biome { public: SavannaBiome(int id); - - virtual Feature *getTreeFeature(Random *random); - virtual int getFolageColor() const override; - virtual int getGrassColor() const override; - //virtual int getWaterColor() override; - virtual Feature *getFlowerFeature(Random *random, int x, int y, int z) override; - virtual int getRandomDoublePlantType(Random *random) override; - virtual void decorate(Level *level, Random *random, int xo, int zo) override; + virtual Feature* getTreeFeature(Random* random) override; + virtual int getFolageColor() const override; + virtual int getGrassColor() const override; + virtual Feature* getFlowerFeature(Random* random, int x, int y, int z) override; + virtual int getRandomDoublePlantType(Random* random) override; + virtual void decorate(Level* level, Random* random, int xo, int zo) override; + virtual Biome* createMutatedCopy(int newId); }; class MutatedSavannaBiome : public MutatedBiome { public: MutatedSavannaBiome(int id, Biome* baseBiome); - - virtual void buildSurfaceAtDefault(Level *level, Random *random, byte* chunkBlocks, int x, int z, double noiseVal) override; - virtual void decorate(Level *level, Random *random, int xo, int zo) override; + virtual void buildSurfaceAtDefault(Level* level, Random* random, + byte* chunkBlocks, int x, int z, + double noiseVal) override; + virtual void decorate(Level* level, Random* random, int xo, int zo) override; }; \ No newline at end of file