底座判断1
This commit is contained in:
1 parent
5b2d0e9291
commit
be7e56d966
8 files changed
+105
-639
No files matched your search
@@ -47,7 +47,7 @@ blockEntityDataComp = comp.CreateBlockEntityData(LevelId)
|
||||
|
||||
# ---- 导入所有配方 ----
|
||||
# RECIPES 是一个列表,每条配方是一个 dict,格式见 RecipeData.py 顶部注释
|
||||
from ..RecipeData import RECIPES
|
||||
from ..RecipeData import RECIPES, inferBaseBlock, BELOW_CAMPFIRE
|
||||
|
||||
# ---- 导入工具方块切换规则 ----
|
||||
# BLOCK_SWITCHES 是一个列表,每条规则是一个 dict,格式见 BlockSwitchData.py 顶部注释
|
||||
@@ -229,6 +229,10 @@ class CookingService(BlueFoxServerSystem):
|
||||
# 没找到匹配的配方 → 不是做菜操作,不拦截,让游戏正常处理
|
||||
return
|
||||
|
||||
# ---- 底座检查:锅下面必须有灶台/营火,否则不让操作 ----
|
||||
if not self.checkBaseBlock(recipe, playerId, pos, dim):
|
||||
return
|
||||
|
||||
# 找到配方后,取消默认行为(如喝药水、吃食物等),由本 Mod 全权接管
|
||||
args['cancel'] = True
|
||||
# 同时标记该玩家下一次物品使用事件也要取消,防止喝药水等默认行为
|
||||
@@ -578,6 +582,53 @@ class CookingService(BlueFoxServerSystem):
|
||||
self.replaceBlock(pos, dim, recipe["target"], playerId)
|
||||
self.clearStirData(key, playerId, pos, dim)
|
||||
|
||||
# ============================================================================
|
||||
# 底座检查(入口统一拦截)
|
||||
# ============================================================================
|
||||
|
||||
def checkBaseBlock(self, recipe, playerId, pos, dim):
|
||||
"""
|
||||
检查锅下面有没有合法的底座(灶台或营火)。
|
||||
|
||||
优先级:
|
||||
1. 配方里明确写了 "below" 字段 → 用配方的值
|
||||
- below=[] 表示不需要底座,直接通过
|
||||
- below=["xxx"] 表示必须是这些方块之一
|
||||
2. 配方没写 "below" → 调用 inferBaseBlock 自动推断
|
||||
- 大多数烹饪方块默认需要灶台(BELOW_STOVE)
|
||||
- 架锅系列需要营火(BELOW_CAMPFIRE)
|
||||
- 手工工具(榨汁机、搅拌器等)不需要底座
|
||||
|
||||
返回 True=底座合法/不需要底座,False=底座不合法
|
||||
"""
|
||||
# 配方显式指定了 below
|
||||
if "below" in recipe:
|
||||
required = recipe["below"]
|
||||
if not required: # 空列表 = 不需要底座
|
||||
return True
|
||||
else:
|
||||
# 自动推断
|
||||
required = inferBaseBlock(recipe["source"])
|
||||
if not required: # 推断结果为空 = 不需要底座
|
||||
return True
|
||||
|
||||
# 检查下面一格方块
|
||||
belowPos = (pos[0], pos[1] - 1, pos[2])
|
||||
try:
|
||||
belowBlock = comp.CreateBlockInfo(playerId).GetBlockNew(belowPos, dim)
|
||||
if belowBlock.get("name") in required:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
|
||||
# ---- 底座不通过,给玩家提示 ----
|
||||
if required == BELOW_CAMPFIRE:
|
||||
tip = "§c架锅下面需要放一个营火,才能做饭!"
|
||||
else:
|
||||
tip = "§c锅下面需要放一个灶台(点燃的炉灶),才能做饭!"
|
||||
comp.CreateMsg(playerId).NotifyOneMessage(playerId, tip)
|
||||
return False
|
||||
|
||||
# ============================================================================
|
||||
# 条件检查
|
||||
# ============================================================================
|
||||
@@ -586,27 +637,10 @@ class CookingService(BlueFoxServerSystem):
|
||||
"""
|
||||
检查配方的前置条件是否满足。
|
||||
|
||||
目前支持两种条件:
|
||||
1. below:锅下面一格必须是特定方块(比如灶台或营火)
|
||||
2. needOil:玩家手里的物品必须带有油标签
|
||||
|
||||
两个条件都满足才返回 True,有一个不满足就返回 False。
|
||||
目前只检查 needOil:玩家手里的物品必须带有油标签。
|
||||
底座检查已移到入口 checkBaseBlock 统一处理。
|
||||
"""
|
||||
# ---- 条件1:检查下面是否有指定方块(底座检查) ----
|
||||
if recipe.get("below"):
|
||||
# 下面一格坐标:(x, y-1, z)
|
||||
belowPos = (pos[0], pos[1] - 1, pos[2])
|
||||
blockComp = comp.CreateBlockInfo(playerId)
|
||||
try:
|
||||
belowBlock = blockComp.GetBlockNew(belowPos, dim)
|
||||
# 比较下面方块的名字是否和配方要求的底座一致
|
||||
if belowBlock.get("name") != recipe["below"]:
|
||||
return False
|
||||
except:
|
||||
# 读取失败(比如方块不存在)→ 条件不满足
|
||||
return False
|
||||
|
||||
# ---- 条件2:检查物品是否有油标签 ----
|
||||
# ---- 检查物品是否有油标签 ----
|
||||
if recipe.get("needOil") and itemDict:
|
||||
if not self.getItemOil(itemDict):
|
||||
return False
|
||||
@@ -643,18 +677,19 @@ class CookingService(BlueFoxServerSystem):
|
||||
"""
|
||||
消耗玩家主手物品的指定数量。
|
||||
|
||||
如果数量不够 → 清空主手(SetEntityItem 传 None)
|
||||
如果数量不够 → 清空主手
|
||||
如果数量够 → 减少对应数量
|
||||
|
||||
重要:SetInvItemNum 的参数是背包槽位索引(int),不是 ItemPosType 枚举。
|
||||
清空主手必须用 SetEntityItem(CARRIED, None),不能用 SetInvItemNum。
|
||||
"""
|
||||
if itemDict is None:
|
||||
return
|
||||
count = itemDict.get("count", 0)
|
||||
if count <= amount:
|
||||
# 数量不够或刚好用完 → 清空主手
|
||||
comp.CreateItem(playerId).SetEntityItem(
|
||||
serverApi.GetMinecraftEnum().ItemPosType.CARRIED,
|
||||
None)
|
||||
{"count": 0})
|
||||
else:
|
||||
# 数量够 → 减少 amount 个
|
||||
itemDict["count"] = count - amount
|
||||
|
||||
Reference in new issue
Block a user