|
| 1 | +num randPrecision = 100; |
| 2 | +num goldenAngle = 2.39996; |
| 3 | +num pi = 3.14159; |
| 4 | + |
| 5 | +num trunkHeight = 3+randomInt(4); |
| 6 | +str trunkBlock = "minecraft:stripped_pale_oak_log"; |
| 7 | +str rootBlockX = "minecraft:stripped_pale_oak_wood[axis=x]"; |
| 8 | +str rootBlockZ = "minecraft:stripped_pale_oak_wood[axis=z]"; |
| 9 | + |
| 10 | +num sideBranchInterval = 1; |
| 11 | +num sideBranchMinHeight = 2 + randomInt(3); |
| 12 | +num sideBranchLengthMin = 3; |
| 13 | +num sideBranchLengthVariation = 2; |
| 14 | +num sideBranchVerticalVariation = 0; |
| 15 | +num sideBranchVerticalDirection = 0.5 + randomInt(randPrecision) / randPrecision / 2; |
| 16 | +num sideBranchLeafRadiusMin = 3; |
| 17 | +num sideBranchLeafTranslate = 0; |
| 18 | +num sideBranchLeafTopFlatness = 1; |
| 19 | +num sideBranchLeafBottomFlatness = 2; |
| 20 | +num sideBranchLeafDensity = 0.6; |
| 21 | +str sideBranchLeafStructure = "blank"; |
| 22 | +str sideBranchBlockX = "minecraft:stripped_pale_oak_wood[axis=x]"; |
| 23 | +str sideBranchBlockY = "minecraft:stripped_pale_oak_wood[axis=y]"; |
| 24 | +str sideBranchBlockZ = "minecraft:stripped_pale_oak_wood[axis=z]"; |
| 25 | + |
| 26 | +num topBranches = 1; |
| 27 | +num topBranchRadius = 1.15; |
| 28 | +num topBranchLengthUpwardsMin = 6; |
| 29 | +num topBranchLengthOutwardsMin = 1; |
| 30 | +num topBranchVerticalDirection = randomInt(randPrecision) / randPrecision / 2; |
| 31 | +num topBranchLeafRadiusMin = 0; |
| 32 | +num topBranchLeafTranslate = 0; |
| 33 | +num topBranchLeafTopFlatness = 1; |
| 34 | +num topBranchLeafBottomFlatness = 2; |
| 35 | +num topBranchLeafDensity = 0.6; |
| 36 | +str topBranchLeafStructure = "oak_leaves_clump"; |
| 37 | +str topBranchBlockX = "minecraft:stripped_pale_oak_wood[axis=x]"; |
| 38 | +str topBranchBlockY = "minecraft:stripped_pale_oak_wood[axis=y]"; |
| 39 | +str topBranchBlockZ = "minecraft:stripped_pale_oak_wood[axis=z]"; |
| 40 | + |
| 41 | +num endBranches = 2 + randomInt(3); |
| 42 | +num endBranchLengthUpwardsMin = 4; |
| 43 | +num endBranchLengthOutwardsMin = 5; |
| 44 | +num endBranchVerticalDirection = 0.5 + randomInt(randPrecision) / randPrecision / 2; |
| 45 | +num endBranchLeafRadiusMin = 2.5; |
| 46 | +num endBranchLeafTranslate = 0; |
| 47 | +num endBranchLeafTopFlatness = 1; |
| 48 | +num endBranchLeafBottomFlatness = 2; |
| 49 | +num endBranchLeafDensity = 0.6; |
| 50 | +str endBranchLeafStructure = "oak_leaves_clump"; |
| 51 | +str endBranchBlockX = "minecraft:stripped_pale_oak_wood[axis=x]"; |
| 52 | +str endBranchBlockY = "minecraft:stripped_pale_oak_wood[axis=y]"; |
| 53 | +str endBranchBlockZ = "minecraft:stripped_pale_oak_wood[axis=z]"; |
| 54 | + |
| 55 | +num leafBranches = 0; |
| 56 | +num leafBranchLengthUpwardsMin = 6; |
| 57 | +num leafBranchLengthOutwardsMin = 7; |
| 58 | +num leafBranchVerticalDirection = 0.5 - randomInt(randPrecision) / randPrecision / 2; |
| 59 | +num leafBranchLeafRadiusMin = 3.5; |
| 60 | +num leafBranchLeafTranslate = 0; |
| 61 | +num leafBranchLeafTopFlatness = 1; |
| 62 | +num leafBranchLeafBottomFlatness = 2; |
| 63 | +num leafBranchLeafDensity = 1; |
| 64 | +str leafBranchLeafStructure = "oak_leaves_clump"; |
| 65 | +str leafBranchBlockX = "minecraft:stripped_pale_oak_wood[axis=x]"; |
| 66 | +str leafBranchBlockY = "minecraft:stripped_pale_oak_wood[axis=y]"; |
| 67 | +str leafBranchBlockZ = "minecraft:stripped_pale_oak_wood[axis=z]"; |
| 68 | + |
| 69 | +num droopBase = 0.04; |
| 70 | +num droopVariation = 0.04; |
| 71 | + |
| 72 | +// Generate roots at base of trunk |
| 73 | +num roots = 3; |
| 74 | +num rootMaxDepth = 3; |
| 75 | +num rootHeight = 4; |
| 76 | +num rootLength = 4; |
| 77 | +num rootAngle = randomInt(randPrecision) / randPrecision * 2 * pi; |
| 78 | +for (num r = 0; r < roots; r = r + 1) { |
| 79 | + num rdx = sin(rootAngle); |
| 80 | + num rdz = cos(rootAngle); |
| 81 | + str rootBlock = rootBlockX; |
| 82 | + if (abs(rdz) > abs(rdx)) rootBlock = rootBlockZ; |
| 83 | + for (num l = 0; l <= rootLength; l = l + 1) { |
| 84 | + num height = rootHeight * (1 - (l / rootLength)); |
| 85 | + bool bottomedOut = false; |
| 86 | + for (num h = height; h >= -rootMaxDepth; h = h - 1) { |
| 87 | + if (check(round(l * rdx), round(h), round(l * rdz)) != "AIR") { |
| 88 | + bottomedOut = true; |
| 89 | + break; |
| 90 | + } |
| 91 | + block(l * rdx, h, l * rdz, rootBlock); |
| 92 | + } |
| 93 | + if (!bottomedOut) break; |
| 94 | + } |
| 95 | + rootAngle = rootAngle + goldenAngle; |
| 96 | +} |
| 97 | + |
| 98 | +num branchAngle = randomInt(randPrecision) / randPrecision * 2 * pi; |
| 99 | +for (num i = 0; i < trunkHeight; i = i + 1) { |
| 100 | + if (i > sideBranchMinHeight) { |
| 101 | + if (i % sideBranchInterval == 0) { |
| 102 | + // Branch direction vector |
| 103 | + num dx = sin(branchAngle); |
| 104 | + num dy = sideBranchVerticalDirection + randomInt(randPrecision) / randPrecision * sideBranchVerticalVariation; |
| 105 | + num dz = cos(branchAngle); |
| 106 | + // Normalize vector |
| 107 | + num mag = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2)); |
| 108 | + dx = dx / mag; |
| 109 | + dy = dy / mag; |
| 110 | + dz = dz / mag; |
| 111 | + // Branch origin |
| 112 | + num ox = 0; |
| 113 | + num oy = i; |
| 114 | + num oz = 0; |
| 115 | + // Set branch block based on largest unsigned vector component |
| 116 | + str branchBlock = sideBranchBlockY; |
| 117 | + if (abs(dx) > max(abs(dy), abs(dz))) branchBlock = sideBranchBlockX; |
| 118 | + else if (abs(dz) > max(abs(dy), abs(dx))) branchBlock = sideBranchBlockZ; |
| 119 | + num branchLength = sideBranchLengthMin + randomInt(randPrecision) / randPrecision * sideBranchLengthVariation; |
| 120 | + // Generate branch |
| 121 | + for (num l = 1; l <= branchLength; l = l + 1) { |
| 122 | + block(l * dx + ox, l * dy + oy, l * dz + oz, branchBlock); |
| 123 | + } |
| 124 | + // Rotate angle of next branch |
| 125 | + branchAngle = branchAngle + goldenAngle; |
| 126 | + // Generate leaf cluster at the end of the branch |
| 127 | + num radius = sideBranchLeafRadiusMin; |
| 128 | + num radiusSquared = pow(radius, 2); |
| 129 | + // Leaf cluster origin (end of branch) |
| 130 | + num lox = ox + branchLength * dx; |
| 131 | + num loy = oy + branchLength * dy + sideBranchLeafTranslate; |
| 132 | + num loz = oz + branchLength * dz; |
| 133 | + for (num cx = ceil(-radius); cx <= ceil(radius); cx = cx + 1) { |
| 134 | + for (num cy = ceil(-radius / sideBranchLeafBottomFlatness); cy <= ceil(radius / sideBranchLeafTopFlatness); cy = cy + 1) { |
| 135 | + for (num cz = ceil(-radius); cz <= ceil(radius); cz = cz + 1) { |
| 136 | + num squashFactor = sideBranchLeafBottomFlatness; |
| 137 | + if (cy > 0) squashFactor = sideBranchLeafTopFlatness; |
| 138 | + num distanceSquared = pow(cx, 2) + pow(cy * squashFactor, 2) + pow(cz, 2); |
| 139 | + if (distanceSquared < radiusSquared && randomInt(randPrecision) / randPrecision < sideBranchLeafDensity) { |
| 140 | + structure(lox + cx, loy + cy, loz + cz, sideBranchLeafStructure, "NONE", "CW_90", "CCW_90", "CW_180"); |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + block(0, i, 0, trunkBlock); |
| 148 | + block(1, i, 0, trunkBlock); |
| 149 | + block(0, i, 1, trunkBlock); |
| 150 | + block(1, i, 1, trunkBlock); |
| 151 | +} |
| 152 | + |
| 153 | +for (num b = 1; b <= topBranches; b = b + 1) { |
| 154 | + num t = b / topBranches; |
| 155 | + num ti = 1 - t; |
| 156 | + // Branch direction vector |
| 157 | + num dx = sin(branchAngle) * t; |
| 158 | + num dy = topBranchVerticalDirection; |
| 159 | + num dz = cos(branchAngle) * t; |
| 160 | + // Normalize vector |
| 161 | + num mag = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2)); |
| 162 | + dx = dx / mag; |
| 163 | + dy = dy / mag; |
| 164 | + dz = dz / mag; |
| 165 | + // Branch origin |
| 166 | + num ox = 0; |
| 167 | + num oy = trunkHeight; |
| 168 | + num oz = 0; |
| 169 | + // Set branch block based on largest unsigned vector component |
| 170 | + str branchBlock = topBranchBlockY; |
| 171 | + if (abs(dx) > max(abs(dy), abs(dz))) branchBlock = topBranchBlockX; |
| 172 | + else if (abs(dz) > max(abs(dy), abs(dx))) branchBlock = topBranchBlockZ; |
| 173 | + num branchLength = topBranchLengthUpwardsMin * ti + topBranchLengthOutwardsMin * t; |
| 174 | + // Generate branch |
| 175 | + num r = topBranchRadius; |
| 176 | + for (num l = 0; l <= branchLength; l = l + 1) { |
| 177 | + for (num x = -r; x <= r; x = x + 1) { |
| 178 | + for (num y = -r; y <= r; y = y + 1) { |
| 179 | + for (num z = -r; z <= r; z = z + 1) { |
| 180 | + if (pow(x, 2) + pow(y, 2) + pow(z, 2) < pow(r, 2)) { |
| 181 | + block((l * dx + ox) + x, (l * dy + oy) + y, (l * dz + oz) + z, branchBlock); |
| 182 | + } |
| 183 | + } |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | + // Rotate angle of next branch |
| 188 | + branchAngle = branchAngle + goldenAngle; |
| 189 | + // Generate leaf cluster at the end of the branch |
| 190 | + num radius = topBranchLeafRadiusMin; |
| 191 | + num radiusSquared = pow(radius, 2); |
| 192 | + // Leaf cluster origin (end of branch) |
| 193 | + num lox = ox + branchLength * dx; |
| 194 | + num loy = oy + branchLength * dy + topBranchLeafTranslate; |
| 195 | + num loz = oz + branchLength * dz; |
| 196 | + for (num cx = ceil(-radius); cx <= ceil(radius); cx = cx + 1) { |
| 197 | + for (num cy = ceil(-radius / topBranchLeafBottomFlatness); cy <= ceil(radius / topBranchLeafTopFlatness); cy = cy + 1) { |
| 198 | + for (num cz = ceil(-radius); cz <= ceil(radius); cz = cz + 1) { |
| 199 | + num squashFactor = topBranchLeafBottomFlatness; |
| 200 | + if (cy > 0) squashFactor = topBranchLeafTopFlatness; |
| 201 | + num distanceSquared = pow(cx, 2) + pow(cy * squashFactor, 2) + pow(cz, 2); |
| 202 | + if (distanceSquared < radiusSquared && randomInt(randPrecision) / randPrecision < topBranchLeafDensity) { |
| 203 | + structure(lox + cx, loy + cy, loz + cz, topBranchLeafStructure, "NONE", "CW_90", "CCW_90", "CW_180"); |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + // Generates end branches |
| 210 | + num endBranchAngle = randomInt(randPrecision) / randPrecision * 2 * pi; |
| 211 | + for (num eb = 1; eb <= endBranches; eb = eb + 1) { |
| 212 | + num et = eb / endBranches; |
| 213 | + num eti = 1 - et; |
| 214 | + // Branch direction vector |
| 215 | + num edx = sin(endBranchAngle) * et; |
| 216 | + num edy = endBranchVerticalDirection; |
| 217 | + num edz = cos(endBranchAngle) * et; |
| 218 | + // Normalize vector |
| 219 | + num emag = sqrt(pow(edx, 2) + pow(edy, 2) + pow(edz, 2)); |
| 220 | + edx = edx / emag; |
| 221 | + edy = edy / emag; |
| 222 | + edz = edz / emag; |
| 223 | + // Branch origin |
| 224 | + num eox = branchLength * dx + ox; |
| 225 | + num eoy = branchLength * dy + oy; |
| 226 | + num eoz = branchLength * dz + oz; |
| 227 | + // Set branch block based on largest unsigned vector component |
| 228 | + branchBlock = endBranchBlockY; |
| 229 | + if (abs(edx) > max(abs(edy), abs(edz))) branchBlock = endBranchBlockX; |
| 230 | + else if (abs(edz) > max(abs(edy), abs(edx))) branchBlock = endBranchBlockZ; |
| 231 | + num endBranchLength = endBranchLengthUpwardsMin * eti + endBranchLengthOutwardsMin * et; |
| 232 | + // Generate branch |
| 233 | + for (num l = 0; l <= endBranchLength; l = l + 1) { |
| 234 | + block(l * edx + eox, l * edy + eoy, l * edz + eoz, branchBlock); |
| 235 | + } |
| 236 | + // Rotate angle of next branch |
| 237 | + endBranchAngle = endBranchAngle + goldenAngle; |
| 238 | + // Generate leaf cluster at the end of the branch |
| 239 | + radius = endBranchLeafRadiusMin; |
| 240 | + radiusSquared = pow(radius, 2); |
| 241 | + // Leaf cluster origin (end of branch) |
| 242 | + num leox = eox + endBranchLength * edx; |
| 243 | + num leoy = eoy + endBranchLength * edy + endBranchLeafTranslate; |
| 244 | + num leoz = eoz + endBranchLength * edz; |
| 245 | + for (num cx = ceil(-radius); cx <= ceil(radius); cx = cx + 1) { |
| 246 | + for (num cy = ceil(-radius / endBranchLeafBottomFlatness); cy <= ceil(radius / endBranchLeafTopFlatness); cy = cy + 1) { |
| 247 | + for (num cz = ceil(-radius); cz <= ceil(radius); cz = cz + 1) { |
| 248 | + num squashFactor = endBranchLeafBottomFlatness; |
| 249 | + if (cy > 0) squashFactor = endBranchLeafTopFlatness; |
| 250 | + num distanceSquared = pow(cx, 2) + pow(cy * squashFactor, 2) + pow(cz, 2); |
| 251 | + if (distanceSquared < radiusSquared && randomInt(randPrecision) / randPrecision < endBranchLeafDensity) { |
| 252 | + structure(leox + cx, leoy + cy, leoz + cz, endBranchLeafStructure, "NONE", "CW_90", "CCW_90", "CW_180"); |
| 253 | + } |
| 254 | + } |
| 255 | + } |
| 256 | + } |
| 257 | + |
| 258 | + // generates leaf branches |
| 259 | + num leafBranchAngle = randomInt(randPrecision) / randPrecision * 2 * pi; |
| 260 | + for (num fb = 1; fb <= leafBranches; fb = fb + 1) { |
| 261 | + num ft = fb / leafBranches; |
| 262 | + num fti = 1 - ft; |
| 263 | + |
| 264 | + num droopDir = 1; |
| 265 | + |
| 266 | + // Branch direction vector |
| 267 | + num fdx = sin(leafBranchAngle) * ft; |
| 268 | + num fdy = leafBranchVerticalDirection; |
| 269 | + num fdz = cos(leafBranchAngle) * ft; |
| 270 | + // Normalize vector |
| 271 | + num fmag = sqrt(pow(fdx, 2) + pow(fdy, 2) + pow(fdz, 2)); |
| 272 | + fdx = fdx / fmag; |
| 273 | + fdy = fdy / fmag; |
| 274 | + fdz = fdz / fmag; |
| 275 | + // Branch origin |
| 276 | + num fox = endBranchLength * edx + eox; |
| 277 | + num foy = endBranchLength * edy + eoy; |
| 278 | + num foz = endBranchLength * edz + eoz; |
| 279 | + // Set branch block based on largest unsigned vector component |
| 280 | + branchBlock = leafBranchBlockY; |
| 281 | + if (abs(fdx) > max(abs(fdy), abs(fdz))) branchBlock = leafBranchBlockX; |
| 282 | + else if (abs(fdz) > max(abs(fdy), abs(fdx))) branchBlock = leafBranchBlockZ; |
| 283 | + num leafBranchLength = leafBranchLengthUpwardsMin * fti + leafBranchLengthOutwardsMin * ft; |
| 284 | + // Generate branch |
| 285 | + for (num l = 0; l <= leafBranchLength; l = l + 1) { |
| 286 | + num droop = droopBase-(randomInt(droopVariation*100)/100); |
| 287 | + // Point vector down more |
| 288 | + fdy = fdy - droop*droopDir; |
| 289 | + // Normalize vector |
| 290 | + fmag = sqrt(pow2(fdx)+pow2(fdy)+pow2(fdz)); |
| 291 | + fdx = fdx/fmag; |
| 292 | + fdy = fdy/fmag; |
| 293 | + fdz = fdz/fmag; |
| 294 | + |
| 295 | + block(l * fdx + fox, l * fdy + foy, l * fdz + foz, branchBlock); |
| 296 | + } |
| 297 | + // Rotate angle of next branch |
| 298 | + leafBranchAngle = leafBranchAngle + goldenAngle; |
| 299 | + // Generate leaf cluster at the end of the branch |
| 300 | + radius = leafBranchLeafRadiusMin; |
| 301 | + radiusSquared = pow(radius, 2); |
| 302 | + // Leaf cluster origin (end of branch) |
| 303 | + num lfox = fox + leafBranchLength * fdx; |
| 304 | + num lfoy = foy + leafBranchLength * fdy + leafBranchLeafTranslate; |
| 305 | + num lfoz = foz + leafBranchLength * fdz; |
| 306 | + for (num cx = ceil(-radius); cx <= ceil(radius); cx = cx + 1) { |
| 307 | + for (num cy = ceil(-radius / leafBranchLeafBottomFlatness); cy <= ceil(radius / leafBranchLeafTopFlatness); cy = cy + 1) { |
| 308 | + for (num cz = ceil(-radius); cz <= ceil(radius); cz = cz + 1) { |
| 309 | + num squashFactor = leafBranchLeafBottomFlatness; |
| 310 | + if (cy > 0) squashFactor = leafBranchLeafTopFlatness; |
| 311 | + num distanceSquared = pow(cx, 2) + pow(cy * squashFactor, 2) + pow(cz, 2); |
| 312 | + if (distanceSquared < radiusSquared && randomInt(randPrecision) / randPrecision < leafBranchLeafDensity) { |
| 313 | + structure(lfox + cx, lfoy + cy, lfoz + cz, leafBranchLeafStructure, "NONE", "CW_90", "CCW_90", "CW_180"); |
| 314 | + } |
| 315 | + } |
| 316 | + } |
| 317 | + } |
| 318 | + } |
| 319 | + } |
| 320 | +} |
| 321 | + |
| 322 | +block(0, -1, 0, "minecraft:dirt"); |
0 commit comments