- 致编者:请牢记我们的域名wiki.mcbe-dev.net!
- 致编者:欢迎加入本Wiki的官方交流QQ群或Discord服务器!
- 基岩版1.19.31现已发布!(了解更多)
- Inner Core现已支持Xbox模组联机!(了解更多)
- 如果您是第一次来到本Wiki,欢迎注册一个账户
- 点击顶部的“编辑”或“编辑源代码”按钮即可编辑当前页面
- 请知悉:在不登录时也可以编辑和新建页面,但是您当前的IP地址会记录在编辑历史中
手冊:實例/附加包/方塊/農作物
出自Minecraft基岩版开发Wiki
該頁面的編輯正在進行中。 請幫助我們擴充或改進這篇文章。 |
引言[編輯]
我們可以透過方塊置換來實現類似於原版農作物的方塊,本實例將幫助你製作一個屬於自己的自訂農作物。 由於原版農作物的工作機制較為複雜,本實例只提供一個由純數據驅動內容實現的,僅受遊戲隨機刻影響的,最基本的自訂農作物。
前置知識[編輯]
你在閱讀本實例前應該掌握如下知識:
- 附加包的構建
- 自訂物品
- 自訂方塊
- 對方塊置換的基本知識
教學[編輯]
加入種子[編輯]
首先在行為包的items
資料夾下新建一個JSON檔案,命名為,並插入以下內容:custom_seed.json
{
"format_version":"1.20.50",
"minecraft:item":{
"description":{
"identifier":"wiki:custom_seed",
// 物品分组,这里将其归类至“种子”分组
"menu_category":{
"category": "nature",
"group":"itemGroup.name.seed"
},
},
"components":{
// 该物品显示名称,填本地化字符串
"minecraft:display_name":{
"value":"item.wiki:custom_seed.name"
},
// 该物品纹理,填物品短名称
"minecraft:icon":{
"texture":"wiki.custom_seed"
},
// 重中之重,添加这个组件可以使物品像原版的种子一样播种作物
"minecraft:block_placer":{
// 播种方块的ID
"block": "wiki:custom_crop",
// 可以在何种方块上播种,这里填farmland(耕地)
"use_on": ["farmland"]
}
}
}
}
然後為這個物品加入紋理與名稱,由於篇幅原因,這裏不再贅述。
加入作物方塊[編輯]
行為包部分[編輯]
在行為包的blocks
資料夾下新建一個JSON檔案,命名為,並插入以下內容:custom_crop.json
{
"format_version": "1.20.50",
"minecraft:block": {
"description": {
//方块ID需与种子物品的"block_placer"组件中填写的ID保持一致
"identifier": "wiki:custom_crop",
"states": {
//定义农作物的总生长阶段数
"custom_crop:growth": [0,1,2,3,4,5,6,7]
}
},
//设置每个生长阶段对应的方块置换,主要为纹理与选择箱的修改
"permutations": [
{
//"query.block_state(<block_state_name>)"是用于查询方块状态的molang,此处用于查询自定义农作物的当前生长阶段
"condition": "query.block_state('custom_crop:growth') == 0",
"components": {
//将方块纹理调为当前阶段对应的纹理
"minecraft:material_instances": {
"*": {
//在terrain_texture.json中定义的方块纹理字段
"texture": "custom_crop_stage0",
//取消环境光
"ambient_occlusion": false,
"face_dimming": false,
"render_method": "alpha_test"
}
},
//调整方块选择箱,该实例对应原版小麦
"minecraft:selection_box": {
"origin": [-8,0,-8],
"size": [16,3,16]
}
}
},
{
"condition": "query.block_state('custom_crop:growth') == 1",
"components": {
"minecraft:material_instances": {
"*": {
"texture": "custom_crop_stage1",
"ambient_occlusion": false,
"face_dimming": false,
"render_method": "alpha_test"
}
},
"minecraft:selection_box": {
"origin": [-8,0,-8],
"size": [16,4,16]
}
}
},
{
"condition": "query.block_state('custom_crop:growth') == 2",
"components": {
"minecraft:material_instances": {
"*": {
"texture": "custom_crop_stage2",
"ambient_occlusion": false,
"face_dimming": false,
"render_method": "alpha_test"
}
},
"minecraft:selection_box": {
"origin": [-8,0,-8],
"size": [16,7,16]
}
}
},
{
"condition": "query.block_state('custom_crop:growth') == 3",
"components": {
"minecraft:material_instances": {
"*": {
"texture": "custom_crop_stage3",
"ambient_occlusion": false,
"face_dimming": false,
"render_method": "alpha_test"
}
},
"minecraft:selection_box": {
"origin": [-8,0,-8],
"size": [16,9,16]
}
}
},
{
"condition": "query.block_state('custom_crop:growth') == 4",
"components": {
"minecraft:material_instances": {
"*": {
"texture": "custom_crop_stage4",
"ambient_occlusion": false,
"face_dimming": false,
"render_method": "alpha_test"
}
},
"minecraft:selection_box": {
"origin": [-8,0,-8],
"size": [16,12,16]
}
}
},
{
"condition": "query.block_state('custom_crop:growth') == 5",
"components": {
"minecraft:material_instances": {
"*": {
"texture": "custom_crop_stage5",
"ambient_occlusion": false,
"face_dimming": false,
"render_method": "alpha_test"
}
},
"minecraft:selection_box": {
"origin": [-8,0,-8],
"size": [16,14,16]
}
}
},
{
"condition": "query.block_state('custom_crop:growth') == 6",
"components": {
"minecraft:material_instances": {
"*": {
"texture": "custom_crop_stage6",
"ambient_occlusion": false,
"face_dimming": false,
"render_method": "alpha_test"
}
},
"minecraft:selection_box": {
"origin": [-8,0,-8],
"size": [16,15,16]
}
}
},
{
"condition": "query.block_state('custom_crop:growth') == 7",
"components": {
//设置成熟之后农作物的战利品表
"minecraft:loot": "loot_tables/blocks/custom_crop_riped.json",
"minecraft:material_instances": {
"*": {
"texture": "custom_crop_stage7",
"ambient_occlusion": false,
"face_dimming": false,
"render_method": "alpha_test"
}
},
"minecraft:selection_box": {
"origin": [-8,0,-8],
"size": [16,16,16]
}
}
}
],
"components": {
//设置未成熟时农作物的战利品表
"minecraft:loot": "loot_tables/blocks/custom_crop.json",
//使该方块可被瞬间破坏
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 0.0
},
//使该方块不阻挡光线
"minecraft:light_dampening": 0,
//设置农作物模型,此处模型需手动装载,详情见下文
"minecraft:geometry": "geometry.bush_crop",
"minecraft:destructible_by_explosion": {
"explosion_resistance": 0.0
},
//取消该方块的碰撞箱
"minecraft:collision_box": false,
//设置该方块的骨粉催熟事件触发器
"minecraft:on_interact": {
"event": "wiki:on_interact",
//条件限制,若手持物品非骨粉或状态等于7则不触发事件
"condition": "query.is_item_name_any('slot.weapon.mainhand','minecraft:bone_meal' && query.block_state('custom_crop:growth')<7)"
},
//设置该方块只能放置在耕地上方
"minecraft:placement_filter": {
"conditions": [
{
"block_filter": ["farmland"],
"allowed_faces": ["up"]
}
]
},
//设置该方块的随机刻生长事件触发器
"minecraft:random_ticking": {
"on_tick": {
"event": "grow_stage",
"target": "self"
}
},
"tag:crop": {}
},
"events": {
//设置该方块的随机刻生长事件响应
"grow_stage": {
//若未成熟,则使生长阶段+1
"condition": "query.block_state('custom_crop:growth')<7",
"set_block_state": {
"custom_crop:growth": "(query.block_state('custom_crop:growth')<7) ? query.block_state('custom_crop:growth') + 1 : 7"
}
},
//设置该方块的骨粉催熟事件响应
"wiki:on_interact": {
"condition": "query.block_state('custom_crop:growth')<7"
"sequence": [
{
//有12/17的概率使生长阶段+3,若超过最大阶段则设为最大阶段
"randomize": [
{
"weight": 5
},
{
"weight": 12,
"sequence": [
{
"set_block_state": {
"custom_crop:growth": "(query.block_state('custom_crop:growth')<4) ? query.block_state('custom_crop:growth') + 3 : 7"
}
}
]
}
]
},
{
//消耗一个骨粉物品
"decrement_stack": {}
},
{
//在方块上播放催熟粒子
"run_command": {
"command": [
"particle minecraft:crop_growth_emitter ~~~"
]
}
}
]
}
}
}
}
至此,該作物方塊的行為部分就寫好了。
資源包部分[編輯]
雖然方塊紋理已經在行為包部分進行了組態,但是其聲音仍需在blocks.json
中單獨設定,其中農作物對應的欄位是"grass"
。
上文中的農作物模型遊戲並未內建,所以我們需要在models/blocks
資料夾下新建一個bush_crop.geo.json
,具體內容如下:
{
//该文件对应原版小麦模型
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.bush_crop",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 2,
"visible_bounds_height": 2.5,
"visible_bounds_offset": [0, 0.75, 0]
},
"bones": [
{
"name": "bone",
"pivot": [8, -1, -8],
"cubes": [
{
"origin": [4, -1, -8],
"size": [0, 15, 16],
"uv": {
"west": {"uv": [16, 0], "uv_size": [-16, 16]}
}
},
{
"origin": [-4, -1, -8],
"size": [0, 15, 16],
"uv": {
"east": {"uv": [16, 0], "uv_size": [-16, 16]}
}
},
{
"origin": [-8, -1, -4],
"size": [16, 15, 0],
"uv": {
"north": {"uv": [16, 0], "uv_size": [-16, 16]}
}
},
{
"origin": [-8, -1, 4],
"size": [16, 15, 0],
"uv": {
"south": {"uv": [16, 0], "uv_size": [-16, 16]}
}
}
]
}
]
}
]
}
至此,該方塊的模型和聲音也組態完畢了,只需要再組態名稱即可。
結語[編輯]
如果你看到了這裏,那麼恭喜你,你已經學會了如何自訂一個基礎的農作物了!然而,農作物的實現方式遠遠不止這一種,你可以對其中的任意一個環節進行修改,來做出更酷的效果或者更複雜的生長機制,甚至可以配合腳本API編寫更深刻的邏輯。