胡萝卜牛肉汤ceshi2 位置缓存清空 退游戏保存数据
This commit is contained in:
1 parent
0c48f7f546
commit
6a35cee4be
2 files changed
+85
-20
No files matched your search
@@ -4,18 +4,18 @@
|
|||||||
每加一道新菜,只需要在这里加一条配方,不用写任何Python代码。
|
每加一道新菜,只需要在这里加一条配方,不用写任何Python代码。
|
||||||
|
|
||||||
配方字段说明:
|
配方字段说明:
|
||||||
source: 被右键的方块ID(必填)
|
source: 被右键的方块ID(必填)
|
||||||
item: 玩家手里必须拿的物品,None=空手也行
|
item: 玩家手里必须拿的物品,None=空手也行
|
||||||
target: 替换成什么方块,None=不替换
|
target: 替换成什么方块,None=不替换
|
||||||
consume: 消耗物品数量,0=不消耗(默认1)
|
consume: 消耗物品数量,0=不消耗(默认1)
|
||||||
giveItem: 额外给玩家什么物品
|
giveItem: 额外给玩家什么物品
|
||||||
stirCount: 需要翻炒几次才变身
|
stirCount: 需要翻炒几次才变身
|
||||||
stirCd: 翻炒冷却时间(秒)
|
stirCd: 翻炒冷却时间(秒)
|
||||||
onDone: "finish"=标记熟了不替换
|
onDone: "finish"=标记熟了不替换
|
||||||
doneMsg: 完成后的提示消息
|
needFinished: True=只熟了才触发,False=熟了就不触发
|
||||||
failMsg: 冷却中/失败时的提示
|
doneMsg: 完成后的提示消息
|
||||||
dropIfDone: 熟了后拆掉掉落什么
|
dropIfDone: 熟了后拆掉掉落什么
|
||||||
dropIfNot: 没熟拆掉掉落什么
|
dropIfNot: 没熟拆掉掉落什么
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RECIPES = [
|
RECIPES = [
|
||||||
@@ -35,7 +35,6 @@ RECIPES = [
|
|||||||
"consume": 0,
|
"consume": 0,
|
||||||
"stirCount": 5,
|
"stirCount": 5,
|
||||||
"stirCd": 1.2,
|
"stirCd": 1.2,
|
||||||
"failMsg": "这时候翻动会不好熟的!",
|
|
||||||
},
|
},
|
||||||
|
|
||||||
# ===== 步骤3:第二阶段 + 木剑翻炒3次 → 标记熟了 =====
|
# ===== 步骤3:第二阶段 + 木剑翻炒3次 → 标记熟了 =====
|
||||||
@@ -47,9 +46,19 @@ RECIPES = [
|
|||||||
"stirCount": 3,
|
"stirCount": 3,
|
||||||
"stirCd": 0.8,
|
"stirCd": 0.8,
|
||||||
"onDone": "finish",
|
"onDone": "finish",
|
||||||
"doneMsg": "出锅啦!拿盘子盛出来",
|
"needFinished": False,
|
||||||
"failMsg": "这时候翻动会不好熟的!",
|
"doneMsg": "出锅啦!空手右键盛出来",
|
||||||
"dropIfDone": ["minecraft:cooked_beef", "rtdd:wok"],
|
"dropIfDone": ["minecraft:cooked_beef", "rtdd:wok"],
|
||||||
"dropIfNot": ["minecraft:beef", "rtdd:wok"],
|
"dropIfNot": ["minecraft:beef", "rtdd:wok"],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# ===== 步骤4:熟了之后,空手右键 → 拿熟牛肉,锅变回空锅 =====
|
||||||
|
{
|
||||||
|
"source": "rtdd:carrotandbeef_1",
|
||||||
|
"item": None,
|
||||||
|
"needFinished": True,
|
||||||
|
"target": "rtdd:wok",
|
||||||
|
"giveItem": "minecraft:cooked_beef",
|
||||||
|
"consume": 0,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
@@ -101,11 +101,23 @@ class CookingService(BlueFoxServerSystem):
|
|||||||
if not recipe:
|
if not recipe:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# 从内存或方块数据加载翻炒进度
|
||||||
|
stirInfo = self.stirData.get(key)
|
||||||
|
if stirInfo is None:
|
||||||
|
stirInfo = self.loadStirData(playerId, pos, dim, recipe)
|
||||||
|
if stirInfo:
|
||||||
|
self.stirData[key] = stirInfo
|
||||||
|
|
||||||
|
if recipe.get("needFinished") is True and not stirInfo.get("finished"):
|
||||||
|
return
|
||||||
|
if recipe.get("needFinished") is False and stirInfo.get("finished"):
|
||||||
|
return
|
||||||
|
|
||||||
if recipe.get("stirCount"):
|
if recipe.get("stirCount"):
|
||||||
self.handleStir(key, recipe, playerId, pos, dim, itemDict)
|
self.handleStir(key, recipe, playerId, pos, dim, itemDict)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.executeRecipe(recipe, playerId, pos, dim, itemDict)
|
self.executeRecipe(recipe, playerId, pos, dim, itemDict, key)
|
||||||
|
|
||||||
# ==================== 配方匹配 ====================
|
# ==================== 配方匹配 ====================
|
||||||
|
|
||||||
@@ -121,7 +133,7 @@ class CookingService(BlueFoxServerSystem):
|
|||||||
|
|
||||||
# ==================== 配方执行(普通替换) ====================
|
# ==================== 配方执行(普通替换) ====================
|
||||||
|
|
||||||
def executeRecipe(self, recipe, playerId, pos, dim, itemDict):
|
def executeRecipe(self, recipe, playerId, pos, dim, itemDict, key):
|
||||||
if not self.checkConditions(recipe, playerId, pos, dim, itemDict):
|
if not self.checkConditions(recipe, playerId, pos, dim, itemDict):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -132,6 +144,7 @@ class CookingService(BlueFoxServerSystem):
|
|||||||
|
|
||||||
if recipe.get("target"):
|
if recipe.get("target"):
|
||||||
self.replaceBlock(pos, dim, recipe["target"], playerId)
|
self.replaceBlock(pos, dim, recipe["target"], playerId)
|
||||||
|
self.clearStirData(key, playerId, pos, dim)
|
||||||
|
|
||||||
if recipe.get("giveItem"):
|
if recipe.get("giveItem"):
|
||||||
self.giveItem(playerId, recipe["giveItem"])
|
self.giveItem(playerId, recipe["giveItem"])
|
||||||
@@ -154,6 +167,7 @@ class CookingService(BlueFoxServerSystem):
|
|||||||
data["count"] += 1
|
data["count"] += 1
|
||||||
data["lastTime"] = now
|
data["lastTime"] = now
|
||||||
self.stirData[key] = data
|
self.stirData[key] = data
|
||||||
|
self.saveStirData(playerId, pos, dim, data)
|
||||||
|
|
||||||
# 提示进度
|
# 提示进度
|
||||||
comp.CreateMsg(playerId).NotifyOneMessage(
|
comp.CreateMsg(playerId).NotifyOneMessage(
|
||||||
@@ -164,11 +178,12 @@ class CookingService(BlueFoxServerSystem):
|
|||||||
if recipe.get("onDone") == "finish":
|
if recipe.get("onDone") == "finish":
|
||||||
data["finished"] = True
|
data["finished"] = True
|
||||||
self.stirData[key] = data
|
self.stirData[key] = data
|
||||||
|
self.saveStirData(playerId, pos, dim, data)
|
||||||
if recipe.get("doneMsg"):
|
if recipe.get("doneMsg"):
|
||||||
comp.CreateMsg(playerId).NotifyOneMessage(playerId, recipe["doneMsg"])
|
comp.CreateMsg(playerId).NotifyOneMessage(playerId, recipe["doneMsg"])
|
||||||
elif recipe.get("target"):
|
elif recipe.get("target"):
|
||||||
self.replaceBlock(pos, dim, recipe["target"], playerId)
|
self.replaceBlock(pos, dim, recipe["target"], playerId)
|
||||||
self.stirData.pop(key, None)
|
self.clearStirData(key, playerId, pos, dim)
|
||||||
|
|
||||||
# ==================== 条件检查 ====================
|
# ==================== 条件检查 ====================
|
||||||
|
|
||||||
@@ -254,6 +269,44 @@ class CookingService(BlueFoxServerSystem):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# ==================== 翻炒数据持久化 ====================
|
||||||
|
|
||||||
|
def loadStirData(self, playerId, pos, dim, recipe):
|
||||||
|
"""从方块上读取之前保存的翻炒进度"""
|
||||||
|
try:
|
||||||
|
blockComp = comp.CreateBlockInfo(playerId)
|
||||||
|
blockData = blockComp.GetBlockEntityData(pos, dim)
|
||||||
|
if blockData and "rtdd_sc" in blockData:
|
||||||
|
return {
|
||||||
|
"count": blockData.get("rtdd_sc", 0),
|
||||||
|
"lastTime": blockData.get("rtdd_slt", 0.0),
|
||||||
|
"finished": blockData.get("rtdd_sf", False),
|
||||||
|
"dropIfDone": recipe.get("dropIfDone", []),
|
||||||
|
"dropIfNot": recipe.get("dropIfNot", []),
|
||||||
|
}
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def saveStirData(self, playerId, pos, dim, data):
|
||||||
|
"""把翻炒进度保存到方块上,退游戏再进也不会丢"""
|
||||||
|
try:
|
||||||
|
comp.CreateBlockInfo(playerId).SetBlockEntityData(pos, dim, {
|
||||||
|
"rtdd_sc": data["count"],
|
||||||
|
"rtdd_slt": data["lastTime"],
|
||||||
|
"rtdd_sf": data["finished"],
|
||||||
|
})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def clearStirData(self, key, playerId, pos, dim):
|
||||||
|
"""清除内存和方块上的翻炒数据"""
|
||||||
|
self.stirData.pop(key, None)
|
||||||
|
try:
|
||||||
|
comp.CreateBlockInfo(playerId).SetBlockEntityData(pos, dim, {})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# ==================== 拆方块处理 ====================
|
# ==================== 拆方块处理 ====================
|
||||||
|
|
||||||
def OnDestroy(self, args):
|
def OnDestroy(self, args):
|
||||||
@@ -269,7 +322,10 @@ class CookingService(BlueFoxServerSystem):
|
|||||||
|
|
||||||
data = self.stirData.get(key)
|
data = self.stirData.get(key)
|
||||||
if not data:
|
if not data:
|
||||||
return
|
# 尝试从方块数据加载
|
||||||
|
data = self.loadStirData(playerId, (x, y, z), dim, {})
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
if data.get("finished"):
|
if data.get("finished"):
|
||||||
dropItems = data.get("dropIfDone", [])
|
dropItems = data.get("dropIfDone", [])
|
||||||
@@ -279,4 +335,4 @@ class CookingService(BlueFoxServerSystem):
|
|||||||
for itemName in dropItems:
|
for itemName in dropItems:
|
||||||
self.giveItem(playerId, itemName)
|
self.giveItem(playerId, itemName)
|
||||||
|
|
||||||
self.stirData.pop(key, None)
|
self.clearStirData(key, playerId, (x, y, z), dim)
|
||||||
Reference in new issue
Block a user