猫史档案馆


再看一眼就会爆炸!

用户:NysidlaNysidla查看:0 回复:1 评论:0 创建时间:2023-06-08T13:45:01


world.onPress(async ({ button, entity, raycast, tick }) => {
    if (entity.setUp.onhand[0].includes('火焰弹') && button == "action1") {
        let e = world.createEntity({
            position: entity.position.add(new Box3Vector3(raycast.direction.x, raycast.direction.y, raycast.direction.z)),
            mesh: `mesh/火焰弹.vb`,//要提前准备好模型
            gravity: false,
            meshScale: new Box3Vector3(1 / 16, 1 / 16, 1 / 16),
            meshOrientation: new Box3Quaternion(0, 0, 0, 1).rotateY(Math.atan2(raycast.direction.z, raycast.direction.x)).rotateY(Math.PI / 2),
            velocity: raycast.direction.mul(new Box3Vector3(2, 2, 2)),
            friction: 1.5,
            particleColor: [new Box3RGBColor(1, 1, 0), new Box3RGBColor(1, 1, 0), new Box3RGBColor(1, 1, 0), new Box3RGBColor(0, 0, 0), new Box3RGBColor(0, 0, 0)],
            particleLifetime: 0.5,
            particleRate: 100,
            particleSize: [10, 9, 8, 7, 6],
            meshScale: new Box3Vector3(0.07, 0.07, 0.07),
        })
        e.addTag(entity.setUp.onhand[0].slice(0, entity.setUp.onhand[0].indexOf('*')))
        entity.player.sound('audio/fireball4.mp3')
        e.zhu = entity.player.name
        findNum(entity)
    }
})

function findNum(entity) {
    if (entity.setUp.onhand[0].slice(entity.setUp.onhand[0].indexOf('*') + 1) == 1) {
        entity.setUp.bar[entity.setUp.onhand[1]] = '空'
        entity.setUp.onhand[0] = '空'
        entity.player.removeWearable(entity.player.wearables('rightHand')[0])
    } else {
        let bar = entity.setUp.bar[entity.setUp.onhand[1]]
        entity.setUp.bar[entity.setUp.onhand[1]] = bar.slice(0, bar.indexOf('*') + 1) + (Number(bar.slice(bar.indexOf('*') + 1)) - 1)
        entity.setUp.onhand[0] = entity.setUp.bar[entity.setUp.onhand[1]]
    }
}
entity.setUp = { bar: ['空', '空', '空', '空', '空', '空', '空', '空', '空'], bag: [], armor: '无', k: 0, d: 0, team: '', onhand: ['空', 0], tick: 0, gold: 100, silver: 100, copper: 100, effect: [] }  onhand就是主手

发射火球的代码,之前讲过,和火力的一模一样()

mul是xx相乘,yy相乘,zz相乘(第一个[x,y,z]是原本的,第二个[x,y,z]是乘的,听不懂(我也不知道怎么说好)直接在控制台打出new Box3Vector3)

旋转我找GPT写的,edge重置了,应该是用反正切函数得到底角和斜边角的角度。

 

 

爆炸:

setInterval(async () => {
    world.querySelectorAll('.火焰弹').forEach((e) => {
        if (e.voxelContacts.length > 0) {
            boom(e.position.x, e.position.y, e.position.z, 2, ['white', 'plank_02'])
            e.destroy()
        }
    })
}, 10)

//MC判断爆炸会从爆炸点射出1300多条射线!所以爆炸只能自己想。
async function boom(x, y, z, r, breakBlock) {
    for (let a = x - r; a <= x + r; a++) {
        for (let b = y - r; b <= y + r; b++) {
            for (let c = z - r; c <= z + r; c++) {
                if (Math.round(Math.sqrt((a - x) * (a - x) + (b - y) * (b - y) + (c - z) * (c - z))) <= r && breakBlock.includes(voxels.name(voxels.getVoxel(a, b, c)))) {
                    voxels.setVoxel(a, b, c, 'air')
                }
            }
        }//API还是有点用的()
    } world.querySelectorAll('player').filter(a => a.setUp.team != '' && a.position.distance(new Box3Vector3(x, y, z)) <= r * 2).forEach((e) => {//搜索所有玩家,在筛选出满足条件的
        let dir = new Box3Vector3(x, y, z).sub(e.position).scale(1 / new Box3Vector3(x, y, z).distance(e.position))
        let protection = e.setUp.armor.includes('保护II') ? 2 : e.setUp.armor.includes('保护I') ? 1 : 0
        let defense = e.setUp.armor.includes('皮革') ? 3 : e.setUp.armor.includes('金') ? 5 : e.setUp.armor.includes('钻石') ? 8 : 0
        let toughness = e.setUp.armor.includes('钻石') ? 2 : 0
        e.hurt(takeDamage(e.position.distance(new Box3Vector3(x, y, z)) * r, defense, toughness, protection), { damageType: '爆炸了' })
        //不知道伤害代码的论坛搜索MC伤害计算代码
        //wiki伤害计算看不懂,直接编一个
        e.velocity.x += -dir.x / 3
        e.velocity.y += -dir.y / 3
        e.velocity.z += -dir.z / 3
        //我用setIn检测的,10tick检测一次,所以会爆炸6——7次,要/三,如果setIn检测延时高的话乘2。
    })
}

然后呢,就完了()

entity.player.sound也要提前准备欧()


回复

上一页1 页 / 共 1下一页
NysidlaNysidla

伤害计算错了,这样距离越远伤害越高()正确的:

e.hurt(takeDamage(r * 2 - e.position.distance(new Box3Vector3(x, y, z)), defense, toughness, protection), { damageType: '爆炸了' })当然还是希望伤害计算自己写,因为这是我编的(  

点赞0


评论