教學:製作附加包/地物

出自Minecraft基岩版开发Wiki
地物
系列教學
所屬系列
難易度
中級
前置知識
實踐裝置
WindowsAndroid
所需軟體
  • 假日創作者功能
  • 自訂生態域

引言[編輯]

地物(Feature)是分散在世界各地的裝飾結構。樹木、植物、村莊、地牢、神廟、礦石和珊瑚等事物都是地物。開發人員可透過在行為包中加入地物組態檔來自訂地物及其生成的規則。

ore_feature是最基本的地物之一,它們可以透過替換生成方塊來形成礦簇,本教學將向展示如何製造自然產生的礦物礦石。

準備[編輯]

我們首先要準備兩個用作礦石的方塊:一個是正常礦石,另一個是深板岩礦石。以下程式碼可供參考:

{
    "format_version": "1.20.0",
    "minecraft:block": {
        "description": {
            "identifier": "wiki:custom_ore",
            "menu_category": {
                "group": "itemGroup.name.ore",
                "category": "nature"
            }
        },
        "components": {
            // 将这个方块的战利品表设置为空
            "minecraft:loot": "loot_tables/empty.json",
            "minecraft:destructible_by_mining": {
                "seconds_to_destroy": 0.8
            },
            "minecraft:destructible_by_explosion": {
                "explosion_resistance": 3.0
            },
            "minecraft:map_color": "#565656",
            // 方块被挖掘后触发的事件,用于有条件地生成掉落物
            "minecraft:on_player_destroyed": {
                "event": "wiki.spawn_loot",
                // 触发事件的条件:手持物品为镐(有is_pickaxe标签)
                "condition": "query.equipped_item_any_tag('slot.weapon.mainhand', 'minecraft:is_pickaxe')"
            },
            "tag:minecraft:stone_pick_diggable": {}
        },
        "events": {
            "wiki.spawn_loot": {
                // 生成战利品
                "spawn_loot": {
                    "table": "方块战利品表路径"
                }
            }
        }
    }
}

請不要忘了為這個方塊加入紋理及名稱

加入地物[編輯]

行为包/features資料夾中新建一個名為custom_ore_feature.json的檔案,插入以下內容:

{
	"format_version": "1.17.0",
	"minecraft:ore_feature": {
		"description": {
			"identifier": "wiki:custom_ore_feature"// 地物ID,在地物规则中要用到
		},
		"count": 8, // 尝试放置的次数
		"replace_rules": [
			{
				// 被放置的方块
				"places_block": "wiki:custom_ore",
				// 会被矿石替换的方块
				"may_replace": ["minecraft:stone"]
			},
			{
				// 同上
				"places_block": "wiki:deepslate_custom_ore",
				"may_replace": ["minecraft:deepslate"]
			}
		]
	}
}

現在我們成功註冊了這個地物,但它還不能在世界中生成,因為我們還需要一個地物規則

加入地物規則[編輯]

行为包/feature_rules資料夾中新建一個名為overworld_underground_custom_ore_feature.json的檔案,插入以下內容:

{
	"format_version": "1.13.0",
	"minecraft:feature_rules": {
		"description": {
			"identifier": "wiki:overworld_underground_custom_ore_feature", // 地物规则的ID
			"places_feature": "wiki:custom_ore_feature" // 地物的ID,要和上一节的相匹配
		},
		"conditions": {
			"placement_pass": "underground_pass",
			"minecraft:biome_filter": [
				{
					"any_of": [
						{
							"test": "has_biome_tag",
							"operator": "==",
							"value": "overworld"
						},
						{
							"test": "has_biome_tag",
							"operator": "==",
							"value": "overworld_generation"
						}
					]
				}
			]
		},
		"distribution": {
			"iterations": 10, // 尝试放置地物的次数
			"coordinate_eval_order": "zyx",
			"x": {
				"distribution": "uniform",
				"extent": [0, 16]
			},
			"y": {
				"distribution": "uniform", // 可以填“triangle”使矿石在中层更常见
				"extent": [
					0, // 地物可以生成的y轴最低处
					62 // 地物可以生成的y轴最高处
				]
			},
			"z": {
				"distribution": "uniform",
				"extent": [0, 16]
			}
		}
	}
}

< 交易表 | 生態域 >