跑酷代碼-1
//冰塊打破代碼
/*?如果實(shí)體碰到冰塊,冰塊會被打破?*/
world.onVoxelContact(({?x,?y,?z,?voxel?})?=>?{?const?voxelName?=?voxels.name(voxel);?//?將方塊id轉(zhuǎn)換名稱?
if?(voxelName?===?'ice'){?//?如果方塊名稱是冰塊?
voxels.setVoxel(x,?y,?z,?0);?//?將方塊變成空氣?
}
})
//存檔點(diǎn)
const?saveNpcs?=?world.querySelectorAll('.存檔點(diǎn)')
let?saveNpc
for?(saveNpc?of?saveNpcs)?{
????saveNpc.enableInteract?=?true;?//?允許進(jìn)行互動
????saveNpc.interactRadius?=?2;???//?實(shí)體的互動范圍
????saveNpc.onInteract(async?({?entity,?targetEntity?})?=>?{
????????entity.player.spawnPoint.set(targetEntity.position.x,?targetEntity.position.y?+?2,?targetEntity.position.z)
????????entity.player.directMessage('已刷新存檔點(diǎn),加油')
????})
}
//玩家死亡
world.onVoxelContact(async?({?entity,?voxel?})?=>?{
????if?(voxels.name(voxel)?===?'grass')?{
????????entity.position.set(entity.player.spawnPoint.x,?entity.player.spawnPoint.y,?entity.player.spawnPoint.z)
????}
})