实现功能:

玩家走过绿宝石块后会保存当前位置(绿宝石位置)并以actionbar的形式显示玩家存点位置

玩家手持金锄右键时就会传送到最近一次踩的绿宝石位置

代码实现部分:

(sever_scripts)

//绿宝石存档点
var playerlist = {}
PlayerEvents.tick(event => {
	const { player, sever } = event
	let pos = player.block.offset(0, -1, 0)
	if (pos.id == 'minecraft:emerald_block') {
		playerlist[player.name] = [Math.floor(Number(player.x)), Math.floor(Number(player.y)), Math.floor(Number(player.z))];//获取玩家坐标使用Math.floor()舍去小数部分
        player.runCommandSilent(`title @a actionbar "\u00A74记录点已设定至${playerlist[player.name][0]},${playerlist[player.name][1]},${playerlist[player.name][2]}"`);
	}
})
ItemEvents.rightClicked(event => {
	let player = event.player
	//判断是否手持金锄右键(右键耕地不触发)
	if (player.getHeldItem(event.hand) == Item.of('minecraft:golden_hoe')) {
		if (player.name in playerlist) {
			player.setPosition(playerlist[player.name][0] + 0.5, playerlist[player.name][1], playerlist[player.name][2] + 0.5)//传送时将玩家传送至方块中心,所以x、z值+0.5
		}

	}

})

【跑酷套件】系列源码

点击跳转~~别忘了star哦