用户:
翎with珝查看:1 回复:6 评论:1 创建时间:2023-04-01T12:48:09
效果图

代码
(async function () {
let map_x = 128;//地图x长度
let map_z = 128;//地图z长度
let i = 48;//地图y长度:建议将y高度-16
let n = 5;
let Tree = true;
for (z = 0; z <= map_z; z += n) {
for (y = 0; y <= i; y++) {
for (zn = 0; zn <= z; zn++) {
for (x = 0; x <= map_x; x++) {
voxels.setVoxel(x, y, zn, 'dirt');
};
for (xs = 0; xs <= map_x; xs += 1) {
if (voxels.getVoxelId(xs, i + 1, zn) !== voxels.id('dirt')) {
voxels.setVoxel(xs, i + 1, zn, 'grass');
};
};
};
};
await sleep(10);
if (Math.random() <= 0.75) {
i -= getRandomInt(1, 2);
} else {
i -= getRandomInt(2, 3);
};
n = getRandomInt(2, 5);
};
if (Tree) {
for (let i = 0; i < map_x; i++) {
for (let j = 0; j < map_z; j++) {
for (let k = 0; k < 100; k++) {
if (voxels.getVoxel(i, k, j) == voxels.id("grass")) {
if (Math.random() * 60 <= 1) {
tree(i, k, j);
};
};
};
};
await sleep(10);
};
};
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
};
function tree(x, y, z) {
if (voxels.getVoxel(x, y, z) != voxels.id("water")) {
var rand = 1;
for (let i = y + rand; i < y + 4 + rand; i++) {
voxels.setVoxel(x, i, z, "acacia");
};
for (let i = 3 + rand; i < 5 + rand; i++) {
for (let j = -2; j < 3; j++) {
for (let k = -2; k < 3; k++) {
voxels.setVoxel(x + j, y + i, z + k, "green_leaf");
};
};
};
for (let j = -1; j < 2; j++) {
for (let k = -1; k < 2; k++) {
voxels.setVoxel(x + j, y + 5 + rand, z + k, "green_leaf");
};
};
voxels.setVoxel(x - 1, y + 6 + rand, z, "green_leaf");
voxels.setVoxel(x, y + 6 + rand, z, "green_leaf");
voxels.setVoxel(x + 1, y + 6 + rand, z, "green_leaf");
voxels.setVoxel(x, y + 6 + rand, z - 1, "green_leaf");
voxels.setVoxel(x, y + 6 + rand, z + 1, "green_leaf");
}
};
})();(async function () {
let map_x = 128;//地图x长度
let map_z = 128;//地图z长度
let i = 48;//地图y长度:建议将y高度-16
let n = 5;
let Tree = true;
for (z = 0; z <= map_z; z += n) {
for (y = 0; y <= i; y++) {
for (zn = 0; zn <= z; zn++) {
for (x = 0; x <= map_x; x++) {
voxels.setVoxel(x, y, zn, 'dirt');
};
for (xs = 0; xs <= map_x; xs += 1) {
if (voxels.getVoxelId(xs, i + 1, zn) !== voxels.id('dirt')) {
voxels.setVoxel(xs, i + 1, zn, 'grass');
};
};
};
};
await sleep(10);
if (Math.random() <= 0.75) {
i -= getRandomInt(1, 2);
} else {
i -= getRandomInt(2, 3);
};
n = getRandomInt(2, 5);
};
if (Tree) {
for (let i = 0; i < map_x; i++) {
for (let j = 0; j < map_z; j++) {
for (let k = 0; k < 100; k++) {
if (voxels.getVoxel(i, k, j) == voxels.id("grass")) {
if (Math.random() * 60 <= 1) {
tree(i, k, j);
};
};
};
};
await sleep(10);
};
};
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
};
function tree(x, y, z) {
if (voxels.getVoxel(x, y, z) != voxels.id("water")) {
var rand = 1;
for (let i = y + rand; i < y + 4 + rand; i++) {
voxels.setVoxel(x, i, z, "acacia");
};
for (let i = 3 + rand; i < 5 + rand; i++) {
for (let j = -2; j < 3; j++) {
for (let k = -2; k < 3; k++) {
voxels.setVoxel(x + j, y + i, z + k, "green_leaf");
};
};
};
for (let j = -1; j < 2; j++) {
for (let k = -1; k < 2; k++) {
voxels.setVoxel(x + j, y + 5 + rand, z + k, "green_leaf");
};
};
voxels.setVoxel(x - 1, y + 6 + rand, z, "green_leaf");
voxels.setVoxel(x, y + 6 + rand, z, "green_leaf");
voxels.setVoxel(x + 1, y + 6 + rand, z, "green_leaf");
voxels.setVoxel(x, y + 6 + rand, z - 1, "green_leaf");
voxels.setVoxel(x, y + 6 + rand, z + 1, "green_leaf");
}
};
})();点赞0
评论