Files
2025-03-20 11:52:46 +08:00

2.7 KiB
Raw Permalink Blame History

title, category, tags, mentions
title category tags mentions
高度图噪声 巧思案例
experimental
tutorial
Apex360
SirLich

高度图噪声

:::tip 本教程假设您已掌握Molang、特征feature及特征规则feature rule的基础知识。 :::

在本教程中,我们将学习如何通过q.noise Molang查询实现基于噪声的地形生成。

单方块特征

首先定义用于生成地形的单方块特征。本教程将使用石头作为示例。

::: code-group

{
	"format_version": "1.13.0",
	"minecraft:single_block_feature": {
		"description": {
			"identifier": "wiki:stone_feature"
		},
		"places_block": "minecraft:stone",
		"enforce_survivability_rules": false,
		"enforce_placement_rules": false
	}
}

:::

散布特征

散布特征scatter feature是地形生成的核心组件。

::: code-group

{
	"format_version": "1.13.0",
	"minecraft:scatter_feature": {
		"description": {
			"identifier": "wiki:column"
		},
		"iterations": "t.height=64+(q.noise(v.originz/64,v.originx/64))*16; return t.height;",
		"places_feature": "wiki:stone_feature",
		"x": 0,
		"z": 0,
		"y": {
			"extent": [-64, "t.height"],
			"distribution": "fixed_grid"
		}
	}
}

:::

迭代参数解析

  • 我们通过临时变量t.height定义噪声函数
  • 64是基准高度(函数的起始高度)
  • q.noise查询Perlin噪声值范围-1到1除以64用于平滑噪声曲线
  • 乘以16控制地形起伏幅度

该逻辑通过y参数的取值范围[-64, t.height]生成地形柱体。由于q.noise基于Perlin噪声算法相邻柱体高度呈现渐变效果如64,65,66,68...),而非随机突变。

特征规则

::: code-group

{
	"format_version": "1.13.0",
	"minecraft:feature_rules": {
		"description": {
			"identifier": "wiki:column_grid_placement",
			"places_feature": "wiki:column"
		},
		"conditions": {
			"placement_pass": "first_pass",
			"minecraft:biome_filter": {
				"any_of": [
					{
						"test": "has_biome_tag",
						"value": "overworld"
					},
					{
						"test": "has_biome_tag",
						"value": "overworld_generation"
					}
				]
			}
		},
		"distribution": {
			"iterations": 256,
			"x": {
				"extent": [0, 15],
				"distribution": "fixed_grid"
			},
			"y": 0,
			"z": {
				"extent": [0, 15],
				"distribution": "fixed_grid"
			}
		}
	}
}

:::

关键配置

  • iterations设为256以覆盖整个区块16x16区域
  • fixed_grid分布模式确保柱体均匀排列

至此,基于噪声的自定义地形已构建完成!您可以自由调整参数进行地形形态实验。