编程农场胡萝卜代码 — 翻地、种植、浇水
按 1.0+ 重写。胡萝卜要耕地。没有种子商店:`plant(Entities.Carrot)` 直接扣背包里的干草和木头。`trade()` 已从游戏移除。
1.0 胡萝卜规则(别再用旧写法)
- `get_ground_type() == Grounds.Soil` 才能种。草地上先 `till()`。再 `till()` 一次会把土翻回草地。
- **没有 `Items.Carrot_Seed`。** 种植自动扣干草+木头。用 `get_cost(Entities.Carrot)` 查看(随胡萝卜升级缩放)。
- **没有 `trade()`。** 水每 10 秒自动进包。浇水用 `use_item(Items.Water)`(旧名 `Water_Tank` 已改名)。
- `get_water()` 为 0–1。水位 1 时生长最高约 5×。未解锁浇水就删掉浇水段。
可复制胡萝卜循环(已核对 1.0 API)
python
while True:
if can_harvest():
harvest()
if get_ground_type() != Grounds.Soil:
till()
# Optional: only plant if you can afford it
cost = get_cost(Entities.Carrot)
can_pay = True
for item in cost:
if num_items(item) < cost[item]:
can_pay = False
if can_pay:
plant(Entities.Carrot)
if get_water() < 0.75:
use_item(Items.Water)
move(East)
if get_pos_x() == 0:
move(North) 若尚未解锁 `get_cost` / `Unlocks.Costs`,删掉 cost 判断,直接 `plant(Entities.Carrot)`——有资源时仍会扣干草+木头。
下一步作物
南瓜也要土,种植耗胡萝卜;约 20% 变成 Dead_Pumpkin。树木要棋盘格,否则邻居让生长翻倍。