Minecraft(我的世界)中文论坛

 找回密码
 注册(register)
查看: 2149|回复: 32

[命令] 【CBL|SPG】精确方块穿透判定

[复制链接]
发表于 2018-8-4 20:24:28 | 显示全部楼层 |阅读模式

您尚未登录,立即登录享受更好的浏览体验!

您需要 登录 才可以下载或查看,没有帐号?注册(register)

x
本帖最后由 SPGoding 于 2018-8-8 00:22 编辑

目前常用的方块穿透判定,是把可穿透的方块 ID 写到一个 Block Tag 里,然后用 execute unless block ~ ~ ~ #foobar 来判定这个方块是否可穿透。
不过,这种做法其实是不准确的,例如台阶、楼梯、栅栏等方块,它们的模型并不是占据了一整个方块。于是本人编写了一个可复用的 Function 与相关 Tags。


                               
登录/注册后可看大图


                               
登录/注册后可看大图


                               
登录/注册后可看大图


spgoding:player_through
记录了所有可由玩家穿透的方块。
  1. {
  2.     "replace": false,
  3.     "values": [
  4.         "minecraft:oak_sapling",
  5.         "minecraft:spruce_sapling",
  6.         "minecraft:birch_sapling",
  7.         "minecraft:jungle_sapling",
  8.         "minecraft:acacia_sapling",
  9.         "minecraft:dark_oak_sapling",
  10.         "minecraft:tube_coral",
  11.         "minecraft:brain_coral",
  12.         "minecraft:bubble_coral",
  13.         "minecraft:fire_coral",
  14.         "minecraft:horn_coral",
  15.         "minecraft:tube_coral_fan",
  16.         "minecraft:brain_coral_fan",
  17.         "minecraft:bubble_coral_fan",
  18.         "minecraft:fire_coral_fan",
  19.         "minecraft:horn_coral_fan",
  20.         "minecraft:dead_tube_coral_fan",
  21.         "minecraft:dead_brain_coral_fan",
  22.         "minecraft:dead_bubble_coral_fan",
  23.         "minecraft:dead_fire_coral_fan",
  24.         "minecraft:dead_horn_coral_fan",
  25.         "minecraft:flower_pot",
  26.         "minecraft:potted_poppy",
  27.         "minecraft:potted_blue_orchid",
  28.         "minecraft:potted_allium",
  29.         "minecraft:potted_azure_bluet",
  30.         "minecraft:potted_red_tulip",
  31.         "minecraft:potted_orange_tulip",
  32.         "minecraft:potted_white_tulip",
  33.         "minecraft:potted_pink_tulip",
  34.         "minecraft:potted_oxeye_daisy",
  35.         "minecraft:potted_dandelion",
  36.         "minecraft:potted_oak_sapling",
  37.         "minecraft:potted_spruce_sapling",
  38.         "minecraft:potted_birch_sapling",
  39.         "minecraft:potted_jungle_sapling",
  40.         "minecraft:potted_acacia_sapling",
  41.         "minecraft:potted_dark_oak_sapling",
  42.         "minecraft:potted_red_mushroom",
  43.         "minecraft:potted_brown_mushroom",
  44.         "minecraft:potted_dead_bush",
  45.         "minecraft:potted_fern",
  46.         "minecraft:potted_cactus",
  47.         "minecraft:acacia_trapdoor",
  48.         "minecraft:birch_trapdoor",
  49.         "minecraft:dark_oak_trapdoor",
  50.         "minecraft:jungle_trapdoor",
  51.         "minecraft:oak_trapdoor",
  52.         "minecraft:spruce_trapdoor",
  53.         "minecraft:iron_trapdoor",
  54.         "minecraft:cobweb",
  55.         "minecraft:grass",
  56.         "minecraft:fern",
  57.         "minecraft:dead_bush",
  58.         "minecraft:seagrass",
  59.         "minecraft:sea_pickle",
  60.         "minecraft:sea_pickle",
  61.         "minecraft:poppy",
  62.         "minecraft:blue_orchid",
  63.         "minecraft:allium",
  64.         "minecraft:azure_bluet",
  65.         "minecraft:red_tulip",
  66.         "minecraft:orange_tulip",
  67.         "minecraft:white_tulip",
  68.         "minecraft:pink_tulip",
  69.         "minecraft:oxeye_daisy",
  70.         "minecraft:dandelion",
  71.         "minecraft:oak_sapling",
  72.         "minecraft:spruce_sapling",
  73.         "minecraft:birch_sapling",
  74.         "minecraft:jungle_sapling",
  75.         "minecraft:acacia_sapling",
  76.         "minecraft:dark_oak_sapling",
  77.         "minecraft:red_mushroom",
  78.         "minecraft:brown_mushroom",
  79.         "minecraft:dead_bush",
  80.         "minecraft:fern",
  81.         "minecraft:cactus",
  82.         "minecraft:torch",
  83.         "minecraft:end_rod",
  84.         "minecraft:ladder",
  85.         "minecraft:snow",
  86.         "minecraft:vine",
  87.         "minecraft:white_carpet",
  88.         "minecraft:orange_carpet",
  89.         "minecraft:magenta_carpet",
  90.         "minecraft:light_blue_carpet",
  91.         "minecraft:yellow_carpet",
  92.         "minecraft:lime_carpet",
  93.         "minecraft:pink_carpet",
  94.         "minecraft:gray_carpet",
  95.         "minecraft:light_gray_carpet",
  96.         "minecraft:cyan_carpet",
  97.         "minecraft:purple_carpet",
  98.         "minecraft:blue_carpet",
  99.         "minecraft:brown_carpet",
  100.         "minecraft:green_carpet",
  101.         "minecraft:red_carpet",
  102.         "minecraft:black_carpet",
  103.         "minecraft:sunflower",
  104.         "minecraft:lilac",
  105.         "minecraft:rose_bush",
  106.         "minecraft:peony",
  107.         "minecraft:tall_grass",
  108.         "minecraft:large_fern",
  109.         "minecraft:lever",
  110.         "minecraft:stone_pressure_plate",
  111.         "minecraft:oak_pressure_plate",
  112.         "minecraft:spruce_pressure_plate",
  113.         "minecraft:birch_pressure_plate",
  114.         "minecraft:jungle_pressure_plate",
  115.         "minecraft:acacia_pressure_plate",
  116.         "minecraft:dark_oak_pressure_plate",
  117.         "minecraft:light_weighted_pressure_plate",
  118.         "minecraft:heavy_weighted_pressure_plate",
  119.         "minecraft:redstone_torch",
  120.         "minecraft:stone_button",
  121.         "minecraft:oak_button",
  122.         "minecraft:spruce_button",
  123.         "minecraft:birch_button",
  124.         "minecraft:jungle_button",
  125.         "minecraft:acacia_button",
  126.         "minecraft:dark_oak_button",
  127.         "minecraft:daylight_detector",
  128.         "minecraft:repeater",
  129.         "minecraft:comparator",
  130.         "minecraft:redstone_wire",
  131.         "minecraft:powered_rail",
  132.         "minecraft:detector_rail",
  133.         "minecraft:rail",
  134.         "minecraft:activator_rail",
  135.         "minecraft:pumpkin_stem",
  136.         "minecraft:melon_stem",
  137.         "minecraft:carrots",
  138.         "minecraft:potatoes",
  139.         "minecraft:air",
  140.         "minecraft:water"
  141.     ]
  142. }
复制代码


spgoding:through
记录了所有可由子!弹穿透的方块。继承了上一个 Tag。
  1. {
  2.     "replace": false,
  3.     "values": [
  4.         "#spgoding:player_through",
  5.         "minecraft:acacia_fence",
  6.         "minecraft:birch_fence",
  7.         "minecraft:dark_oak_fence",
  8.         "minecraft:jungle_fence",
  9.         "minecraft:oak_fence",
  10.         "minecraft:spruce_fence",
  11.         "minecraft:acacia_fence_gate",
  12.         "minecraft:birch_fence_gate",
  13.         "minecraft:dark_oak_fence_gate",
  14.         "minecraft:jungle_fence_gate",
  15.         "minecraft:oak_fence_gate",
  16.         "minecraft:spruce_fence_gate",
  17.         "minecraft:iron_bars",
  18.         "minecraft:stone_slab",
  19.         "minecraft:stone_brick_slab",
  20.         "minecraft:sandstone_slab",
  21.         "minecraft:acacia_slab",
  22.         "minecraft:birch_slab",
  23.         "minecraft:dark_oak_slab",
  24.         "minecraft:jungle_slab",
  25.         "minecraft:oak_slab",
  26.         "minecraft:spruce_slab",
  27.         "minecraft:purpur_slab",
  28.         "minecraft:quartz_slab",
  29.         "minecraft:red_sandstone_slab",
  30.         "minecraft:brick_slab",
  31.         "minecraft:cobblestone_slab",
  32.         "minecraft:nether_brick_slab",
  33.         "minecraft:petrified_oak_slab",
  34.         "minecraft:prismarine_slab",
  35.         "minecraft:prismarine_brick_slab",
  36.         "minecraft:dark_prismarine_slab",
  37.         "minecraft:cobblestone_wall",
  38.         "minecraft:mossy_cobblestone_wall",
  39.         "minecraft:glass_pane",
  40.         "minecraft:white_stained_glass_pane",
  41.         "minecraft:orange_stained_glass_pane",
  42.         "minecraft:magenta_stained_glass_pane",
  43.         "minecraft:light_blue_stained_glass_pane",
  44.         "minecraft:yellow_stained_glass_pane",
  45.         "minecraft:lime_stained_glass_pane",
  46.         "minecraft:pink_stained_glass_pane",
  47.         "minecraft:gray_stained_glass_pane",
  48.         "minecraft:light_gray_stained_glass_pane",
  49.         "minecraft:cyan_stained_glass_pane",
  50.         "minecraft:purple_stained_glass_pane",
  51.         "minecraft:brown_stained_glass_pane",
  52.         "minecraft:green_stained_glass_pane",
  53.         "minecraft:red_stained_glass_pane",
  54.         "minecraft:black_stained_glass_pane"
  55.     ]
  56. }
复制代码


spgoding:solid_four_directions
记录了所有实心的、可有四个方向的模型拓展的方块。
  1. {
  2.     "replace": false,
  3.     "values": [
  4.         "minecraft:cobblestone_wall",
  5.         "minecraft:mossy_cobblestone_wall",
  6.         "minecraft:glass_pane",
  7.         "minecraft:white_stained_glass_pane",
  8.         "minecraft:orange_stained_glass_pane",
  9.         "minecraft:magenta_stained_glass_pane",
  10.         "minecraft:light_blue_stained_glass_pane",
  11.         "minecraft:yellow_stained_glass_pane",
  12.         "minecraft:lime_stained_glass_pane",
  13.         "minecraft:pink_stained_glass_pane",
  14.         "minecraft:gray_stained_glass_pane",
  15.         "minecraft:light_gray_stained_glass_pane",
  16.         "minecraft:cyan_stained_glass_pane",
  17.         "minecraft:purple_stained_glass_pane",
  18.         "minecraft:brown_stained_glass_pane",
  19.         "minecraft:green_stained_glass_pane",
  20.         "minecraft:red_stained_glass_pane",
  21.         "minecraft:black_stained_glass_pane"
  22.     ]
  23. }
复制代码


spgoding:is_hit
判定 Function 执行位置是否与方块撞击。
有 #####  注释的内容请在 18w31a 后启用
  1. # spgoding:is_hit
  2. # as A area_effect_cloud.
  3. # return @s spg_return
  4. #         0 - is not hitting any blocks
  5. #         1 - is hitting blocks

  6. # 获取 x 坐标小数点后 1 位
  7. summon minecraft:area_effect_cloud ~ ~ ~ {Duration:2,NoGravity:1b,Tags:["NEW"]}
  8. execute store result score $x spg_mw_tmp run data get entity @e[tag=NEW,limit=1,distance=..1,sort=nearest] Pos[0] 10
  9. scoreboard players operation $x_after_dot spg_mw_tmp = $x spg_mw_tmp
  10. scoreboard players operation $x_after_dot spg_mw_tmp %= 10 const
  11. ##### execute if score $x spg_mw_tmp matches ..-1 run scoreboard players operation $x_after_dot spg_mw_tmp *= -1 const
  12. kill @e[tag=NEW]
  13. # 获取 y 坐标小数点后 1 位
  14. summon minecraft:area_effect_cloud ~ ~ ~ {Duration:2,NoGravity:1b,Tags:["NEW"]}
  15. execute store result score $y spg_mw_tmp run data get entity @e[tag=NEW,limit=1,distance=..1,sort=nearest] Pos[1] 10
  16. scoreboard players operation $y_after_dot spg_mw_tmp = $y spg_mw_tmp
  17. scoreboard players operation $y_after_dot spg_mw_tmp %= 10 const
  18. kill @e[tag=NEW]
  19. # 获取 z 坐标小数点后 1 位
  20. summon minecraft:area_effect_cloud ~ ~ ~ {Duration:2,NoGravity:1b,Tags:["NEW"]}
  21. execute store result score $z spg_mw_tmp run data get entity @e[tag=NEW,limit=1,distance=..1,sort=nearest] Pos[2] 10
  22. scoreboard players operation $z_after_dot spg_mw_tmp = $z spg_mw_tmp
  23. scoreboard players operation $z_after_dot spg_mw_tmp %= 10 const
  24. ##### execute if score $z spg_mw_tmp matches ..-1 run scoreboard players operation $z_after_dot spg_mw_tmp *= -1 const
  25. kill @e[tag=NEW]

  26. execute unless block ~ ~ ~ #spgoding:through run scoreboard players set @s spg_return 1

  27. execute if block ~ ~ ~ #spgoding:through run scoreboard players set @s spg_return 0
  28. execute if block ~ ~ ~ #minecraft:slabs[type=bottom] if score $y_after_dot spg_mw_tmp matches 1..4 run scoreboard players set @s spg_return 1
  29. execute if block ~ ~ ~ #minecraft:slabs[type=top] if score $y_after_dot spg_mw_tmp matches 6..9 run scoreboard players set @s spg_return 1
  30. execute if block ~ ~ ~ #minecraft:slabs[type=double] run scoreboard players set @s spg_return 1

  31. execute if block ~ ~ ~ #spgoding:solid_four_directions[east=true] if score $x_after_dot spg_mw_tmp matches 6..9 run scoreboard players set @s spg_return 1
  32. execute if block ~ ~ ~ #spgoding:solid_four_directions[east=true] if score $x_after_dot spg_mw_tmp matches -4..-1 run scoreboard players set @s spg_return 1
  33. execute if block ~ ~ ~ #spgoding:solid_four_directions[west=true] if score $x_after_dot spg_mw_tmp matches 1..4 run scoreboard players set @s spg_return 1
  34. execute if block ~ ~ ~ #spgoding:solid_four_directions[west=true] if score $x_after_dot spg_mw_tmp matches -9..-6 run scoreboard players set @s spg_return 1
  35. execute if block ~ ~ ~ #spgoding:solid_four_directions[south=true] if score $z_after_dot spg_mw_tmp matches 6..9 run scoreboard players set @s spg_return 1
  36. execute if block ~ ~ ~ #spgoding:solid_four_directions[south=true] if score $z_after_dot spg_mw_tmp matches -4..-1 run scoreboard players set @s spg_return 1
  37. execute if block ~ ~ ~ #spgoding:solid_four_directions[north=true] if score $z_after_dot spg_mw_tmp matches 1..4 run scoreboard players set @s spg_return 1
  38. execute if block ~ ~ ~ #spgoding:solid_four_directions[north=true] if score $z_after_dot spg_mw_tmp matches -9..-6 run scoreboard players set @s spg_return 1

  39. execute if block ~ ~ ~ #minecraft:stairs[facing=north,half=bottom] if score $z_after_dot spg_mw_tmp matches 5..9 if score $y_after_dot spg_mw_tmp matches 5..9 run scoreboard players set @s spg_return 0
  40. execute if block ~ ~ ~ #minecraft:stairs[facing=north,half=bottom] if score $z_after_dot spg_mw_tmp matches -5..0 if score $y_after_dot spg_mw_tmp matches 5..9 run scoreboard players set @s spg_return 0
  41. execute if block ~ ~ ~ #minecraft:stairs[facing=north,half=top] if score $z_after_dot spg_mw_tmp matches 5..9 if score $y_after_dot spg_mw_tmp matches 0..5 run scoreboard players set @s spg_return 0
  42. execute if block ~ ~ ~ #minecraft:stairs[facing=north,half=top] if score $z_after_dot spg_mw_tmp matches -5..0 if score $y_after_dot spg_mw_tmp matches 0..5 run scoreboard players set @s spg_return 0
  43. execute if block ~ ~ ~ #minecraft:stairs[facing=south,half=bottom] if score $z_after_dot spg_mw_tmp matches 0..5 if score $y_after_dot spg_mw_tmp matches 5..9 run scoreboard players set @s spg_return 0
  44. execute if block ~ ~ ~ #minecraft:stairs[facing=south,half=bottom] if score $z_after_dot spg_mw_tmp matches -9..-5 if score $y_after_dot spg_mw_tmp matches 5..9 run scoreboard players set @s spg_return 0
  45. execute if block ~ ~ ~ #minecraft:stairs[facing=south,half=top] if score $z_after_dot spg_mw_tmp matches 0..5 if score $y_after_dot spg_mw_tmp matches 0..5 run scoreboard players set @s spg_return 0
  46. execute if block ~ ~ ~ #minecraft:stairs[facing=south,half=top] if score $z_after_dot spg_mw_tmp matches -9..-5 if score $y_after_dot spg_mw_tmp matches 0..5 run scoreboard players set @s spg_return 0
  47. execute if block ~ ~ ~ #minecraft:stairs[facing=west,half=bottom] if score $x_after_dot spg_mw_tmp matches 5..9 if score $y_after_dot spg_mw_tmp matches 5..9 run scoreboard players set @s spg_return 0
  48. execute if block ~ ~ ~ #minecraft:stairs[facing=west,half=bottom] if score $x_after_dot spg_mw_tmp matches -5..0 if score $y_after_dot spg_mw_tmp matches 5..9 run scoreboard players set @s spg_return 0
  49. execute if block ~ ~ ~ #minecraft:stairs[facing=west,half=top] if score $x_after_dot spg_mw_tmp matches 5..9 if score $y_after_dot spg_mw_tmp matches 0..5 run scoreboard players set @s spg_return 0
  50. execute if block ~ ~ ~ #minecraft:stairs[facing=west,half=top] if score $x_after_dot spg_mw_tmp matches -5..0 if score $y_after_dot spg_mw_tmp matches 0..5 run scoreboard players set @s spg_return 0
  51. execute if block ~ ~ ~ #minecraft:stairs[facing=east,half=bottom] if score $x_after_dot spg_mw_tmp matches 0..5 if score $y_after_dot spg_mw_tmp matches 5..9 run scoreboard players set @s spg_return 0
  52. execute if block ~ ~ ~ #minecraft:stairs[facing=east,half=bottom] if score $x_after_dot spg_mw_tmp matches -9..-5 if score $y_after_dot spg_mw_tmp matches 5..9 run scoreboard players set @s spg_return 0
  53. execute if block ~ ~ ~ #minecraft:stairs[facing=east,half=top] if score $x_after_dot spg_mw_tmp matches 0..5 if score $y_after_dot spg_mw_tmp matches 1..5 run scoreboard players set @s spg_return 0
  54. execute if block ~ ~ ~ #minecraft:stairs[facing=east,half=top] if score $x_after_dot spg_mw_tmp matches -9..-5 if score $y_after_dot spg_mw_tmp matches 1..5 run scoreboard players set @s spg_return 0
复制代码


无损升级方法:让递归函数以一个 aec marker(或其他 marker)的身份执行,在原先 execute unless block ~ ~ ~ #through 的位置之前加入 function spgoding:hit,并把后文 execute unless block ~ ~ ~ #through 改为 execute if score @s spg_return 1, execute if block ~ ~ ~ #through 改为 execute if score @s spg_return 0。





来自群组: Command Block Logic

评分

参与人数 4人气 +8 金粒 +40 收起 理由
橘子冰 + 1 MCBBS有你更精彩~
玄素 + 3 + 40 MCBBS有你更精彩~
ruhuasiyu + 2 神乎其技,不服不行!
wangtianen + 2 好奇心让我展开的[/w\]

查看全部评分

发表于 2018-8-4 21:00:10 | 显示全部楼层
火把,玻璃,铁栏杆什么的都有吗?
回复

使用道具 举报

 楼主| 发表于 2018-8-4 21:03:51 | 显示全部楼层
本帖最后由 SPGoding 于 2018-8-5 01:20 编辑
ruhuasiyu 发表于 2018-8-5 01:00
火把,玻璃,铁栏杆什么的都有吗?

我看火把那弱不禁风的样子就把它直接归为可穿透了【跑
玻璃、铁栏杆是正确的
回复

使用道具 举报

发表于 2018-8-4 22:32:22 | 显示全部楼层
SPGoding 发表于 2018-8-4 21:03
我看火把那弱不禁风的样子就把它直接归为可穿透了【跑
玻璃、铁栏杆是正确的 ...

不过火把反正没碰撞箱就是喽
回复

使用道具 举报

发表于 2018-8-4 22:59:13 | 显示全部楼层
夸爆,穿透方块完全体
回复

使用道具 举报

发表于 2018-8-5 07:54:01 | 显示全部楼层
大佬大佬(虽然我到现在也不明白1.13的函数是怎么回事)
回复

使用道具 举报

发表于 2018-8-5 20:02:47 来自手机 | 显示全部楼层
我想的获取方块内位置方法是先偏移再对齐(都是execute有的能力)

评分

参与人数 1人气 +2 收起 理由
SPGoding + 2 神乎其技,不服不行!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2018-8-5 20:17:01 | 显示全部楼层
本帖最后由 SPGoding 于 2018-8-6 02:09 编辑
chyx 发表于 2018-8-6 00:02
我想的获取方块内位置方法是先偏移再对齐(都是execute有的能力)

wdm!
原来还能这么用,我一直都是忽视了对齐那个功能的…

Edit:啊啊啊啊啊我好丢人啊啊啊啊啊啊 啊啊啊啊啊啊
回复

使用道具 举报

发表于 2018-8-5 22:00:02 | 显示全部楼层
SPGoding 发表于 2018-8-5 20:17
wdm!
原来还能这么用,我一直都是忽视了对齐那个功能的…

偏移再对齐不还是要获取坐标么?难道变方便了?

评分

参与人数 1人气 +1 收起 理由
SPGoding + 1 毫无主见.spg

查看全部评分

回复

使用道具 举报

发表于 2018-8-6 02:30:34 | 显示全部楼层
顶!    顶!    顶!    顶!   顶!    顶!    顶!    顶!  

评分

参与人数 1人气 -2 金粒 -20 收起 理由
Zero_Exact -2 -20 灌水

查看全部评分

回复

使用道具 举报

发表于 2018-8-6 11:14:37 | 显示全部楼层
ruhuasiyu 发表于 2018-8-5 22:00
偏移再对齐不还是要获取坐标么?难道变方便了?

我想的是比如我已经知道了这个格子是一个下半砖 我先向下0.5再y对齐 如果和y对齐在同一个地方之类的……
回复

使用道具 举报

发表于 2018-8-6 11:23:48 | 显示全部楼层
chyx 发表于 2018-8-6 11:14
我想的是比如我已经知道了这个格子是一个下半砖 我先向下0.5再y对齐 如果和y对齐在同一个地方之类的…… ...

比较y并没有比get y方便多少啊……
回复

使用道具 举报

发表于 2018-8-6 15:28:48 | 显示全部楼层
看不懂都是大佬
回复

使用道具 举报

发表于 2018-8-6 20:48:35 | 显示全部楼层
大佬,大佬。楼主辛苦了。这是枪战地图的福音
回复

使用道具 举报

发表于 2018-8-6 21:06:49 | 显示全部楼层
666666666666666666666

评分

参与人数 1人气 -1 金粒 -10 收起 理由
玄素 -1 -10 无意义

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册(register)

本版积分规则

Archiver|小黑屋|Mcbbs.net ( 京ICP备15023768号-1 ) | 手机版本

GMT+8, 2018-11-15 04:33 , Processed in 0.115454 second(s), 22 queries , Memcache On.

"Minecraft"以及"我的世界"为Mojang Synergies AB的商标。本站与Mojang以及微软公司没有从属关系。

© 2010-2019 我的世界中文论坛 版权所有。本站原创图文内容版权属于原创作者,未经许可不得转载。

快速回复 返回顶部 返回列表