Skip to content

区块加载、合成、伤害、原版战利品表与 TNT(草稿,进行中) - #4

Draft
hekuo5310 wants to merge 4 commits into
mainfrom
claude/magical-dijkstra-nro58t
Draft

hekuo5310 wants to merge 4 commits into
mainfrom
claude/magical-dijkstra-nro58t

Conversation

@hekuo5310

Copy link
Copy Markdown
Member

概要

接在 #3 之后的修复与原版机制。仍在进行中,所以先开草稿。

打包与启动

  • 打包版现在会带上原生组件(terrain_gen、mob_ai 等)。Nuitka 的 --include-data-dir 会静默跳过 .exe/.dll/.so/.dylib,所以之前的打包版只能用很慢的 Python 生成器。现在改为显式列出这些文件,CI 打包前也会检查它们是否存在。
  • 准备出生区期间,stop / Ctrl+C / SIGTERM 会立即生效。如果停服时出生点还没选好,会在 level.dat 里记为 initialized=0,下次启动重新选。
  • 没有原生生成器时只预生成 3×3 区块,并逐区块显示进度。

区块加载

  • 区块编码改为批量处理(world/fastpack.py),输出与之前逐字节一致。每个新区块从约 150 毫秒降到约 35 毫秒。
  • 修复读取生成器输出时的平方级字节拼接。
  • 视距内的区块按由近到远的顺序分批生成和发送(流水线)。视距 10 时,外圈区块原来要约 60 秒后才一次性出现,现在几秒内就开始出现,约 18 秒全部加载完。

合成

  • 背包 2×2 和工作台 3×3 都能合成:
    • 产物格的点击、Shift 批量合成、数字键、Q 丢出;
    • 关闭界面或下线时,合成格里的物品退回背包。
  • 配方使用原版 1.21.1 全部有序/无序配方(634 + 253 个,由 tools/gen_recipe_data.py 生成),支持标签展开、左右镜像和合成剩余物(如空桶)。
  • 物品栏点击改为原版的差异同步:只发送客户端预测错的格子,一次回应只用一个 state id,产物格按 slotChangedCraftingGrid 规则发送。

伤害与生物

  • 生物把草、花、火把等没有碰撞箱的方块当成墙,在原版地形上寸步难行,敌对生物因此几乎碰不到玩家。现在改用 blocks.json 的碰撞数据。
  • 原版伤害规则:
    • 武器伤害和攻击速度;攻击冷却改为按蓄力缩放伤害,不再丢弃攻击;
    • 暴击;
    • 护甲与韧性、保护类附魔;
    • 生物伤害的难度倍率;
    • 10 刻受击无敌时间(玩家和生物);
    • 进服和重生后 3 秒无敌。
  • 修复区域文件被多个线程并发写入的问题(Failed to save region),所有区域读写现在都串行执行。

掉落(原版战利品表)

  • 方块和生物掉落使用原版 1.21.1 战利品表(由 tools/gen_loot_data.py 生成):
    • 时运、抢夺、精准采集、剪刀;
    • 随机概率(砂砾掉燧石、草掉种子、树苗等);
    • 作物成熟度、仅玩家击杀掉落、爆炸衰减;
    • 羊按颜色掉羊毛。
  • 采集规则改用 blocks.json 的 harvestTools。之前泥土、原木、沙子等空手挖什么都不掉。

TNT 与爆炸

  • TNT 被点燃(打火石、红石)后变成带 80 刻引信的 TNT 实体,会受重力下落,不再瞬间爆炸。
  • 爆炸使用原版射线算法:
    • 按方块爆炸抗性衰减;
    • 被波及的 TNT 连锁引爆;
    • 被破坏的方块按战利品表掉落;
    • 按暴露度计算实体伤害和击退。
  • 爆炸包改为 1.21.1 格式。旧格式会导致客户端解析失败而断线。

测试

  • pytest:184 个测试全部通过。新增:
    • tests/test_crafting_and_drops.py:配方匹配、合成窗口、差异同步、树叶掉落、编码器;
    • 打包工作流的检查步骤。
  • 用 mineflayer 1.21.1 客户端做了端到端验证:
    • 区块到达时间;
    • 2×2 / 3×3 合成,连续 4 次结果一致;
    • 僵尸伤害:无护甲 3 点,全套钻石甲 0.69 点;
    • 打猪:空手 10 下,钻石剑 2 下;
    • 摔落伤害;
    • TNT 引信、连锁引爆、爆炸包、伤害和掉落。
  • 掉落率统计与原版一致,例如钻石矿时运 III 平均 2.20、砂砾掉燧石 10%、青金石平均 6.5。

进行中 / 已知问题

  • 一次爆炸仍会占用主线程约 1 秒,正在优化。
  • 用 /setblock 放的红石块不会触发相邻 TNT;红石引擎和生电相关特性(BUD、刷线机、刷钩机、0t 活塞)正在评估。
  • instant_health 等药水效果未实现。

Generated by Claude Code

Nuitka's --include-data-dir silently skips .exe/.dll/.so/.dylib files,
so the packaged servers never contained terrain_gen/mob_ai and fell
back to the Python generator (~8 s per chunk). List the native files
explicitly with --include-data-files and fail the build if they are
missing or report the wrong worldgen version.

While the spawn area is prepared, /stop (console), Ctrl+C and SIGTERM
now take effect after the current chunk instead of after startup; a
world stopped before its spawn was chosen is saved with
initialized=0 so the next start searches again. Without the native
generator only 3x3 spawn chunks are prepared, with per-chunk progress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqNsCYYKLCUPjt3r1MFKgu
Chunks: section/heightmap/NBT encoding now works on whole lists
(world/fastpack.py, output byte-identical to before) and the native
generator output is read without quadratic concatenation, ~150 ms ->
~35 ms per new chunk. Chunks beyond the join radius are generated and
sent nearest first in pipelined batches of 32, so the view fills in
within seconds instead of everything arriving after ~1 minute.

Crafting: the 2x2 inventory grid and the crafting table now work, with
all vanilla 1.21.1 shaped/shapeless recipes (tags resolved, mirrored
shapes, crafting remainders; tools/gen_recipe_data.py builds
world/data/recipes.json). Result slot clicks, shift-crafting, number
keys and dropping behave like vanilla; grids empty back into the
inventory on close or logout. Clicks are answered like vanilla with
only the slots the client predicted wrong (one state id per answer)
instead of a full window each time, which raced with fast clicking.

Leaves drop by the vanilla loot table (saplings 1/20, jungle 1/40,
sticks 1/50, apples 1/200, Fortune-scaled; shears/Silk Touch keep the
leaves) instead of always dropping a sapling or the leaves themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqNsCYYKLCUPjt3r1MFKgu
Mobs treated grass, flowers, torches and every other block without a
collision box as walls, so on vanilla terrain they got stuck within a
block and hostile mobs never got close enough to hurt anyone. Mob
physics now uses the collision data from blocks.json.

Damage follows vanilla: weapon damage/attack speed tables, attack
strength scaling instead of dropping clicks within 0.4 s, critical
hits, armor + toughness, protection enchantments, difficulty scaling of
mob damage, the 10-tick invulnerability window (for players and mobs)
and 3 s spawn invulnerability on join/respawn.

Region files were written concurrently by the event loop and chunk
worker threads, racing on the same .tmp file ("Failed to save region");
all region access is now serialized.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqNsCYYKLCUPjt3r1MFKgu
Block and entity drops now come from the vanilla 1.21.1 loot tables
(tools/gen_loot_data.py -> world/data/loot_tables.json): Fortune and
Looting formulas, Silk Touch, shears, random chances, crop ages,
killed-by-player drops, explosion decay, sheep wool by colour.
Blocks drop with bare hands unless vanilla requires the correct tool
(blocks.json harvestTools); before, dirt, logs, sand etc. dropped
nothing without a tool.

TNT is primed into a TNT entity with an 80-tick fuse (flint and steel,
redstone) instead of exploding instantly. Explosions use the vanilla
ray algorithm with block blast resistance, chain-prime TNT, drop blocks
through their loot tables, damage and push entities by exposure, and
send the 1.21.1 Explosion packet (the old packet layout would make
clients disconnect).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqNsCYYKLCUPjt3r1MFKgu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants