烧烤 动物养殖 分类 转换功能 计时转换 退出重新判断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

@@ -42,7 +42,7 @@ ANIMAL_SWITCHES = [
"target": "rtdd:chickencoop_1",
"consume": 1,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"tip": "§a鸡蛋已放入鸡窝 (1/5)",
"giveItem": None,
},
@@ -53,7 +53,7 @@ ANIMAL_SWITCHES = [
"target": "rtdd:chickencoop_2",
"consume": 1,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"tip": "§a鸡蛋已放入鸡窝 (2/5)",
"giveItem": None,
},
@@ -64,7 +64,7 @@ ANIMAL_SWITCHES = [
"target": "rtdd:chickencoop_3",
"consume": 1,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"tip": "§a鸡蛋已放入鸡窝 (3/5)",
"giveItem": None,
},
@@ -75,7 +75,7 @@ ANIMAL_SWITCHES = [
"target": "rtdd:chickencoop_4",
"consume": 1,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"tip": "§a鸡蛋已放入鸡窝 (4/5)",
"giveItem": None,
},
@@ -86,7 +86,7 @@ ANIMAL_SWITCHES = [
"target": "rtdd:chickencoop_5",
"consume": 1,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"tip": "§a鸡蛋已放入鸡窝 (5/5)",
"giveItem": None,
},
@@ -221,8 +221,9 @@ class AnimalService(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)
@@ -232,33 +233,46 @@ class AnimalService(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):
def _tickProcess(self, dim, pos, blockName):
"""
tick 主逻辑:读方块上记录的计时数据,到点就执行转换。
即便服务器重启过,只要 tick 恢复,时间戳照常生效,
比如烤制进行到 40 秒退出,回来时按原时间戳继续,只剩 20 秒。
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.animalTimers.get(tid)
recipe = self.animalTimers.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
@@ -279,13 +293,13 @@ class AnimalService(BlueFoxServerSystem):
nextRecipe = self.animalTimers.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
@@ -297,8 +311,9 @@ class AnimalService(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: