def periodic_event_handler(self): """Triggered every 5 seconds by a timer""" # Search the hotbar for cobblestone slot = self.inventory.find_slot(4, self.inventory.window.hotbar_slots) logger.info(slot) # Switch to slot with cobblestone if slot is not None: self.inventory.select_active_slot(slot) # Switch to first slot because there is no cobblestone in hotbar else: self.inventory.select_active_slot(0) logger.info('My position: {0} pitch: {1} yaw: {2}'.format( self.clientinfo.position, self.clientinfo.position.pitch, self.clientinfo.position.yaw)) # Place a block in front of the player self.interact.place_block(self.clientinfo.position + Vector3(-1, -1, 0)) # Read a block under the player block_pos = self.clientinfo.position block_id, meta = self.world.get_block(block_pos.x, block_pos.y, block_pos.z) block_at = mapdata.get_block(block_id, meta) self.interact.chat('Found block %s at %s' % (block_at.display_name, block_pos))
def block_collision(self, cb, x=0, y=0, z=0): block_id, meta = self.world.get_block(cb.x + x, cb.y + y, cb.z + z) block = mapdata.get_block(block_id, meta) if block is None: return False # possibly we want to use the centers of blocks as the starting # points for bounding boxes instead of 0,0,0 this might make thinks # easier when we get to more complex shapes that are in the center # of a block aka fences but more complicated for the player uncenter # the player position and bump it up a little down to prevent # colliding in the floor pos1 = Position(self.pos.x - self.playerbb.w / 2, self.pos.y - 0.2, self.pos.z - self.playerbb.d / 2) bb1 = self.playerbb bb2 = block.bounding_box if bb2 is not None: pos2 = Position(cb.x + x + bb2.x, cb.y + y + bb2.y, cb.z + z + bb2.z) if ((pos1.x + bb1.w) >= (pos2.x) and (pos1.x) <= ( pos2.x + bb2.w)) and ( (pos1.y + bb1.h) >= (pos2.y) and (pos1.y) <= ( pos2.y + bb2.h)) and ( (pos1.z + bb1.d) >= (pos2.z) and (pos1.z) <= ( pos2.z + bb2.d)): return True return False
def get_block_slip(self): if self.pos.on_ground: block_pos = self.pos.floor() block_id, meta = self.world.get_block( block_pos.x, block_pos.y - 1, block_pos.z ) return mapdata.get_block(block_id, meta).slipperiness return 1
def get_generic_names(): generic = [] for bid in range(198): block = mapdata.get_block(bid) namelist = block.display_name.upper().split() name = namelist[0].strip() if len(namelist) > 1: for partial in namelist[1:]: name = name + '_' + partial.strip() name = get_correct_name(name) if name not in generic: generic.append(name)
def periodic_event_handler(self): """Triggered every 5 seconds by a timer""" print('My position: {0} pitch: {1} yaw: {2}'.format( self.clinfo.position, self.clinfo.position.pitch, self.clinfo.position.yaw)) delta = random.choice([-10, 0, 10]) # self.clinfo.position.x += delta # self.clinfo.position.yaw += delta # print(dir(self.clinfo.position)) # # # Rotates the bot by 1 degree # self.yaw += 1 # self.clinfo.position.yaw = (self.yaw) # % 360 # self.clinfo.position.x += 1 print(self.clinfo.position.yaw) # self.emit_chat_message(msg='Bot active.') # # # self.clinfo.position.x = 3 # # self.clinfo.position.y = 2 # # self.clinfo.position.z = 0 # # # -50 64 410 # # self.yaw += 1 # s = '/tp 10 10 10'.format(int(0)) # print(s) # import time # time.sleep(3) # self.emit_chat_message(msg="frogs") # Read a block x, y, z = 5, 5, 5 block_id, meta = self.world.get_block(x, y, z) block_placed = mapdata.get_block(block_id, meta) print('Before changing the block, the type had id {0} and name {1}.'.format(block_id, block_placed.name)) # Place a block (choosing the type randomly from a list of types) self.place_block(x, y, z, random.choice(['red_mushroom', 'brown_mushroom']))
def periodic_event_handler(self): """Triggered every 5 seconds by a timer""" print('My position: {0} pitch: {1} yaw: {2}'.format( self.clinfo.position, self.clinfo.position.pitch, self.clinfo.position.yaw)) # Rotates the bot by 1 degree self.clinfo.position.yaw = (self.clinfo.position.yaw + 1) % 360 # Read a block x, y, z = 5, 5, 5 block_id, meta = self.world.get_block(x, y, z) block_placed = mapdata.get_block(block_id, meta) print('Before changing the block, the type had id {0} and name {1}.'.format(block_id, block_placed.name)) # Place a block (choosing the type randomly from a list of types) self.place_block(x, y, z, random.choice(['waterlily', 'red_mushroom', 'brown_mushroom']))
def block_collision(self, pos): for block_pos in gen_block_set(pos): block_id, meta = self.world.get_block( block_pos.x, block_pos.y, block_pos.z ) block = mapdata.get_block(block_id, meta) if not block.bounding_box: continue transform_vectors = [] for i, axis in enumerate(UNIT_VECTORS): axis_pen = check_axis( axis, pos[i], pos[i] + self.bounding_box[i], block_pos[i], block_pos[i] + block.bounding_box[i] ) if not axis_pen: break transform_vectors.append(axis_pen) else: return transform_vectors return [Vector3()]*3
def block_collision(self, cb, x=0, y=0, z=0): block_id, meta = self.world.get_block(cb.x + x, cb.y + y, cb.z + z) block = mapdata.get_block(block_id, meta) if block == None: return False #possibly we want to use the centers of blocks as the starting points for bounding boxes instead of 0,0,0 #this might make thinks easier when we get to more complex shapes that are in the center of a block aka fences but more complicated for the player #uncenter the player position and bump it up a little down to prevent colliding in the floor pos1 = Vector3(self.pos.x - self.playerbb.w / 2, self.pos.y - 0.2, self.pos.z - self.playerbb.d / 2) bb1 = self.playerbb bb2 = block.bounding_box if bb2 != None: pos2 = Vector3(cb.x + x + bb2.x, cb.y + y + bb2.y, cb.z + z + bb2.z) if ((pos1.x + bb1.w) >= (pos2.x) and (pos1.x) <= (pos2.x + bb2.w)) and \ ((pos1.y + bb1.h) >= (pos2.y) and (pos1.y) <= (pos2.y + bb2.h)) and \ ((pos1.z + bb1.d) >= (pos2.z) and (pos1.z) <= (pos2.z + bb2.d)): return True return False
def block_test(self, event, blockdata): block_id, meta = mapshort2id(blockdata['block_data']) block = mapdata.get_block(block_id, meta) print('Block update at:', blockdata['location']) print('New block data:', block.display_name if block else None)
single material type, and map to a common list of names """ import roslib roslib.load_manifest("minecraft_bot") import rospy import mcidmap_blocks, mcidmap_items from spock.mcmap import mapdata mats = {} for bid in range(198): block = mapdata.get_block(bid) namelist = block.display_name.upper().split() name = namelist[0].strip() if len(namelist) > 1: for partial in namelist[1:]: name = name + "_" + partial.strip() # name = get_correct_name(name) def get_block_name(namestring): namelist = list(reversed(namestring.split())) name = namelist[0] if len(namelist) > 1:
script to gather material metadata from Spock, combine similar types (e.g. all types of wood) into a single material type, and map to a common list of names """ import roslib; roslib.load_manifest('minecraft_bot') import rospy import mcidmap_blocks, mcidmap_items from spock.mcmap import mapdata mats = {} for bid in range(198): block = mapdata.get_block(bid) namelist = block.display_name.upper().split() name = namelist[0].strip() if len(namelist) > 1: for partial in namelist[1:]: name = name + '_' + partial.strip() #name = get_correct_name(name) def get_block_name(namestring): namelist = list(reversed(namestring.split())) name = namelist[0] if len(namelist) > 1: for item in namelist[1:]: