我们今天在模组中实现一个传送门,让我们可以传送到自己的维度中。(文末附数据包下载链接)
1.在src\main\resources\data
中新建一个我们的传送门的数据包re8portals
:
2.在re8portals
包中新建三个文件夹:functions
、predicates
、tags
。
3.在tags包中新建一个blocks文件夹
blocks中新建activation包 -> 包中新建一个以我们的维度名称命名的类re8_dimension
:
re8_dimension.json
{
"replace": false,
"values": [
# 什么方块可以激活传送门
"minecraft:water"
]
}
blocks中新建frame包 -> 包中新建一个以我们的维度名称命名的类re8_dimension
:
re8_dimension.json
{
"replace": false,
"values": [
# 什么方块可以搭传送门(命名格式为你的modid:方块名称,原版为minecraft:方块名称)
"re8joymod:dhands_block"
]
}
blocks中新建portal包 -> 包中新建一个以我们的维度名称命名的类re8_dimension
:
re8_dimension.json
{
"replace": false,
"values": [
# 这个为传送判定,不用修改
"minecraft:moving_piston"
]
}
blocks中新建air文件
air.json
{
"replace": false,
"values": [
# 判定传送门中的合法空气方块
"minecraft:air",
"minecraft:cave_air",
"minecraft:void_air"
]
}
4.在predicates包中新建dimensions包 -> dimensions包中新建一个以我们维度命名的文件:
re8_dimension.json
{
"condition": "minecraft:location_check",
"predicate": {
# 命名:你的modid:你模组中的维度
"dimension": "re8joymod:re8_dimension"
}
}
此外,还需在dimensions
包中将原版三个维度的文件创建出来:
overworld.json
{
"condition": "minecraft:location_check",
"predicate": {
"dimension": "minecraft:overworld"
}
}
the_nether.json
{
"condition": "minecraft:location_check",
"predicate": {
"dimension": "minecraft:the_nether"
}
}
the_end.json
{
"condition": "minecraft:location_check",
"predicate": {
"dimension": "minecraft:the_end"
}
}
在predicates包中新建travellers包 -> 包中新建all_mobs
文件,说明什么动物可以穿过该传送门:
all_mobs.json
{
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:alternative",
"terms": [
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:area_effect_cloud"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:armor_stand"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:arrow"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:boat"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:dragon_fireball"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:egg"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:end_crystal"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:ender_dragon"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:ender_pearl"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:evoker_fangs"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:experience_bottle"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:experience_orb"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:eye_of_ender"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:falling_block"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:fireball"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:firework_rocket"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:fishing_bobber"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:glow_item_frame"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:item_frame"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:leash_knot"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:lightning_bolt"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:llama_spit"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:marker"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:painting"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:potion"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:shulker_bullet"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:small_fireball"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:snowball"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:spectral_arrow"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:tnt"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:trident"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:wither"
}
},
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"nbt": "{\"Tags\":[\"re8portals_blocked\"]}"
}
}
]
}
}
travellers包新建blocked
文件,说明带有什么nbt标签的生物进不去传送门
blocked.json
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"nbt": "{\"Tags\":[\"re8portals_blocked\"]}"
}
}
5.在functions包中新建load.mcfunction
文件,用于查看我们的传送门冷却时间等参数:
load.mcfunction
scoreboard objectives add re8_dimension_portal_activation_check minecraft.used:water_bucket
scoreboard objectives add player_reach_range dummy
scoreboard objectives add re8portals_timer dummy
scoreboard objectives add re8portals_cooldown dummy
在functions包中新建tick.mcfunction
文件,用于查看我们是否可以进行传送:
tick.mcfunction
scoreboard players set @a player_reach_range 13
execute as @a[scores={re8_dimension_portal_activation_check=1..},predicate=re8portals:dimensions/overworld] at @s rotated as @s anchored eyes run function re8portals:activate/locate_block/re8_dimension
execute as @a[scores={re8_dimension_portal_activation_check=1..},predicate=re8portals:dimensions/re8_dimension] at @s rotated as @s anchored eyes run function re8portals:activate/locate_block/re8_dimension
scoreboard players set @a re8_dimension_portal_activation_check 0
function re8portals:run/main/re8_dimension
execute as @e[predicate=re8portals:travellers/all_mobs] unless score @s re8portals_cooldown = @s re8portals_cooldown run scoreboard players set @s re8portals_cooldown 0
execute as @e[predicate=re8portals:travellers/all_mobs,scores={re8portals_cooldown=1..}] unless entity @e[type=armor_stand,tag=re8portals_portal_stand,distance=...5] run scoreboard players remove @s re8portals_cooldown 1
在functions包中新建timer.mcfunction
文件,对我们当前进行计时:
timer.mcfunction
scoreboard players add #re8portals_timer re8portals_timer 1
execute if score #re8portals_timer re8portals_timer matches 10.. run scoreboard players set #re8portals_timer re8portals_timer 0
在functions包中新建run
包 -> run
包中新建main
包 -> main
包中新建以我们维度名称命名的功能文件re8_dimension.mcfunction
re8_dimension.mcfunction
# If there's an entity in the portal, load the other dimension to check if there's a portal
execute as @e[type=armor_stand,tag=wabportals_aether_portal_stand,predicate=re8portals:dimensions/overworld] at @s if entity @e[predicate=re8portals:travellers/all_mobs,distance=..0.5,scores={re8portals_cooldown=0}] as @e[type=marker,tag=re8portals_re8_dimension_marker,sort=nearest,limit=1] in re8joymod:re8_dimension run forceload add ~5 ~5 ~-5 ~-5
execute as @e[type=armor_stand,tag=wabportals_aether_portal_stand,predicate=re8portals:dimensions/re8_dimension] at @s if entity @e[predicate=re8portals:travellers/all_mobs,distance=..0.5,scores={re8portals_cooldown=0}] as @e[type=marker,tag=re8portals_re8_dimension_marker,sort=nearest,limit=1] in minecraft:overworld run forceload add ~5 ~5 ~-5 ~-5
# If there is a portal in the other dimension, tp the player
execute as @e[type=armor_stand,tag=wabportals_aether_portal_stand,predicate=re8portals:dimensions/overworld] at @s if entity @e[predicate=re8portals:travellers/all_mobs,distance=..0.5,scores={re8portals_cooldown=0}] as @e[type=marker,sort=nearest,limit=1,tag=re8portals_re8_dimension_marker] at @s in re8joymod:re8_dimension if entity @e[type=marker,tag=re8portals_re8_dimension_marker,predicate=re8portals:dimensions/re8_dimension,distance=..384] in minecraft:overworld as @e[predicate=re8portals:travellers/all_mobs,predicate=re8portals:dimensions/overworld,distance=...5,scores={re8portals_cooldown=0}] at @s run function re8portals:run/teleport/re8_dimension/dim1
execute as @e[type=armor_stand,tag=wabportals_aether_portal_stand,predicate=re8portals:dimensions/re8_dimension] at @s if entity @e[predicate=re8portals:travellers/all_mobs,distance=..0.5,scores={re8portals_cooldown=0}] as @e[type=marker,sort=nearest,limit=1,tag=re8portals_re8_dimension_marker] at @s in minecraft:overworld if entity @e[type=marker,tag=re8portals_re8_dimension_marker,predicate=re8portals:dimensions/overworld,distance=..384] in re8joymod:re8_dimension as @e[predicate=re8portals:travellers/all_mobs,predicate=re8portals:dimensions/re8_dimension,distance=...5,scores={re8portals_cooldown=0}] at @s run function re8portals:run/teleport/re8_dimension/dim2
# Make a portal if there isn't one
execute as @e[type=armor_stand,tag=wabportals_aether_portal_stand,predicate=re8portals:dimensions/overworld] at @s if entity @e[predicate=re8portals:travellers/all_mobs,distance=..0.5,scores={re8portals_cooldown=0}] as @e[type=marker,sort=nearest,limit=1,tag=re8portals_re8_dimension_marker] at @s in re8joymod:re8_dimension unless entity @e[type=marker,tag=re8portals_re8_dimension_marker,predicate=re8portals:dimensions/re8_dimension,distance=..384] align xyz run function re8portals:run/create_alternate/re8_dimension/dim1
execute as @e[type=armor_stand,tag=wabportals_aether_portal_stand,predicate=re8portals:dimensions/re8_dimension] at @s if entity @e[predicate=re8portals:travellers/all_mobs,distance=..0.5,scores={re8portals_cooldown=0}] as @e[type=marker,sort=nearest,limit=1,tag=re8portals_re8_dimension_marker] at @s in minecraft:overworld unless entity @e[type=marker,tag=re8portals_re8_dimension_marker,predicate=re8portals:dimensions/overworld,distance=..384] align xyz run function re8portals:run/create_alternate/re8_dimension/dim2
# Check if any portals got broken, and if so, close them.
execute as @e[type=marker,tag=re8portals_re8_dimension_marker_z] at @s run function re8portals:run/check_if_broken/re8_dimension/z
execute as @e[type=marker,tag=re8portals_re8_dimension_marker_x] at @s run function re8portals:run/check_if_broken/re8_dimension/x
run
包中新建create_alternate
包 -> 包中新建我们的维度包re8_dimension
-> 包中新建两个功能类,一个是
dim1.mcfunction
,一个是dim2.mcfunction
,用于创建两个维度的传送门。
dim1.mcfunction
fill ~2 ~-1 ~ ~-1 ~3 ~ re8joymod:dhands_block
fill ~ ~ ~ ~1 ~2 ~ minecraft:moving_piston
# Summon armor stands for portal blocks
summon armor_stand ~.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.5 ~1 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~1 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.5 ~2 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:panic_rose",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~2 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:panic_rose",Count:1b,tag:{CustomModelData:286000}}]}
# Summon the marker to make the portal work
summon marker ~.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,Tags:["re8portals_re8_dimension_marker","re8portals_re8_dimension_marker_x"]}
# Play a portal opening sound (OPTIONAL)
playsound minecraft:block.end_portal.spawn master @a ~ ~ ~ 15 1
# Get rid of everything unnecessary
forceload remove ~-10 ~-10 ~10 ~10
dim2.mcfunction
# Make the portal frame itself
fill ~2 ~-1 ~ ~-1 ~3 ~ re8joymod:dhands_block
fill ~ ~ ~ ~1 ~2 ~ minecraft:moving_piston
# Summon armor stands for portal blocks
summon armor_stand ~.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.5 ~1 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~1 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.5 ~2 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:panic_rose",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~2 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:panic_rose",Count:1b,tag:{CustomModelData:286000}}]}
# Summon the marker to make the portal work
summon marker ~.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,Tags:["re8portals_re8_dimension_marker","re8portals_re8_dimension_marker_x"]}
# Play a portal opening sound (OPTIONAL)
playsound minecraft:block.end_portal.spawn master @a ~ ~ ~ 15 1
# Get rid of everything unnecessary
forceload remove ~-10 ~-10 ~10 ~10
run
包中新建teleport
包 -> 包中新建我们的维度包re8_dimension
-> 包中新建两个功能类,一个是
dim1.mcfunction
,一个是dim2.mcfunction
,用于在两个维度之间实现传送。
dim1.mcfunction
# 执行从主世界中传送到我们的维度的指令,这里要修改为你的modid:你的维度
execute in re8joymod:re8_dimension run teleport @s ~ ~ ~
scoreboard players set @s re8portals_cooldown 300
execute in re8joymod:re8_dimension run forceload remove ~5 ~5 ~-5 ~-5
execute in minecraft:overworld run forceload remove ~5 ~5 ~-5 ~-5
dim2.mcfunction
# 从我们的维度传送回主世界
execute in minecraft:overworld run teleport @s ~ ~ ~
scoreboard players set @s re8portals_cooldown 300
execute in re8joymod:re8_dimension run forceload remove ~5 ~5 ~-5 ~-5
execute in minecraft:overworld run forceload remove ~5 ~5 ~-5 ~-5
run
包中新建check_if_broken
包 -> 包中新建我们的维度包re8_dimension
-> 包中新建两个功能类,一个是
x.mcfunction
,一个是z.mcfunction
,用于判断两个维度的传送门是否损坏。
x.mcfunction
# 判断东西方向是否损坏
execute if block ~ ~-1 ~ #re8portals:frame/re8_dimension if block ~1 ~-1 ~ #re8portals:frame/re8_dimension if block ~2 ~ ~ #re8portals:frame/re8_dimension if block ~-1 ~ ~ #re8portals:frame/re8_dimension if block ~2 ~1 ~ #re8portals:frame/re8_dimension if block ~-1 ~1 ~ #re8portals:frame/re8_dimension if block ~2 ~2 ~ #re8portals:frame/re8_dimension if block ~-1 ~2 ~ #re8portals:frame/re8_dimension if block ~ ~3 ~ #re8portals:frame/re8_dimension if block ~1 ~3 ~ #re8portals:frame/re8_dimension if block ~1 ~ ~ #re8portals:portal/re8_dimension if block ~ ~1 ~ #re8portals:portal/re8_dimension if block ~1 ~1 ~ #re8portals:portal/re8_dimension if block ~ ~2 ~ #re8portals:portal/re8_dimension if block ~1 ~2 ~ #re8portals:portal/re8_dimension run tag @s add unbroken
# If it was, kill all the portal block armor stands
execute as @s[tag=!unbroken] positioned ~ ~ ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~ ~1 ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~ ~2 ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~1 ~ ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~1 ~1 ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~1 ~2 ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
# If it was, destroy all the portal blocks (OPTIONAL if you just used air)
execute as @s[tag=!unbroken] run fill ~ ~ ~ ~1 ~2 ~ air replace #re8portals:portal/re8_dimension
# If it was, play a portal breaking sound (OPTIONAL)
execute as @s[tag=!unbroken] positioned ~ ~ ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~ ~1 ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~ ~2 ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~1 ~ ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~1 ~1 ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~1 ~2 ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
# If it was, kill the marker to fully delete the portal
execute as @s[tag=!unbroken] run kill @s
# If it wasn't broken, remove the unbroken tag so that it can be checked again
execute as @s[tag=unbroken] run tag @s remove unbroken
z.mcfunction
# 判断南北方向是否损坏
execute if block ~ ~-1 ~ #re8portals:frame/re8_dimension if block ~ ~-1 ~1 #re8portals:frame/re8_dimension if block ~ ~ ~-1 #re8portals:frame/re8_dimension if block ~ ~ ~2 #re8portals:frame/re8_dimension if block ~ ~1 ~-1 #re8portals:frame/re8_dimension if block ~ ~1 ~2 #re8portals:frame/re8_dimension if block ~ ~2 ~-1 #re8portals:frame/re8_dimension if block ~ ~2 ~2 #re8portals:frame/re8_dimension if block ~ ~3 ~ #re8portals:frame/re8_dimension if block ~ ~3 ~1 #re8portals:frame/re8_dimension if block ~ ~ ~1 #re8portals:portal/re8_dimension if block ~ ~1 ~ #re8portals:portal/re8_dimension if block ~ ~1 ~1 #re8portals:portal/re8_dimension if block ~ ~2 ~ #re8portals:portal/re8_dimension if block ~ ~2 ~1 #re8portals:portal/re8_dimension run tag @s add unbroken
# If it was, kill all the portal block armor stands (OPTIONAL if you didn't add these in the create file)
execute as @s[tag=!unbroken] positioned ~ ~ ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~ ~1 ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~ ~2 ~ run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~ ~ ~1 run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~ ~1 ~1 run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
execute as @s[tag=!unbroken] positioned ~ ~2 ~1 run kill @e[distance=..0.5,type=armor_stand,tag=wabportals_aether_portal_stand]
# If it was, destroy all the portal blocks (OPTIONAL if you just used air)
execute as @s[tag=!unbroken] run fill ~ ~ ~ ~ ~2 ~1 air replace #re8portals:portal/re8_dimension
# If it was, play a portal breaking sound (OPTIONAL)
execute as @s[tag=!unbroken] positioned ~ ~ ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~ ~1 ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~ ~2 ~ run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~ ~ ~1 run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~ ~1 ~1 run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
execute as @s[tag=!unbroken] positioned ~ ~2 ~1 run playsound minecraft:block.glass.break master @a ~ ~ ~ 15 1
# If it was, kill the marker to fully delete the portal
execute as @s[tag=!unbroken] run kill @s
# If it wasn't broken, remove the unbroken tag so that it can be checked again
execute as @s[tag=unbroken] run tag @s remove unbroken
在functions包中新建activate
包 -> activate
包中新建check_frame
包 -> check_frame
包中新建以我们维度名称命名的包re8_dimension
-> 包中新建三个功能文件bottom.mcfunction
、mid.mcfunction
、top.mcfunction
bottom.mcfunction
# 查看我们传送门底部是否有对应的方块
# North
execute if block ~ ~-1 ~ #re8portals:frame/re8_dimension if block ~ ~-1 ~1 #re8portals:frame/re8_dimension if block ~ ~ ~-1 #re8portals:frame/re8_dimension if block ~ ~ ~2 #re8portals:frame/re8_dimension if block ~ ~1 ~-1 #re8portals:frame/re8_dimension if block ~ ~1 ~2 #re8portals:frame/re8_dimension if block ~ ~2 ~-1 #re8portals:frame/re8_dimension if block ~ ~2 ~2 #re8portals:frame/re8_dimension if block ~ ~3 ~ #re8portals:frame/re8_dimension if block ~ ~3 ~1 #re8portals:frame/re8_dimension if block ~ ~ ~1 #re8portals:air if block ~ ~1 ~ #re8portals:air if block ~ ~1 ~1 #re8portals:air if block ~ ~2 ~ #re8portals:air if block ~ ~2 ~1 #re8portals:air positioned ~ ~ ~ align xyz run function re8portals:activate/create/re8_dimension/z
# South
execute if block ~ ~-1 ~ #re8portals:frame/re8_dimension if block ~ ~-1 ~-1 #re8portals:frame/re8_dimension if block ~ ~ ~-2 #re8portals:frame/re8_dimension if block ~ ~ ~1 #re8portals:frame/re8_dimension if block ~ ~1 ~-2 #re8portals:frame/re8_dimension if block ~ ~1 ~1 #re8portals:frame/re8_dimension if block ~ ~2 ~-2 #re8portals:frame/re8_dimension if block ~ ~2 ~1 #re8portals:frame/re8_dimension if block ~ ~3 ~ #re8portals:frame/re8_dimension if block ~ ~3 ~-1 #re8portals:frame/re8_dimension if block ~ ~ ~-1 #re8portals:air if block ~ ~1 ~ #re8portals:air if block ~ ~1 ~-1 #re8portals:air if block ~ ~2 ~ #re8portals:air if block ~ ~2 ~-1 #re8portals:air positioned ~ ~ ~-1 align xyz run function re8portals:activate/create/re8_dimension/z
# East
execute if block ~ ~-1 ~ #re8portals:frame/re8_dimension if block ~-1 ~-1 ~ #re8portals:frame/re8_dimension if block ~1 ~ ~ #re8portals:frame/re8_dimension if block ~-2 ~ ~ #re8portals:frame/re8_dimension if block ~1 ~1 ~ #re8portals:frame/re8_dimension if block ~-2 ~1 ~ #re8portals:frame/re8_dimension if block ~1 ~2 ~ #re8portals:frame/re8_dimension if block ~-2 ~2 ~ #re8portals:frame/re8_dimension if block ~ ~3 ~ #re8portals:frame/re8_dimension if block ~-1 ~3 ~ #re8portals:frame/re8_dimension if block ~-1 ~ ~ #re8portals:air if block ~ ~1 ~ #re8portals:air if block ~-1 ~1 ~ #re8portals:air if block ~ ~2 ~ #re8portals:air if block ~-1 ~2 ~ #re8portals:air positioned ~-1 ~ ~ align xyz run function re8portals:activate/create/re8_dimension/x
# West
execute if block ~ ~-1 ~ #re8portals:frame/re8_dimension if block ~1 ~-1 ~ #re8portals:frame/re8_dimension if block ~2 ~ ~ #re8portals:frame/re8_dimension if block ~-1 ~ ~ #re8portals:frame/re8_dimension if block ~2 ~1 ~ #re8portals:frame/re8_dimension if block ~-1 ~1 ~ #re8portals:frame/re8_dimension if block ~2 ~2 ~ #re8portals:frame/re8_dimension if block ~-1 ~2 ~ #re8portals:frame/re8_dimension if block ~ ~3 ~ #re8portals:frame/re8_dimension if block ~1 ~3 ~ #re8portals:frame/re8_dimension if block ~1 ~ ~ #re8portals:air if block ~ ~1 ~ #re8portals:air if block ~1 ~1 ~ #re8portals:air if block ~ ~2 ~ #re8portals:air if block ~1 ~2 ~ #re8portals:air positioned ~ ~ ~ align xyz run function re8portals:activate/create/re8_dimension/x
mid.mcfunction
# 查看我们传送门中部是否有对应的方块
# North
execute if block ~ ~-2 ~ #re8portals:frame/re8_dimension if block ~ ~-2 ~1 #re8portals:frame/re8_dimension if block ~ ~-1 ~-1 #re8portals:frame/re8_dimension if block ~ ~-1 ~2 #re8portals:frame/re8_dimension if block ~ ~ ~-1 #re8portals:frame/re8_dimension if block ~ ~ ~2 #re8portals:frame/re8_dimension if block ~ ~1 ~-1 #re8portals:frame/re8_dimension if block ~ ~1 ~2 #re8portals:frame/re8_dimension if block ~ ~2 ~ #re8portals:frame/re8_dimension if block ~ ~2 ~1 #re8portals:frame/re8_dimension if block ~ ~-1 ~ #re8portals:air if block ~ ~-1 ~1 #re8portals:air if block ~ ~ ~1 #re8portals:air if block ~ ~1 ~ #re8portals:air if block ~ ~1 ~1 #re8portals:air positioned ~ ~-1 ~ align xyz run function re8portals:activate/create/re8_dimension/z
# South
execute if block ~ ~-2 ~ #re8portals:frame/re8_dimension if block ~ ~-2 ~-1 #re8portals:frame/re8_dimension if block ~ ~-1 ~-2 #re8portals:frame/re8_dimension if block ~ ~-1 ~1 #re8portals:frame/re8_dimension if block ~ ~ ~-2 #re8portals:frame/re8_dimension if block ~ ~ ~1 #re8portals:frame/re8_dimension if block ~ ~1 ~-2 #re8portals:frame/re8_dimension if block ~ ~1 ~1 #re8portals:frame/re8_dimension if block ~ ~2 ~ #re8portals:frame/re8_dimension if block ~ ~2 ~-1 #re8portals:frame/re8_dimension if block ~ ~-1 ~ #re8portals:air if block ~ ~-1 ~-1 #re8portals:air if block ~ ~ ~-1 #re8portals:air if block ~ ~1 ~ #re8portals:air if block ~ ~1 ~-1 #re8portals:air positioned ~ ~-1 ~-1 align xyz run function re8portals:activate/create/re8_dimension/z
# East
execute if block ~ ~-2 ~ #re8portals:frame/re8_dimension if block ~-1 ~-2 ~ #re8portals:frame/re8_dimension if block ~1 ~-1 ~ #re8portals:frame/re8_dimension if block ~-2 ~-1 ~ #re8portals:frame/re8_dimension if block ~1 ~ ~ #re8portals:frame/re8_dimension if block ~-2 ~ ~ #re8portals:frame/re8_dimension if block ~1 ~1 ~ #re8portals:frame/re8_dimension if block ~-2 ~1 ~ #re8portals:frame/re8_dimension if block ~ ~2 ~ #re8portals:frame/re8_dimension if block ~-1 ~2 ~ #re8portals:frame/re8_dimension if block ~ ~-1 ~ #re8portals:air if block ~-1 ~-1 ~ #re8portals:air if block ~-1 ~ ~ #re8portals:air if block ~ ~1 ~ #re8portals:air if block ~-1 ~1 ~ #re8portals:air positioned ~-1 ~-1 ~ align xyz run function re8portals:activate/create/re8_dimension/x
# West
execute if block ~ ~-2 ~ #re8portals:frame/re8_dimension if block ~1 ~-2 ~ #re8portals:frame/re8_dimension if block ~2 ~-1 ~ #re8portals:frame/re8_dimension if block ~-1 ~-1 ~ #re8portals:frame/re8_dimension if block ~2 ~ ~ #re8portals:frame/re8_dimension if block ~-1 ~ ~ #re8portals:frame/re8_dimension if block ~2 ~1 ~ #re8portals:frame/re8_dimension if block ~-1 ~1 ~ #re8portals:frame/re8_dimension if block ~ ~2 ~ #re8portals:frame/re8_dimension if block ~1 ~2 ~ #re8portals:frame/re8_dimension if block ~ ~-1 ~ #re8portals:air if block ~1 ~-1 ~ #re8portals:air if block ~1 ~ ~ #re8portals:air if block ~ ~1 ~ #re8portals:air if block ~1 ~1 ~ #re8portals:air positioned ~ ~-1 ~ align xyz run function re8portals:activate/create/re8_dimension/x
top.mcfunction
# 查看我们传送门头部是否有对应的方块
# North
execute if block ~ ~-3 ~ #re8portals:frame/re8_dimension if block ~ ~-3 ~1 #re8portals:frame/re8_dimension if block ~ ~-2 ~-1 #re8portals:frame/re8_dimension if block ~ ~-2 ~2 #re8portals:frame/re8_dimension if block ~ ~-1 ~-1 #re8portals:frame/re8_dimension if block ~ ~-1 ~2 #re8portals:frame/re8_dimension if block ~ ~ ~-1 #re8portals:frame/re8_dimension if block ~ ~ ~2 #re8portals:frame/re8_dimension if block ~ ~1 ~ #re8portals:frame/re8_dimension if block ~ ~1 ~1 #re8portals:frame/re8_dimension if block ~ ~-2 ~ #re8portals:air if block ~ ~-2 ~1 #re8portals:air if block ~ ~-1 ~ #re8portals:air if block ~ ~-1 ~1 #re8portals:air if block ~ ~ ~1 #re8portals:air positioned ~ ~-2 ~ align xyz run function re8portals:activate/create/re8_dimension/z
# South
execute if block ~ ~-3 ~ #re8portals:frame/re8_dimension if block ~ ~-3 ~-1 #re8portals:frame/re8_dimension if block ~ ~-2 ~-2 #re8portals:frame/re8_dimension if block ~ ~-2 ~1 #re8portals:frame/re8_dimension if block ~ ~-1 ~-2 #re8portals:frame/re8_dimension if block ~ ~-1 ~1 #re8portals:frame/re8_dimension if block ~ ~ ~-2 #re8portals:frame/re8_dimension if block ~ ~ ~1 #re8portals:frame/re8_dimension if block ~ ~1 ~ #re8portals:frame/re8_dimension if block ~ ~1 ~-1 #re8portals:frame/re8_dimension if block ~ ~-2 ~ #re8portals:air if block ~ ~-2 ~-1 #re8portals:air if block ~ ~-1 ~ #re8portals:air if block ~ ~-1 ~-1 #re8portals:air if block ~ ~ ~-1 #re8portals:air positioned ~ ~-2 ~-1 align xyz run function re8portals:activate/create/re8_dimension/z
# East
execute if block ~ ~-3 ~ #re8portals:frame/re8_dimension if block ~-1 ~-3 ~ #re8portals:frame/re8_dimension if block ~1 ~-2 ~ #re8portals:frame/re8_dimension if block ~-2 ~-2 ~ #re8portals:frame/re8_dimension if block ~1 ~-1 ~ #re8portals:frame/re8_dimension if block ~-2 ~-1 ~ #re8portals:frame/re8_dimension if block ~1 ~ ~ #re8portals:frame/re8_dimension if block ~-2 ~ ~ #re8portals:frame/re8_dimension if block ~ ~1 ~ #re8portals:frame/re8_dimension if block ~-1 ~1 ~ #re8portals:frame/re8_dimension if block ~ ~-2 ~ #re8portals:air if block ~-1 ~-2 ~ #re8portals:air if block ~ ~-1 ~ #re8portals:air if block ~-1 ~-1 ~ #re8portals:air if block ~-1 ~ ~ #re8portals:air positioned ~-1 ~-2 ~ align xyz run function re8portals:activate/create/re8_dimension/x
# West
execute if block ~ ~-3 ~ #re8portals:frame/re8_dimension if block ~1 ~-3 ~ #re8portals:frame/re8_dimension if block ~2 ~-2 ~ #re8portals:frame/re8_dimension if block ~-1 ~-2 ~ #re8portals:frame/re8_dimension if block ~2 ~-1 ~ #re8portals:frame/re8_dimension if block ~-1 ~-1 ~ #re8portals:frame/re8_dimension if block ~2 ~ ~ #re8portals:frame/re8_dimension if block ~-1 ~ ~ #re8portals:frame/re8_dimension if block ~ ~1 ~ #re8portals:frame/re8_dimension if block ~1 ~1 ~ #re8portals:frame/re8_dimension if block ~ ~-2 ~ #re8portals:air if block ~1 ~-2 ~ #re8portals:air if block ~ ~-1 ~ #re8portals:air if block ~1 ~-1 ~ #re8portals:air if block ~1 ~ ~ #re8portals:air positioned ~ ~-2 ~ align xyz run function re8portals:activate/create/re8_dimension/x
在activate
包中新建create
包 -> create
包中新建以我们维度名称命名的包re8_dimension
-> 包中新建两个功能文件x.mcfunction
、z.mcfunction
x.mcfunction
# 填充传送方块
fill ~ ~ ~ ~1 ~2 ~ minecraft:moving_piston
# Summon armor stands for portal blocks (OPTIONAL)
summon armor_stand ~.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.5 ~1 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~1 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.5 ~2 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:panic_rose",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~1.5 ~2 ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:panic_rose",Count:1b,tag:{CustomModelData:286000}}]}
summon marker ~.5 ~ ~.506 {NoGravity:1b,Silent:1b,Invulnerable:1b,Tags:["re8portals_re8_dimension_marker","re8portals_re8_dimension_marker_x"]}
# Play a portal opening sound (OPTIONAL)
playsound minecraft:block.end_portal.spawn master @a ~ ~ ~ 15 1
z.mcfunction
# 填充传送方块
fill ~ ~ ~ ~ ~2 ~1 minecraft:moving_piston
# Summon armor stands for portal blocks
summon armor_stand ~.506 ~ ~0.5 {Rotation:[90F,0F],NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.506 ~ ~1.5 {Rotation:[90F,0F],NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.506 ~1 ~.5 {Rotation:[90F,0F],NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.506 ~1 ~1.5 {Rotation:[90F,0F],NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:aterrimus_glass_pane",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.506 ~2 ~.5 {Rotation:[90F,0F],NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:panic_rose",Count:1b,tag:{CustomModelData:286000}}]}
summon armor_stand ~.506 ~2 ~1.5 {Rotation:[90F,0F],NoGravity:1b,Silent:1b,Invulnerable:1b,ShowArms:1b,Marker:1b,Invisible:1b,Tags:["wabportals_aether_portal_stand","wabportals_portal_stand"],ArmorItems:[{},{},{},{id:"re8joymod:panic_rose",Count:1b,tag:{CustomModelData:286000}}]}
summon marker ~.506 ~ ~.5 {NoGravity:1b,Silent:1b,Invulnerable:1b,Tags:["re8portals_re8_dimension_marker","re8portals_re8_dimension_marker_z"]}
# Play a portal opening sound (OPTIONAL)
playsound minecraft:block.end_portal.spawn master @a ~ ~ ~ 15 1
在activate
包中新建locate_block
包 -> locate_block
包中新建以我们维度命名的功能文件re8_dimension.mcfunction
re8_dimension.mcfunction
# 查看玩家在哪个地点创建了传送门
execute if block ~ ~ ~ #re8portals:activation/re8_dimension if block ~ ~-1 ~ #re8portals:frame/re8_dimension run function re8portals:activate/check_frame/re8_dimension/bottom
execute if block ~ ~ ~ #re8portals:activation/re8_dimension if block ~ ~-2 ~ #re8portals:frame/re8_dimension run function re8portals:activate/check_frame/re8_dimension/mid
execute if block ~ ~ ~ #re8portals:activation/re8_dimension if block ~ ~-3 ~ #re8portals:frame/re8_dimension run function re8portals:activate/check_frame/re8_dimension/top
scoreboard players remove @s player_reach_range 1
execute if score @s player_reach_range matches 1.. if block ~ ~ ~ #re8portals:air positioned ^ ^ ^0.5 run function re8portals:activate/locate_block/re8_dimension
6.在resources\data\minecraft\tags\functions
中新建load.json
和tick.json
监视我们的传送门
load.json
{
"values": [
# 名称为我们之前的传送门文件夹名称
"re8portals:load"
]
}
tick.json
{
"values": [
"re8portals:tick"
]
}