代码测试 2026年7月30日 3 加cd

This commit is contained in:
wenhe committed 2026-07-30 14:19:42 +08:00
1 parent 5db5d547ea
commit 6bd2af9a79
1 file changed
+16 -7
@@ -41,15 +41,14 @@ from ...BlueFoxTools.SpecialFunciton.BlueFoxSystem import BlueFoxServerSystem
from ...BlueFoxTools.ToolsConfig import LevelId
# ---- 方块实体数据组件 ----
# 每个方块都可以存一点自定义数据(比如"翻炒了几次")。
# 根据网易文档:
# GetBlockEntityData 在 blockEntityExDataCompServer 组件上(CreateBlockEntityData)
# SetBlockEntityData 在 blockInfoCompServer 组件上(CreateBlockInfo)
# 两个 API 在不同组件上!
# 正确用法:用 CreateBlockEntityData 创建 → GetBlockEntityData 返回 dict-like 对象
# → 直接修改该对象,自动保存,不需要调 SetBlockEntityData。
# 参照同项目 BlockBlock.py 的用法。
# 两个 API 在不同组件上,所以要创建两个组件:
# blockEntityDataComp → 读数据(GetBlockEntityData)
# blockInfoComp → 写数据(SetBlockEntityData)
blockEntityDataComp = comp.CreateBlockEntityData(LevelId)
blockInfoComp = comp.CreateBlockInfo(LevelId)
# ---- 导入所有配方 ----
# RECIPES 是一个列表,每条配方是一个 dict,格式见 RecipeData.py 顶部注释
@@ -135,6 +134,7 @@ class CookingService(BlueFoxServerSystem):
print "===== CookingService init ====="
self.stirData = {} # 内存中的翻炒数据字典
self.switchRecord = {} # 工具方块的记录数据(箭桶数量、药水架顺序等)
self.switchCooldown = {} # 工具方块切换冷却时间(防止连点)
self.ListenEvent() # 注册游戏事件监听
# ---- 构建统一配方字典(O(1) 查找) ----
@@ -318,6 +318,14 @@ class CookingService(BlueFoxServerSystem):
if recipe["tool"] not in carriedItem:
return
# ---- 冷却检查:防止连点右键瞬间切换多次 ----
now = time.time()
lastOp = self.switchCooldown.get(key, 0)
cd = recipe.get("switchCd", 0.5)
if now - lastOp < cd:
return
self.switchCooldown[key] = now
# ---- 计时型:直接替换方块,不消耗物品,不记录 ----
if recipe.get("type") == "timer":
if recipe.get("target"):
@@ -734,13 +742,14 @@ class CookingService(BlueFoxServerSystem):
"""
通用方块实体数据写入。
GetBlockEntityData 返回的是 dict-like 对象,直接修改即自动保存,
不需要调 SetBlockEntityData(参照同项目 BlockBlock.py 的用法)。
读用 blockEntityDataComp(GetBlockEntityData),写用 blockInfoComp(SetBlockEntityData)。
两个 API 在不同组件上,所以要分开调用。
"""
try:
blockData = blockEntityDataComp.GetBlockEntityData(dim, pos)
for key, value in kwargs.items():
blockData[key] = value
blockInfoComp.SetBlockEntityData(dim, pos, blockData)
except Exception as e:
print "[CookingService] _writeBlockData 写入失败: pos=%s dim=%s err=%s" % (pos, dim, str(e))