在原版中实现地皮模组攻略

联机侠

大家好,下面是小编给大家分享的在原版中实现地皮模组攻略详情,希望能帮到大家哦!

代码编写使用:1.11.2

此原版模组包含功能有“随机创建地皮” “地皮保护” 以及 还未写的 “地皮传送”,编写版本为1.11.2,多说无益,还是先上图再贴代码。

我的世界命令方块 在原版中实现地皮模组

我的世界命令方块 在原版中实现地皮模组

我的世界命令方块 在原版中实现地皮模组

我的世界命令方块 在原版中实现地皮模组

我的世界命令方块 在原版中实现地皮模组

我的世界命令方块 在原版中实现地皮模组

图片就介绍到这里,下面是思路以及代码部分~

整体思路:

每个玩家只允许拥有一个地皮,所以先要使已经创建地皮的玩家无法创建地皮。这里我是通过检测到按钮按下后,如果玩家具有created标签(已经创建过地皮),则将按下的按钮弹起,继而在接下来的再一次检测按钮按下中检测失败故无法启动地皮创建模块。而当未创建玩家按下按钮后,按钮会一直保持按下状态直到随机创建以及检测结束,目的是为了防止玩家再次按下出现Bug。

地皮随机取点创建我采用的是扩散(spreadplayers),将实体ASdp在最近半径100外,最远半径9999中扩散。为了防止小几率的地皮重叠,则在扩散后,先检测ASdp附近90格内是否存在已经创建的地皮(具有标签dp的实体),如果有,则重新扩散,如果无,则进入下一模块。即开始创建地皮,注意,虽然这里的名字为开始创建地皮,但实质上地皮的四边是在设置XYZ参数时创建的,因为这里的开始地皮创建只会执行一次,且这几个系统过渡中无长时延迟,所以如果在此模块执行地皮四边的创建时,即使玩家已经被传送,但地形还未加载出来,则无法被执行创建操作。所以在这个模块主要是为参数设置需要的一些信息进行配置,并将按钮弹起。

设置地皮XYZ参数主要是为了后续的地皮传送做准备,故这里不再详细介绍。不过得提醒一下,上一步将x y z设置为99999的原因。这里检测x y z是否已经设置是通过检测x y z是否在规定范围内(扩散的最远情况),x的范围为-9999到9999,y为0到255,z为-9999到9999。如果在这个范围内,则完成设置,允许玩家移动。不过你可能会问,玩家x y z没有任何值的时候也不再检测范围内啊,将x y z设置为99999是多余的啊,为什么还要设置呢?那你可能不知道,如果当一个准则为trigger的变量被enable时,且他不具有任何值,他的值会变为0(或理解为 add 0),故我设置为了99999。

在最后设置的部分就比较简单了,提示玩家地皮创建完成,删除ASdp的dpsetting标签。

最后的地皮保护,其实是通过将进入地皮范围玩家的ID与领地ID相减,如不等于0,则是在他人地皮范围。

整体思路完,以下是代码部分

创建变量:

  /scoreboard objectives add creating dummy

/scoreboard objectives add x trigger

/scoreboard objectives add y trigger

/scoreboard objectives add z trigger

/scoreboard objectives add dpID dummy

/scoreboard objectives add dpper dummy

/scoreboard objectives add dpcache dummy

基础探测部分[高频] (此部分坐标抽象,如需了解请下载地图):

----------------------------------

探测地皮创建按钮是否存在

/testforblock 0 9 6 minecraft:stone_button

非门激活:

tellraw

["",{"text":"[甘小蔗] ","color":"dark_green","bold":true},{"text":" 探测到按钮疑似被 ","color":"red","bold":false},{"selector":"@a[x=0,y=9,z=6,r=7]","color":"dark_red"},{"text":" 恶意破坏,已自动修复","color":"red","bold":false}]

/setblock 0 9 6 minecraft:stone_button 4

-----------------------------------

检测按钮是否被按下

part1:

/testforblock 0 9 6 minecraft:stone_button 12

如果上指令检测成功,执行如下指令:

tellraw @a[tag=created,x=0,y=9,z=6,r=7] [{"selector":"@p","color":"gold"},{"text":" 您已经拥有地皮了,给别人留点位置吧!","color":"green"}]

execute @a[tag=created,x=0,y=9,z=6,r=7] ~ ~ ~ /setblock 0 9 6 minecraft:stone_button 4

part2:

/testforblock 0 9 6 minecraft:stone_button 12

如果上指令检测成功,执行如下指令:

/setblock 0 9 6 minecraft:air

/setblock 0 9 6 minecraft:stone_button 12

/setblock -2 9 10 redstone_block 0

----------------------------------基础探测部分—END

地皮随机创建以及检测

<font size="2">----------------------------------

初始化:

scoreboard players reset @a creating

scoreboard players set @p[x=0,y=9,z=6,r=7] creating -1

/blockdata -1 8 10 {auto:1b}

----------------------------------

判定随机取点处是否有足够空间,有则创建,无则重新随机取点

blockdata ~ ~ ~ {auto:0b}

scoreboard players set @a[score_creating_min=-2,score_creating=-2] creating -1

title @a[score_creating=-1] title [{"text":"甘小蔗正在拼命创建中...","color":"gold","bold":"true"}]

summon armor_stand ~ ~ ~ {CustomName:"ASdp",NoBasePlate:1,NoGravity:1,Invisible:1,Tags:["dptest"]}

spreadplayers ~ ~ 100 9999 false @e[type=armor_stand,name=ASdp,tag=dptest,c=1]

execute @e[type=armor_stand,name=ASdp,tag=dptest] ~ ~ ~ execute @e[type=armor_stand,name=ASdp,tag=dp,r=90] ~ ~ ~ scoreboard players set @a[score_creating_min=-1,score_creating=-1] creating -2

kill @e[type=armor_stand,name=ASdp,tag=dptest] (条件制约)

tellraw @a[score_creating_min=-2,score_creating=-2] ["",{"text":"[甘小蔗] ","color":"dark_green","bold":true},{"text":" 地皮创建失败。","color":"red","bold":true},{"text":"原因:随机地皮位置空间不足,正在尝试重新随机取点。","color":"red","bold":false}] (条件制约)

execute @a[score_creating_min=-1,score_creating=-1] ~ ~ ~ tp @p[r=0] @e[type=armor_stand,name=ASdp,tag=dptest]

execute @a[score_creating_min=-1,score_creating=-1] ~ ~ ~ /blockdata 0 8 10 {auto:1b}

execute @a[score_creating_min=-2,score_creating=-2] ~ ~ ~ /blockdata -1 8 10 {auto:1b}

----------------------------------

开始创建地皮:

blockdata ~ ~ ~ {auto:0b}

/scoreboard players set @a[score_creating_min=-1,score_creating=-1] creating 0

/scoreboard players tag @e[type=armor_stand,name=ASdp,tag=dptest] add dpsetting

/scoreboard players tag @e[type=armor_stand,name=ASdp,tag=dptest] add dp (防止极小几率的地皮重叠)

/scoreboard players tag @e[type=armor_stand,name=ASdp,tag=dptest] remove dptest

tellraw @a[score_creating_min=0,score_creating=0] ["",{"text":"[甘小蔗] ","color":"dark_green","bold":true},{"text":" 地皮创建成功!","color":"green","bold":true},{"text":"接下来,请按照提示依次输入您当前位置的坐标。(按下F3即可看到对应XYZ)","color":"green","bold":false}]

scoreboard players set @a[score_creating_min=0,score_creating=0] x 99999

scoreboard players set @a[score_creating_min=0,score_creating=0] y 99999

scoreboard players set @a[score_creating_min=0,score_creating=0] z 99999

scoreboard players enable @a[score_creating_min=0,score_creating=0] x

scoreboard players enable @a[score_creating_min=0,score_creating=0] y

scoreboard players enable @a[score_creating_min=0,score_creating=0] z

scoreboard players set @a[score_creating_min=0,score_creating=0] creating 1

setblock 0 9 6 minecraft:stone_button 4

/setblock -2 9 10 wool 5

----------------------------------地皮随机创建以及检测—END</font>

地皮XYZ设置引导:(为玩家执行返回领地命令做参数)[高频]

  ----------------------------------

execute @a[score_creating_min=1,score_creating=3] ~ ~ ~ tp @p[r=0] @p[r=0]

---

title @a[score_creating_min=1,score_creating=1,tag=!setx] actionbar [{"text":"请执行 ","color":"gold","bold":false},{"text":"/trigger x set 你目前X坐标","color":"gold","bold":"true"},{"text":" 来记录你的地皮位置","color":"gold","bold":false}]

title @a[score_creating_min=2,score_creating=2,tag=!sety] actionbar [{"text":"请执行 ","color":"gold","bold":false},{"text":"/trigger y set 你目前Y坐标","color":"gold","bold":"true"},{"text":" 来记录你的地皮位置","color":"gold","bold":false}]

title @a[score_creating_min=3,score_creating=3,tag=!setz] actionbar [{"text":"请执行 ","color":"gold","bold":false},{"text":"/trigger z set 你目前Z坐标","color":"gold","bold":"true"},{"text":" 来记录你的地皮位置","color":"gold","bold":false}]

---

scoreboard players tag @a[score_creating_min=1,score_creating=4,score_x_min=-10999,score_x=10999,tag=!setx] add setx

scoreboard players tag @a[score_creating_min=1,score_creating=4,score_y_min=0,score_y=255,tag=!sety] add sety

scoreboard players tag @a[score_creating_min=1,score_creating=4,score_z_min=-10999,score_z=10999,tag=!setz] add setz

判定玩家已全部设置:

scoreboard players set @a[score_creating_min=1,score_creating=3] creating 1

scoreboard players add @a[score_creating_min=1,score_creating=4,tag=setx] creating 1

scoreboard players add @a[score_creating_min=1,score_creating=4,tag=sety] creating 1

scoreboard players add @a[score_creating_min=1,score_creating=4,tag=setz] creating 1

/tellraw @a[score_creating_min=4,score_creating=4] [{"text":" 恭喜你! XYZ设置成功!","color":"green","bold":true}]

scoreboard players set @a[score_creating_min=4,score_creating=4] creating 9

地皮边界:

execute @e[type=armor_stand,name=ASdp,tag=dpsetting] ~ ~ ~ /fill ~-20 ~ ~-20 ~-20 ~ ~20 minecraft:stone_slab 0 replace air

execute @e[type=armor_stand,name=ASdp,tag=dpsetting] ~ ~ ~ /fill ~20 ~ ~-20 ~20 ~ ~20 minecraft:stone_slab 0 replace air

execute @e[type=armor_stand,name=ASdp,tag=dpsetting] ~ ~ ~ /fill ~-20 ~ ~20 ~20 ~ ~20 minecraft:stone_slab 0 replace air

execute @e[type=armor_stand,name=ASdp,tag=dpsetting] ~ ~ ~ /fill ~-20 ~ ~-20 ~20 ~ ~-20 minecraft:stone_slab 0 replace air

--------------------------地皮XYZ设置引导—END

地皮最后设置:[高频]

  tellraw @a[score_creating_min=9,score_creating=9] ["",{"text":"[甘小蔗] ","color":"dark_green","bold":true},{"text":" 甘小蔗正在为您完成最后设置...","color":"green","bold":true},{"text":"(在这之后,您可以随时联系OP重置您的XYZ参数)","color":"green","bold":false}]

execute @a[score_creating_min=9,score_creating=9] ~ ~ ~ scoreboard players tag @e[type=armor_stand,name=ASdp,tag=dpsetting,r=40,c=1] remove dpsetting

scoreboard players tag @a[score_creating_min=9,score_creating=9] add created

scoreboard players set @a[score_creating_min=9,score_creating=9] creating 10

地皮保护

地皮ID分配:(以检测玩家是否踏入他人领地)[高频]

创建实体:summon armor_stand ~ ~ ~ {CustomName:"dpIDStats"}

循环部分:

/scoreboard players add @a[score_creating_min=1,score_creating=1] dpID 0

/execute @a[score_creating_min=1,score_creating=1] ~ ~ ~ scoreboard players add @e[type=armor_stand,name=ASdp,tag=dpsetting,r=40,c=1] dpID 0

/execute @p[score_dpID_min=0,score_dpID=0] ~ ~ ~ scoreboard players add @e[type=armor_stand,name=dpIDStats] dpID 1

/execute @p[score_dpID_min=0,score_dpID=0] ~ ~ ~ scoreboard players operation @p[r=0] dpID = @e[type=armor_stand,name=dpIDStats] dpID

/execute @a[type=armor_stand,name=ASdp,tag=dpsetting,score_dpID=0] ~ ~ ~ scoreboard players operation @e[tag=dpsetting,r=0,c=1] dpID = @p[score_dpID_min=1,r=40] dpID

-----------------------------检测是否在他人地皮

scoreboard players reset @a dpper

scoreboard players add @a dpper 0

execute @e[type=armor_stand,name=ASdp,tag=tp] ~ ~ ~ scoreboard players operation @a[r=40] dpper = @e[tag=dp,r=0,c=1] dpID

execute @a[score_dpper_min=1] ~ ~ ~ scoreboard players operation @p[r=0] dpcache = @p[r=0] dpper

execute @a ~ ~ ~ scoreboard players operation @p[r=0] dpper -= @p[r=0] dpID

scoreboard players tag @a[score_dpper_min=0,score_dpper=0] add noton

execute @a[tag=!noton] ~ ~ ~ title @p[r=0] actionbar [{"text":"[甘小蔗] ","color":"dark_green","bold":true},{"selector":"@p[r=0]","color":"gold","bold":"true"},{"text":" 您正在编号为","color":"yellow","bold":true},{"score":{"name":"@p[score_dpcache_min=1]","objective":"dpcache"},"color":"gold","bold":"true"},{"text":"的地皮上","color":"yellow","bold":true}]

gamemode 2 @a[tag=!noton,m=0]

gamemode 0 @a[tag=noton,m=2]

联机侠

发表评论

您必须 登录 才能发表留言!