如果玩家背包有这个成品菜,优先给这个数量加一,也就是把取到的成品菜放到同类项,次优先则:当我们主手没有物品时,获取到玩家主手上去,再次级,则是玩家主手有东西,背包有空余位置,那么将成品菜放到玩家背包里去,最次就是玩家背包满了,主手也有东西,那么就以现在我们这样的掉落物形式获得
This commit is contained in:
1 parent
36af4e3c59
commit
14de700929
6 files changed
+73
-10
No files matched your search
+21
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user