the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "Arrays.h"
3#include "FixedBiomeSource.h"
4
5FixedBiomeSource::FixedBiomeSource(Biome *fixed, float temperature, float downfall)
6{
7 biome = fixed;
8 this->temperature = temperature;
9 this->downfall = downfall;
10}
11
12Biome *FixedBiomeSource::getBiome(ChunkPos *cp)
13{
14 return biome;
15}
16
17Biome *FixedBiomeSource::getBiome(int x, int z)
18{
19 return biome;
20}
21
22float FixedBiomeSource::getTemperature(int x, int z)
23{
24 return temperature;
25}
26
27void FixedBiomeSource::getTemperatureBlock(floatArray& temperatures, int x, int z, int w, int h) const
28{
29 if (temperatures.data == NULL || temperatures.length < w * h)
30 {
31 if(temperatures.data != NULL) delete [] temperatures.data;
32 temperatures = floatArray(w * h);
33 }
34
35 Arrays::fill(temperatures, 0, w * h, temperature);
36}
37
38floatArray FixedBiomeSource::getTemperatureBlock(int x, int z, int w, int h) const
39{
40 floatArray temps(w*h);
41 getTemperatureBlock(temps, x, z, w, h);
42 return temps;
43}
44
45// 4J - note that caller is responsible for deleting returned array. temperatures array is for output only.
46void FixedBiomeSource::getTemperatureBlock(doubleArray& temperatures, int x, int z, int w, int h) const
47{
48 temperatures = doubleArray(w * h);
49
50 Arrays::fill(temperatures, 0, w * h, (double)temperature);
51}
52
53void FixedBiomeSource::getDownfallBlock(floatArray &downfalls, int x, int z, int w, int h) const
54{
55 if (downfalls.data == NULL || downfalls.length < w * h)
56 {
57 if(downfalls.data != NULL) delete [] downfalls.data;
58 downfalls = floatArray(w * h);
59 }
60 Arrays::fill(downfalls, 0, w * h, downfall);
61}
62
63floatArray FixedBiomeSource::getDownfallBlock(int x, int z, int w, int h) const
64{
65 floatArray downfalls(w*h);
66 getDownfallBlock(downfalls, x, z, w, h);
67 return downfalls;
68}
69
70float FixedBiomeSource::getDownfall(int x, int z) const
71{
72 return downfall;
73}
74
75void FixedBiomeSource::getDownfallBlock(doubleArray downfalls, int x, int z, int w, int h)
76{
77 if (downfalls.data == NULL || downfalls.length < w * h)
78 {
79 if(downfalls.data != NULL) delete [] downfalls.data;
80 downfalls = doubleArray(w * h);
81 }
82 Arrays::fill(downfalls, 0, w * h, (double) downfall);
83}
84
85// 4J - caller is responsible for deleting biomes array, plus any optional arrays output if pointers are passed in (_temperatures, _downfalls)
86void FixedBiomeSource::getBiomeBlock(BiomeArray& biomes, int x, int z, int w, int h, bool useCache) const
87{
88 MemSect(36);
89 biomes = BiomeArray(w * h);
90 MemSect(0);
91
92 Arrays::fill(biomes, 0, w * h, biome);
93}
94
95// 4J - caller is responsible for deleting biomes array, plus any optional arrays output if pointers are passed in (_temperatures, _downfalls)
96void FixedBiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z, int w, int h, bool useCache) const
97{
98 MemSect(36);
99 biomeIndices = byteArray(w * h);
100 MemSect(0);
101 int biomeIndex = biome->id;
102 Arrays::fill(biomeIndices, 0, w * h, biomeIndex);
103}
104
105// 4J-PB added in from beyond 1.8.2
106// 4J - caller is responsible for deleting biomes array, plus any optional arrays output if pointers are passed in (_temperatures, _downfalls)
107void FixedBiomeSource::getRawBiomeBlock(BiomeArray& biomes,int x, int z, int w, int h) const
108{
109 MemSect(36);
110 biomes = BiomeArray(w * h);
111 MemSect(0);
112
113 Arrays::fill(biomes, 0, w * h, biome);
114}
115
116// 4J-PB added in from beyond 1.8.2
117// 4J - caller is responsible for deleting biomes array, plus any optional arrays output if pointers are passed in (_temperatures, _downfalls)
118BiomeArray FixedBiomeSource::getRawBiomeBlock( int x, int z, int w, int h) const
119{
120 BiomeArray biomes;
121 getRawBiomeBlock(biomes, x, z, w, h);
122 return biomes;
123}
124
125TilePos *FixedBiomeSource::findBiome(int x, int z, int r, Biome *toFind, Random *random)
126{
127 if (toFind == biome)
128 {
129 return new TilePos(x - r + random->nextInt(r * 2 + 1), 0, z - r + random->nextInt(r * 2 + 1));
130 }
131
132 return NULL;
133}
134
135TilePos *FixedBiomeSource::findBiome(int x, int z, int r, vector<Biome *> allowed, Random *random)
136{
137 if (find(allowed.begin(), allowed.end(), biome) != allowed.end())
138 {
139 return new TilePos(x - r + random->nextInt(r * 2 + 1), 0, z - r + random->nextInt(r * 2 + 1));
140 }
141
142 return NULL;
143}
144
145bool FixedBiomeSource::containsOnly(int x, int z, int r, Biome *allowed)
146{
147 return allowed == biome;
148}
149
150bool FixedBiomeSource::containsOnly(int x, int z, int r, vector<Biome *> allowed)
151{
152 return find(allowed.begin(), allowed.end(), biome) != allowed.end();
153}