汤锅功能实现 6

This commit is contained in:
wenhe committed 2026-09-16 14:08:24 +08:00
1 parent c342dcc93d
commit 72172ba09c
8 files changed
+679 -568

No files matched your search

@@ -84,19 +84,19 @@ SWITCH_RULES = [
{"block": OILPOT_1, "item": BREADED_CHICKEN, "target": CHICKEN_0,
"consume": 1, "startTimer": CHICKEN_0,
"needBelow": LIT_STOVE, "belowTip": "§c油锅需要放在点燃的炉灶上",
"tip": "§a放入裹粉鸡块, 开始炸制(共90秒: 先60秒半熟, 再30秒熟); 计时结束变成 炸鸡块(熟)"},
"tip": "§a放入裹粉鸡块,开始炸制共90秒,先60秒半熟,再30秒熟,计时结束变成 炸鸡块(熟)"},
{"block": OILPOT_1, "item": BREADED_PORK, "target": PORK_0,
"consume": 1, "startTimer": PORK_0,
"needBelow": LIT_STOVE, "belowTip": "§c油锅需要放在点燃的炉灶上",
"tip": "§a放入裹粉猪肉, 开始炸制(共90秒: 先60秒半熟, 再30秒熟); 计时结束变成 炸猪排(熟)"},
"tip": "§a放入裹粉猪肉,开始炸制共90秒,先60秒半熟,再30秒熟,计时结束变成 炸猪排(熟)"},
{"block": OILPOT_1, "item": BREADED_FRIES, "target": FRIES_0,
"consume": 3, "startTimer": FRIES_0,
"needBelow": LIT_STOVE, "belowTip": "§c油锅需要放在点燃的炉灶上",
"tip": "§a放入裹粉薯条x3, 开始炸制(共90秒: 先60秒半熟, 再30秒熟); 计时结束变成 炸薯条(熟)"},
"tip": "§a放入裹粉薯条x3,开始炸制共90秒,先60秒半熟,再30秒熟,计时结束变成 炸薯条(熟)"},
{"block": OILPOT_1, "item": BREADED_FISH, "target": FISH_0,
"consume": 1, "startTimer": FISH_0,
"needBelow": LIT_STOVE, "belowTip": "§c油锅需要放在点燃的炉灶上",
"tip": "§a放入裹粉鱼, 开始炸制(共90秒: 先60秒半熟, 再30秒熟); 计时结束变成 炸鱼块(熟)"},
"tip": "§a放入裹粉鱼,开始炸制共90秒,先60秒半熟,再30秒熟,计时结束变成 炸鱼块(熟)"},
{"block": OILPOT_1, "item": BREADED_TEMPURA, "target": TEMPURA_1,
"consume": 4, "startTimer": TEMPURA_1,
"needBelow": LIT_STOVE, "belowTip": "§c油锅需要放在点燃的炉灶上",
@@ -75,6 +75,31 @@ class YouguoService(BlueFoxServerSystem):
cur = nxt
self._timerTotal[src] = (total, stages)
# 级数信息: source -> (当前第几级, 总级数) 用于提示"第X级/共Y级"
self._timerStages = {}
nextMap, prevMap = {}, {}
for r in TIMER_RULES:
nextMap[r["source"]] = r["target"]
prevMap.setdefault(r["target"], r["source"])
for src in self._timerBySrc:
if src not in nextMap:
self._timerStages[src] = (1, 1)
continue
head = src
while head in prevMap and prevMap[head] in self._timerBySrc:
head = prevMap[head]
totalLevel, cur, seen = 0, head, set()
while cur in self._timerBySrc and cur not in seen:
seen.add(cur)
totalLevel += 1
cur = nextMap[cur]
cur, level, seen2 = head, 1, set()
while cur != src and cur in nextMap and cur not in seen2:
seen2.add(cur)
level += 1
cur = nextMap[cur]
self._timerStages[src] = (level, totalLevel)
# 终点方块 -> 成品名(从出锅规则 tip 的"取出 XX"提取, 用于计时提示)
self._finalNames = {}
for r in SWITCH_RULES:
@@ -85,23 +110,37 @@ class YouguoService(BlueFoxServerSystem):
if nm:
self._finalNames[r["block"]] = nm
# 终点方块 -> 出锅动作(出锅规则 item 为盘子)
self._finalInfo = {}
for r in SWITCH_RULES:
if r.get("action") == "take_out":
self._finalInfo[r["block"]] = "手持盘子出锅"
self.timerSources = set()
self.startTimerTips = {} # 空手右键启动计时 -> 提示(含总共多少秒)
self.timingTips = {} # 空手右键"已在计时中" -> 提示(同样含总共多少秒)
for src, r in self._timerBySrc.items():
self.timerSources.add(src)
self.featureBlocks.add(src)
total, stages = self._timerTotal[src]
if len(stages) == 1:
stage = ""
total, stages = self._timerTotal[src] # total = 从当前级到终点剩余秒数
curLv, totLv = self._timerStages.get(src, (1, 1))
lvTip = "(第%d级/共%d级)" % (curLv, totLv) if totLv > 1 else ""
if len(stages) <= 1:
perTip = ""
elif len(set(stages)) == 1:
perTip = "每级%d秒" % stages[0]
else:
stage = "(%d级: %s)" % (len(stages), "→".join("%d秒" % s for s in stages))
tip = "§a开始炸制…共需计时%d秒%s" % (total, stage)
t2 = "§e正在炸制中…共需计时%d秒%s" % (total, stage)
end = self._oilTerminalName(src)
if end:
tip += "; 计时结束变成 %s" % end
t2 += ", 计时结束变成 %s" % end
perTip = "先%d秒,再%s" % (stages[0], ",".join("%d秒" % s for s in stages[1:]))
perStr = (", " + perTip) if perTip else ""
endBlock = self._oilTerminal(src)
endName = self._finalNames.get(endBlock, "") if endBlock else ""
act = self._finalInfo.get(endBlock) if endBlock else None
actStr = (", " + act) if act else ""
base = "还需%d秒%s" % (total, perStr)
if endName:
base += ", 计时结束变成 %s%s" % (endName, actStr)
tip = "§a开始炸制%s: %s" % (lvTip, base)
t2 = "§e正在炸制中%s: %s" % (lvTip, base)
self.startTimerTips[src] = tip
self.timingTips[src] = t2
@@ -163,18 +202,18 @@ class YouguoService(BlueFoxServerSystem):
started = FeatureDispatcher.startTimerFor(blockName, dim, pos, playerId)
if started:
comp.CreateMsg(playerId).NotifyOneMessage(
playerId, self.startTimerTips.get(blockName, "§a开始计时…"))
playerId, self.startTimerTips.get(blockName, "§a已启动计时"))
else:
comp.CreateMsg(playerId).NotifyOneMessage(
playerId, "§c油锅需要放在点燃的炉灶上才能开始计时")
def _oilTerminalName(self, src):
"""沿计时链走到终点方块, 返回成品名(未取到则返回空串)"""
def _oilTerminal(self, src):
"""沿计时链走到终点方块(返回方块id)"""
cur, seen = src, set()
while cur in self._timerBySrc and cur not in seen:
seen.add(cur)
cur = self._timerBySrc[cur]["target"]
return self._finalNames.get(cur, "")
return cur
# ============================================================================
# 二、通用转换执行
@@ -219,7 +258,7 @@ class YouguoService(BlueFoxServerSystem):
comp.CreateMsg(playerId).NotifyOneMessage(playerId, recipe["tip"])
# ============================================================================
# 三、工具方法:判断正下方是否指定方块(点燃炉灶)
# 三、工具方法,判断正下方是否指定方块(点燃炉灶)
# ============================================================================
def _belowIs(self, dim, pos, blockName):
@@ -230,7 +269,7 @@ class YouguoService(BlueFoxServerSystem):
return False
# ============================================================================
# 四、工具方法:获取玩家主手物品
# 四、工具方法,获取玩家主手物品
# ============================================================================
def getCarriedItem(self, playerId):
@@ -239,7 +278,7 @@ class YouguoService(BlueFoxServerSystem):
serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
# ============================================================================
# 五、工具方法:给玩家物品
# 五、工具方法,给玩家物品
# ============================================================================
def giveItem(self, playerId, itemName, count=1, aux=0):
@@ -250,7 +289,7 @@ class YouguoService(BlueFoxServerSystem):
pass
# ============================================================================
# 六、工具方法:消耗物品
# 六、工具方法,消耗物品
# ============================================================================
def consumeItem(self, playerId, itemDict, amount=1):
@@ -271,7 +310,7 @@ class YouguoService(BlueFoxServerSystem):
"userData": itemDict.get("userData", {})})
# ============================================================================
# 七、工具方法:以掉落物形式生成物品
# 七、工具方法,以掉落物形式生成物品
# ============================================================================
def dropItem(self, dim, pos, itemName, count=1, aux=0):
@@ -282,7 +321,7 @@ class YouguoService(BlueFoxServerSystem):
pass
# ============================================================================
# 八、工具方法:替换方块 / 清空方块(清空时 aux 强制 0, 兼容定向变体)
# 八、工具方法,替换方块 / 清空方块(清空时 aux 强制 0, 兼容定向变体)
# ============================================================================
def replaceBlock(self, pos, dim, newBlockName, playerId=None):
@@ -303,7 +342,7 @@ class YouguoService(BlueFoxServerSystem):
oldBlockHandling=0, dimensionId=dim)
# ============================================================================
# 九、工具方法:冷却检查
# 九、工具方法,冷却检查
# ============================================================================
def checkCooldown(self, key, cd=0.4):