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 "net.minecraft.world.level.h"
3#include "net.minecraft.world.level.tile.h"
4#include "net.minecraft.world.level.biome.h"
5#include "LargeCaveFeature.h"
6
7void LargeCaveFeature::addRoom(__int64 seed, int xOffs, int zOffs, byteArray blocks, double xRoom, double yRoom, double zRoom)
8{
9 addTunnel(seed, xOffs, zOffs, blocks, xRoom, yRoom, zRoom, 1 + random->nextFloat() * 6, 0, 0, -1, -1, 0.5);
10}
11
12void LargeCaveFeature::addTunnel(__int64 seed, int xOffs, int zOffs, byteArray blocks, double xCave, double yCave, double zCave, float thickness, float yRot, float xRot, int step, int dist, double yScale)
13{
14 double xMid = xOffs * 16 + 8;
15 double zMid = zOffs * 16 + 8;
16
17 float yRota = 0;
18 float xRota = 0;
19 Random random = Random(seed);
20
21 if (dist <= 0)
22 {
23 int max = radius * 16 - 16;
24 dist = max - random.nextInt(max / 4);
25 }
26 bool singleStep = false;
27
28 if (step == -1)
29 {
30 step = dist / 2;
31 singleStep = true;
32 }
33
34
35 int splitPoint = random.nextInt(dist / 2) + dist / 4;
36 bool steep = random.nextInt(6) == 0;
37
38 for (; step < dist; step++)
39 {
40 double rad = 1.5 + (Mth::sin(step * PI / dist) * thickness) * 1;
41 double yRad = rad * yScale;
42
43 float xc = Mth::cos(xRot);
44 float xs = Mth::sin(xRot);
45 xCave += Mth::cos(yRot) * xc;
46 yCave += xs;
47 zCave += Mth::sin(yRot) * xc;
48
49 if (steep)
50 {
51 xRot *= 0.92f;
52 }
53 else
54 {
55 xRot *= 0.7f;
56 }
57 xRot += xRota * 0.1f;
58 yRot += yRota * 0.1f;
59
60 xRota *= 0.90f;
61 yRota *= 0.75f;
62 xRota += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 2;
63 yRota += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 4;
64
65
66 if (!singleStep && step == splitPoint && thickness > 1 && dist > 0)
67 {
68 addTunnel(random.nextLong(), xOffs, zOffs, blocks, xCave, yCave, zCave, random.nextFloat() * 0.5f + 0.5f, yRot - PI / 2, xRot / 3, step, dist, 1.0);
69 addTunnel(random.nextLong(), xOffs, zOffs, blocks, xCave, yCave, zCave, random.nextFloat() * 0.5f + 0.5f, yRot + PI / 2, xRot / 3, step, dist, 1.0);
70 return;
71 }
72 if (!singleStep && random.nextInt(4) == 0) continue;
73 {
74 double xd = xCave - xMid;
75 double zd = zCave - zMid;
76 double remaining = dist - step;
77 double rr = (thickness + 2) + 16;
78 if (xd * xd + zd * zd - (remaining * remaining) > rr * rr)
79 {
80 return;
81 }
82 }
83
84 if (xCave < xMid - 16 - rad * 2 || zCave < zMid - 16 - rad * 2 || xCave > xMid + 16 + rad * 2 || zCave > zMid + 16 + rad * 2) continue;
85
86 int x0 = Mth::floor(xCave - rad) - xOffs * 16 - 1;
87 int x1 = Mth::floor(xCave + rad) - xOffs * 16 + 1;
88
89 int y0 = Mth::floor(yCave - yRad) - 1;
90 int y1 = Mth::floor(yCave + yRad) + 1;
91
92 int z0 = Mth::floor(zCave - rad) - zOffs * 16 - 1;
93 int z1 = Mth::floor(zCave + rad) - zOffs * 16 + 1;
94
95 if (x0 < 0) x0 = 0;
96 if (x1 > 16) x1 = 16;
97
98 if (y0 < 1) y0 = 1;
99 if (y1 > Level::genDepth - 8) y1 = Level::genDepth - 8;
100
101 if (z0 < 0) z0 = 0;
102 if (z1 > 16) z1 = 16;
103
104 bool detectedWater = false;
105 for (int xx = x0; !detectedWater && xx < x1; xx++)
106 {
107 for (int zz = z0; !detectedWater && zz < z1; zz++)
108 {
109 for (int yy = y1 + 1; !detectedWater && yy >= y0 - 1; yy--)
110 {
111 int p = (xx * 16 + zz) * Level::genDepth + yy;
112 if (yy < 0 || yy >= Level::genDepth) continue;
113 if (blocks[p] == Tile::water_Id || blocks[p] == Tile::calmWater_Id)
114 {
115 detectedWater = true;
116 }
117 if (yy != y0 - 1 && xx != x0 && xx != x1 - 1 && zz != z0 && zz != z1 - 1)
118 {
119 yy = y0;
120 }
121 }
122 }
123 }
124 if (detectedWater) continue;
125
126 for (int xx = x0; xx < x1; xx++)
127 {
128 double xd = ((xx + xOffs * 16 + 0.5) - xCave) / rad;
129 for (int zz = z0; zz < z1; zz++)
130 {
131 double zd = ((zz + zOffs * 16 + 0.5) - zCave) / rad;
132 int p = (xx * 16 + zz) * Level::genDepth + y1;
133 bool hasGrass = false;
134 if (xd * xd + zd * zd < 1)
135 {
136 for (int yy = y1 - 1; yy >= y0; yy--)
137 {
138 double yd = (yy + 0.5 - yCave) / yRad;
139 if (yd > -0.7 && xd * xd + yd * yd + zd * zd < 1)
140 {
141 int block = blocks[p];
142 if (block == Tile::grass_Id) hasGrass = true;
143 if (block == Tile::stone_Id || block == Tile::dirt_Id || block == Tile::grass_Id)
144 {
145 if (yy < 10)
146 {
147 blocks[p] = (byte) Tile::lava_Id;
148 }
149 else
150 {
151 blocks[p] = (byte) 0;
152 if (hasGrass && blocks[p - 1] == Tile::dirt_Id) blocks[p - 1] = (byte) level->getBiome(xx + xOffs * 16, zz + zOffs * 16)->topMaterial;
153 }
154 }
155 }
156 p--;
157 }
158 }
159 }
160 }
161 if (singleStep) break;
162 }
163
164}
165
166void LargeCaveFeature::addFeature(Level *level, int x, int z, int xOffs, int zOffs, byteArray blocks)
167{
168 int caves = random->nextInt(random->nextInt(random->nextInt(40) + 1) + 1);
169 if (random->nextInt(15) != 0) caves = 0;
170
171 for (int cave = 0; cave < caves; cave++)
172 {
173 double xCave = x * 16 + random->nextInt(16);
174 double yCave = random->nextInt(random->nextInt(Level::genDepth - 8) + 8);
175 double zCave = z * 16 + random->nextInt(16);
176
177 int tunnels = 1;
178 if (random->nextInt(4) == 0)
179 {
180 addRoom(random->nextLong(), xOffs, zOffs, blocks, xCave, yCave, zCave);
181 tunnels += random->nextInt(4);
182 }
183
184 for (int i = 0; i < tunnels; i++)
185 {
186
187 float yRot = random->nextFloat() * PI * 2;
188 float xRot = ((random->nextFloat() - 0.5f) * 2) / 8;
189 float thickness = random->nextFloat() * 2 + random->nextFloat();
190 if (random->nextInt(10) == 0) thickness *= random->nextFloat() * random->nextFloat() * 3 + 1;
191
192 addTunnel(random->nextLong(), xOffs, zOffs, blocks, xCave, yCave, zCave, thickness, yRot, xRot, 0, 0, 1.0);
193 }
194 }
195
196}