aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/RandomScatteredLargeFeature.cpp
blob: d460dc1452d8576db4dae50ed1d49ec472e8121f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.biome.h"
#include "ScatteredFeaturePieces.h"
#include "RandomScatteredLargeFeature.h"

vector<Biome *> RandomScatteredLargeFeature::allowedBiomes;

void RandomScatteredLargeFeature::staticCtor()
{
	allowedBiomes.push_back( Biome::desert );
	allowedBiomes.push_back( Biome::desertHills );
	allowedBiomes.push_back( Biome::jungle );
}

RandomScatteredLargeFeature::RandomScatteredLargeFeature()
{
}

bool RandomScatteredLargeFeature::isFeatureChunk(int x, int z, bool bIsSuperflat)
{
	int featureSpacing = 32;
	int minFeatureSeparation = 8;

	int xx = x;
	int zz = z;
	if (x < 0) x -= featureSpacing - 1;
	if (z < 0) z -= featureSpacing - 1;

	int xCenterFeatureChunk = x / featureSpacing;
	int zCenterFeatureChunk = z / featureSpacing;
	Random *r = level->getRandomFor(xCenterFeatureChunk, zCenterFeatureChunk, 14357617);
	xCenterFeatureChunk *= featureSpacing;
	zCenterFeatureChunk *= featureSpacing;
	xCenterFeatureChunk += r->nextInt(featureSpacing - minFeatureSeparation);
	zCenterFeatureChunk += r->nextInt(featureSpacing - minFeatureSeparation);
	x = xx;
	z = zz;

	bool forcePlacement = false;
	LevelGenerationOptions *levelGenOptions = app.getLevelGenerationOptions();
	if( levelGenOptions != NULL )
	{
		forcePlacement = levelGenOptions->isFeatureChunk(x,z,eFeature_Temples);
	}

	if (forcePlacement || (x == xCenterFeatureChunk && z == zCenterFeatureChunk))
	{
		bool biomeOk = level->getBiomeSource()->containsOnly(x * 16 + 8, z * 16 + 8, 0, allowedBiomes);
		if (biomeOk)
		{
			//                System.out.println("feature at " + (x * 16) + " " + (z * 16));
			return true;
		}
	}

	return false;

}

StructureStart *RandomScatteredLargeFeature::createStructureStart(int x, int z)
{
	//        System.out.println("feature at " + (x * 16) + " " + (z * 16));
	return new ScatteredFeatureStart(level, random, x, z);
}


RandomScatteredLargeFeature::ScatteredFeatureStart::ScatteredFeatureStart(Level *level, Random *random, int chunkX, int chunkZ)
{
	if (level->getBiome(chunkX * 16 + 8, chunkZ * 16 + 8) == Biome::jungle)
	{
		ScatteredFeaturePieces::JunglePyramidPiece *startRoom = new ScatteredFeaturePieces::JunglePyramidPiece(random, chunkX * 16, chunkZ * 16);
		pieces.push_back(startRoom);
		//                System.out.println("jungle feature at " + (chunkX * 16) + " " + (chunkZ * 16));
	}
	else
	{
		ScatteredFeaturePieces::DesertPyramidPiece *startRoom = new ScatteredFeaturePieces::DesertPyramidPiece(random, chunkX * 16, chunkZ * 16);
		pieces.push_back(startRoom);
		//                System.out.println("desert feature at " + (chunkX * 16) + " " + (chunkZ * 16));
	}

	calculateBoundingBox();
}