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

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

@@ -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