乡野食材 功能实现 2
This commit is contained in:
1 parent
098290c6b6
commit
51804de264
10 files changed
+145
-34
No files matched your search
@@ -63,7 +63,8 @@ GARLIC_BLOCK = "rtdd:cutgarlic"
|
||||
GARLIC_CHOP_COUNT = 3
|
||||
GARLIC_DROP = {"name": "rtdd:crushedgarlic", "count": 16}
|
||||
|
||||
# ---- 裹粉: 面粉块 + 生食材 -> 掉落裹粉半成品 ----
|
||||
# ---- 裹粉: 面粉块(farineblock_3) + 生食材 -> 掉落裹粉半成品 ----
|
||||
# 只支持"面粉块"这一个方块(用户指定 tile.rtdd:farineblock_3.name=面粉块)
|
||||
FLOUR_BLOCK = "rtdd:farineblock_3"
|
||||
COATING_RULES = [
|
||||
{"item": "rtdd:sashimi", "count": 6,
|
||||
@@ -78,6 +79,14 @@ COATING_RULES = [
|
||||
"drop": {"name": "rtdd:oilfrenchfries", "count": 10}},
|
||||
]
|
||||
|
||||
# ---- 肉馅按压: 空手右键 生猪肉馅/生牛肉馅 -> 按压成型 ----
|
||||
MEAT_PRESS_RULES = [
|
||||
{"source": "rtdd:rawmeatball_0", "target": "rtdd:rawmeatball_2",
|
||||
"tip": "§a生猪肉馅按压成型了"},
|
||||
{"source": "rtdd:rawmeatball_1", "target": "rtdd:rawmeatball_3",
|
||||
"tip": "§a生牛肉馅按压成型了"},
|
||||
]
|
||||
|
||||
# ---- 左键破坏掉落: 摆在地上的切配方块 -> 原版食材(相对"切配态"的原版不切物品) ----
|
||||
DESTROY_DROP = {
|
||||
"rtdd:cutcarrot_0": "minecraft:carrot",
|
||||
|
||||
+62
-8
@@ -35,6 +35,7 @@ from ....BlueFoxTools.ToolsConfig import LevelId
|
||||
from ..ShicaiData import (
|
||||
CLEAVER_ITEM, CHOP_CHAINS, GARLIC_BLOCK, GARLIC_CHOP_COUNT,
|
||||
GARLIC_DROP, FLOUR_BLOCK, COATING_RULES, DESTROY_DROP,
|
||||
MEAT_PRESS_RULES,
|
||||
)
|
||||
|
||||
# ---- 统一分发器 ----
|
||||
@@ -58,9 +59,20 @@ class ShicaiService(BlueFoxServerSystem):
|
||||
self.chopMap[b] = (chain, i)
|
||||
self.featureBlocks.add(b)
|
||||
|
||||
# ---- 蒜末方块 + 面粉块 ----
|
||||
# ---- 蒜末方块 + 肉馅(按压) + 面粉块 ----
|
||||
# 面粉块(farineblock_3) 注册进 blockOwner 仅用于"去重标记": 裹粉本身走
|
||||
# OnItemUseOn(ServerItemUseOnEvent), 但把它标记为 ShicaiService 管辖后,
|
||||
# 原版放置(YuanbanService) 手持土豆/鸡肉/猪肉右键面粉块时会因去重跳过放置。
|
||||
# (OnBlockUse 路由到本类 handleBlockUse 时无裹粉分支, 直接返回 False, 无副作用)
|
||||
self.featureBlocks.add(GARLIC_BLOCK)
|
||||
self.featureBlocks.add(FLOUR_BLOCK)
|
||||
for r in MEAT_PRESS_RULES:
|
||||
self.featureBlocks.add(r["source"])
|
||||
|
||||
# ---- 肉馅按压映射 ----
|
||||
self.meatPressMap = {}
|
||||
for r in MEAT_PRESS_RULES:
|
||||
self.meatPressMap[r["source"]] = r
|
||||
|
||||
# ---- 裹粉规则映射: 手持物品名 -> 规则 ----
|
||||
self.coatingMap = {}
|
||||
@@ -85,8 +97,35 @@ class ShicaiService(BlueFoxServerSystem):
|
||||
return self.featureBlocks
|
||||
|
||||
def getItemUseOnRules(self):
|
||||
"""手持物品右键方块表面不需要单独路由, 返回空"""
|
||||
return {}
|
||||
"""手持生食材右键方块表面路由(裹粉): 注册全部裹粉食材(含原版物品)。
|
||||
与原版放置(YuanbanService) 的物品冲突由 FeatureDispatcher 多服务 fallback 解决:
|
||||
本服务先试(面粉块裹粉), 失败再交给 YuanbanService(放置)。"""
|
||||
rules = {}
|
||||
for r in COATING_RULES:
|
||||
rules[r["item"]] = True
|
||||
return rules
|
||||
|
||||
def handleItemUseOn(self, args):
|
||||
"""由 FeatureDispatcher 转发的"手持物品右键方块表面"入口(裹粉):
|
||||
手持生食材右键 面粉块(farineblock_3) 表面 -> 裹粉。
|
||||
返回 True=处理了; False=不属本功能管(交还其他服务/默认行为)。"""
|
||||
itemName = args.get("itemName")
|
||||
playerId = args.get("playerId") or args.get("entityId")
|
||||
x, y, z = args.get("x"), args.get("y"), args.get("z")
|
||||
dim = comp.CreateDimension(playerId).GetEntityDimensionId()
|
||||
key = (dim, x, y, z)
|
||||
|
||||
# 被点方块必须是 面粉块(farineblock_3)
|
||||
try:
|
||||
cur = comp.CreateBlockInfo(LevelId).GetBlockNew((x, y, z), dim)
|
||||
if not cur or cur.get("name") != FLOUR_BLOCK:
|
||||
return False
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
itemDict = self.getCarriedItem(playerId)
|
||||
itemName2 = itemDict.get("newItemName") if itemDict else None
|
||||
return self._handleCoating(playerId, (x, y, z), dim, itemDict, itemName2, key)
|
||||
|
||||
def handleDestroy(self, args):
|
||||
"""由 FeatureDispatcher 转发的"玩家左键破坏方块"入口。
|
||||
@@ -134,6 +173,10 @@ class ShicaiService(BlueFoxServerSystem):
|
||||
itemDict = self.getCarriedItem(playerId)
|
||||
itemName = itemDict.get("newItemName") if itemDict else None
|
||||
|
||||
# ---- 肉馅按压(空手右键) ----
|
||||
if blockName in self.meatPressMap:
|
||||
return self._handleMeatPress(blockName, playerId, pos, dim, itemName, key)
|
||||
|
||||
# ---- 菜刀切分 ----
|
||||
if blockName in self.chopMap:
|
||||
return self._handleChop(blockName, playerId, pos, dim, itemDict, itemName, key)
|
||||
@@ -142,14 +185,25 @@ class ShicaiService(BlueFoxServerSystem):
|
||||
if blockName == GARLIC_BLOCK:
|
||||
return self._handleGarlic(playerId, pos, dim, itemDict, itemName, key)
|
||||
|
||||
# ---- 裹粉 ----
|
||||
if blockName == FLOUR_BLOCK:
|
||||
return self._handleCoating(playerId, pos, dim, itemDict, itemName, key)
|
||||
|
||||
return False
|
||||
|
||||
# ============================================================================
|
||||
# 二、菜刀切分配
|
||||
# 二、肉馅按压(空手右键)
|
||||
# ============================================================================
|
||||
|
||||
def _handleMeatPress(self, blockName, playerId, pos, dim, itemName, key):
|
||||
# 必须空手
|
||||
if itemName and itemName != "minecraft:air":
|
||||
return False
|
||||
rule = self.meatPressMap[blockName]
|
||||
if not self.checkCooldown(key, 0.5):
|
||||
return True
|
||||
self.replaceBlock(pos, dim, rule["target"], playerId)
|
||||
comp.CreateMsg(playerId).NotifyOneMessage(playerId, rule["tip"])
|
||||
return True
|
||||
|
||||
# ============================================================================
|
||||
# 三、菜刀切分配
|
||||
# ============================================================================
|
||||
|
||||
def _handleChop(self, blockName, playerId, pos, dim, itemDict, itemName, key):
|
||||
|
||||
Reference in new issue
Block a user