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

@@ -36,6 +36,7 @@
tip: 转换成功时给玩家的提示(绿色§a开头)
startTip: 计时型规则启动计时时给玩家的提示(仅玩家主动触发时发)
doneTip: 计时到点完成时给启动者的提示(如"烤鸡烤熟了!")
autoStart: 放置时是否自动开始计时,默认True(自动);烧烤烤制设为False=必须右键激活
================================================================================
"""
@@ -88,7 +89,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:beefkebabs_0",
"consume": 0,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"below": ["rtdd:barbecuegrill_1"],
"tip": "§a牛肉串正在翻烤…",
"giveItem": None,
@@ -99,7 +100,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:beefkebabs_3",
"consume": 0,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"below": ["rtdd:barbecuegrill_1"],
"tip": "§e牛肉串烤熟了!",
"giveItem": None,
@@ -111,7 +112,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:lambkebabs_0",
"consume": 0,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"below": ["rtdd:barbecuegrill_1"],
"tip": "§a羊肉串正在翻烤…",
"giveItem": None,
@@ -122,7 +123,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:lambkebabs_3",
"consume": 0,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"below": ["rtdd:barbecuegrill_1"],
"tip": "§e羊肉串烤熟了!",
"giveItem": None,
@@ -134,7 +135,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:roasted_vegetables_1",
"consume": 0,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"below": ["rtdd:barbecuegrill_1"],
"tip": "§a烤蔬菜串正在翻烤…",
"giveItem": None,
@@ -145,7 +146,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:roasted_vegetables_3",
"consume": 0,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"below": ["rtdd:barbecuegrill_1"],
"tip": "§e烤蔬菜串烤熟了!",
"giveItem": None,
@@ -157,7 +158,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:roastedmushrooms_1",
"consume": 0,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"below": ["rtdd:barbecuegrill_1"],
"tip": "§a烤香菇串正在翻烤…",
"giveItem": None,
@@ -168,7 +169,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:roastedmushrooms_3",
"consume": 0,
"type": "switch",
"switchCd": 0.15,
"switchCd": 0.5,
"below": ["rtdd:barbecuegrill_1"],
"tip": "§e烤香菇串烤熟了!",
"giveItem": None,
@@ -184,7 +185,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:roastchicken_0",
"consume": 1,
"type": "switch",
"tip": "§a烤鸡已上杆,等待篝火烤制…",
"tip": "§a烤鸡已上杆,右键开始烤制",
"giveItem": None,
},
# 【上烤乳猪】支杆 + 死猪 → 烤乳猪(生)
@@ -194,7 +195,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:roastpig_0",
"consume": 1,
"type": "switch",
"tip": "§a烤乳猪已上杆,等待篝火烤制…",
"tip": "§a烤乳猪已上杆,右键开始烤制",
"giveItem": None,
},
# 【上烤鳕鱼】支杆 + 鳕鱼 → 烤鳕鱼(生)
@@ -204,7 +205,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:grilledcod_0",
"consume": 1,
"type": "switch",
"tip": "§a烤鳕鱼已上杆,等待篝火烤制…",
"tip": "§a烤鳕鱼已上杆,右键开始烤制",
"giveItem": None,
},
# 【上烤鲑鱼】支杆 + 鲑鱼 → 烤鲑鱼(生)
@@ -214,7 +215,7 @@ BARBECUE_SWITCHES = [
"target": "rtdd:grilled_fish",
"consume": 1,
"type": "switch",
"tip": "§a烤鲑鱼已上杆,等待篝火烤制…",
"tip": "§a烤鲑鱼已上杆,右键开始烤制",
"giveItem": None,
},
@@ -222,6 +223,7 @@ BARBECUE_SWITCHES = [
# 四、计时烤制(上杆后,支杆下方篝火,计时自动转换)
# ============================================================
# 【烤熟】烤鸡(上烤架_生) → 烤鸡(上烤架_熟),下方需篝火,约60秒
# autoStart=False:放置/上杆后必须右键一下才开始烤制
{
"source": "rtdd:roastchicken_0",
"item": None,
@@ -230,6 +232,7 @@ BARBECUE_SWITCHES = [
"type": "timer",
"time": 60,
"below": ["minecraft:campfire"],
"autoStart": False,
"startTip": "§e开始烤制烤鸡,约60秒…",
"doneTip": "§e烤鸡烤熟了!",
"giveItem": None,
@@ -243,6 +246,7 @@ BARBECUE_SWITCHES = [
"type": "timer",
"time": 60,
"below": ["minecraft:campfire"],
"autoStart": False,
"startTip": "§e开始烤制烤乳猪,约60秒…",
"doneTip": "§e烤乳猪烤熟了!",
"giveItem": None,
@@ -256,6 +260,7 @@ BARBECUE_SWITCHES = [
"type": "timer",
"time": 60,
"below": ["minecraft:campfire"],
"autoStart": False,
"startTip": "§e开始烤制烤鳕鱼,约60秒…",
"doneTip": "§e烤鳕鱼烤熟了!",
"giveItem": None,
@@ -269,6 +274,7 @@ BARBECUE_SWITCHES = [
"type": "timer",
"time": 60,
"below": ["minecraft:campfire"],
"autoStart": False,
"startTip": "§e开始烤制烤鲑鱼,约60秒…",
"doneTip": "§e烤鲑鱼烤熟了!",
"giveItem": None,
@@ -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: