代码测试 2026年7月30日 2
This commit is contained in:
1 parent
842befe7dd
commit
5db5d547ea
1 file changed
+11
-11
@@ -42,10 +42,14 @@ from ...BlueFoxTools.ToolsConfig import LevelId
|
||||
|
||||
# ---- 方块实体数据组件 ----
|
||||
# 每个方块都可以存一点自定义数据(比如"翻炒了几次")。
|
||||
# GetBlockEntityData / SetBlockEntityData 都在 BlockInfo 组件上。
|
||||
# 注意:CreateBlockEntityData 返回的组件只有 GetBlockEntityData(只读),
|
||||
# 没有 SetBlockEntityData,所以必须用 CreateBlockInfo。
|
||||
blockEntityDataComp = comp.CreateBlockInfo(LevelId)
|
||||
# 根据网易文档:
|
||||
# GetBlockEntityData 在 blockEntityExDataCompServer 组件上(CreateBlockEntityData)
|
||||
# SetBlockEntityData 在 blockInfoCompServer 组件上(CreateBlockInfo)
|
||||
# 两个 API 在不同组件上!
|
||||
# 正确用法:用 CreateBlockEntityData 创建 → GetBlockEntityData 返回 dict-like 对象
|
||||
# → 直接修改该对象,自动保存,不需要调 SetBlockEntityData。
|
||||
# 参照同项目 BlockBlock.py 的用法。
|
||||
blockEntityDataComp = comp.CreateBlockEntityData(LevelId)
|
||||
|
||||
# ---- 导入所有配方 ----
|
||||
# RECIPES 是一个列表,每条配方是一个 dict,格式见 RecipeData.py 顶部注释
|
||||
@@ -728,19 +732,15 @@ class CookingService(BlueFoxServerSystem):
|
||||
|
||||
def _writeBlockData(self, dim, pos, **kwargs):
|
||||
"""
|
||||
通用方块实体数据写入:读 → 改 → 写。
|
||||
通用方块实体数据写入。
|
||||
|
||||
把 saveStirData / clearStirData / saveSwitchRecord / clearSwitchRecord
|
||||
四个方法里重复的 try/except/GetBlockEntityData/SetBlockEntityData 抽出来,
|
||||
一行搞定,不用每次写一样的 try/except。
|
||||
GetBlockEntityData 返回的是 dict-like 对象,直接修改即自动保存,
|
||||
不需要调 SetBlockEntityData(参照同项目 BlockBlock.py 的用法)。
|
||||
"""
|
||||
try:
|
||||
blockData = blockEntityDataComp.GetBlockEntityData(dim, pos)
|
||||
if blockData is None:
|
||||
blockData = {}
|
||||
for key, value in kwargs.items():
|
||||
blockData[key] = value
|
||||
blockEntityDataComp.SetBlockEntityData(dim, pos, blockData)
|
||||
except Exception as e:
|
||||
print "[CookingService] _writeBlockData 写入失败: pos=%s dim=%s err=%s" % (pos, dim, str(e))
|
||||
|
||||
|
||||
Reference in new issue
Block a user