用户:
13661555450查看:36 回复:6 评论:36 创建时间:2022-08-19T14:55:08
右键放置,左键点燃,使用记得导入模型,诸位听我一句劝:”此物威力甚大,请谨慎使用“
由23332808编写
async function tnt(x,y,z){
const e=world.createEntity({
mesh:"mesh/TNT.vb",
meshScale:[1/16,1/16,1/16],
collides:true,
gravity:false,
friction:1.5,
position:[x,y,z],
})
e.enableDamage=true
e.fixed=true
e.maxHp=1
e.hp=1
e.addTag("TNT")
e.showHealthBar=false
e.onTakeDamage(async()=>{e.enableDamage=false
e.gravity=true
e.fixed=false
for(i=0;i<3;i++){
e.meshEmissive = 1
await sleep(500)
e.meshEmissive = 0
await sleep(500)}
const bounds = new Box3Bounds3(new Box3Vector3(e.position.x-4,e.position.y-4,e.position.z-4), new Box3Vector3(e.position.x+4,e.position.y+4,e.position.z+4))
world.searchBox(bounds).forEach((entityInBounds) => {
entityInBounds.hurt(10,{attacker:"TNT"})
var direction = entityInBounds.position.sub(e.position)
if(direction.x>0){entityInBounds.velocity.x+=1}else{entityInBounds.velocity.x-=1}
if(direction.y>0){entityInBounds.velocity.y+=1}else{entityInBounds.velocity.y-=1}
if(direction.z>0){entityInBounds.velocity.z+=1}else{entityInBounds.velocity.z-=1}
})
sphere("air",e.position.x,e.position.y,e.position.z,3)
e.destroy()})}
world. onPress(({button, raycast: { voxelIndex, normal}}) =>{
if (button == Box3ButtonType.ACTION1){
let v = voxelIndex.add(normal)
tnt(Math.round(v.x)+0.5,v.y+0.5,Math.round(v.z)+0.5)}})
world.onclick(({entity,button})=>{
if(entity.hasTag("TNT")&&button=="action1){
entity.hurt(1)
})
async function tnt(x,y,z){
const e=world.createEntity({
mesh:"mesh/TNT.vb",
meshScale:[1/16,1/16,1/16],
collides:true,
gravity:false,
friction:1.5,
position:[x,y,z],
})
e.enableDamage=true
e.fixed=true
e.maxHp=1
e.hp=1
e.addTag("TNT")
e.showHealthBar=false
e.onTakeDamage(async()=>{e.enableDamage=false
e.gravity=true
e.fixed=false
for(i=0;i<3;i++){
e.meshEmissive = 1
await sleep(500)
e.meshEmissive = 0
await sleep(500)}
const bounds = new Box3Bounds3(new Box3Vector3(e.position.x-4,e.position.y-4,e.position.z-4), new Box3Vector3(e.position.x+4,e.position.y+4,e.position.z+4))
world.searchBox(bounds).forEach((entityInBounds) => {
entityInBounds.hurt(10,{attacker:"TNT"})
var direction = entityInBounds.position.sub(e.position)
if(direction.x>0){entityInBounds.velocity.x+=1}else{entityInBounds.velocity.x-=1}
if(direction.y>0){entityInBounds.velocity.y+=1}else{entityInBounds.velocity.y-=1}
if(direction.z>0){entityInBounds.velocity.z+=1}else{entityInBounds.velocity.z-=1}
})
sphere("air",e.position.x,e.position.y,e.position.z,3)
e.destroy()})}
world. onPress(({button, raycast: { voxelIndex, normal}}) =>{
if (button == Box3ButtonType.ACTION1){
let v = voxelIndex.add(normal)
tnt(Math.round(v.x)+0.5,v.y+0.5,Math.round(v.z)+0.5)}})
world.onClick(({entity,button})=>{
if(entity.hasTag("TNT")&&button=="action1"){
entity.hurt(1)
}})
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)
}
}}}
}点赞0
评论