def build(): global selected_build # make sure cursor is visible if selected_build not in range(len(player['inventory'])): selected_build = 0 max_build_dist = 3 mouse_coords = get_coords_at_mouse() mouse_x, mouse_y = mouse_coords mouse_wants_to_build = pygame.mouse.get_pressed()[2] == 1 if not rules['powder_like']: mouse_distance_good = dist(mouse_coords, player['pos']) <= max_build_dist if not mouse_distance_good: return None if set(von_neumann_neighborhood(mouse_coords, world)) == {None}: return None mouse_on_map = (0 <= mouse_x < len(world[0])) and (0 <= mouse_y < len(world)) if mouse_on_map and mouse_wants_to_build and player[ 'inventory'] and not world[mouse_y][mouse_x]: block_name = list(player['inventory'].keys())[selected_build] block_block = get_block_by_name(block_name) if 'item' not in block_block.tags: # remove block from inventory if not rules['powder_like']: inv_edit(block_name, -1) # place block in world world[mouse_y][mouse_x] = block_block
def main(**kwargs) -> list: """ Grows grass on dirt exposed to light randomly 1/200 chance per tick """ world = kwargs['world'] for y, row in enumerate(world): for x, block in enumerate(row): if not block: continue if 'dirt' not in block.tags: continue if 1 / 10 < random(): continue vnns = set(von_neumann_neighborhood((x, y), world)) grass_in_hood = True in [ 'grass' in i.tags for i in vnns if isinstance(i, Block) ] if not grass_in_hood: continue grass = [ i for i in vnns if isinstance(i, Block) and 'grass' in i.tags ][0] if is_exposed_to_sun((x, y), world): world[y][x] = grass return world
def main(**kwargs) -> list: """ Turns flammable blocks 1/4 chance into fire if they're in the VNN of a fire_starter Deletes burning blocks 1/20 chance """ blocks = kwargs['blocks'] world = kwargs['world'] for y, row in enumerate(world): for x, block in enumerate(row): if not block: continue # BALEET FIRE if random() < 1 / 20 and 'burning' in block.tags: world[y][x] = None # burn shit elif random() < 1 / 4 and 'flammable' in block.tags: vnns = set(von_neumann_neighborhood((x, y), world)) fire_starter_in_hood = True in [ 'fire_starter' in i.tags for i in vnns if isinstance(i, Block) ] if not fire_starter_in_hood: continue fire = [ i for i in blocks if isinstance(i, Block) and 'burning' in i.tags ][0] world[y][x] = fire return world
def main(**kwargs) -> list: """ Regrows leaves if both leaves and wood in VNN and only those and air are in VNN """ world = kwargs['world'] # check for regrowth for y, row in enumerate(world): # wood_check_area = (world[y-1] if y else []) + row + (world[y+1] if y+1 < len(world) else []) # if wood not in wood_check_area: # continue for x, block in enumerate(row): if not block and random() < 1 / 10: vnns = set(von_neumann_neighborhood((x, y), world)) wood_in_hood = True in [ 'wood' in i.tags for i in vnns if isinstance(i, Block) ] if not wood_in_hood: continue leaves_in_hood = True in [ 'leaves' in i.tags for i in vnns if isinstance(i, Block) ] if not leaves_in_hood: continue leaves = [ i for i in vnns if isinstance(i, Block) and 'leaves' in i.tags ][0] only_alw_in_hood = False not in [ 'wood' in i.tags or 'leaves' in i.tags for i in vnns if isinstance(i, Block) ] if only_alw_in_hood: world[y][x] = leaves return world
def main(**kwargs) -> list: """ Regrows or decays leaves on wood under certain conditions """ world = kwargs['world'] # check for decay for y, row in enumerate(world): for x, block in enumerate(row): if block and 'leaves' in block.tags and random() < 1 / 10: vnns = set(von_neumann_neighborhood((x, y), world)) wood_in_hood = True in [ 'wood' in i.tags for i in vnns if isinstance(i, Block) ] if not wood_in_hood: world[y][x] = None return world