Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 91 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,23 @@ jobs:
cmake --install . --prefix stage
- name: Run tests
run: python3 -m pytest tests/ -v
- name: Check native binaries
# Nuitka's --include-data-dir silently drops executables and shared
# libraries, so they are listed explicitly; make sure they exist.
run: |
ls -l build/stage/native
test -x build/stage/native/terrain_gen
test -x build/stage/native/mob_ai
test -f build/stage/native/libpymc_vanilla.*
build/stage/native/terrain_gen --version | grep -q "pymc-worldgen 2"
- name: Build with Nuitka
run: |
pip install nuitka
python3 -m nuitka --standalone --onefile --assume-yes-for-downloads \
--include-data-file=world/blocks.json=world/blocks.json \
--include-data-dir=protocol/data=protocol/data \
--include-data-dir=world/data=world/data \
--include-data-dir=build/stage/native=native \
'--include-data-files=build/stage/native/*=native/' \
main.py -o pymc-server-linux-x86_64
- name: Upload Linux artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -67,14 +76,23 @@ jobs:
cmake --install . --prefix stage
- name: Run tests
run: python3 -m pytest tests/ -v
- name: Check native binaries
# Nuitka's --include-data-dir silently drops executables and shared
# libraries, so they are listed explicitly; make sure they exist.
run: |
ls -l build/stage/native
test -x build/stage/native/terrain_gen
test -x build/stage/native/mob_ai
test -f build/stage/native/libpymc_vanilla.*
build/stage/native/terrain_gen --version | grep -q "pymc-worldgen 2"
- name: Build with Nuitka
run: |
pip install nuitka
python3 -m nuitka --standalone --onefile --assume-yes-for-downloads \
--include-data-file=world/blocks.json=world/blocks.json \
--include-data-dir=protocol/data=protocol/data \
--include-data-dir=world/data=world/data \
--include-data-dir=build/stage/native=native \
'--include-data-files=build/stage/native/*=native/' \
main.py -o pymc-server-macos-arm64
- name: Upload macOS artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -118,6 +136,16 @@ jobs:
cmake --install . --config Release --prefix stage
- name: Run tests
run: python -m pytest tests/ -v
- name: Check native binaries
# Nuitka's --include-data-dir silently drops .exe/.dll files, so they
# are listed explicitly; make sure they exist.
shell: bash
run: |
ls -l build/stage/native
test -f build/stage/native/terrain_gen.exe
test -f build/stage/native/mob_ai.exe
test -f build/stage/native/pymc_vanilla.dll
build/stage/native/terrain_gen.exe --version | grep -q "pymc-worldgen 2"
- name: Build with Nuitka
# Nuitka on Windows defaults to MSVC. No --mingw64 flag, so it
# picks up the MSVC environment set up by ilammy/msvc-dev-cmd above.
Expand All @@ -127,7 +155,7 @@ jobs:
--include-data-file=world/blocks.json=world/blocks.json `
--include-data-dir=protocol/data=protocol/data `
--include-data-dir=world/data=world/data `
--include-data-dir=build/stage/native=native `
'--include-data-files=build/stage/native/*=native/' `
main.py -o pymc-server-windows-x86_64.exe
- name: Stage native binaries for separate download
# Copy the MSVC-built, statically-linked /MT .exe files so users
Expand All @@ -137,7 +165,8 @@ jobs:
run: |
cp build/Release/terrain_gen.exe terrain_gen.exe
cp build/Release/mob_ai.exe mob_ai.exe
ls -lh terrain_gen.exe mob_ai.exe
cp build/Release/pymc_vanilla.dll pymc_vanilla.dll
ls -lh terrain_gen.exe mob_ai.exe pymc_vanilla.dll
# Sanity check: list DLL dependencies. We expect only KERNEL32.dll
# and the api-ms-win-crt-* stubs (which are part of Windows itself,
# not the Visual C++ Redistributable).
Expand All @@ -150,12 +179,49 @@ jobs:
pymc-server-windows-x86_64.exe
terrain_gen.exe
mob_ai.exe
pymc_vanilla.dll
retention-days: 1

# ── Auto pre-release for non-tagged pushes ──
# ── Was this push to main the merge of a "[release-vX.Y.Z] ..." pull request? ──
# Then the release job tags the merge commit vX.Y.Z and publishes a stable release
# (tags pushed with GITHUB_TOKEN would not start another workflow, so it is done here).
detect-release:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
version: ${{ steps.find.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Find release version in the merged pull request title
id: find
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION=""
if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
TITLES=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls" --jq '.[].title' 2>/dev/null || true)
TITLES="${TITLES}
$(git log -1 --format=%B "${GITHUB_SHA}")"
VERSION=$(printf '%s\n' "$TITLES" \
| grep -oiE '\[release[- ]v?[0-9]+\.[0-9]+\.[0-9]+[0-9A-Za-z.-]*\]' | head -1 \
| sed -E 's/^\[release[- ]v?//I; s/\]$//')
if [ -n "$VERSION" ] && git rev-parse -q --verify "refs/tags/v${VERSION}" >/dev/null; then
echo "Tag v${VERSION} already exists; publishing a pre-release instead"
VERSION=""
fi
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Release version: ${VERSION:-<none>}"

# ── Auto pre-release for other pushes ──
auto-prerelease:
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v')
needs: [build-linux, build-macos, build-windows]
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v') && needs.detect-release.outputs.version == ''
needs: [build-linux, build-macos, build-windows, detect-release]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down Expand Up @@ -206,20 +272,25 @@ jobs:
your local `native/` directory with these:
- `terrain_gen.exe` — C++ terrain generator (statically linked, no DLL dependencies)
- `mob_ai.exe` — C++ mob AI engine (statically linked, no DLL dependencies)
- `pymc_vanilla.dll` — C++ redstone / hopper / explosion engine (loaded in-process)

These are built with MSVC (/MT) and have the C++ runtime baked in,
so they run on stock Windows 10/11 without the Visual C++ Redistributable.

- name: Tag summary
run: echo "Created pre-release tag ${{ steps.tag.outputs.tag }} with build artifacts"

# ── Stable release for version tags (v1.2.0, ...) ──
# ── Stable release: a pushed v* tag, or a merged "[release-vX.Y.Z]" pull request ──
release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
needs: [build-linux, build-macos, build-windows]
if: >-
github.event_name == 'push' &&
(startsWith(github.ref, 'refs/tags/v') || needs.detect-release.outputs.version != '')
needs: [build-linux, build-macos, build-windows, detect-release]
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || format('v{0}', needs.detect-release.outputs.version) }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -239,12 +310,12 @@ jobs:
ls -lh
- name: Release notes
run: |
VERSION="${GITHUB_REF_NAME#v}"
VERSION="${TAG#v}"
# Previous stable version tag (highest v* below this one, no pre-releases)
PREV=$(git tag --list 'v[0-9]*' --sort=-v:refname | grep -v -- '-' \
| awk -v cur="$GITHUB_REF_NAME" 'seen { print; exit } $0 == cur { seen = 1 }')
PREV=$( (git tag --list 'v[0-9]*'; echo "$TAG") | sort -u | sort -rV | grep -v -- '-' \
| awk -v cur="$TAG" 'seen { print; exit } $0 == cur { seen = 1 }')
{
echo "## PyMC ${GITHUB_REF_NAME}"
echo "## PyMC ${TAG}"
echo
# The section of CHANGELOG.md for this version
awk -v v="$VERSION" '
Expand All @@ -255,19 +326,21 @@ jobs:
echo "- \`PyMC-windows.exe\`:Windows (x86_64),双击运行"
echo "- \`PyMC-linux\`:Linux (x86_64),\`chmod +x PyMC-linux && ./PyMC-linux\`"
echo "- \`PyMC-macos\`:macOS (ARM64),\`chmod +x PyMC-macos && ./PyMC-macos\`"
echo "- \`terrain_gen.exe\` / \`mob_ai.exe\`:从 Python 源码在 Windows 上运行时放进 \`native/\` 的原生组件"
echo "- \`terrain_gen.exe\` / \`mob_ai.exe\` / \`pymc_vanilla.dll\`:从 Python 源码在 Windows 上运行时放进 \`native/\` 的原生组件"
echo
echo "Minecraft Java 1.21.1 客户端连接 \`ip:25565\`。"
if [ -n "$PREV" ]; then
echo
echo "**Full Changelog**: ${{ github.server_url }}/${{ github.repository }}/compare/${PREV}...${GITHUB_REF_NAME}"
echo "**Full Changelog**: ${{ github.server_url }}/${{ github.repository }}/compare/${PREV}...${TAG}"
fi
} > release-notes.md
cat release-notes.md
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: PyMC ${{ github.ref_name }}
tag_name: ${{ env.TAG }}
target_commitish: ${{ github.sha }}
name: PyMC ${{ env.TAG }}
prerelease: ${{ contains(env.TAG, '-') }}
body_path: release-notes.md
files: release-assets/*
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ native/pymc_native_server
native/pymc_native_server.exe
native/libpymc_native.so
native/pymc_native.dll
native/libpymc_vanilla.so
native/libpymc_vanilla.dylib
native/pymc_vanilla.dll

# 服务端运行时文件 (原版布局)
/logs/
Expand Down
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
# 更新日志

## 1.2.1

### 合成与掉落
- 合成可用了:背包 2×2 合成格和工作台 3×3 都会实时显示产物,可点击取走、Shift 批量合成、数字键放入快捷栏、Q 丢出,关闭界面时合成格里的物品退回背包(满了就掉在地上)。
- 配方改用原版 1.21.1 完整数据(634 个有序 + 253 个无序配方,标签全部展开):任意木板都能做工作台、木棍等,可以混用不同木板;有序配方支持左右镜像;牛奶桶等合成后会留下空桶。数据由 `tools/gen_recipe_data.py` 生成。
- 物品栏点击改为原版的差异同步:只把客户端预测错的格子发回去,快速连续点击时不再出现物品闪烁、错位。
- 树叶掉落改为原版战利品表:树苗 5%(丛林 2.5%)、木棍 2%、橡树/深色橡树 0.5% 苹果,时运提高概率;用剪刀或精准采集才掉树叶本身。之前橡树叶 100% 掉树苗,其他树叶空手就掉树叶。

### 红石(按原版 1.21.1 重写)
- 红石引擎改为移植原版的事件驱动模型:方块更新(西东下上北南)、形状更新、按 (触发刻, 优先级, 加入顺序) 排序的计划刻、方块事件、移动中的活塞方块实体,每个游戏刻按原版阶段顺序执行。
- 元件按原版实现:红石线(连接形状、强弱充能、Java HashSet 顺序的更新)、红石火把(含烧毁)、中继器(延迟、锁存、优先级)、比较器(比较/减法,读取容器、炼药锅、堆肥桶、蛋糕)、侦测器、拉杆、按钮、压力板、红石灯、TNT、音符盒、门/活板门/栅栏门、发射器/投掷器、漏斗、充能/激活铁轨、绊线和绊线钩、活塞/粘性活塞(结构解析、粘液/蜂蜜、推动上限 12、推动反应、移动中方块、finalTick、快速收回)。
- 准连接、BUD、0t 活塞等行为不做特判,而是由与原版相同的更新顺序自然产生;计划刻在重启后保留。
- 放置方块使用原版规则:活塞/侦测器/中继器/比较器/漏斗朝向,拉杆/按钮附着面,墙上火把,台阶/楼梯上下半,原木轴向,活板门,门和床的两半,告示牌,含水;红石粉、线、种子等终于能放置了。
- `/setblock`、`/fill`、`/clone`、爆炸等所有改方块的途径都会触发红石更新;`/setblock` 支持 `方块[属性=值]` 语法。

### 战斗、掉落与 TNT
- 修复生物把草、花、火把当墙导致无法靠近玩家(所以伤害不到人)的问题;伤害规则改为原版:武器数值与攻击冷却蓄力、暴击、护甲与韧性、保护附魔、难度倍率、受击无敌时间、出生无敌。
- 方块和生物掉落使用原版战利品表(时运、抢夺、精准采集、剪刀、各种随机概率);空手挖泥土、原木等终于会掉落。
- TNT 复制机可用:活塞先缓存被推方块的状态,期间被更新点燃的 BUD TNT 仍会被放到新位置(原版机制);珊瑚扇可被推动且失去支撑会掉落(MC-133541),铁轨可被推动,充能/探测/激活铁轨移除时更新周围方块。
- 爆炸的计算(射线、暴露度、掉落)在独立的爆炸线程中进行,不受多线程开关影响;结果回到主线程应用,游戏刻不再等待爆炸。
- TNT 点燃后变成带 4 秒引信的 TNT 实体;爆炸使用原版射线算法、连锁引爆、按暴露度计算伤害和击退,爆炸包改为 1.21.1 格式(旧格式会让客户端断线)。

### C++ 原生引擎(爆炸、BUD/方块更新、漏斗)
- 新增 `native/vanilla`:红石/方块更新引擎(含 BUD、准连接、0t、活塞、TNT 复制)逐行移植自 Python 版,作为共享库 (`libpymc_vanilla.so` / `pymc_vanilla.dll` / `.dylib`) 在进程内通过 ctypes 调用;重负载红石电路约快 30 倍以上。
- 漏斗按原版 `HopperBlockEntity` 实现:8 刻冷却(漏斗链的 7/8 刻细节)、先向朝向容器推出再从上方容器抽取、红石锁定、比较器随内容更新、熔炉按面进出(上方进原料、侧面只进燃料、下方取产物)、吸取上方掉落物,打开的容器界面会实时刷新。
- 大箱子:放置时按原版规则与旁边的单箱子合并(潜行只连点击的那只),破坏一半时另一半变回单箱子;打开显示 54 格大箱子界面;漏斗、比较器都把两半当作一个容器(右半在前)。
- 漏斗矿车:用物品放到铁轨上,沿直轨、弯轨、坡轨行驶,充能铁轨加速/刹车(靠墙起步),容器矿车按装载量减速;不在充能的激活铁轨上时每刻从上方容器吸一个物品或捡起掉落物;漏斗能向旁边/上方的漏斗矿车推入和抽取;右键打开 5 格界面,打几下会坏并掉出物品和内容物;随世界保存(`pymc_minecarts.json`)。也可以放普通矿车。
- 矿车可以乘坐(右键上车,W 推动,潜行下车),玩家走过去会推动矿车,矿车之间会相互碰撞推开,探测铁轨检测到矿车时充能、比较器读取容器矿车的装载量;运动中的矿车每刻同步位置。
- 酿造台:5 格容器和界面;漏斗按原版分面规则投放(上方只进原料,侧面进空瓶/药水和烈焰粉,下方取出药水)。
- 堆肥桶:漏斗从上方投入可堆肥物品(原版概率表),满 7 层 20 刻后变成可取,下方漏斗取出骨粉;玩家右键投料、取骨粉;比较器读取层数。
- 爆炸的射线与暴露度改由 C++ 计算(仍在爆炸线程中,约快 10 倍)。
- 有 C++ 编译器时首次启动自动编译;CMake、`build.sh`、`build.bat` 和 CI 打包都会生成并带上该库。没有该库或设置 `PYMC_NATIVE_ENGINE=0` 时使用 Python 引擎(Python 引擎不搬运漏斗物品)。
- 新增差分测试:所有红石测试在 C++ 引擎上重跑,300 个随机电路逐刻比对两个引擎的方块结果,爆炸射线/暴露度与 Python 版逐项比对。

### 其他
- 修复远处区块迟迟不加载:区块编码改为批量操作(每个新区块从约 150 毫秒降到约 35 毫秒),并且由近到远分批生成、分批发送。视距 10 时外圈区块原来要等约 1 分钟才一次性出现,现在几秒内就从身边开始逐圈出现,约 18 秒全部加载完。
- 修复打包版(PyMC-windows.exe 等)不含 `terrain_gen`/`mob_ai`、只能退回到极慢的 Python 生成器的问题:Nuitka 的 `--include-data-dir` 会静默跳过 `.exe`/`.dll`/`.so`,现在改为显式打包,CI 打包前也会检查原生组件是否齐全。
- GitHub Actions:合并标题含 `[release-vX.Y.Z]` 的 PR 时,自动给合并提交打 `vX.Y.Z` tag 并发布正式版(tag 已存在时只发预发布);直接推送 `v*` tag 也照旧发布。
- 准备出生区时 `stop` / Ctrl+C 会立即生效(不再等世界生成完);没有原生生成器时出生区只预生成 3x3,并逐区块显示进度。

### 已知限制
- 酿造台还不会真正酿造(只有容器、界面和漏斗规则);普通矿车不会自动载上生物。

## 1.2.0

### 原版地形
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ elseif(UNIX)
target_link_libraries(pymc_mod_loader PUBLIC Threads::Threads rt dl)
endif()

# ===========================================================
# Vanilla engine library: redstone / block updates, hoppers, explosions
# (loaded in-process by world/rs/native.py through ctypes)
# ===========================================================
add_library(pymc_vanilla SHARED native/vanilla/api.cpp)
target_compile_features(pymc_vanilla PRIVATE cxx_std_17)
if(MSVC)
target_compile_options(pymc_vanilla PRIVATE /DNOMINMAX)
endif()

# ===========================================================
# Install targets
# ===========================================================
Expand All @@ -239,6 +249,7 @@ install(TARGETS
pymc_native
pymc_plugin_loader
pymc_mod_loader
pymc_vanilla
RUNTIME DESTINATION native
LIBRARY DESTINATION native
)
Expand All @@ -262,4 +273,5 @@ if(MINGW)
target_link_options(terrain_gen PRIVATE ${MINGW_STATIC_LINK_FLAGS})
target_link_options(mob_ai PRIVATE ${MINGW_STATIC_LINK_FLAGS})
target_link_options(pymc_native_server PRIVATE ${MINGW_STATIC_LINK_FLAGS})
target_link_options(pymc_vanilla PRIVATE ${MINGW_STATIC_LINK_FLAGS})
endif()
Loading
Loading