Port and tune 26.3 wood farming

This commit is contained in:
Tanner
2026-11-05 16:36:10 +00:00
parent b89f0f6ed2
commit 4c27f5058e
15 changed files with 412 additions and 40 deletions
+14 -3
View File
@@ -17,6 +17,8 @@ from mosfet.info import mcdata
from mosfet.info import mobs
class ClearLeavesStates:
LEAF_BREAK_INTERVAL = 0.6
def idle(self):
return None
@@ -26,9 +28,13 @@ class ClearLeavesStates:
self.state = self.cleanup
return
sapling_type = self.g.chopped_tree + '_sapling'
sapling_item = items.get_id(sapling_type)
sapling_item = items.get_sapling_id(self.g.chopped_tree)
if sapling_item is None:
print('No sapling for chopped tree, skipping leaf cleanup')
self.state = self.cleanup
return
num_saplings = self.g.game.count_items([sapling_item])
sapling_type = items.get_name(sapling_item)
print('Have', num_saplings, sapling_type, 'in inventory')
if num_saplings > 8:
@@ -57,9 +63,13 @@ class ClearLeavesStates:
def break_leaves(self):
if not self.g.breaking:
if self.leaves:
now = time.monotonic()
if now < self.next_break_at:
return
leaf = self.leaves.pop(0)
self.g.look_at = leaf
self.g.game.break_block(leaf)
if self.g.game.break_block(leaf):
self.next_break_at = now + self.LEAF_BREAK_INTERVAL
print('Breaking leaf', leaf)
else:
self.wait_time = 1
@@ -86,6 +96,7 @@ class ClearLeavesStates:
self.leaves = []
self.wait_time = 0
self.next_break_at = 0.0
def run(self):
self.state()
+9 -3
View File
@@ -32,15 +32,21 @@ class GatherWoodStates:
for tree in w.find_trees(p, 100):
print('Found tree:', tree)
if tree not in self.bad_trees:
break
if tree in self.bad_trees:
continue
tree_type = blocks.BLOCKS[w.block_at(*tree)].replace('_log', '')
if items.get_sapling_id(tree_type) is None:
print('No plantable sapling for', tree_type, '- skipping')
self.bad_trees.append(tree)
continue
break
else: # for
print('No good trees left, aborting.')
self.state = self.cleanup
return
self.tree = tree
self.type = blocks.BLOCKS[w.block_at(*tree)].replace('_log', '')
self.type = tree_type
print('Type:', self.type)
self.state = self.find_openings
+3 -7
View File
@@ -13,7 +13,6 @@ from mosfet import utils
from mosfet import path
from mosfet.info import blocks
from mosfet.info import items
from mosfet.info import mcdata
from mosfet.info import mobs
class GrabSuppliesStates:
@@ -160,8 +159,8 @@ class GrabSuppliesStates:
print('Didnt get a window, aborting')
self.state = self.cleanup
return
if w.data.window_type != mcdata.SINGLE_CHEST:
print('Got wrong window, aborting')
if w.get('container_slots', 0) != 27:
print('Got wrong container size, aborting')
self.state = self.cleanup
return
used_slots = self.g.game.count_inventory_slots()
@@ -173,10 +172,7 @@ class GrabSuppliesStates:
self.state = self.cleanup
return
w_info = mcdata.WINDOWS[w.data.window_type]
w_container_slots = w_info.container
for slot_num in w_container_slots:
for slot_num in range(w.container_slots):
if slot_num not in w.contents:
continue
+6 -2
View File
@@ -39,10 +39,14 @@ class PlantTreeStates:
def select_sapling(self):
p = utils.pint(self.g.pos)
sapling_type = self.g.chopped_tree + '_sapling'
sapling_item = items.get_id(sapling_type)
sapling_item = items.get_sapling_id(self.g.chopped_tree)
if sapling_item is None:
print('Aborting planting, no sapling for', self.g.chopped_tree)
self.state = self.cleanup
return
if self.g.game.select_item([sapling_item]):
sapling_type = items.get_name(sapling_item)
self.g.look_at = utils.padd(p, path.BLOCK_BELOW)
self.state = self.wait_select
self.wait_time = 1