the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 191 lines 5.2 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "DungeonFeature.h" 4#include "net.minecraft.world.level.tile.h" 5 6void DungeonFeature::addRoom(int xOffs, int zOffs, byteArray blocks, double xRoom, double yRoom, double zRoom) 7{ 8 addTunnel(xOffs, zOffs, blocks, xRoom, yRoom, zRoom, 1 + random->nextFloat() * 6, 0, 0, -1, -1, 0.5); 9} 10 11void DungeonFeature::addTunnel(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 = new Random(this->random->nextLong()); 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(xOffs, zOffs, blocks, xCave, yCave, zCave, random->nextFloat() * 0.5f + 0.5f, yRot - PI / 2, xRot / 3, step, dist, 1.0); 68 addTunnel(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::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 for (int yy = y1 - 1; yy >= y0; yy--) 135 { 136 double yd = (yy + 0.5 - yCave) / yRad; 137 if (yd > -0.7 && xd * xd + yd * yd + zd * zd < 1) 138 { 139 int block = blocks[p]; 140 if (block == Tile::grass_Id) hasGrass = true; 141 if (block == Tile::stone_Id || block == Tile::dirt_Id || block == Tile::grass_Id) 142 { 143 if (yy < 10) 144 { 145 blocks[p] = (byte) Tile::lava_Id; 146 } 147 else 148 { 149 blocks[p] = (byte) 0; 150 if (hasGrass && blocks[p - 1] == Tile::dirt_Id) blocks[p - 1] = (byte) Tile::grass_Id; 151 } 152 } 153 } 154 p--; 155 } 156 } 157 } 158 if (singleStep) break; 159 } 160 161} 162 163void DungeonFeature::addFeature(Level *level, int x, int z, int xOffs, int zOffs, byteArray blocks) 164{ 165 int caves = random->nextInt(random->nextInt(random->nextInt(40) + 1) + 1); 166 if (random->nextInt(15) != 0) caves = 0; 167 168 for (int cave = 0; cave < caves; cave++) 169 { 170 double xCave = x * 16 + random->nextInt(16); 171 double yCave = random->nextInt(random->nextInt(Level::genDepth - 8) + 8); 172 double zCave = z * 16 + random->nextInt(16); 173 174 int tunnels = 1; 175 if (random->nextInt(4) == 0) 176 { 177 addRoom(xOffs, zOffs, blocks, xCave, yCave, zCave); 178 tunnels += random->nextInt(4); 179 } 180 181 for (int i = 0; i < tunnels; i++) 182 { 183 184 float yRot = random->nextFloat() * PI * 2; 185 float xRot = ((random->nextFloat() - 0.5f) * 2) / 8; 186 float thickness = random->nextFloat() * 2 + random->nextFloat(); 187 188 addTunnel(xOffs, zOffs, blocks, xCave, yCave, zCave, thickness, yRot, xRot, 0, 0, 1.0); 189 } 190 } 191}