Replant the same tree that was chopped
This commit is contained in:
		
							
								
								
									
										9
									
								
								game.py
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								game.py
									
									
									
									
									
								
							@@ -37,6 +37,8 @@ import mcdata
 | 
				
			|||||||
importlib.reload(mcdata)
 | 
					importlib.reload(mcdata)
 | 
				
			||||||
import mobs
 | 
					import mobs
 | 
				
			||||||
importlib.reload(mobs)
 | 
					importlib.reload(mobs)
 | 
				
			||||||
 | 
					import bot
 | 
				
			||||||
 | 
					importlib.reload(bot)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MCWorld:
 | 
					class MCWorld:
 | 
				
			||||||
    def __init__(self, global_state):
 | 
					    def __init__(self, global_state):
 | 
				
			||||||
@@ -651,9 +653,7 @@ class Game:
 | 
				
			|||||||
                            reply += ', I need a bed'
 | 
					                            reply += ', I need a bed'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if command == 'stop':
 | 
					                if command == 'stop':
 | 
				
			||||||
                    self.g.job.stop()
 | 
					                    bot.init(self.g)
 | 
				
			||||||
                    self.g.path = []
 | 
					 | 
				
			||||||
                    self.g.look_at = None
 | 
					 | 
				
			||||||
                    reply = 'ok'
 | 
					                    reply = 'ok'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if command == 'drop':
 | 
					                if command == 'drop':
 | 
				
			||||||
@@ -739,6 +739,9 @@ class Game:
 | 
				
			|||||||
                            print(len(navpath))
 | 
					                            print(len(navpath))
 | 
				
			||||||
                            print(navpath)
 | 
					                            print(navpath)
 | 
				
			||||||
                            print(round(time.time() - start, 3), 'seconds')
 | 
					                            print(round(time.time() - start, 3), 'seconds')
 | 
				
			||||||
 | 
					                            if self.g.job:
 | 
				
			||||||
 | 
					                                self.g.job.stop()
 | 
				
			||||||
 | 
					                            self.g.look_at = None
 | 
				
			||||||
                            reply = 'ok'
 | 
					                            reply = 'ok'
 | 
				
			||||||
                        else:
 | 
					                        else:
 | 
				
			||||||
                            reply = 'no path'
 | 
					                            reply = 'no path'
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								items.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								items.py
									
									
									
									
									
								
							@@ -56,13 +56,13 @@ ITEM_NAMES = {}
 | 
				
			|||||||
for item_name, item in ITEMS.items():
 | 
					for item_name, item in ITEMS.items():
 | 
				
			||||||
    ITEM_NAMES[ITEMS[item_name]['protocol_id']] = item_name.replace('minecraft:', '')
 | 
					    ITEM_NAMES[ITEMS[item_name]['protocol_id']] = item_name.replace('minecraft:', '')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CHEST_ID = set([ITEMS['minecraft:chest']['protocol_id']])
 | 
					def get_id(name):
 | 
				
			||||||
 | 
					    return ITEMS['minecraft:' + name]['protocol_id']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GAPPLE_ID = set([ITEMS['minecraft:enchanted_golden_apple']['protocol_id']])
 | 
					CHEST_ID = get_id('chest')
 | 
				
			||||||
 | 
					GAPPLE_ID = get_id('enchanted_golden_apple')
 | 
				
			||||||
 | 
					SAND_ID = get_id('sand')
 | 
				
			||||||
 | 
					NETHERWART_ID = get_id('nether_wart')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SAND_ID = set([ITEMS['minecraft:sand']['protocol_id']])
 | 
					NEEDED_ITEMS = BED_IDS | set([CHEST_ID])
 | 
				
			||||||
 | 
					WANTED_ITEMS = SAPLING_IDS | set([NETHERWART_ID])
 | 
				
			||||||
NETHERWART_ID = set([ITEMS['minecraft:nether_wart']['protocol_id']])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
NEEDED_ITEMS = BED_IDS | CHEST_ID
 | 
					 | 
				
			||||||
WANTED_ITEMS = SAPLING_IDS | NETHERWART_ID
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										35
									
								
								jobs.py
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								jobs.py
									
									
									
									
									
								
							@@ -259,6 +259,9 @@ class GatherWoodStates:
 | 
				
			|||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.tree = tree
 | 
					        self.tree = tree
 | 
				
			||||||
 | 
					        self.type = blocks.BLOCKS[w.block_at(*tree)].replace('_log', '')
 | 
				
			||||||
 | 
					        print('Type:', self.type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.state = self.find_openings
 | 
					        self.state = self.find_openings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def find_openings(self):
 | 
					    def find_openings(self):
 | 
				
			||||||
@@ -360,7 +363,7 @@ class GatherWoodStates:
 | 
				
			|||||||
        if self.wait_time > 0:
 | 
					        if self.wait_time > 0:
 | 
				
			||||||
            self.wait_time -= utils.TICK
 | 
					            self.wait_time -= utils.TICK
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.g.chopped_tree = True
 | 
					            self.g.chopped_tree = self.type
 | 
				
			||||||
            self.good_trees.append(self.tree)
 | 
					            self.good_trees.append(self.tree)
 | 
				
			||||||
            self.state = self.check_pos
 | 
					            self.state = self.check_pos
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -386,6 +389,7 @@ class GatherWoodStates:
 | 
				
			|||||||
        self.state = self.idle
 | 
					        self.state = self.idle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.tree = None
 | 
					        self.tree = None
 | 
				
			||||||
 | 
					        self.type = None
 | 
				
			||||||
        self.openings = []
 | 
					        self.openings = []
 | 
				
			||||||
        self.bad_trees = []
 | 
					        self.bad_trees = []
 | 
				
			||||||
        self.good_trees = []
 | 
					        self.good_trees = []
 | 
				
			||||||
@@ -766,7 +770,7 @@ class CacheItemsStates:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def select_chest(self):
 | 
					    def select_chest(self):
 | 
				
			||||||
        if self.g.game.select_item(items.CHEST_ID):
 | 
					        if self.g.game.select_item([items.CHEST_ID]):
 | 
				
			||||||
            self.state = self.find_cache_spot
 | 
					            self.state = self.find_cache_spot
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            print('No chest, aborting')
 | 
					            print('No chest, aborting')
 | 
				
			||||||
@@ -931,13 +935,15 @@ class PlantTreeStates:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def select_sapling(self):
 | 
					    def select_sapling(self):
 | 
				
			||||||
        p = utils.pint(self.g.pos)
 | 
					        p = utils.pint(self.g.pos)
 | 
				
			||||||
 | 
					        sapling_type = self.g.chopped_tree + '_sapling'
 | 
				
			||||||
 | 
					        sapling_item = items.get_id(sapling_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if self.g.game.select_random_item(items.SAPLING_IDS):
 | 
					        if self.g.game.select_item([sapling_item]):
 | 
				
			||||||
            self.g.look_at = utils.padd(p, path.BLOCK_BELOW)
 | 
					            self.g.look_at = utils.padd(p, path.BLOCK_BELOW)
 | 
				
			||||||
            self.state = self.wait_select
 | 
					            self.state = self.wait_select
 | 
				
			||||||
            self.wait_time = 1
 | 
					            self.wait_time = 1
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            print('Aborting planting, no saplings')
 | 
					            print('Aborting planting, no', sapling_type)
 | 
				
			||||||
            self.state = self.cleanup
 | 
					            self.state = self.cleanup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def wait_select(self):
 | 
					    def wait_select(self):
 | 
				
			||||||
@@ -1005,14 +1011,19 @@ class ClearLeavesStates:
 | 
				
			|||||||
        return None
 | 
					        return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def init(self):
 | 
					    def init(self):
 | 
				
			||||||
        num_saplings = self.g.game.count_items(items.SAPLING_IDS)
 | 
					        if self.g.chopped_tree:
 | 
				
			||||||
        print('Have', num_saplings, 'saplings in inventory')
 | 
					            sapling_type = self.g.chopped_tree + '_sapling'
 | 
				
			||||||
        if num_saplings < 8:
 | 
					            sapling_item = items.get_id(sapling_type)
 | 
				
			||||||
            self.state = self.find_leaves
 | 
					            num_saplings = self.g.game.count_items([sapling_item])
 | 
				
			||||||
            print('Clearing leaves...')
 | 
					            print('Have', num_saplings, sapling_type, 'in inventory')
 | 
				
			||||||
        else:
 | 
					
 | 
				
			||||||
            print('Aborting clearing leaves')
 | 
					            if num_saplings > 8:
 | 
				
			||||||
            self.state = self.cleanup
 | 
					                print('Aborting clearing leaves')
 | 
				
			||||||
 | 
					                self.state = self.cleanup
 | 
				
			||||||
 | 
					                return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.state = self.find_leaves
 | 
				
			||||||
 | 
					        print('Clearing leaves...')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def find_leaves(self):
 | 
					    def find_leaves(self):
 | 
				
			||||||
        w = self.g.world
 | 
					        w = self.g.world
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user