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 "LargeHellCaveFeature.h"
4#include "net.minecraft.world.level.tile.h"
5
6void LargeHellCaveFeature::addRoom(__int64 seed, int xOffs, int zOffs, byteArray blocks, double xRoom, double yRoom, double zRoom)
7{
8 addTunnel(seed, xOffs, zOffs, blocks, xRoom, yRoom, zRoom, 1 + random->nextFloat() * 6, 0, 0, -1, -1, 0.5);
9}
10
11void LargeHellCaveFeature::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)
12{
13 double xMid = xOffs * 16 + 8;
14 double zMid = zOffs * 16 + 8;
15
16 float yRota = 0;
17 float xRota = 0;
18 Random random(seed);
19
20 if (dist <= 0)
21 {
22 int max = radius * 16 - 16;
23 dist = max - random.nextInt(max / 4);
24 }
25 bool singleStep = false;
26
27 if (step == -1)
28 {
29 step = dist / 2;
30 singleStep = true;
31 }
32
33
34 int splitPoint = random.nextInt(dist / 2) + dist / 4;
35 bool steep = random.nextInt(6) == 0;
36
37 for (; step < dist; step++)
38 {
39 double rad = 1.5 + (Mth::sin(step * PI / dist) * thickness) * 1;
40 double yRad = rad * yScale;
41
42 float xc = Mth::cos(xRot);
43 float xs = Mth::sin(xRot);
44 xCave += Mth::cos(yRot) * xc;
45 yCave += xs;
46 zCave += Mth::sin(yRot) * xc;
47
48 if (steep)
49 {
50 xRot *= 0.92f;
51 }
52 else
53 {
54 xRot *= 0.7f;
55 }
56 xRot += xRota * 0.1f;
57 yRot += yRota * 0.1f;
58
59 xRota *= 0.90f;
60 yRota *= 0.75f;
61 xRota += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 2;
62 yRota += (random.nextFloat() - random.nextFloat()) * random.nextFloat() * 4;
63
64
65 if (!singleStep && step == splitPoint && thickness > 1)
66 {
67 addTunnel(random.nextLong(), xOffs, zOffs, blocks, xCave, yCave, zCave, random.nextFloat() * 0.5f + 0.5f, yRot - PI / 2, xRot / 3, step, dist, 1.0);
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 return;
70 }
71 if (!singleStep && random.nextInt(4) == 0) continue;
72
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::lava_Id || blocks[p] == Tile::calmLava_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 for (int yy = y1 - 1; yy >= y0; yy--)
134 {
135 double yd = (yy + 0.5 - yCave) / yRad;
136 if (yd > -0.7 && xd * xd + yd * yd + zd * zd < 1)
137 {
138 int block = blocks[p];
139 if (block == Tile::netherRack_Id || block == Tile::dirt_Id || block == Tile::grass_Id)
140 {
141 blocks[p] = (byte) 0;
142 }
143 }
144 p--;
145 }
146 }
147 }
148 if (singleStep) break;
149 }
150}
151
152
153void LargeHellCaveFeature::addFeature(Level *level, int x, int z, int xOffs, int zOffs, byteArray blocks)
154{
155 int caves = random->nextInt(random->nextInt(random->nextInt(10) + 1) + 1);
156 if (random->nextInt(5) != 0) caves = 0;
157
158 for (int cave = 0; cave < caves; cave++)
159 {
160 double xCave = x * 16 + random->nextInt(16);
161 double yCave = random->nextInt(Level::genDepth);
162 double zCave = z * 16 + random->nextInt(16);
163
164 int tunnels = 1;
165 if (random->nextInt(4) == 0)
166 {
167 addRoom(random->nextLong(), xOffs, zOffs, blocks, xCave, yCave, zCave);
168 tunnels += random->nextInt(4);
169 }
170
171 for (int i = 0; i < tunnels; i++)
172 {
173
174 float yRot = random->nextFloat() * PI * 2;
175 float xRot = ((random->nextFloat() - 0.5f) * 2) / 8;
176 float thickness = random->nextFloat() * 2 + random->nextFloat();
177
178 addTunnel(random->nextLong(), xOffs, zOffs, blocks, xCave, yCave, zCave, thickness*2, yRot, xRot, 0, 0, 0.5);
179 }
180 }
181}
182
183