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