配方 替换方块ceshi5

This commit is contained in:
wenhe committed 2026-07-21 16:04:04 +08:00
1 parent 9ef1fedc2e
commit fcb08e0119
5 files changed
+23 -84

No files matched your search

@@ -1,4 +1,5 @@
# coding=utf-8
from mod.common.mod import Mod
from OtherTools import *
from SpecialFunciton.BlueFoxSystem import *
from SystemTools import *
@@ -35,4 +36,4 @@ class BlueFoxModLoader:
RegisterSystemFastly(serverApi, BlueFoxServerSystem)
lastSubclasses = GetLastSubclass(BlueFoxServerSystem)
for lastSubclass in lastSubclasses:
RegisterSystemFastly(serverApi, lastSubclass)
RegisterSystemFastly(serverApi, lastSubclass)
@@ -132,6 +132,8 @@ class PlayerBehaviorTree(object):
}
from .ModConfig import MOD_NAME, MOD_VERSION
LevelId = serverApi.GetLevelId() or clientApi.GetLevelId()
Platform = serverApi.GetPlatform() or clientApi.GetPlatform()
# Platform = 1 # 测试用
@@ -153,4 +155,4 @@ if not serverApi.IsInServer():
nativeScreenManager = clientApi.GetNativeScreenManagerCls().instance() # type:clientApi.GetNativeScreenManagerCls()
viewBinder = clientApi.GetViewBinderCls()
baseScreen = clientApi.GetScreenNodeCls()
customUIScreenProxy = clientApi.GetUIScreenProxyCls()
customUIScreenProxy = clientApi.GetUIScreenProxyCls()
@@ -1,85 +1,31 @@
# -*- coding: utf-8 -*-
"""
配方数据文件 - 所有"右键方块→消耗物品→替换方块"的配方都在这里
===============================================================
每加一道新菜,只需要在这里加一条配方,不用写任何Python代码。
配方数据文件 - 所有烹饪配方都在这里
===================================
每加一道菜,在这里加一条配方就行,不用写代码。
配方字典字段说明([] = 可选,{} = 特殊类型):
{
"source": str, # 被右键的方块ID(必填)
"item": str|None, # 玩家手里必须拿的物品,None=空手也行
[below]: str, # 方块下面必须是什么
[needOil]: bool, # 物品必须有"油标签"
[target]: str|None, # 替换成什么方块,None=不替换
[consume]: int, # 消耗物品数量,0=不消耗(默认1)
[giveItem]: str, # 额外给玩家什么物品
[sound]: str, # 播放什么声音
[soundPitch]: float, # 声音频率(默认1.0)
[stirCount]: int, # 需要翻炒几次才变身
[stirCd]: float, # 翻炒冷却时间(秒)
[onDone]: str, # 完成动作:"finish"=标记熟了不替换
[doneMsg]: str, # 完成后的提示消息
[failMsg]: str, # 冷却中/失败时的提示
[dropIfDone]: list, # 熟了后拆掉掉落什么
[dropIfNot]: list, # 没熟拆掉掉落什么
}
字段说明:
source = 被右键的方块ID(必填)
item = 手里必须拿的物品,None=空手也行
target = 替换成什么方块
consume = 消耗几个物品(默认1,0=不消耗)
giveItem = 额外给玩家什么物品
below = 方块下面必须垫什么(可选)
"""
# ============================================================
# 炒菜示例:胡萝卜牛肉(完整一条链)
# ============================================================
# 流程:空锅 → 加油 → 放牛肉 → 翻炒 → 熟了 → 拆掉拿熟牛肉
RECIPES = [
# ===== 步骤1:空炒锅 + 有油的物品 → 带油煎锅 =====
# ================================================================
# 测试配方(最简单的一条,验证引擎能不能跑通)
# ================================================================
# 玩法:放一个 rtdd:wok(炒锅),手里拿生牛肉右键它
# 锅会变成钻石块,牛肉消失,背包里多一块熟牛肉
{
"source": "rtdd:wok",
"item": None,
"below": "minecraft:campfire",
"needOil": True,
"target": "rtdd:cookinggarlic",
"consume": 0,
"sound": "random.fizz",
"soundPitch": 2.4,
},
# ===== 步骤2:带油煎锅 + 生牛肉 → 胡萝卜牛肉锅 =====
{
"source": "rtdd:cookinggarlic",
"item": "minecraft:beef",
"target": "rtdd:carrotandbeef",
"target": "minecraft:diamond_block",
"consume": 1,
"sound": "random.fizz",
"soundPitch": 0.8,
"giveItem": "minecraft:cooked_beef",
},
# ===== 步骤3:胡萝卜牛肉锅 + 木剑翻炒 → 第二阶段 =====
{
"source": "rtdd:carrotandbeef",
"item": "minecraft:wooden_sword",
"target": "rtdd:carrotandbeef_1",
"consume": 0,
"stirCount": 5,
"stirCd": 1.2,
"sound": "random.fizz",
"soundPitch": 2.1,
"failMsg": "这时候翻动会不好熟的!",
},
# ===== 步骤4:第二阶段 + 木剑翻炒 → 标记熟了 =====
{
"source": "rtdd:carrotandbeef_1",
"item": "minecraft:wooden_sword",
"target": None,
"consume": 0,
"stirCount": 3,
"stirCd": 0.8,
"sound": "random.fizz",
"soundPitch": 2.1,
"onDone": "finish",
"doneMsg": "出锅啦!拿盘子盛出来",
"failMsg": "这时候翻动会不好熟的!",
"dropIfDone": ["minecraft:cooked_beef", "rtdd:wok"],
"dropIfNot": ["minecraft:beef", "rtdd:wok"],
},
]
@@ -88,10 +88,6 @@ class CookingService(BlueFoxServerSystem):
# ==================== 主入口:玩家右键方块 ====================
def OnBlockUse(self, args):
"""
玩家右键方块时触发。
流程:查配方 → 验条件 → 处理翻炒 → 消耗物品 → 替换方块 → 给物品 → 播声音
"""
blockName = args.get("blockName")
playerId = args.get("playerId")
x, y, z = args.get("x"), args.get("y"), args.get("z")
@@ -126,26 +122,20 @@ class CookingService(BlueFoxServerSystem):
# ==================== 配方执行(普通替换) ====================
def executeRecipe(self, recipe, playerId, pos, dim, itemDict):
# 1. 检查附加条件
if not self.checkConditions(recipe, playerId, pos, dim, itemDict):
return
# 2. 消耗物品
if recipe.get("consume", 1) > 0:
self.consumeItem(playerId, itemDict, recipe.get("consume", 1))
if recipe.get("needOil"):
self.removeOil(itemDict, playerId)
# 3. 替换方块
if recipe.get("target"):
self.replaceBlock(pos, dim, recipe["target"], playerId)
# 4. 给物品
if recipe.get("giveItem"):
self.giveItem(playerId, recipe["giveItem"])
# 5. 播放声音(需要配合 BlueFox 框架的客户端 PlaySound 事件,此处暂不实现)
# ==================== 翻炒处理 ====================
def handleStir(self, key, recipe, playerId, pos, dim, itemDict):
@@ -2,4 +2,4 @@ from BlueFoxTools.ModLoader import *
if not serverApi.IsInServer():
pass
LoadMod()
LoadMod()