This commit is contained in:
wenhe committed 2026-09-11 11:44:28 +08:00
1 parent 052e4844b2
commit a4c5ad43e4
5 files changed
+163 -70

No files matched your search

@@ -35,9 +35,9 @@ from ....BlueFoxTools.ToolsConfig import LevelId
# ---- 只导入面食自己的数据库 ----
from ..MianshiData import (
CLEAVER, ROLLINGPIN, BOWL, OVEN,
CLEAVER, ROLLINGPIN, BOWL, OVEN, STEAMER,
MEAT_ITEMS, FILLING_ITEMS, RICH_MEAT_ITEMS,
SWITCH_RULES, KNEAD_COUNTERS, ITEM_USE_ON_RULES,
SWITCH_RULES, KNEAD_COUNTERS, ITEM_USE_ON_RULES, OVEN_FIX_BLOCKS,
)
# ---- 统一分发器 ----
@@ -75,6 +75,16 @@ class MianshiService(BlueFoxServerSystem):
for b in KNEAD_COUNTERS:
self.featureBlocks.add(b)
# 蒸笼也要登记为本服务管辖: 手持生食右键蒸笼(itemUseOn)时, 分发器
# 要求当前服务在被点方块的归属列表里才放行(蒸笼已归 ChujuService 管辖)
self.featureBlocks.add(STEAMER)
# 烤炉固定的方块全部登记右键路由(蛋糕面糊/可颂胚/舒芙蕾半成品/发面等
# 不在 SWITCH_RULES 里), 否则右键它们时不会被分发器路由到本服务,
# "烤炉固定 + 开始烤制提示"就不生效
for b in OVEN_FIX_BLOCKS:
self.featureBlocks.add(b)
# ---- itemUseOn 映射: 手持物品 -> 规则 ----
self.itemUseOnMap = {}
for r in ITEM_USE_ON_RULES:
@@ -117,6 +127,13 @@ class MianshiService(BlueFoxServerSystem):
if blockName in KNEAD_COUNTERS and (not itemName or itemName == "minecraft:air"):
return self._handleKnead(blockName, playerId, pos, dim, key)
# ---- 烤炉固定: 胚/面糊/蛋液等放在烤炉上 -> 禁止右键转换, 固定开始烤制 ----
if blockName in OVEN_FIX_BLOCKS and self._belowIs(dim, pos, OVEN):
FeatureDispatcher.startTimerFor(blockName, dim, pos, playerId)
if self.checkCooldown(key, 0.4):
comp.CreateMsg(playerId).NotifyOneMessage(playerId, "§a开始烤制…(60秒)")
return True
# ---- 常规转换 ----
recipe = self.findRecipe(blockName, itemDict)
if not recipe:
@@ -130,6 +147,7 @@ class MianshiService(BlueFoxServerSystem):
"""由 FeatureDispatcher 转发的"手持物品右键方块表面"入口:
1) 手持 生面饼 右键 烤炉 -> 烤炉上方放置 馍(烙制), 消耗1个生面饼
2) 手持 面粉(加鸡蛋) 右键 木碗 -> 木碗变 蛋糕面糊(生), 消耗1个
3) 手持 生食 右键 蒸笼 -> 蒸笼变 蒸X_生(蒸笼下要点燃的炉灶, 消耗1个)
返回 True=处理了; False=不属本功能管(交还默认行为)。"""
itemName = args.get("itemName")
playerId = args.get("playerId") or args.get("entityId")
@@ -148,13 +166,25 @@ class MianshiService(BlueFoxServerSystem):
except Exception:
return False
# 需要下方方块(如蒸笼下要点燃的炉灶): 不满足则提示并拦截, 不消耗物品
needBelow = rule.get("needBelow")
if needBelow and not self._belowIs(dim, (x, y, z), needBelow):
comp.CreateMsg(playerId).NotifyOneMessage(
playerId, rule.get("belowTip", "§c下方方块不符合"))
return True
if not self.checkCooldown((dim, x, y, z), 0.4):
return True
itemDict = self.getCarriedItem(playerId)
if not itemDict:
return False
self.consumeItem(playerId, itemDict, rule.get("consume", 1))
consume = rule.get("consume", 1)
if consume > 1 and (itemDict.get("count") or 0) < consume:
comp.CreateMsg(playerId).NotifyOneMessage(
playerId, "§c数量不足, 需要 %d 个" % consume)
return True
self.consumeItem(playerId, itemDict, consume)
if rule.get("above"):
# 在表面方块上方放置结果(烙制)
@@ -168,9 +198,14 @@ class MianshiService(BlueFoxServerSystem):
pass
self.replaceBlock(targetPos, dim, rule["above"], playerId)
elif rule.get("replace"):
# 表面方块本身被替换(木碗变蛋糕面糊)
# 表面方块本身被替换(木碗变蛋糕面糊/蒸笼变蒸X_生)
self.replaceBlock((x, y, z), dim, rule["replace"], playerId)
# 替换/放置后立刻启动计时(记录发起玩家, 蒸熟完成/暂停提示能送达)
if rule.get("startTimer"):
FeatureDispatcher.startTimerFor(
rule["startTimer"], dim, (x, y, z), playerId)
if rule.get("tip"):
comp.CreateMsg(playerId).NotifyOneMessage(playerId, rule["tip"])
return True
@@ -211,9 +246,14 @@ class MianshiService(BlueFoxServerSystem):
# ============================================================================
def handleSwitch(self, recipe, playerId, pos, dim, itemDict):
# 消耗物品
if recipe.get("consume", 0) > 0:
self.consumeItem(playerId, itemDict, recipe["consume"])
# 消耗物品(数量不足则拦截, 不转换)
consume = recipe.get("consume", 0)
if consume > 1 and itemDict is not None and (itemDict.get("count") or 0) < consume:
comp.CreateMsg(playerId).NotifyOneMessage(
playerId, "§c数量不足, 需要 %d 个" % consume)
return
if consume > 0:
self.consumeItem(playerId, itemDict, consume)
# 替换方块
if recipe.get("target"):
self.replaceBlock(pos, dim, recipe["target"], playerId)
@@ -243,16 +283,31 @@ class MianshiService(BlueFoxServerSystem):
for _ in range(2):
self.dropItem(dim, pos, recipe["dropItem"])
elif action == "take_steamer":
# 蒸笼取出: 蒸食物块 -> 变回空蒸笼 + 掉落成品
# 蒸笼取出: 蒸食物块 -> 变回空蒸笼 + 掉落成品(数量按 dropCount, 默认1)
self.replaceBlock(pos, dim, "rtdd:steamer", playerId)
if recipe.get("dropItem"):
self.dropItem(dim, pos, recipe["dropItem"])
for _ in range(recipe.get("dropCount", 1)):
self.dropItem(dim, pos, recipe["dropItem"])
# 转换后启动计时(发酵等, 记录玩家以便完成提示送达)
if recipe.get("startTimer"):
FeatureDispatcher.startTimerFor(recipe["startTimer"], dim, pos, playerId)
# 提示
if recipe.get("tip"):
comp.CreateMsg(playerId).NotifyOneMessage(playerId, recipe["tip"])
# ============================================================================
# 五、工具方法:获取玩家主手物品
# 五、工具方法:判断正下方是否指定方块(烤炉/点燃炉灶)
# ============================================================================
def _belowIs(self, dim, pos, blockName):
try:
b = comp.CreateBlockInfo(LevelId).GetBlockNew((pos[0], pos[1] - 1, pos[2]), dim)
return bool(b) and b.get("name") == blockName
except Exception:
return False
# ============================================================================
# 六、工具方法:获取玩家主手物品
# ============================================================================
def getCarriedItem(self, playerId):
@@ -261,7 +316,7 @@ class MianshiService(BlueFoxServerSystem):
serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
# ============================================================================
# 六、工具方法:给玩家物品
# 七、工具方法:给玩家物品
# ============================================================================
def giveItem(self, playerId, itemName, count=1, aux=0):
@@ -272,7 +327,7 @@ class MianshiService(BlueFoxServerSystem):
pass
# ============================================================================
# 七、工具方法:消耗物品
# 八、工具方法:消耗物品
# ============================================================================
def consumeItem(self, playerId, itemDict, amount=1):
@@ -293,7 +348,7 @@ class MianshiService(BlueFoxServerSystem):
"userData": itemDict.get("userData", {})})
# ============================================================================
# 八、工具方法:以掉落物形式生成物品
# 九、工具方法:以掉落物形式生成物品
# ============================================================================
def dropItem(self, dim, pos, itemName, count=1, aux=0):
@@ -304,7 +359,7 @@ class MianshiService(BlueFoxServerSystem):
pass
# ============================================================================
# 九、工具方法:替换方块 / 清空方块(保留 aux, 兼容定向变体)
# 十、工具方法:替换方块 / 清空方块(保留 aux, 兼容定向变体)
# ============================================================================
def replaceBlock(self, pos, dim, newBlockName, playerId=None):
@@ -325,7 +380,7 @@ class MianshiService(BlueFoxServerSystem):
oldBlockHandling=0, dimensionId=dim)
# ============================================================================
# 十、工具方法:冷却检查
# 十一、工具方法:冷却检查
# ============================================================================
def checkCooldown(self, key, cd=0.4):
@@ -162,7 +162,9 @@ class MianshiTimerService(BlueFoxServerSystem):
rule = r
break
if rule is None:
return # 蒸笼等: 暂停
# 蒸笼等: 暂停计时(数据保留, 炉灶回来继续) + 提示发起玩家
self._notifyIfOnline(data.get("rtdd_tp"), "§c蒸笼下的炉灶移走了, 暂停蒸制")
return
# 烤炉被打碎: 方块掉落 + 变空气 + 终止计时 + 提示
self._clearTimerData(dim, pos)
self._dropBlockItem(dim, pos, blockName)