乡野自然实现 3

This commit is contained in:
wenhe committed 2026-09-08 11:28:14 +08:00
1 parent 97da44ab18
commit b947847def
9 files changed
+94 -83

No files matched your search

@@ -32,7 +32,7 @@ from ....BlueFoxTools.SpecialFunciton.BlueFoxSystem import BlueFoxServerSystem
from ....BlueFoxTools.ToolsConfig import LevelId
# ---- 只导入乡野自然自己的数据库 ----
from ..NaturalData import NATURAL_SWITCHES, RICE_PLANT
from ..NaturalData import NATURAL_SWITCHES, RICE_PLANT, RICE_BLOCKS, RICE_SEED_ITEM, RICE_CROP_ITEM
# ---- 统一分发器 ----
from ...service.FeatureDispatcher import FeatureDispatcher
@@ -53,6 +53,9 @@ class NaturalService(BlueFoxServerSystem):
for r in NATURAL_SWITCHES:
self.switchRecipes[(r["source"], r.get("item"))] = r
self.featureBlocks.add(r["source"])
# 水稻方块: 只为接收"左键破坏掉落"事件注册(右键无规则, handleBlockUse 会返回 False)
for b in RICE_BLOCKS:
self.featureBlocks.add(b)
# ---- 右键冷却表 ----
self.cooldown = {}
@@ -92,6 +95,49 @@ class NaturalService(BlueFoxServerSystem):
self.handleSwitch(recipe, playerId, pos, dim, itemDict, key)
return True
def handleDestroy(self, args):
"""由 FeatureDispatcher 转发的"玩家左键破坏方块"入口(水稻收获, 类似原版作物)。
水稻方块(刚种下/生长中/成熟)被左键破坏 -> 掉落稻谷(1个, 回收种子);
成熟(riceseedlingsd)额外掉落 16 个大米(brownrice)。
返回 True=处理了; False=不属本功能管。"""
blockName = args.get("fullName") or args.get("blockName")
if blockName not in RICE_BLOCKS:
return False
playerId = args.get("playerId")
x, y, z = args.get("x"), args.get("y"), args.get("z")
pos = (x, y, z)
dim = comp.CreateDimension(playerId).GetEntityDimensionId()
# 取消默认破坏+默认掉落(不让水稻方块本身掉出来)
args['cancel'] = True
args['spawnResources'] = False
# 清空方块为空气
try:
comp.CreateBlockInfo(LevelId).SetBlockNew(
pos, blockDict={"name": "minecraft:air", "aux": 0},
oldBlockHandling=0, dimensionId=dim)
except Exception:
pass
# 掉落稻谷(种子回收)
try:
self.CreateEngineItemEntity(
{"itemName": RICE_SEED_ITEM, "count": 1, "auxValue": 0},
dim, (x, y + 0.5, z))
except Exception:
pass
# 成熟水稻额外掉落大米
if blockName == "rtdd:riceseedlingsd":
try:
self.CreateEngineItemEntity(
{"itemName": RICE_CROP_ITEM, "count": 16, "auxValue": 0},
dim, (x, y + 0.5, z))
except Exception:
pass
return True
def handleItemUseOn(self, args):
"""由 FeatureDispatcher 转发的"手持物品右键方块表面"入口(稻谷种水稻)"""
itemName = args.get("itemName")