Minecraft 1.18.1、1.18.2模组开发 21.传送门(Portal)

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

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

1.在src\main\resources\data中新建一个我们的传送门的数据包re8portals:

cr1.png

2.在re8portals包中新建三个文件夹:functionspredicatestags

cr2.png

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",
     
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jay_fearless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值