如果玩家背包有这个成品菜,优先给这个数量加一,也就是把取到的成品菜放到同类项,次优先则:当我们主手没有物品时,获取到玩家主手上去,再次级,则是玩家主手有东西,背包有空余位置,那么将成品菜放到玩家背包里去,最次就是玩家背包满了,主手也有东西,那么就以现在我们这样的掉落物形式获得

This commit is contained in:
wenhe committed 2026-09-29 12:12:32 +08:00
1 parent 36af4e3c59
commit 14de700929
6 files changed
+73 -10

No files matched your search

@@ -271,7 +271,7 @@ class ChaoguoService(BlueFoxServerSystem):
elif action == "take_out":
# 出锅: 锅变回 炒锅(空) + 掉落盘装成品(掉落物形式)
self.replaceBlock(pos, dim, WOK, playerId)
self.dropItem(dim, pos, recipe["dropItem"])
self.dropItem(dim, pos, recipe["dropItem"], playerId=playerId)
self._clearWokData(dim, pos)
# 普通替换方块(盖锅/锅底/放料/加料)
# 注意: 翻炒(stir)的 target 由 _handleStir 满4次才替换, 这里必须排除,
@@ -400,9 +400,28 @@ class ChaoguoService(BlueFoxServerSystem):
# 七、工具方法,以掉落物形式生成物品
# ============================================================================
def dropItem(self, dim, pos, itemName, count=1, aux=0):
def dropItem(self, dim, pos, itemName, count=1, aux=0, playerId=None):
"""取成品/返容器: playerId 给出时【优先入包】—— 主手空->放主手;
否则入背包(同类叠加/空位); 背包满(返回False)->落回地面掉落物。
不传 playerId(无玩家上下文, 如破坏掉落) 保持原掉落物, 零影响。"""
try:
itemDict = {"itemName": itemName, "count": count, "auxValue": aux}
if playerId is not None:
# 1) 主手空 -> 放主手
cur = self.getCarriedItem(playerId)
handItem = (cur or {}).get("newItemName")
if not handItem or handItem == "minecraft:air":
try:
if comp.CreateItem(playerId).SpawnItemToPlayerCarried(itemDict, playerId):
return
except Exception:
pass
# 2) 否则入包(同类叠加/空位); 失败(满)->掉落
try:
if comp.CreateItem(playerId).SpawnItemToPlayerInv(itemDict, playerId):
return
except Exception:
pass
self.CreateEngineItemEntity(itemDict, dim, (pos[0], pos[1] + 0.5, pos[2]))
except Exception:
pass
@@ -301,14 +301,14 @@ class TangguoService(BlueFoxServerSystem):
action = recipe.get("action")
if action == "take_out":
self.replaceBlock(pos, dim, recipe.get("target") or self._defaultPot(), playerId)
self.dropItem(dim, pos, recipe["dropItem"], recipe.get("count", 1))
self.dropItem(dim, pos, recipe["dropItem"], recipe.get("count", 1), playerId=playerId)
# 普通替换方块(加水/盖锅/下汤底/组合/加料/汤面)
if recipe.get("target") and action != "take_out":
self.replaceBlock(pos, dim, recipe["target"], playerId)
# 额外掉落(倒水掉水桶 / 蔬菜乱炖掉汤锅(空) / 汤面掉木碗)
if recipe.get("drop"):
self.dropItem(dim, pos, recipe["drop"])
self.dropItem(dim, pos, recipe["drop"], playerId=playerId)
# 加料后启动计时(记录发起玩家); 下方无点燃炉灶时提示
if recipe.get("startTimer"):
@@ -375,9 +375,28 @@ class TangguoService(BlueFoxServerSystem):
# 六、工具方法,以掉落物形式生成物品
# ============================================================================
def dropItem(self, dim, pos, itemName, count=1, aux=0):
def dropItem(self, dim, pos, itemName, count=1, aux=0, playerId=None):
"""取成品/返容器: playerId 给出时【优先入包】—— 主手空->放主手;
否则入背包(同类叠加/空位); 背包满(返回False)->落回地面掉落物。
不传 playerId(无玩家上下文, 如破坏掉落) 保持原掉落物, 零影响。"""
try:
itemDict = {"itemName": itemName, "count": count, "auxValue": aux}
if playerId is not None:
# 1) 主手空 -> 放主手
cur = self.getCarriedItem(playerId)
handItem = (cur or {}).get("newItemName")
if not handItem or handItem == "minecraft:air":
try:
if comp.CreateItem(playerId).SpawnItemToPlayerCarried(itemDict, playerId):
return
except Exception:
pass
# 2) 否则入包(同类叠加/空位); 失败(满)->掉落
try:
if comp.CreateItem(playerId).SpawnItemToPlayerInv(itemDict, playerId):
return
except Exception:
pass
self.CreateEngineItemEntity(itemDict, dim, (pos[0], pos[1] + 0.5, pos[2]))
except Exception:
pass
@@ -267,7 +267,7 @@ class YouguoService(BlueFoxServerSystem):
action = recipe.get("action")
if action == "take_out":
self.replaceBlock(pos, dim, OILPOT_1, playerId)
self.dropItem(dim, pos, recipe["dropItem"])
self.dropItem(dim, pos, recipe["dropItem"], playerId=playerId)
# 替换方块(倒油/取油/放料)
if recipe.get("target"):
self.replaceBlock(pos, dim, recipe["target"], playerId)
@@ -340,9 +340,28 @@ class YouguoService(BlueFoxServerSystem):
# 七、工具方法,以掉落物形式生成物品
# ============================================================================
def dropItem(self, dim, pos, itemName, count=1, aux=0):
def dropItem(self, dim, pos, itemName, count=1, aux=0, playerId=None):
"""取成品/返容器: playerId 给出时【优先入包】—— 主手空->放主手;
否则入背包(同类叠加/空位); 背包满(返回False)->落回地面掉落物。
不传 playerId(无玩家上下文, 如破坏掉落) 保持原掉落物, 零影响。"""
try:
itemDict = {"itemName": itemName, "count": count, "auxValue": aux}
if playerId is not None:
# 1) 主手空 -> 放主手
cur = self.getCarriedItem(playerId)
handItem = (cur or {}).get("newItemName")
if not handItem or handItem == "minecraft:air":
try:
if comp.CreateItem(playerId).SpawnItemToPlayerCarried(itemDict, playerId):
return
except Exception:
pass
# 2) 否则入包(同类叠加/空位); 失败(满)->掉落
try:
if comp.CreateItem(playerId).SpawnItemToPlayerInv(itemDict, playerId):
return
except Exception:
pass
self.CreateEngineItemEntity(itemDict, dim, (pos[0], pos[1] + 0.5, pos[2]))
except Exception:
pass