烧烤 动物养殖 分类 转换功能 计时转换 退出重新判断tick (可用版本)

This commit is contained in:
wenhe committed 2026-09-02 00:43:16 +08:00
1 parent 6686e80d22
commit f359008ac3
6 files changed
+136 -87

No files matched your search

@@ -221,12 +221,8 @@ class BarbecueService(BlueFoxServerSystem):
if recipe.get("giveItem"):
self.giveItem(playerId, recipe["giveItem"], recipe.get("giveCount", 1))
# 上杆后若新方块是计时源 → 尝试启动计时(下方需有篝火)
if recipe.get("target") in self.barbecueTimers:
nextTimer = self.barbecueTimers[recipe["target"]]
if self.checkBelow(nextTimer, dim, pos):
self.startTimer(key, nextTimer, dim, playerId)
# 注意:上杆/点火后【不自动启动烤制】。
# 烤制规则 autoStart=False,必须玩家右键烤制方块才激活计时(见 handleBlockUse)
# 转换成功提示(点火/上杆等)
if recipe.get("tip"):
comp.CreateMsg(playerId).NotifyOneMessage(playerId, recipe["tip"])
@@ -277,8 +273,9 @@ class BarbecueService(BlueFoxServerSystem):
# 去重:已在本规则计时中的方块不重置
try:
data = blockEntityDataComp.GetBlockEntityData(dim, pos)
if data and data.get("rtdd_tid") == recipe["source"]:
return
if data:
if data["rtdd_tid"] == recipe["source"]:
return
except Exception:
pass
self._writeTimerData(dim, pos, recipe, playerId)
@@ -288,29 +285,45 @@ class BarbecueService(BlueFoxServerSystem):
def handleBlockEntityTick(self, args):
"""FeatureDispatcher 转发:烤制方块每 tick 检查是否到点"""
posDim = args.get("posDim")
if not posDim:
return
dim = posDim[3]
pos = (posDim[0], posDim[1], posDim[2])
self._tickProcess(dim, pos)
dim = args.get("dimension")
pos = (args.get("posX"), args.get("posY"), args.get("posZ"))
blockName = args.get("blockName", "")
self._tickProcess(dim, pos, blockName)
def _tickProcess(self, dim, pos):
"""tick 主逻辑:读计时数据,到点执行转换(重启后照样生效)"""
def _tickProcess(self, dim, pos, blockName):
"""
tick 主逻辑:
1) 按事件自带的当前方块名判断是否计时源(创造直接放置也会进来)
2) 是计时源但没有计时数据 → 自动补写计时(放置即开始计时)
3) 有计时数据 → 到点执行转换(重启后时间戳照常生效)
方块被拆掉后 tick 停止、数据随方块消失,不会在原位置继续计时转换。
注意:GetBlockEntityData 返回的对象不支持 .get(),这里统一用 [] 读取。
"""
try:
data = blockEntityDataComp.GetBlockEntityData(dim, pos)
if not data:
return
tid = data.get("rtdd_tid")
if not tid:
return
recipe = self.barbecueTimers.get(tid)
recipe = self.barbecueTimers.get(blockName)
if not recipe:
return # 当前方块不是计时源(tick 只对计时源方块开启)
blockData = blockEntityDataComp.GetBlockEntityData(dim, pos)
if blockData is None:
return
tstart = data.get("rtdd_tstart", 0)
tdur = data.get("rtdd_tdur", 0)
# 读取计时标识;没有或与当前方块不符
try:
tid = blockData["rtdd_tid"]
except Exception:
tid = ""
if tid != blockName:
# 烧烤必须右键激活烤制:autoStart=False 时不自动补写计时
if recipe.get("autoStart", True):
self._writeTimerData(dim, pos, recipe, None)
return
tstart = blockData["rtdd_tstart"]
tdur = blockData["rtdd_tdur"]
if time.time() - tstart >= tdur:
self._finishTimer(dim, pos, recipe, data)
self._finishTimer(dim, pos, recipe, blockData)
except Exception:
pass
@@ -330,12 +343,12 @@ class BarbecueService(BlueFoxServerSystem):
self.replaceBlock(pos, dim, recipe["target"], None)
nextRecipe = self.barbecueTimers.get(recipe["target"])
if nextRecipe:
self._writeTimerData(dim, pos, nextRecipe, data.get("rtdd_tp"))
self._writeTimerData(dim, pos, nextRecipe, data["rtdd_tp"])
else:
self._clearTimerData(dim, pos)
doneTip = recipe.get("doneTip")
if doneTip:
self._notifyIfOnline(data.get("rtdd_tp"), doneTip)
self._notifyIfOnline(data["rtdd_tp"], doneTip)
except Exception:
pass
@@ -347,8 +360,9 @@ class BarbecueService(BlueFoxServerSystem):
blockData = blockEntityDataComp.GetBlockEntityData(dim, pos)
if blockData is None:
return
now = time.time()
blockData["rtdd_tid"] = recipe["source"]
blockData["rtdd_tstart"] = time.time()
blockData["rtdd_tstart"] = now
blockData["rtdd_tdur"] = recipe.get("time", 60)
blockData["rtdd_tp"] = playerId if playerId else ""
except Exception: