我们今天在模组中实现一个传送门,让我们可以传送到自己的维度中。(文末附数据包下载链接)
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",

本文详细介绍了如何在Mod中实现一个可激活的传送门,包括数据包结构、方块定义、预设条件和功能实现,带你构建一个能连接不同维度的游戏传送门。
最低0.47元/天 解锁文章
3952





