Terrain Place
一个小型 NeoForge 模组,添加了 /placeterrain 命令,作为自定义地形(例如 WorldPainter 生成的世界)中原版 /place 命令的替代方案。
原版的 /place 命令使用 Minecraft 的 ChunkGenerator 来获取待放置结构区域的高度图,而 ChunkGenerator 则基于世界种子计算该高度图。然而,对于自定义地形,高度图已被修改,因此使用 /place 会导致结构悬浮或埋入地下。此模组重写了 ChunkGenerator 的高度图计算逻辑,改为截取实际地形的快照。/placeterrain 读取的是已加载的地形高度图而非种子,因此结构会贴合到真实地表(尽管效果较为粗糙)。
警告:此方法绝非完美,可能导致结构放置位置尴尬。为此,提供了 /placeterrain undo 命令以撤销结构放置操作(最多可撤销最近 8 次)
用法
/placeterrain structure <structure_id> [pos] [size]
<structure_id> 是任何当前已加载的结构注册表 ID(例如 minecraft:village_plains 或 terralith:fortified_village),
[pos] 是可选的目标方块坐标(默认为玩家所站立的方块)。
[size],可选值 1–20。对于拼图结构,这表示拼图“最大深度”:结构从其起点向外扩展的距离。大多数村庄默认约为 6。非拼图结构将忽略此参数。实际扩散范围仍受结构自身的 max_distance_from_center 限制,因此当达到该半径时,增长将停止。通常情况下,max_distance_from_center 会覆盖此设置,因此不要期望它对大多数结构都有效。
/placeterrain undo 会还原当前维度中最近的一次放置操作,恢复之前的精确方块状态。它会在每个维度保留最近 8 次放置记录,因此你可以多次撤销。历史记录仅存在于内存中——服务器重启后会被清除,且非常大的放置操作不会被保留。
示例
/placeterrain structure minecraft:desert_pyramid ~ ~ ~
/placeterrain structure minecraft:village_plains ~ ~ ~ 10 # 一个大型平原村庄
构建
目标版本为 Minecraft 1.21.1 / NeoForge 21.1.x,Java 21,使用 ModDevGradle 构建。
gradle wrapper --gradle-version 8.8
./gradlew build
移植到其他 Minecraft 版本
唯一涉及版本敏感性的代码位于 TerrainAwareChunkGenerator 底部的生成器转发方法块(applyCarvers、buildSurface、fillFromNoise 等)。它们不会由命令调用,但 ChunkGenerator 要求必须实现这些方法。如果你升级了版本并在此处遇到构建报错,请将这些方法的签名与新版本的 ChunkGenerator 对齐。大部分高度逻辑和命令部分可以保持不变直接沿用。
已知限制
- 此模组读取的是运行时高度图,因此它仅反映世界中当前存在的内容,包括玩家放置的方块和树木。对于大多数结构而言,
WORLD_SURFACE 是你需要的;如果某个结构在森林中看起来像是高出了一个方块,那是高度图将树叶也计算在内的结果。
Terrain Place
A small NeoForge mod that adds /placeterrain which acts as an alternative to the
vanilla '/place' command for custom terrain (e.g. WorldPainter-generated worlds)
The Vanilla /place command uses Minecraft's ChunkGenerator for the height map of
the area where the structure is to be placed, and in turn the ChunkGenerator calculates
this heightmap based on the world seed. However, for custom terrain the heightmap is modified
so using /place will result in either floating or underground structures. This mod overrides
the ChunkGenerator's heightmap calculations and instead takes a snapshot of the actual terrain.
/placeterrain reads the loaded terrain heightmap instead of the seed, so the
structure wraps onto the real surface (crudely).
WARNING: This method is by no means perfect and can result in awkward structure placements.
For this reason, a /placeterrain undo command exists to undo structure placements (up to the last 8)
Usage
/placeterrain structure <structure_id> [pos] [size]
<structure_id> is any currently loaded structure registry id (e.g. minecraft:village_plains or terralith:fortified_village),
[pos] is optional target block position (defaults to the block where the user is standing).
[size], optional 1–20. For jigsaw structures this is
the jigsaw "max depth": how far the structure expands from its start. Most villages
default to ~6. Ignored for non-jigsaw structures. The actual spread is still
capped by the structure's own max_distance_from_center, so very large values stop
growing once that radius is reached. Most of the time, the max_distance_from_center
overrides this so don't expect it to work for most structures.
/placeterrain undo reverts the most recent placement in the current dimension, restoring
the exact blocks that were there before. It keeps the last 8 placements per dimension,
so you can undo repeatedly. History is in-memory only — it's cleared on server restart,
and very large placements aren't kept.
Examples
/placeterrain structure minecraft:desert_pyramid ~ ~ ~
/placeterrain structure minecraft:village_plains ~ ~ ~ 10 # a big plains village
Build
Targets Minecraft 1.21.1 / NeoForge 21.1.x, Java 21, built with ModDevGradle.
gradle wrapper --gradle-version 8.8
./gradlew build
Porting to another Minecraft version
The only version-sensitive code is the block of generator forwarding methods at the bottom of
TerrainAwareChunkGenerator
(applyCarvers, buildSurface, fillFromNoise, etc.). They are never called by the
command, but ChunkGenerator requires them to be implemented. If you bump the version and
the build complains there, align those signatures with the new ChunkGenerator. Most of the
height logic and command should carry over unchanged.
Known limitations
- This mod reads the runtime heightmap, so it reflects only whatever is currently in the world,
including player-placed blocks and trees. For most structures
WORLD_SURFACE is what you
want; if a structure looks like it's sitting one block too high in a forest, that's the
heightmap counting leaves.
评论 0
登录后参与评分
还没有评论,来抢沙发吧