用户:
翎with珝查看:0 回复:0 评论:0 创建时间:2023-05-26T07:09:26
没图见码
world.onPress(({ button, raycast }) => {
const pos = raycast.voxelIndex;
if (button == 'action1') {
let e = world.createEntity({
mesh: 'mesh/tnt.vb',
position: [pos.x + 0.5, pos.y + 1.5, pos.z + 0.5],
meshScale: new Box3Vector3(1 / 16, 1 / 16, 1 / 16),
meshEmissive: 0,
collides: true,
fixed: false,
gravity: false,
mass: Math.pow(999999999999999999999999999999, 99999999999999999999999999999999)
});
e.addTag('未激活');
};
});
world.onClick(async ({ entity }) => {
if (!entity.isPlayer && entity.hasTag('未激活')) {
entity.collides = false;
entity.removeTag('未激活');
for (let i = 0; i <= 7; i++) {
entity.meshEmissive = 1;
await sleep(250);
entity.meshEmissive = 0;
await sleep(250);
};
entity.meshEmissive = 1;
for (let i = 0; i <= 8; i += 0.5) {
entity.meshScale = new Box3Vector3(1 / (16 - i), 1 / (16 - i), 1 / (16 - i));
entity.position.y += 0.03125;
await sleep(24);
};
sphere('air', Math.floor(entity.position.x), Math.floor(entity.position.y), Math.floor(entity.position.z), 5);
entity.destroy();
};
});
function sphere(vox, cx, cy, cz, radius) {
let xend = cx + radius;
let yend = cy + radius;
let zend = cz + radius;
for (let x = cx - radius; x <= xend; x++) {
for (let y = cy - radius; y <= yend; y++) {
for (let z = cz - radius; z <= zend; z++) {
let dx = x - cx;
let dy = y - cy;
let dz = z - cz;
if (Math.round(Math.sqrt(dx * dx + dy * dy + dz * dz)) <= radius) {
voxels.setVoxel(x, y, z, vox);
};
};
};
};
};