用户:
高贵的木叶龙A35d查看:4 回复:10 评论:4 创建时间:2020-12-02T14:30:54
--------------------------------------------------分割线--------------------------------------------------------------------
效果图:

思路:
首先,要做出摔落引擎,必须要有方块碰撞事件
world.onVoxelContact(async({entity,x,y,z,voxel})=>{
搭建框架
然后,要用玩家变量记录上次摔落摔在哪里(简单起见不用字典了)
world.onPlayerJoin(({entity})=>{
entity.player.fall=0//创建一个玩家变量,名为fall(注意:由于是教程,就不用字典来防止player禁止扩展,作品中可以用字典)
})
补进去
world.onVoxelContact(async({entity,x,y,z,voxel})=>{
let i=entity.player.fall-y//用上次记录减去
entity.hurt(i/5)//防止伤害过高
})
这样一个基本的摔落就弄好了
个喵
,你没记录岂不是永远摔不喵?????
world.onVoxelContact(async({entity,x,y,z,voxel})=>{
let i=entity.player.fall-y
entity.hurt(i/5)
entity.player.fall=y
})
很快,你会发现你从2格跳下去也会受伤……![]()
所以加个距离判定
world.onVoxelContact(async({entity,x,y,z,voxel})=>{
let i=entity.player.fall-y
if(entity.player.fall-y>20){//摔落距离小于19不计算
entity.hurt(i/5)
}
entity.player.fall=y
})
好了,继续玩下去吧
如果你的地图里有模型可以移动,你又会发现报错了……
因为普通模型不属于player类,更没有player变量!!!
world.onVoxelContact(async({entity,x,y,z,voxel})=>{
if (!entity.isPlayer) return;//如果entity不是player取消本事件
let i=entity.player.fall-y
if(entity.player.fall-y>20){
entity.hurt(i/5)
}
entity.player.fall=y
})
可以了吧~
但是fps的人们注意了,你如果这样的话扣血根本不能发现!然后慢慢KO……
world.onVoxelContact(async({entity,x,y,z,voxel})=>{
if (!entity.isPlayer) return;
let i=entity.player.fall-y
if(entity.player.fall-y>20){
entity.hurt(i/5)
entity.player.directMessage('你受到了'+i/5+'点摔落伤害')
}
entity.player.fall=y
})
现在好了吧?
你试试从256格跳进水中
……牛顿的喵都压不住了
……
world.onFluidEnter(async({entity,voxel})=>{
if(!entity.isPlayer){return;}
entity.player.fall=0
})
world.onFluidLeave(async({entity,voxel})=>{
if(!entity.isPlayer){return;}
entity.player.fall=0
})
这下好了,跳入水中时把记录清零,就喵不掉啦~()
喵亡时清空一下数据:
world.onDie(async({entity,attacker})=>{
entity.player.fall=0
})
完整代码,这次不(po)出(tian)所(huang)料(di)的允许白嫖,反正做他没花啥力气……:
world.onFluidEnter(async({entity,voxel})=>{
if(!entity.isPlayer){return;}
entity.player.fall=0
})
world.onFluidLeave(async({entity,voxel})=>{
if(!entity.isPlayer){return;}
entity.player.fall=0
})
world.onVoxelContact(async({entity,x,y,z,voxel})=>{
if (!entity.isPlayer) return;
let i=entity.player.fall-y
if(entity.player.fall-y>20){
entity.hurt(i/5)
entity.player.directMessage('你受到了'+i/5+'点摔落伤害')
}
entity.player.fall=y
})
world.onPlayerJoin(({entity})=>{
entity.player.fall=0
})
world.onDie(async({entity,attacker})=>{
entity.player.fall=0
})