import pygame as pg
import random
from classes import player, Player

clock = pg.time.Clock()

pg.init()
screen = pg.display.set_mode((1920, 1080))
pg.display.set_caption('PyGame')
pg.display.set_icon(pg.image.load('images/icon.png').convert_alpha())
bg = pg.image.load('images/Фон.jpg').convert_alpha()

walk_left = [
    pg.image.load('images/player/Влево_1.png').convert_alpha(),
    pg.image.load('images/player/Влево_2.png').convert_alpha(),
    pg.image.load('images/player/Влево_3.png').convert_alpha(),
    pg.image.load('images/player/Влево_4.png').convert_alpha(),
    pg.image.load('images/player/Влево_5.png').convert_alpha(),
    pg.image.load('images/player/Влево_6.png').convert_alpha(),
    pg.image.load('images/player/Влево_7.png').convert_alpha(),
    pg.image.load('images/player/Влево_8.png').convert_alpha(),
    pg.image.load('images/player/Влево_9.png').convert_alpha(),
    pg.image.load('images/player/Влево_10.png').convert_alpha(),
    pg.image.load('images/player/Влево_11.png').convert_alpha(),
    pg.image.load('images/player/Влево_12.png').convert_alpha()
]
walk_right = [
    pg.image.load('images/player/Вправо_1.png').convert_alpha(),
    pg.image.load('images/player/Вправо_2.png').convert_alpha(),
    pg.image.load('images/player/Вправо_3.png').convert_alpha(),
    pg.image.load('images/player/Вправо_4.png').convert_alpha(),
    pg.image.load('images/player/Вправо_5.png').convert_alpha(),
    pg.image.load('images/player/Вправо_6.png').convert_alpha(),
    pg.image.load('images/player/Вправо_7.png').convert_alpha(),
    pg.image.load('images/player/Вправо_8.png').convert_alpha(),
    pg.image.load('images/player/Вправо_9.png').convert_alpha(),
    pg.image.load('images/player/Вправо_10.png').convert_alpha(),
    pg.image.load('images/player/Вправо_11.png').convert_alpha(),
    pg.image.load('images/player/Вправо_12.png').convert_alpha()
]

jump_count = 7
eat_time_died = 0
eat_time = 150
press = 0
dead = None
player_anim_count = 0
build_plan = 1

step_sound = pg.mixer.Sound('sounds/Звук шагов.mp3')
step_s = 0

slot_1 = False
slot_2 = False
slot_3 = False
slot_4 = False
slot_5 = False
slot_6 = False
slot_7 = False
slot_8 = False
slot_9 = False
slot_10 = False
inventory = {'next,0,0': '1,640,640', '31,640,896': '1,Меч_Вправо', '32,704,896': '1,Кирка_Вправо', '33,768,896': '1,Топор_Вправо', '34,832,896': '1,Лопата_Вправо'}
inv = False
workbench = False
slots = {'y1': False, 'y2': False, 'y3': False, 'y4': False, 'y5': False, 'y6': False, 'y7': False, 'y8': False, 'y9': False, 'y10': False, 'y11': False, 'y12': False, 'y13': False, 'y14': False, 'y15': False, 'y16': False, 'y17': False, 'y18': False, 'y19': False, 'y20': False, 'y21': False, 'y22': False, 'y23': False, 'y24': False, 'y25': False, 'y26': False, 'y27': False, 'y28': False, 'y29': False, 'y30': False, 'y31': False, 'y32': False, 'y33': False, 'y34': False, 'y35': False, 'y36': False, 'y37': False, 'y38': False, 'y39': False, 'y40': False, 'y41': False, 'y42': False, 'y43': False, 'y44': False, 'y45': False, 'y46': False, 'y47': False, 'y48': False, 'y49': False, 'y50': False, 'y51': False, 'y52': False, 'y53': False, 'y54': False}

label_options = pg.font.Font('fonts/font.ttf', 25)
label_other = pg.font.Font('fonts/font.ttf', 40)
restart_label = label_other.render('Возродиться', True, 'Red')
restart_label_rect = restart_label.get_rect(topleft=(770, 320))

slot_button = pg.font.Font('fonts/font.ttf', 50).render('...', True, (115, 132, 148))

tick = 0

generation_earth = 0
generation_tree = 0
generation_grass = 0
gen_tree = {}
gen_grass = {}
seedling_dict = {}
delete_list = []
generation_dict = {}
inter_generation_dict = {}
m = ''
strength_dict = {}
loaded_generation = {}
background_blocks = {}

fps = 32
font = pg.font.Font('fonts/font.ttf', 30)

update_generation_dict = True
update_loaded_generation = True
loading = True
l = 1
load = True
l2 = 1

end_frame = 'left'
dis_things = True

bg_surface = pg.Surface((2112, 1280))

def slot_inv1(nom, x_y, y_y):
    sl_t = None
    for sl in slots:
        if slots[sl]:
            sl_t = sl
    if sl_t == None and inventory.get(f'{nom},{x_y},{y_y}') != None or sl_t == f'{nom}' and inventory.get(f'{nom},{x_y},{y_y}') != None:
        slots[f'{nom}'] = True
    else:
        for iy in inventory:
            if iy.split(',')[0] == sl_t:
                slots[sl_t] = False
                if inventory.get(f'{nom},{x_y},{y_y}') != None:
                    if inventory.get(f'{nom},{x_y},{y_y}').split(',')[1] != inventory[iy].split(',')[1]:
                        med = inventory[f'{nom},{x_y},{y_y}']
                        inventory[f'{nom},{x_y},{y_y}'] = inventory[iy]
                        inventory[iy] = med
                    elif inventory.get(f'{nom},{x_y},{y_y}').split(',')[1] == inventory[iy].split(',')[1]:
                        inventory[f'{nom},{x_y},{y_y}'] = f'{int(inventory[f'{nom},{x_y},{y_y}'].split(',')[0]) + int(inventory[iy].split(',')[0])},{inventory[iy].split(',')[1]}'
                        del inventory[iy]
                else:
                    inventory[f'{nom},{x_y},{y_y}'] = inventory[iy]
                    del inventory[iy]
                break

def slot_inv2(nom, x_y, y_y):
    sl_t = None
    for sl in slots:
        if slots[sl]:
            sl_t = sl
    if sl_t == None and inventory.get(f'{nom},{x_y},{y_y}') != None or sl_t == f'{nom}' and inventory.get(f'{nom},{x_y},{y_y}') != None:
        slots[f'{nom}'] = True
    else:
        for iy in inventory:
            if iy.split(',')[0] == sl_t:
                slots[sl_t] = False
                if inventory.get(f'{nom},{x_y},{y_y}') != None:
                    if inventory.get(f'{nom},{x_y},{y_y}').split(',')[1] != inventory[iy].split(',')[1]:
                        pass
                    else:
                        inventory[f'{nom},{x_y},{y_y}'] = f'{int(inventory[f'{nom},{x_y},{y_y}'].split(',')[0]) + int(inventory[iy].split(',')[0])},{inventory[iy].split(',')[1]}'
                        del inventory[iy]
                else:
                    if int(inventory[iy].split(',')[0]) > 1:
                        if int(inventory[iy].split(',')[0]) / 2 % 2 == 0:
                            inventory[f'{nom},{x_y},{y_y}'] = f'{int(int(inventory[iy].split(',')[0]) / 2)},{inventory[iy].split(',')[1]}'
                        else:
                            inventory[f'{nom},{x_y},{y_y}'] = f'{int(int(inventory[iy].split(',')[0]) / 2 + 0.5)},{inventory[iy].split(',')[1]}'
                        inventory[iy] = f'{int(int(inventory[iy].split(',')[0]) // 2)},{inventory[iy].split(',')[1]}'
                    else:
                        inventory[f'{nom},{x_y},{y_y}'] = inventory[iy]
                        del inventory[iy]
                break

run = True
while run:

    screen.blit(pg.image.load(f'images/player/player_new.jpg').convert_alpha(), (256, 256))

    if generation_earth == 0:
        x = -96
        y = 576
        for c in range(24):
            for p in range(66):
                r = random.randint(0, 10)
                if y == 576:
                    x = str(x)
                    y = str(y)
                    try:
                        if generation_dict.get((str(int(x) - 32)) + ',' + y) == 'images/blocks/whole/Дерн32.png' and generation_dict.get((str(int(x) - 64)) + ',' + y) == 'images/blocks/whole/Дерн32.png':
                            r_high = random.randint(0, 10)
                            if r_high >= 0 and r_high <= 6:
                                x = int(x)
                                y = int(y)
                                m = 'images/blocks/whole/Дерн32.png'
                            else:
                                m = ''
                        else:
                            if generation_dict.get((str(int(x) - 32)) + ',' + y) == None and generation_dict.get((str(int(x) - 64)) + ',' + y) == None and generation_dict.get((str(int(x) - 96)) + ',' + y) == None:
                                r_high = random.randint(0, 10)
                                if r_high >= 0 and r_high <= 3:
                                    m = 'images/blocks/whole/Дерн32.png'
                    except KeyError:
                        pass
                else:
                    if generation_dict.get(str(x) + ',' + str(y - 32)) == 'images/blocks/whole/Дерн32.png':
                        try:
                            m = 'images/blocks/whole/Земля32.png'
                        except KeyError:
                            m = 'images/blocks/whole/Дерн32.png'
                    elif generation_dict.get(str(x) + ',' + str(y - 32)) == None:
                        m = 'images/blocks/whole/Дерн32.png'
                    elif generation_dict.get(str(x) + ',' + str(y - 32)) == 'images/blocks/whole/Земля32.png' or r >= 4 and r <= 10 and generation_dict.get(str(x) + ',' + str(y - 32)) == 'images/blocks/whole/Глина32.png':
                        if r >= 6 and r <= 10:
                            m = 'images/blocks/whole/Глина32.png'
                        else:
                            m = 'images/blocks/whole/Камень32.png'
                    elif generation_dict.get(str(x) + ',' + str(y - 32)) == 'images/blocks/whole/Камень32.png':
                        if r == 3:
                            m = 'images/blocks/whole/Железо руда32.png'
                        else:
                            m = 'images/blocks/whole/Камень32.png'
                x = str(x)
                y = str(y)
                try:
                    if m != '':
                        generation_dict[x + ',' + y] = m
                        strength_dict[x + ',' + y] = 6
                except Exception:
                    pass
                x = int(x)
                y = int(y)
                x += 32
            x = -96
            y += 32
        generation_earth = 1

    if generation_tree == 0:
        for gd in generation_dict:
            if generation_dict[gd].split('/')[3].split('.')[0] == 'Дерн32' or generation_dict[gd].split('/')[3].split('.')[0] == 'Дерн32_оба' or generation_dict[gd].split('/')[3].split('.')[0] == 'Дерн32_влево' or generation_dict[gd].split('/')[3].split('.')[0] == 'Дерн32_вправо':
                if random.randint(1, 10) <= 2 and gen_tree.get(f'{int(gd.split(',')[0]) - 32},{int(gd.split(',')[1]) - 32}') == None:
                    DV = []
                    ran = random.randint(4, 8)
                    for dv in range(ran):
                        r = random.randint(1, 10)
                        DV.append(r)
                    gen_tree[f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}'] = [ran, 5, DV]
                    DV = []
        generation_tree = 1

    if generation_grass == 0:
        for gd in generation_dict:
            if generation_dict[gd].split('/')[3].split('.')[0] == 'Дерн32' or generation_dict[gd].split('/')[3].split('.')[0] == 'Дерн32_оба' or generation_dict[gd].split('/')[3].split('.')[0] == 'Дерн32_влево' or generation_dict[gd].split('/')[3].split('.')[0] == 'Дерн32_вправо':
                rn = random.randint(1, 100)
                if rn <= 25 and gen_tree.get(f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}') == None:
                    gen_grass[f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}'] = f'False,{random.randint(1, 3)},Трава32'
                elif rn > 25 and rn <= 35 and gen_tree.get(f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}') == None:
                    gen_grass[f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}'] = f'False,{random.randint(1, 2)},Гриб32'
                elif rn > 35 and rn <= 50 and gen_tree.get(f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}') == None:
                    gen_grass[f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}'] = f'False,{random.randint(1, 3)},Цветы32'
                elif rn > 50 and rn <= 55 and gen_tree.get(f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}') == None:
                    gen_grass[f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}'] = f'True,1,Куст_Ежевики32,None'
                elif rn > 55 and rn <= 60 and gen_tree.get(f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}') == None:
                    gen_grass[f'{int(gd.split(',')[0])},{int(gd.split(',')[1]) - 32}'] = f'True,1,Куст_Малины32,None'
        generation_grass = 1

    if update_generation_dict or loading:
        if l == 3:
            loading = False
        else:
            l += 1
        x = -96
        y = 0
        update_generation_dict = False
        for c in range(40):
            for p in range(66):
                x = str(x)
                y = str(y)
                k = x + ',' + y
                x = int(x)
                y = int(y)
                try:
                    if generation_dict.get(str(str(x + 32) + ',' + str(y))) == None or generation_dict.get(str(str(x - 32) + ',' + str(y))) == None or generation_dict.get(str(str(x) + ',' + str(y - 32))) == None or generation_dict.get(str(str(x) + ',' + str(y + 32))) == None:
                        if 'Дерн' in generation_dict[k]:
                            if strength_dict[k] == 6:
                                if generation_dict.get(str(str(x - 32) + ',' + str(y))) == None and generation_dict.get(str(str(x + 32) + ',' + str(y))) == None:
                                    loaded_generation[k] = 'images/blocks/whole/Дерн32_оба.png'
                                elif generation_dict.get(str(str(x - 32) + ',' + str(y))) == None:
                                    loaded_generation[k] = 'images/blocks/whole/Дерн32_влево.png'
                                elif generation_dict.get(str(str(x + 32) + ',' + str(y))) == None:
                                    loaded_generation[k] = 'images/blocks/whole/Дерн32_вправо.png'
                                else:
                                    loaded_generation[k] = 'images/blocks/whole/Дерн32.png'
                            else:
                                if generation_dict.get(str(str(x - 32) + ',' + str(y))) == None and generation_dict.get(str(str(x + 32) + ',' + str(y))) == None:
                                    loaded_generation[k] = f'images/blocks/broken/Дерн32_оба {strength_dict[k]} hp.png'
                                elif generation_dict.get(str(str(x - 32) + ',' + str(y))) == None:
                                    loaded_generation[k] = f'images/blocks/broken/Дерн32_влево {strength_dict[k]} hp.png'
                                elif generation_dict.get(str(str(x + 32) + ',' + str(y))) == None:
                                    loaded_generation[k] = f'images/blocks/broken/Дерн32_вправо {strength_dict[k]} hp.png'
                                else:
                                    loaded_generation[k] = f'images/blocks/broken/Дерн32 {strength_dict[k]} hp.png'
                        else:
                            if strength_dict[k] == 6:
                                loaded_generation[k] = f'images/blocks/whole/{generation_dict[k].split('/')[3].split('.')[0]}.png'
                            else:
                                loaded_generation[k] = f'images/blocks/broken/{generation_dict[k].split('/')[3].split('.')[0]} {strength_dict[k]} hp.png'
                    else:
                        if loaded_generation.get(str(str(x) + ',' + str(
                                y - 32))) != 'images/blocks/Пустота_1_32.png' and loaded_generation.get(
                                str(str(x) + ',' + str(
                                        y - 32))) != 'images/blocks/Пустота_2_32.png' and loaded_generation.get(
                                str(str(x) + ',' + str(
                                        y - 32))) != 'images/blocks/Пустота_3_32.png' or loaded_generation.get(
                                str(str(x - 32) + ',' + str(
                                        y))) != 'images/blocks/Пустота_1_32.png' and loaded_generation.get(
                                str(str(x - 32) + ',' + str(
                                        y))) != 'images/blocks/Пустота_2_32.png' and loaded_generation.get(
                                str(str(x - 32) + ',' + str(
                                        y))) != 'images/blocks/Пустота_3_32.png' or loaded_generation.get(
                                str(str(x + 32) + ',' + str(
                                        y))) != 'images/blocks/Пустота_1_32.png' and loaded_generation.get(
                                str(str(x + 32) + ',' + str(
                                        y))) != 'images/blocks/Пустота_2_32.png' and loaded_generation.get(
                                str(str(x + 32) + ',' + str(y))) != 'images/blocks/Пустота_3_32.png':
                            if generation_dict[k] != 'images/blocks/whole/Саженец дуба32.png' and generation_dict[k] != 'images/blocks/whole/Верстак32.png':
                                loaded_generation[k] = 'images/blocks/Пустота_1_32.png'
                            else:
                                loaded_generation[k] = generation_dict[k]
                        elif loaded_generation.get(str(str(x) + ',' + str(
                                y - 32))) == 'images/blocks/Пустота_1_32.png' or loaded_generation.get(
                            str(str(x - 32) + ',' + str(
                                y))) == 'images/blocks/Пустота_1_32.png' or loaded_generation.get(
                            str(str(x + 32) + ',' + str(y))) == 'images/blocks/Пустота_1_32.png':
                            loaded_generation[k] = 'images/blocks/Пустота_2_32.png'
                        elif loaded_generation.get(str(str(x) + ',' + str(
                                y - 32))) == 'images/blocks/Пустота_2_32.png' or loaded_generation.get(
                            str(str(x) + ',' + str(y - 32))) == 'images/blocks/Пустота_3_32.png':
                            loaded_generation[k] = 'images/blocks/Пустота_3_32.png'
                        if loaded_generation.get(str(str(x) + ',' + str(
                                y - 32))) != 'images/blocks/Пустота_1_32.png' and loaded_generation.get(
                            str(str(x) + ',' + str(
                                y - 32))) != 'images/blocks/Пустота_2_32.png' and loaded_generation.get(
                            str(str(x) + ',' + str(
                                y - 32))) != 'images/blocks/Пустота_3_32.png' or loaded_generation.get(
                            str(str(x - 32) + ',' + str(
                                y))) != 'images/blocks/Пустота_1_32.png' and loaded_generation.get(
                            str(str(x - 32) + ',' + str(
                                y))) != 'images/blocks/Пустота_2_32.png' and loaded_generation.get(
                            str(str(x - 32) + ',' + str(
                                y))) != 'images/blocks/Пустота_3_32.png' or loaded_generation.get(
                            str(str(x + 32) + ',' + str(
                                y))) != 'images/blocks/Пустота_1_32.png' and loaded_generation.get(
                            str(str(x + 32) + ',' + str(
                                y))) != 'images/blocks/Пустота_2_32.png' and loaded_generation.get(
                            str(str(x + 32) + ',' + str(y))) != 'images/blocks/Пустота_3_32.png':
                            if generation_dict[k] != 'images/blocks/whole/Саженец дуба32.png' and generation_dict[k] != 'images/blocks/whole/Верстак32.png':
                                loaded_generation[k] = 'images/blocks/Пустота_1_32.png'
                            else:
                                loaded_generation[k] = generation_dict[k]
                        elif loaded_generation.get(str(str(x) + ',' + str(
                                y - 32))) == 'images/blocks/Пустота_1_32.png' or loaded_generation.get(
                            str(str(x - 32) + ',' + str(
                                y))) == 'images/blocks/Пустота_1_32.png' or loaded_generation.get(
                            str(str(x + 32) + ',' + str(y))) == 'images/blocks/Пустота_1_32.png':
                            loaded_generation[k] = 'images/blocks/Пустота_2_32.png'
                        elif loaded_generation.get(str(str(x) + ',' + str(
                                y - 32))) == 'images/blocks/Пустота_2_32.png' or loaded_generation.get(
                            str(str(x) + ',' + str(y - 32))) == 'images/blocks/Пустота_3_32.png':
                            loaded_generation[k] = 'images/blocks/Пустота_3_32.png'
                    if 'Дерн' in background_blocks[k]:
                        if strength_dict[k] == 6:
                            if background_blocks.get(str(str(x - 32) + ',' + str(y))) == None and background_blocks.get(str(str(x + 32) + ',' + str(y))) == None:
                                loaded_generation[k] = 'images/blocks/whole/Дерн32_оба.png'
                            elif background_blocks.get(str(str(x - 32) + ',' + str(y))) == None:
                                loaded_generation[k] = 'images/blocks/whole/Дерн32_влево.png'
                            elif background_blocks.get(str(str(x + 32) + ',' + str(y))) == None:
                                loaded_generation[k] = 'images/blocks/whole/Дерн32_вправо.png'
                            else:
                                loaded_generation[k] = 'images/blocks/whole/Дерн32.png'
                        else:
                            if background_blocks.get(str(str(x - 32) + ',' + str(y))) == None and background_blocks.get(str(str(x + 32) + ',' + str(y))) == None:
                                loaded_generation[k] = f'images/blocks/broken/Дерн32_оба {strength_dict[k]} hp.png'
                            elif background_blocks.get(str(str(x - 32) + ',' + str(y))) == None:
                                loaded_generation[k] = f'images/blocks/broken/Дерн32_влево {strength_dict[k]} hp.png'
                            elif background_blocks.get(str(str(x + 32) + ',' + str(y))) == None:
                                loaded_generation[k] = f'images/blocks/broken/Дерн32_вправо {strength_dict[k]} hp.png'
                            else:
                                loaded_generation[k] = f'images/blocks/broken/Дерн32 {strength_dict[k]} hp.png'
                    else:
                        if strength_dict[k] == 6:
                            loaded_generation[
                                k] = f'images/blocks/whole/{background_blocks[k].split('/')[3].split('.')[0]}.png'
                        else:
                            loaded_generation[
                                k] = f'images/blocks/broken/{background_blocks[k].split('/')[3].split('.')[0]} {strength_dict[k]} hp.png'
                except Exception:
                    pass
                x += 32
            x = -96
            y += 32


    if inv:
        slot_y1_button_rect = slot_button.get_rect(topleft=(640, 640))
        slot_y2_button_rect = slot_button.get_rect(topleft=(704, 640))
        slot_y3_button_rect = slot_button.get_rect(topleft=(768, 640))
        slot_y4_button_rect = slot_button.get_rect(topleft=(832, 640))
        slot_y5_button_rect = slot_button.get_rect(topleft=(896, 640))
        slot_y6_button_rect = slot_button.get_rect(topleft=(960, 640))
        slot_y7_button_rect = slot_button.get_rect(topleft=(1024, 640))
        slot_y8_button_rect = slot_button.get_rect(topleft=(1088, 640))
        slot_y9_button_rect = slot_button.get_rect(topleft=(1152, 640))
        slot_y10_button_rect = slot_button.get_rect(topleft=(1216, 640))
        slot_y11_button_rect = slot_button.get_rect(topleft=(640, 704))
        slot_y12_button_rect = slot_button.get_rect(topleft=(704, 704))
        slot_y13_button_rect = slot_button.get_rect(topleft=(768, 704))
        slot_y14_button_rect = slot_button.get_rect(topleft=(832, 704))
        slot_y15_button_rect = slot_button.get_rect(topleft=(896, 704))
        slot_y16_button_rect = slot_button.get_rect(topleft=(960, 704))
        slot_y17_button_rect = slot_button.get_rect(topleft=(1024, 704))
        slot_y18_button_rect = slot_button.get_rect(topleft=(1088, 704))
        slot_y19_button_rect = slot_button.get_rect(topleft=(1152, 704))
        slot_y20_button_rect = slot_button.get_rect(topleft=(1216, 704))
        slot_y21_button_rect = slot_button.get_rect(topleft=(640, 768))
        slot_y22_button_rect = slot_button.get_rect(topleft=(704, 768))
        slot_y23_button_rect = slot_button.get_rect(topleft=(768, 768))
        slot_y24_button_rect = slot_button.get_rect(topleft=(832, 768))
        slot_y25_button_rect = slot_button.get_rect(topleft=(896, 768))
        slot_y26_button_rect = slot_button.get_rect(topleft=(960, 768))
        slot_y27_button_rect = slot_button.get_rect(topleft=(1024, 768))
        slot_y28_button_rect = slot_button.get_rect(topleft=(1088, 768))
        slot_y29_button_rect = slot_button.get_rect(topleft=(1152, 768))
        slot_y30_button_rect = slot_button.get_rect(topleft=(1216, 768))

        slot_y31_button_rect = slot_button.get_rect(topleft=(640, 896))
        slot_y32_button_rect = slot_button.get_rect(topleft=(704, 896))
        slot_y33_button_rect = slot_button.get_rect(topleft=(768, 896))
        slot_y34_button_rect = slot_button.get_rect(topleft=(832, 896))
        slot_y35_button_rect = slot_button.get_rect(topleft=(896, 896))
        slot_y36_button_rect = slot_button.get_rect(topleft=(960, 896))
        slot_y37_button_rect = slot_button.get_rect(topleft=(1024, 896))
        slot_y38_button_rect = slot_button.get_rect(topleft=(1088, 896))
        slot_y39_button_rect = slot_button.get_rect(topleft=(1152, 896))
        slot_y40_button_rect = slot_button.get_rect(topleft=(1216, 896))

        slot_y41_button_rect = slot_button.get_rect(topleft=(1024, 448))
        slot_y42_button_rect = slot_button.get_rect(topleft=(1088, 448))
        slot_y43_button_rect = slot_button.get_rect(topleft=(1024, 512))
        slot_y44_button_rect = slot_button.get_rect(topleft=(1088, 512))
        slot_y45_button_rect = slot_button.get_rect(topleft=(1216, 480))

        button_plus_rect = slot_button.get_rect(topleft=(448, 896))
        button_minus_rect = slot_button.get_rect(topleft=(512, 896))
    else:
        slot_y1_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y2_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y3_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y4_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y5_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y6_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y7_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y8_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y9_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y10_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y11_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y12_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y13_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y14_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y15_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y16_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y17_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y18_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y19_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y20_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y21_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y22_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y23_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y24_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y25_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y26_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y27_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y28_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y29_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y30_button_rect = slot_button.get_rect(topleft=(10000, 10000))

        slot_y31_button_rect = slot_button.get_rect(topleft=(640, 896))
        slot_y32_button_rect = slot_button.get_rect(topleft=(704, 896))
        slot_y33_button_rect = slot_button.get_rect(topleft=(768, 896))
        slot_y34_button_rect = slot_button.get_rect(topleft=(832, 896))
        slot_y35_button_rect = slot_button.get_rect(topleft=(896, 896))
        slot_y36_button_rect = slot_button.get_rect(topleft=(960, 896))
        slot_y37_button_rect = slot_button.get_rect(topleft=(1024, 896))
        slot_y38_button_rect = slot_button.get_rect(topleft=(1088, 896))
        slot_y39_button_rect = slot_button.get_rect(topleft=(1152, 896))
        slot_y40_button_rect = slot_button.get_rect(topleft=(1216, 896))

        slot_y41_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y42_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y43_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y44_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y45_button_rect = slot_button.get_rect(topleft=(10000, 10000))

        button_plus_rect = slot_button.get_rect(topleft=(448, 896))
        button_minus_rect = slot_button.get_rect(topleft=(512, 896))

    if workbench:
        slot_y46_button_rect = slot_button.get_rect(topleft=(640, 512))
        slot_y47_button_rect = slot_button.get_rect(topleft=(704, 512))
        slot_y48_button_rect = slot_button.get_rect(topleft=(768, 512))
        slot_y49_button_rect = slot_button.get_rect(topleft=(640, 448))
        slot_y50_button_rect = slot_button.get_rect(topleft=(704, 448))
        slot_y51_button_rect = slot_button.get_rect(topleft=(768, 448))
        slot_y52_button_rect = slot_button.get_rect(topleft=(640, 384))
        slot_y53_button_rect = slot_button.get_rect(topleft=(704, 384))
        slot_y54_button_rect = slot_button.get_rect(topleft=(768, 384))
    else:
        slot_y46_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y47_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y48_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y49_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y50_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y51_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y52_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y53_button_rect = slot_button.get_rect(topleft=(10000, 10000))
        slot_y54_button_rect = slot_button.get_rect(topleft=(10000, 10000))

    if update_loaded_generation or load:
        if l2 == 3:
            load = False
        else:
            l2 += 1
        update_loaded_generation = False
        bg_surface.blit(bg, (0, -300))
        for lg in loaded_generation:
            lg_x, lg_y = lg.split(',')
            bg_surface.blit(pg.image.load(loaded_generation[lg]).convert_alpha(), (int(lg_x), int(lg_y)))
        for t in gen_tree:
            bg_surface.blit(pg.image.load(f'images/blocks/broken/Пень32 {gen_tree[t][1]} hp.png').convert_alpha(),(int(t.split(',')[0]), int(t.split(',')[1])))
            for t2 in range(1, int(gen_tree[t][0])):
                if gen_tree[t][2][t2 - 1] < 9:
                    bg_surface.blit(pg.image.load(f'images/blocks/whole/Дерево32_{gen_tree[t][2][t2 - 1]}.png').convert_alpha(),(int(t.split(',')[0]), int(t.split(',')[1]) - 32 * t2))
                else:
                    bg_surface.blit(pg.image.load(f'images/blocks/whole/Дерево32_{gen_tree[t][2][t2 - 1]}.png').convert_alpha(),(int(t.split(',')[0]) - 16, int(t.split(',')[1]) - 32 * t2))
            bg_surface.blit(pg.image.load(f'images/blocks/whole/Верх32.png').convert_alpha(),(int(t.split(',')[0]) - 16, int(t.split(',')[1]) - 35 * int(gen_tree[t][0])))
        for gr in gen_grass:
            bg_surface.blit(pg.image.load(f'images/blocks/whole/{gen_grass[gr].split(',')[2]}_{gen_grass[gr].split(',')[1]}.png').convert_alpha(),(int(gr.split(',')[0]), int(gr.split(',')[1])))

    for gr in gen_grass:
        if gen_grass[gr].split(',')[2] == 'Куст_Малины32':
            if gen_grass[gr].split(',')[0] == 'True':
                update_loaded_generation = True
                gen_grass[gr] = f'False,2,Куст_Малины32,None'
            else:
                if gen_grass[gr].split(',')[3] != 'None':
                    if gen_grass[gr].split(',')[3] == '0':
                        gen_grass[gr] = f'True,1,Куст_Малины32,None'
                    else:
                        gen_grass[gr] = f'False,1,Куст_Малины32,{int(gen_grass[gr].split(',')[3]) - 1}'
        if gen_grass[gr].split(',')[2] == 'Куст_Ежевики32':
            if gen_grass[gr].split(',')[0] == 'True':
                update_loaded_generation = True
                gen_grass[gr] = f'False,2,Куст_Ежевики32,None'
            else:
                if gen_grass[gr].split(',')[3] != 'None':
                    if gen_grass[gr].split(',')[3] == '0':
                        gen_grass[gr] = f'True,1,Куст_Ежевики32,None'
                    else:
                        gen_grass[gr] = f'False,1,Куст_Ежевики32,{int(gen_grass[gr].split(',')[3]) - 1}'

    if pg.mouse.get_pressed()[2]:
        x_block = pg.mouse.get_pos()[0] // 32 * 32
        y_block = pg.mouse.get_pos()[1] // 32 * 32
        if gen_grass.get(f'{x_block},{y_block}') != None:
            r_t = random.randint(350, 750)
            if gen_grass[f'{x_block},{y_block}'].split(',')[2] == 'Куст_Малины32' and gen_grass[f'{x_block},{y_block}'].split(',')[1] == '2':
                update_loaded_generation = True
                gen_grass[f'{x_block},{y_block}'] = f'False,1,Куст_Малины32,{r_t}'
                s = 0
                i_n2 = ''
                for i_n in inventory:
                    if 'Малина' in inventory[i_n]:
                        s += 1
                        i_n2 = i_n
                        break
                r_ber = random.randint(1, 2)
                if s >= 1:
                    S = i_n2.split(',')
                    S2 = inventory[i_n2].split(',')
                    if r_ber != 0:
                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + r_ber},Малина'
                else:
                    for ig in range(30):
                        if inventory.get(inventory['next,0,0']) == None:
                            if r_ber != 0:
                                inventory[f'{inventory['next,0,0']}'] = f'{r_ber},Малина'
                            break
                        else:
                            S = inventory['next,0,0'].split(',')
                            if int(S[0]) + 64 <= 1216:
                                inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                            else:
                                inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                    if r_ber != 0:
                        S = inventory['next,0,0'].split(',')
                        if int(S[0]) + 64 <= 1216:
                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                        else:
                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                s = 0
            if gen_grass[f'{x_block},{y_block}'].split(',')[2] == 'Куст_Ежевики32' and gen_grass[f'{x_block},{y_block}'].split(',')[1] == '2':
                update_loaded_generation = True
                gen_grass[f'{x_block},{y_block}'] = f'False,1,Куст_Ежевики32,{r_t}'
                s = 0
                i_n2 = ''
                for i_n in inventory:
                    if 'Ежевика' in inventory[i_n]:
                        s += 1
                        i_n2 = i_n
                        break
                r_ber = random.randint(1, 2)
                if s >= 1:
                    S = i_n2.split(',')
                    S2 = inventory[i_n2].split(',')
                    if r_ber != 0:
                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + r_ber},Ежевика'
                else:
                    for ig in range(30):
                        if inventory.get(inventory['next,0,0']) == None:
                            if r_ber != 0:
                                inventory[f'{inventory['next,0,0']}'] = f'{r_ber},Ежевика'
                            break
                        else:
                            S = inventory['next,0,0'].split(',')
                            if int(S[0]) + 64 <= 1216:
                                inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                            else:
                                inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                    if r_ber != 0:
                        S = inventory['next,0,0'].split(',')
                        if int(S[0]) + 64 <= 1216:
                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                        else:
                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                s = 0

    screen.blit(bg_surface, (0, 0))

    keys = pg.key.get_pressed()
    if not Player.get_jump(player):
        if keys[pg.K_SPACE] and Player.get_energy(player) >= 20 or keys[pg.K_w] and Player.get_energy(player) >= 20:
            if generation_dict.get(str(Player.get_x(player) // 32 * 32) + ',' + str(Player.get_y(player) // 32 * 32 - 32)) == None and generation_dict.get(str(Player.get_x(player) // 32 * 32) + ',' + str(Player.get_y(player) // 32 * 32 + 64)) != None:
                Player.set_energy(player, Player.get_energy(player) - 20)
                Player.set_jump(player, True)
    else:
        if jump_count >= 0:
            Player.set_y(player, int(Player.get_y(player) - jump_count ** 2 // 2))
            jump_count -= 1
        else:
            Player.set_jump(player, False)
            jump_count = 7

    if not Player.get_jump(player):
        for x in generation_dict:
            if generation_dict.get(str(Player.get_x(player) // 32 * 32) + ',' + str(Player.get_y(player) // 32 * 32)) == None:
                if Player.get_x(player) // 32 * 32 == int(x.split(',')[0]):
                    if int(x.split(',')[1]) >= Player.get_y(player) // 32 * 32:
                        if Player.get_y(player) < int(x.split(',')[1]) - 64:
                            Player.set_y(player, Player.get_y(player) + 20)
                        else:
                            Player.set_y(player, int(x.split(',')[1]) - 64)
                        break

    if Player.get_HP(player) > 0:

        for hpp in range(1, 11):
            screen.blit(pg.image.load(f'images/player/Сердце_2.png').convert_alpha(), (34 * hpp, 20))
            screen.blit(pg.image.load(f'images/player/Еда_2.png').convert_alpha(), (34 * hpp, 55))
            screen.blit(pg.image.load(f'images/player/Армор_2.png').convert_alpha(), (34 * hpp, 90))
            screen.blit(pg.image.load(f'images/player/Энергия_2.png').convert_alpha(), (34 * hpp, 125))

        _pl: int = Player.get_HP(player)
        n = 0
        while _pl >= 10:
            n += 1
            screen.blit(pg.image.load(f'images/player/Сердце.png').convert_alpha(),(34 * n, 20))
            _pl -= 10
        if _pl <= 5 and _pl != 0:
            n += 1
            screen.blit(pg.image.load(f'images/player/ПолСердца.png').convert_alpha(),(34 * n, 20))
        elif _pl > 5 and _pl != 0:
            n += 1
            screen.blit(pg.image.load(f'images/player/Сердце.png').convert_alpha(), (34 * n, 20))

        _pl: int = Player.get_eat(player)
        n = 0
        while _pl >= 10:
            n += 1
            screen.blit(pg.image.load(f'images/player/Еда.png').convert_alpha(), (34 * n, 55))
            _pl -= 10
        if _pl <= 5 and _pl != 0:
            n += 1
            screen.blit(pg.image.load(f'images/player/ПолЕда.png').convert_alpha(), (34 * n, 55))
        elif _pl > 5 and _pl != 0:
            n += 1
            screen.blit(pg.image.load(f'images/player/Еда.png').convert_alpha(), (34 * n, 55))

        _pl: int = Player.get_armor(player)
        n = 0
        while _pl >= 10:
            n += 1
            screen.blit(pg.image.load(f'images/player/Армор.png').convert_alpha(), (34 * n, 90))
            _pl -= 10
        if _pl <= 5 and _pl != 0:
            n += 1
            screen.blit(pg.image.load(f'images/player/ПолАрмор.png').convert_alpha(), (34 * n, 90))
        elif _pl > 5 and _pl != 0:
            n += 1
            screen.blit(pg.image.load(f'images/player/Армор.png').convert_alpha(), (34 * n, 90))

        _pl: int = Player.get_energy(player)
        n = 0
        while _pl >= 10:
            n += 1
            screen.blit(pg.image.load(f'images/player/Энергия.png').convert_alpha(), (34 * n, 125))
            _pl -= 10
        if _pl <= 5 and _pl != 0:
            n += 1
            screen.blit(pg.image.load(f'images/player/ПолЭнергия.png').convert_alpha(), (34 * n, 125))
        elif _pl > 5 and _pl != 0:
            n += 1
            screen.blit(pg.image.load(f'images/player/Энергия.png').convert_alpha(), (34 * n, 125))

        if Player.get_eat(player) > 0 and Player.get_HP(player) <= 99.5:
            if eat_time_died == 0:
                Player.set_HP(player, Player.get_HP(player) + 1)
                Player.set_eat(player, Player.get_eat(player) - 1)
                eat_time_died = 25

        if Player.get_eat(player) <= 0:
            if eat_time_died == 0:
                Player.set_HP(player, Player.get_HP(player) - 1)
                eat_time_died = 25
                dead = 'голода'
        else:
            if eat_time == 0:
                Player.set_eat(player, Player.get_eat(player) - 1)
                eat_time = 150
            else:
                eat_time -= 1

        if eat_time_died != 0:
            eat_time_died -= 1

        if slot_y1_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(1, 640, 640)
                tick = 1
        elif slot_y1_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(1, 640, 640)
                tick = 1

        if slot_y2_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(2,704,640)
                tick = 1
        elif slot_y2_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(2,704,640)
                tick = 1

        if slot_y3_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(3,768,640)
                tick = 1
        elif slot_y3_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(3,768,640)
                tick = 1

        if slot_y4_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(4,832,640)
                tick = 1
        elif slot_y4_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(4,832,640)
                tick = 1

        if slot_y5_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(5,896,640)
                tick = 1
        elif slot_y5_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(5,896,640)
                tick = 1

        if slot_y6_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(6,960,640)
                tick = 1
        elif slot_y6_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(6,960,640)
                tick = 1

        if slot_y7_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(7,1024,640)
                tick = 1
        elif slot_y7_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(7,1024,640)
                tick = 1

        if slot_y8_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(8,1088,640)
                tick = 1
        elif slot_y8_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(8,1088,640)
                tick = 1

        if slot_y9_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(9,1152,640)
                tick = 1
        elif slot_y9_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(9,1152,640)
                tick = 1

        if slot_y10_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(10,1216,640)
                tick = 1
        elif slot_y10_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(10,1216,640)
                tick = 1

        if slot_y11_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(11, 640, 704)
                tick = 1
        elif slot_y11_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(11, 640, 704)
                tick = 1

        if slot_y12_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(12,704,704)
                tick = 1
        elif slot_y12_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(12,704,704)
                tick = 1

        if slot_y13_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(13,768,704)
                tick = 1
        elif slot_y13_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(13,768,704)
                tick = 1

        if slot_y14_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(14,832,704)
                tick = 1
        elif slot_y14_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(14,832,704)
                tick = 1

        if slot_y15_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(15,896,704)
                tick = 1
        elif slot_y15_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(15,896,704)
                tick = 1

        if slot_y16_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(16,960,704)
                tick = 1
        elif slot_y16_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(16,960,704)
                tick = 1

        if slot_y17_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(17,1024,704)
                tick = 1
        elif slot_y17_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(17,1024,704)
                tick = 1

        if slot_y18_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(18,1088,704)
                tick = 1
        elif slot_y18_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(18,1088,704)
                tick = 1

        if slot_y19_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(19,1152,704)
                tick = 1
        elif slot_y19_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(19,1152,704)
                tick = 1

        if slot_y20_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(20,1216,704)
                tick = 1
        elif slot_y20_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(20,1216,704)
                tick = 1

        if slot_y21_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(21, 640, 768)
                tick = 1
        elif slot_y21_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(21, 640, 768)
                tick = 1

        if slot_y22_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(22,704,768)
                tick = 1
        elif slot_y22_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(22,704,768)
                tick = 1

        if slot_y23_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(23,768,768)
                tick = 1
        elif slot_y23_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(23,768,768)
                tick = 1

        if slot_y24_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(24,832,768)
                tick = 1
        elif slot_y24_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(24,832,768)
                tick = 1

        if slot_y25_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(25,896,768)
                tick = 1
        elif slot_y25_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(25,896,768)
                tick = 1

        if slot_y26_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(26,960,768)
                tick = 1
        elif slot_y26_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(26,960,768)
                tick = 1

        if slot_y27_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(27,1024,768)
                tick = 1
        elif slot_y27_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(27,1024,768)
                tick = 1

        if slot_y28_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(28,1088,768)
                tick = 1
        elif slot_y28_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(28,1088,768)
                tick = 1

        if slot_y29_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(29,1152,768)
                tick = 1
        elif slot_y29_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(29,1152,768)
                tick = 1

        if slot_y30_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            if tick == 0:
                slot_inv1(30,1216,768)
                tick = 1
        elif slot_y30_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                slot_inv2(30,1216,768)
                tick = 1

        if slot_y31_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(31, 640, 896)
                tick = 1
        elif slot_y31_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(31, 640, 896)
                tick = 1

        if slot_y32_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(32,704,896)
                tick = 1
        elif slot_y32_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(32,704,896)
                tick = 1

        if slot_y33_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(33, 768, 896)
                tick = 1
        elif slot_y33_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(33, 768, 896)
                tick = 1

        if slot_y34_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(34,832,896)
                tick = 1
        elif slot_y34_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(34,832,896)
                tick = 1

        if slot_y35_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(35, 896, 896)
                tick = 1
        elif slot_y35_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(35, 896, 896)
                tick = 1

        if slot_y36_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(36,960,896)
                tick = 1
        elif slot_y36_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(36,960,896)
                tick = 1

        if slot_y37_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(37, 1024, 896)
                tick = 1
        elif slot_y37_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(37, 1024, 896)
                tick = 1

        if slot_y38_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(38,1088,896)
                tick = 1
        elif slot_y38_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(38,1088,896)
                tick = 1

        if slot_y39_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(39, 1152, 896)
                tick = 1
        elif slot_y39_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(39, 1152, 896)
                tick = 1

        if slot_y40_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(40,1216,896)
                tick = 1
        elif slot_y40_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(40,1216,896)
                tick = 1

        if slot_y41_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(41,1024,448)
                tick = 1
        elif slot_y41_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(41,1024,448)
                tick = 1

        if slot_y42_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(42,1088,448)
                tick = 1
        elif slot_y42_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(42,1088,448)
                tick = 1

        if slot_y43_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(43,1024,512)
                tick = 1
        elif slot_y43_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(43,1024,512)
                tick = 1

        if slot_y44_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
            if tick == 0:
                slot_inv1(44,1088,512)
                tick = 1
        elif slot_y44_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
            if tick == 0:
                slot_inv2(44,1088,512)
                tick = 1

        try:
            if slot_y45_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and inv:
                if tick == 0:
                    slot_inv1(45,1216,480)
                    if int(inventory.get('41,1024,448').split(',')[0]) - 1 == 0:
                        del inventory['41,1024,448']
                    else:
                        inventory['41,1024,448'] = f'{int(inventory['41,1024,448'].split(',')[0]) - 1},{inventory['41,1024,448'].split(',')[1]}'
                    if int(inventory.get('42,1088,448').split(',')[0]) - 1 == 0:
                        del inventory['42,1088,448']
                    else:
                        inventory['42,1088,448'] = f'{int(inventory['42,1088,448'].split(',')[0]) - 1},{inventory['42,1088,448'].split(',')[1]}'
                    if int(inventory.get('43,1024,512').split(',')[0]) - 1 == 0:
                        del inventory['43,1024,512']
                    else:
                        inventory['43,1024,512'] = f'{int(inventory['43,1024,512'].split(',')[0]) - 1},{inventory['43,1024,512'].split(',')[1]}'
                    if int(inventory.get('44,1088,512').split(',')[0]) - 1 == 0:
                        del inventory['44,1088,512']
                    else:
                        inventory['44,1088,512'] = f'{int(inventory['44,1088,512'].split(',')[0]) - 1},{inventory['44,1088,512'].split(',')[1]}'
                    tick = 1
            elif slot_y45_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and inv:
                if tick == 0:
                    slot_inv2(45,1216,480)
                    if int(inventory.get('41,1024,448').split(',')[0]) - 1 == 0:
                        del inventory['41,1024,448']
                    else:
                        inventory['41,1024,448'] = f'{int(inventory['41,1024,448'].split(',')[0]) - 1},{inventory['41,1024,448'].split(',')[1]}'
                    if int(inventory.get('42,1088,448').split(',')[0]) - 1 == 0:
                        del inventory['42,1088,448']
                    else:
                        inventory['42,1088,448'] = f'{int(inventory['42,1088,448'].split(',')[0]) - 1},{inventory['42,1088,448'].split(',')[1]}'
                    if int(inventory.get('43,1024,512').split(',')[0]) - 1 == 0:
                        del inventory['43,1024,512']
                    else:
                        inventory['43,1024,512'] = f'{int(inventory['43,1024,512'].split(',')[0]) - 1},{inventory['43,1024,512'].split(',')[1]}'
                    if int(inventory.get('44,1088,512').split(',')[0]) - 1 == 0:
                        del inventory['44,1088,512']
                    else:
                        inventory['44,1088,512'] = f'{int(inventory['44,1088,512'].split(',')[0]) - 1},{inventory['44,1088,512'].split(',')[1]}'
                    tick = 1
        except KeyError:
            pass

        if slot_y46_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(46,640,512)
                tick = 1
        elif slot_y46_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(46,640,512)
                tick = 1

        if slot_y47_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(47,704,512)
                tick = 1
        elif slot_y47_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(47,704,512)
                tick = 1

        if slot_y48_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(48,768,512)
                tick = 1
        elif slot_y48_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(48,768,512)
                tick = 1

        if slot_y49_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(49,640,448)
                tick = 1
        elif slot_y49_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(49,640,448)
                tick = 1

        if slot_y50_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(50,704,448)
                tick = 1
        elif slot_y50_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(50,704,448)
                tick = 1

        if slot_y51_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(51,768,448)
                tick = 1
        elif slot_y51_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(51,768,448)
                tick = 1

        if slot_y52_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(52,640,384)
                tick = 1
        elif slot_y52_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(52,640,384)
                tick = 1

        if slot_y53_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(53,704,384)
                tick = 1
        elif slot_y53_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(53,704,384)
                tick = 1

        if slot_y54_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] and workbench:
            if tick == 0:
                slot_inv1(54,768,384)
                tick = 1
        elif slot_y54_button_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2] and workbench:
            if tick == 0:
                slot_inv2(54,768,384)
                tick = 1

        if button_plus_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] or button_plus_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                build_plan = 1
                tick = 1
        elif button_minus_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0] or button_minus_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[2]:
            if tick == 0:
                build_plan = 2
                tick = 1

        if tick == 2:
            tick = 0
        elif tick == 0:
            pass
        else:
            tick += 1

        if pg.mouse.get_pressed()[0] and slot_2 and press == 0 or pg.mouse.get_pressed()[0] and slot_3 and press == 0 or pg.mouse.get_pressed()[0] and slot_4 and press == 0:
            dis_things = False
            Player.set_energy(player, Player.get_energy(player) - 5)
            if end_frame == 'left':
                new_th = ''
                for th in inventory[Player.get_hand(player)].split(',')[1]:
                    if th != '_':
                        new_th += th
                    else:
                        break
                screen.blit(pg.image.load(f'images/things/{new_th + '_Влево' + '_Вниз'}.png').convert_alpha(),(Player.get_x(player) - 28, Player.get_y(player) + 25))
            else:
                screen.blit(pg.image.load(f'images/things/{inventory[Player.get_hand(player)].split(',')[1] + '_Вниз'}.png').convert_alpha(),(Player.get_x(player) - 4, Player.get_y(player) + 25))
            update_generation_dict = True
            update_loaded_generation = True
            x_block = pg.mouse.get_pos()[0] // 32 * 32
            y_block = pg.mouse.get_pos()[1] // 32 * 32
            if x_block >= Player.get_x(player) - 300 and x_block <= Player.get_x(player) + 250 and y_block >= Player.get_y(player) - 200 and y_block <= Player.get_y(player) + 300:
                try:
                    if build_plan == 1:
                        if strength_dict.get(str(x_block) + ',' + str(y_block)) == 1:
                            s = 0
                            i_n2 = ''
                            if generation_dict[str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Камень32.png':
                                if slot_2:
                                    for i_n in inventory:
                                        if 'Камень' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + 1},Камень'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Камень'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                            elif generation_dict[str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Земля32.png' or generation_dict[str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Дерн32.png':
                                if slot_4:
                                    for i_n in inventory:
                                        if 'Земля' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0])+1},Земля'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Земля'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                            elif generation_dict[str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Железо руда32.png':
                                if slot_2:
                                    for i_n in inventory:
                                        if 'Железо руда' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + 1},Железо руда'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Железо руда'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                            elif generation_dict[str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Глина32.png':
                                if slot_4:
                                    for i_n in inventory:
                                        if 'Глина' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + 1},Глина'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Глина'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                if slot_2:
                                    for i_n in inventory:
                                        if 'Камень' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + 1},Камень'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Камень'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory[
                                                        'next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory[
                                                        'next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                            del generation_dict[str(x_block) + ',' + str(y_block)]
                            del loaded_generation[str(x_block) + ',' + str(y_block)]
                        elif strength_dict.get(str(x_block) + ',' + str(y_block)) != None:
                            if 'Дерн' in loaded_generation[str(x_block) + ',' + str(y_block)] or 'Земля' in loaded_generation[str(x_block) + ',' + str(y_block)] or 'Глина' in loaded_generation[str(x_block) + ',' + str(y_block)]:
                                if slot_4:
                                    if strength_dict.get(str(x_block) + ',' + str(y_block)) > 1:
                                        strength_dict[str(x_block) + ',' + str(y_block)] -= 1
                            else:
                                if slot_2:
                                    if strength_dict.get(str(x_block) + ',' + str(y_block)) > 1:
                                        strength_dict[str(x_block) + ',' + str(y_block)] -= 1
                        else:
                            s = 0
                            i_n2 = ''
                            if slot_3:
                                if int(gen_tree[str(x_block) + ',' + str(y_block)][1]) > 1:
                                    gen_tree[str(x_block) + ',' + str(y_block)] = [gen_tree[str(x_block) + ',' + str(y_block)][0], int(gen_tree[str(x_block) + ',' + str(y_block)][1]) - 1, gen_tree[str(x_block) + ',' + str(y_block)][2]]
                                else:
                                    for i_n in inventory:
                                        if 'Дерево' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + int(gen_tree[str(x_block) + ',' + str(y_block)][0])},Дерево'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'{int(gen_tree[str(x_block) + ',' + str(y_block)][0])},Дерево'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                    s = 0
                                    ###########################################################################################
                                    for i_n in inventory:
                                        if 'Саженец дуба' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    r_tree = random.randint(0, 2)
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        if r_tree != 0:
                                            inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + r_tree},Саженец дуба'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                if r_tree != 0:
                                                    inventory[f'{inventory['next,0,0']}'] = f'{r_tree},Саженец дуба'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        if r_tree != 0:
                                            S = inventory['next,0,0'].split(',')
                                            if int(S[0]) + 64 <= 1216:
                                                inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                            else:
                                                inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                    s = 0
                                    ########################################################################################################################
                                    for i_n in inventory:
                                        if 'Яблоко' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    r_app = random.randint(0, 1)
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        if r_app != 0:
                                            inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + r_app},Яблоко'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                if r_app != 0:
                                                    inventory[f'{inventory['next,0,0']}'] = f'{r_app},Яблоко'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        if r_app != 0:
                                            S = inventory['next,0,0'].split(',')
                                            if int(S[0]) + 64 <= 1216:
                                                inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                            else:
                                                inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                    s = 0
                                    del gen_tree[str(x_block) + ',' + str(y_block)]

                    elif build_plan == 2:
                        if strength_dict.get(str(x_block) + ',' + str(y_block)) == 1:
                            s = 0
                            i_n2 = ''
                            if background_blocks[str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Камень32.png':
                                if slot_2:
                                    for i_n in inventory:
                                        if 'Камень' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + 1},Камень'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Камень'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                            elif background_blocks[str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Земля32.png' or background_blocks[str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Дерн32.png':
                                if slot_4:
                                    for i_n in inventory:
                                        if 'Земля' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + 1},Земля'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Земля'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                            elif background_blocks[
                                str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Железо руда32.png':
                                if slot_2:
                                    for i_n in inventory:
                                        if 'Железо руда' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + 1},Железо руда'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Железо руда'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                            elif background_blocks[
                                str(x_block) + ',' + str(y_block)] == 'images/blocks/whole/Глина32.png':
                                if slot_4:
                                    for i_n in inventory:
                                        if 'Глина' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + 1},Глина'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[f'{inventory['next,0,0']}'] = f'1,Глина'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                            del background_blocks[str(x_block) + ',' + str(y_block)]
                            del loaded_generation[str(x_block) + ',' + str(y_block)]
                        elif strength_dict.get(str(x_block) + ',' + str(y_block)) != None:
                            if 'Дерн' in loaded_generation[str(x_block) + ',' + str(y_block)] or 'Земля' in \
                                    loaded_generation[str(x_block) + ',' + str(y_block)] or 'Глина' in \
                                    loaded_generation[str(x_block) + ',' + str(y_block)]:
                                if slot_4:
                                    if strength_dict.get(str(x_block) + ',' + str(y_block)) > 1:
                                        strength_dict[str(x_block) + ',' + str(y_block)] -= 1
                            else:
                                if slot_2:
                                    if strength_dict.get(str(x_block) + ',' + str(y_block)) > 1:
                                        strength_dict[str(x_block) + ',' + str(y_block)] -= 1
                        else:
                            s = 0
                            i_n2 = ''
                            if slot_3:
                                if int(gen_tree[str(x_block) + ',' + str(y_block)][1]) > 1:
                                    gen_tree[str(x_block) + ',' + str(y_block)] = [gen_tree[str(x_block) + ',' + str(y_block)][0], int(gen_tree[str(x_block) + ',' + str(y_block)][1]) - 1, gen_tree[str(x_block) + ',' + str(y_block)][2]]
                                else:
                                    for i_n in inventory:
                                        if 'Дерево' in inventory[i_n]:
                                            s += 1
                                            i_n2 = i_n
                                            break
                                    if s >= 1:
                                        S = i_n2.split(',')
                                        S2 = inventory[i_n2].split(',')
                                        inventory[
                                            f'{S[0]},{S[1]},{S[2]}'] = f'{int(S2[0]) + int(gen_tree[str(x_block) + ',' + str(y_block)][0])},Дерево'
                                    else:
                                        for ig in range(30):
                                            if inventory.get(inventory['next,0,0']) == None:
                                                inventory[
                                                    f'{inventory['next,0,0']}'] = f'{int(gen_tree[str(x_block) + ',' + str(y_block)][0])},Дерево'
                                                break
                                            else:
                                                S = inventory['next,0,0'].split(',')
                                                if int(S[0]) + 64 <= 1216:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                                else:
                                                    inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                        S = inventory['next,0,0'].split(',')
                                        if int(S[0]) + 64 <= 1216:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},{str(int(S[1]) + 64)},{S[2]}'
                                        else:
                                            inventory['next,0,0'] = f'{int(S[0]) + 1},640,{str(int(S[1]) + 64)}'
                                    del gen_tree[str(x_block) + ',' + str(y_block)]
                except KeyError:
                    pass
                press = 1
        elif not pg.mouse.get_pressed()[0] and press == 1:
            dis_things = True
            press = 0
        else:
            dis_things = True

        if workbench:
            x_inv = 640
            y_inv = 384
            for yi in range(3):
                for xi in range(3):
                    screen.blit(pg.image.load('images/player/Слот.png').convert_alpha(), (x_inv, y_inv))
                    for i_n in inventory:
                        S = i_n.split(',')
                        if x_inv == int(S[1]) and y_inv == int(S[2]):
                            try:
                                screen.blit(pg.image.load(f'images/blocks/whole/{inventory[i_n].split(',')[1]}32.png').convert_alpha(),(x_inv + 16, y_inv + 16))
                                rez = 0
                            except FileNotFoundError:
                                screen.blit(pg.transform.scale(pg.image.load(f'images/things/{inventory[i_n].split(',')[1]}.png').convert_alpha(),(48, 48)), (x_inv + 8, y_inv + 8))
                                if inventory[i_n].split(',')[1] == 'Меч_Вправо' or inventory[i_n].split(',')[
                                    1] == 'Кирка_Вправо' or inventory[i_n].split(',')[1] == 'Топор_Вправо' or \
                                        inventory[i_n].split(',')[1] == 'Лопата_Вправо':
                                    rez = 1
                                else:
                                    rez = 0
                            if rez == 0:
                                if int(inventory[i_n].split(',')[0]) < 10:
                                    screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),(x_inv + 24, y_inv + 32))
                                else:
                                    screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),(x_inv + 18, y_inv + 32))
                    x_inv += 64
                y_inv += 64
                x_inv = 640

        x_slot = 576
        for x in range(10):
            x_slot += 64
            screen.blit(pg.image.load(f'images/player/Слот.png').convert_alpha(), (x_slot, 896))

        if inv:
            x_inv = 640
            y_inv = 640
            for yi in range(3):
                for xi in range(10):
                    screen.blit(pg.image.load('images/player/Слот.png').convert_alpha(), (x_inv, y_inv))
                    for i_n in inventory:
                        S = i_n.split(',')
                        if x_inv == int(S[1]) and y_inv == int(S[2]):
                            try:
                                screen.blit(pg.image.load(f'images/blocks/whole/{inventory[i_n].split(',')[1]}32.png').convert_alpha(), (x_inv + 16, y_inv + 16))
                                rez = 0
                            except FileNotFoundError:
                                screen.blit(pg.transform.scale(
                                    pg.image.load(f'images/things/{inventory[i_n].split(',')[1]}.png').convert_alpha(),
                                    (48, 48)), (x_inv + 8, y_inv + 8))
                                if inventory[i_n].split(',')[1] == 'Меч_Вправо' or inventory[i_n].split(',')[1] == 'Кирка_Вправо' or inventory[i_n].split(',')[1] == 'Топор_Вправо' or inventory[i_n].split(',')[1] == 'Лопата_Вправо':
                                    rez = 1
                                else:
                                    rez = 0
                            if rez == 0:
                                if int(inventory[i_n].split(',')[0]) < 10:
                                    screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),(x_inv + 24, y_inv + 32))
                                else:
                                    screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),(x_inv + 18, y_inv + 32))
                    x_inv += 64
                y_inv += 64
                x_inv = 640

            x_inv = 1024
            y_inv = 448
            for yi in range(2):
                for xi in range(2):
                    screen.blit(pg.image.load('images/player/Слот.png').convert_alpha(), (x_inv, y_inv))
                    for i_n in inventory:
                        S = i_n.split(',')
                        if x_inv == int(S[1]) and y_inv == int(S[2]):
                            try:
                                screen.blit(pg.image.load(f'images/blocks/whole/{inventory[i_n].split(',')[1]}32.png').convert_alpha(), (x_inv + 16, y_inv + 16))
                                rez = 0
                            except FileNotFoundError:
                                screen.blit(pg.transform.scale(
                                    pg.image.load(f'images/things/{inventory[i_n].split(',')[1]}.png').convert_alpha(),
                                    (48, 48)), (x_inv + 8, y_inv + 8))
                                if inventory[i_n].split(',')[1] == 'Меч_Вправо' or inventory[i_n].split(',')[1] == 'Кирка_Вправо' or inventory[i_n].split(',')[1] == 'Топор_Вправо' or inventory[i_n].split(',')[1] == 'Лопата_Вправо':
                                    rez = 1
                                else:
                                    rez = 0
                            if rez == 0:
                                if int(inventory[i_n].split(',')[0]) < 10:
                                    screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),(x_inv + 24, y_inv + 32))
                                else:
                                    screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),(x_inv + 18, y_inv + 32))
                    x_inv += 64
                y_inv += 64
                x_inv = 1024

            screen.blit(pg.image.load('images/player/Слот.png').convert_alpha(), (1216, 480))
            for i_n in inventory:
                S = i_n.split(',')
                if 1216 == int(S[1]) and 480 == int(S[2]):
                    screen.blit(pg.image.load(f'images/blocks/whole/{inventory[i_n].split(',')[1]}32.png').convert_alpha(),
                                (1216 + 16, 480 + 16))
                    if int(inventory[i_n].split(',')[0]) < 10:
                        screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),
                                    (1216 + 24, 480 + 32))
                    else:
                        screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),
                                    (1216 + 18, 480 + 32))

        y_inv = 896
        x_inv = 640
        for xi in range(10):
            for i_n in inventory:
                S = i_n.split(',')
                if x_inv == int(S[1]) and y_inv == int(S[2]):
                    try:
                        screen.blit(pg.image.load(f'images/blocks/whole/{inventory[i_n].split(',')[1]}32.png').convert_alpha(),(x_inv + 16, 896 + 16))
                        rez = 0
                    except FileNotFoundError:
                        screen.blit(pg.transform.scale(pg.image.load(f'images/things/{inventory[i_n].split(',')[1]}.png').convert_alpha(), (48, 48)), (x_inv + 8, 896 + 8))
                        if inventory[i_n].split(',')[1] == 'Меч_Вправо' or inventory[i_n].split(',')[1] == 'Кирка_Вправо' or inventory[i_n].split(',')[1] == 'Топор_Вправо' or inventory[i_n].split(',')[1] == 'Лопата_Вправо':
                            rez = 1
                        else:
                            rez = 0
                    if rez == 0:
                        if int(inventory[i_n].split(',')[0]) < 10:
                            screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),(x_inv + 24, 896 + 32))
                        else:
                            screen.blit(label_options.render(f'{inventory[i_n].split(',')[0]}', True, 'white'),(x_inv + 18, 896 + 32))
            x_inv += 64

        #screen.blit(pg.image.load(f'images/player/Button-.png').convert_alpha(),(512, 896))
        #screen.blit(pg.image.load(f'images/player/Button+.png').convert_alpha(),(448, 896))

        for sl in slots:
            if slots[sl]:
                for msl in inventory:
                    if msl.split(',')[0] == sl:
                        try:
                            screen.blit(pg.image.load(f'images/blocks/whole/{inventory[msl].split(',')[1]}32.png').convert_alpha(), (pg.mouse.get_pos()[0] - 16, pg.mouse.get_pos()[1] - 16))
                        except FileNotFoundError:
                            screen.blit(pg.image.load(f'images/things/{inventory[msl].split(',')[1]}.png').convert_alpha(), (pg.mouse.get_pos()[0] - 16, pg.mouse.get_pos()[1] - 16))

        try:
            if 'Дерево' in inventory['41,1024,448'] and 'Дерево' in inventory['42,1088,448'] and 'Дерево' in inventory['43,1024,512'] and 'Дерево' in inventory['44,1088,512']:
                inventory['45,1216,480'] = '1,Верстак'
            elif inventory.get('41,1024,448') == None and 'Дерево' in inventory['42,1088,448'] and inventory.get('43,1024,512') == None and 'Дерево' in inventory['44,1088,512'] or 'Дерево' in inventory['41,1024,448'] and inventory.get('42,1088,448') == None and 'Дерево' in inventory['43,1024,512'] and inventory.get('44,1088,512') == None:
                inventory['45,1216,480'] = '4,Палка'
        except KeyError:
            pass

        try:
            if pg.mouse.get_pressed()[0] and inventory.get(Player.get_hand(player)) != None and inventory.get(Player.get_hand(player)) != '1,Кирка_Вправо' and inventory.get(Player.get_hand(player)) != '1,Топор_Вправо' and inventory.get(Player.get_hand(player)) != '1,Лопата_Вправо' and inventory.get(Player.get_hand(player)) != '1,Меч_Вправо' and generation_dict.get(f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}') == None and inventory.get(Player.get_hand(player)).split(',')[1] != 'Яблоко' and inventory.get(Player.get_hand(player)).split(',')[1] != 'Малина' and inventory.get(Player.get_hand(player)).split(',')[1] != 'Ежевика':
                update_generation_dict = True
                update_loaded_generation = True
                if build_plan == 1:
                    sup = True
                    gen_dict = {}
                    for gend in generation_dict:
                        if (pg.mouse.get_pos()[1] // 32) * 32 >= 576:
                            if (pg.mouse.get_pos()[0] // 32) * 32 > int(gend.split(',')[0]) and (pg.mouse.get_pos()[1] // 32) * 32 == int(gend.split(',')[1]) and sup:
                                gen_dict[f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}'] = f'images/blocks/whole/{inventory[Player.get_hand(player)].split(',')[1]}32.png'
                                sup = False
                        else:
                            gen_dict[f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}'] = f'images/blocks/whole/{inventory[Player.get_hand(player)].split(',')[1]}32.png'
                            sup = False
                        gen_dict[gend] = generation_dict[gend]
                    generation_dict = gen_dict
                    gen_dict = {}
                    strength_dict[f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}'] = 6
                    if int(inventory[Player.get_hand(player)].split(',')[0]) > 1:
                        inventory[Player.get_hand(player)] = f'{int(inventory[Player.get_hand(player)].split(',')[0]) - 1},{inventory[Player.get_hand(player)].split(',')[1]}'
                    else:
                        del inventory[Player.get_hand(player)]
                else:
                    sup = True
                    b_b = {}
                    if len(background_blocks) > 0:
                        for gend in background_blocks:
                            if (pg.mouse.get_pos()[0] // 32) * 32 > int(gend.split(',')[0]) and (pg.mouse.get_pos()[1] // 32) * 32 == int(gend.split(',')[1]) and sup:
                                b_b[f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}'] = f'images/blocks/whole/{inventory[Player.get_hand(player)].split(',')[1]}32.png'
                                sup = False
                            b_b[gend] = background_blocks[gend]
                        if sup:
                            b_b[f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}'] = f'images/blocks/whole/{inventory[Player.get_hand(player)].split(',')[1]}32.png'
                            sup = False
                        background_blocks = b_b
                        b_b = {}
                    else:
                        background_blocks[f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}'] = f'images/blocks/whole/{inventory[Player.get_hand(player)].split(',')[1]}32.png'
                    strength_dict[f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}'] = 6
                    if int(inventory[Player.get_hand(player)].split(',')[0]) > 1:
                        inventory[Player.get_hand(player)] = f'{int(inventory[Player.get_hand(player)].split(',')[0]) - 1},{inventory[Player.get_hand(player)].split(',')[1]}'
                    else:
                        del inventory[Player.get_hand(player)]
        except AttributeError:
            pass

        if pg.mouse.get_pressed()[2] and generation_dict.get(f'{(pg.mouse.get_pos()[0] // 32) * 32},{(pg.mouse.get_pos()[1] // 32) * 32}') == 'images/blocks/whole/Верстак32.png':
            workbench = True

        try:
            if pg.mouse.get_pressed()[0] and str(inventory.get(Player.get_hand(player))).split(',')[1] == 'Яблоко' or pg.mouse.get_pressed()[0] and str(inventory.get(Player.get_hand(player))).split(',')[1] == 'Ежевика' or pg.mouse.get_pressed()[0] and str(inventory.get(Player.get_hand(player))).split(',')[1] == 'Малина':
                if str(inventory.get(Player.get_hand(player))).split(',')[1] == 'Яблоко' and Player.get_eat(player) <= 85:
                    Player.set_eat(player, Player.get_eat(player) + 15)
                    if int(inventory[Player.get_hand(player)].split(',')[0]) > 1:
                        inventory[Player.get_hand(
                            player)] = f'{int(inventory[Player.get_hand(player)].split(',')[0]) - 1},{inventory[Player.get_hand(player)].split(',')[1]}'
                    else:
                        del inventory[Player.get_hand(player)]
                elif str(inventory.get(Player.get_hand(player))).split(',')[1] == 'Ежевика' and Player.get_eat(player) <= 90:
                    Player.set_eat(player, Player.get_eat(player) + 10)
                    if int(inventory[Player.get_hand(player)].split(',')[0]) > 1:
                        inventory[Player.get_hand(
                            player)] = f'{int(inventory[Player.get_hand(player)].split(',')[0]) - 1},{inventory[Player.get_hand(player)].split(',')[1]}'
                    else:
                        del inventory[Player.get_hand(player)]
                elif str(inventory.get(Player.get_hand(player))).split(',')[1] == 'Малина' and Player.get_eat(player) <= 90:
                    Player.set_eat(player, Player.get_eat(player) + 10)
                    if int(inventory[Player.get_hand(player)].split(',')[0]) > 1:
                        inventory[Player.get_hand(
                            player)] = f'{int(inventory[Player.get_hand(player)].split(',')[0]) - 1},{inventory[Player.get_hand(player)].split(',')[1]}'
                    else:
                        del inventory[Player.get_hand(player)]
        except IndexError:
            pass

        for sdl in generation_dict:
            if generation_dict[sdl] == 'images/blocks/whole/Саженец дуба32.png':
                if seedling_dict.get(sdl) == None:
                    seedling_dict[sdl] = random.randint(0, 1) / 2
                else:
                    seedling_dict[sdl] += random.randint(0, 1) / 2

        for sdl in seedling_dict:
            if seedling_dict[sdl] >= 100:
                DV = []
                ran = random.randint(4, 8)
                for dv in range(ran):
                    r = random.randint(1, 9)
                    DV.append(r)
                gen_tree[sdl] = [ran, 5, DV]
                delete_list.append(sdl)
                DV = []

        for dl in delete_list:
            del seedling_dict[dl]
            del generation_dict[dl]
            del loaded_generation[dl]
            del strength_dict[dl]
            update_generation_dict = True
            update_loaded_generation = True
            delete_list.pop(delete_list.index(dl))

        keys = pg.key.get_pressed()
        if keys[pg.K_a] and not keys[pg.K_LSHIFT] and Player.get_x(player) > 0:
            if generation_dict.get(str(int((Player.get_x(player) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) == None:
                if player_anim_count == 11:
                    player_anim_count = 0
                else:
                    player_anim_count += 1
                if step_s == 0:
                    step_sound.play()
                if step_s == 26:
                    step_s = 0
                else:
                    step_s += 1
                Player.set_x(player, Player.get_x(player) - 5)
                try:
                    screen.blit(walk_left[player_anim_count], (Player.get_x(player) - 8, Player.get_y(player)))
                except IndexError:
                    player_anim_count = 0
                    screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
                end_frame = 'left'
            elif generation_dict.get(str(int((Player.get_x(player) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) != None and generation_dict.get(str(int(((Player.get_x(player) - 6) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) == None:
                if player_anim_count == 11:
                    player_anim_count = 0
                else:
                    player_anim_count += 1
                if step_s == 0:
                    step_sound.play()
                if step_s == 26:
                    step_s = 0
                else:
                    step_s += 1
                Player.set_x(player, Player.get_x(player) - 5)
                try:
                    screen.blit(walk_left[player_anim_count], (Player.get_x(player) - 8, Player.get_y(player)))
                except IndexError:
                    player_anim_count = 0
                    screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
                end_frame = 'left'
            else:
                screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
                if Player.get_energy(player) < 100:
                    Player.set_eat(player, Player.get_eat(player) - 0.1)
                    Player.set_energy(player, Player.get_energy(player) + 1)
        elif keys[pg.K_d] and not keys[pg.K_LSHIFT] and Player.get_x(player) < 1920:
            if generation_dict.get(str(int((Player.get_x(player) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) == None:
                if player_anim_count == 11:
                    player_anim_count = 0
                else:
                    player_anim_count += 1
                if step_s == 0:
                    step_sound.play()
                if step_s == 26:
                    step_s = 0
                else:
                    step_s += 1
                Player.set_x(player, Player.get_x(player) + 5)
                try:
                    screen.blit(walk_right[player_anim_count], (Player.get_x(player) - 22, Player.get_y(player)))
                except IndexError:
                    player_anim_count = 0
                    screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
                end_frame = 'right'
            elif generation_dict.get(str(int((Player.get_x(player) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) != None and generation_dict.get(str(int(((Player.get_x(player) + 6) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) == None:
                if player_anim_count == 11:
                    player_anim_count = 0
                else:
                    player_anim_count += 1
                if step_s == 0:
                    step_sound.play()
                if step_s == 26:
                    step_s = 0
                else:
                    step_s += 1
                Player.set_x(player, Player.get_x(player) + 5)
                try:
                    screen.blit(walk_right[player_anim_count], (Player.get_x(player) - 22, Player.get_y(player)))
                except IndexError:
                    player_anim_count = 0
                    screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
                end_frame = 'right'
            else:
                screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
                if Player.get_energy(player) < 100:
                    Player.set_eat(player, Player.get_eat(player) - 0.1)
                    Player.set_energy(player, Player.get_energy(player) + 1)
###############################################################################################################################
        elif keys[pg.K_a] and keys[pg.K_LSHIFT] and Player.get_x(player) > 0:
            if generation_dict.get(str(int((Player.get_x(player) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) == None:
                if Player.get_energy(player) >= 0.5:
                    Player.set_energy(player, Player.get_energy(player) - 0.5)
                    if player_anim_count == 10:
                        player_anim_count = 0
                    else:
                        player_anim_count += 2
                    if step_s == 0:
                        step_sound.play()
                    if step_s == 14:
                        step_s = 0
                    else:
                        step_s += 1
                    Player.set_x(player, Player.get_x(player) - 7)
                    try:
                        screen.blit(walk_left[player_anim_count], (Player.get_x(player) - 8, Player.get_y(player)))
                    except IndexError:
                        player_anim_count = 0
                        screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
                    end_frame = 'left'
                else:
                    if player_anim_count == 11:
                        player_anim_count = 0
                    else:
                        player_anim_count += 1
                    if step_s == 0:
                        step_sound.play()
                    if step_s == 26:
                        step_s = 0
                    else:
                        step_s += 1
                    Player.set_x(player, Player.get_x(player) - 5)
                    try:
                        screen.blit(walk_left[player_anim_count], (Player.get_x(player) - 8, Player.get_y(player)))
                    except IndexError:
                        player_anim_count = 0
                        screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
                    end_frame = 'left'
            elif generation_dict.get(str(int((Player.get_x(player) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) != None and generation_dict.get(str(int(((Player.get_x(player) - 6) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) == None:
                if Player.get_energy(player) >= 0.5:
                    Player.set_energy(player, Player.get_energy(player) - 0.5)
                    if player_anim_count == 10:
                        player_anim_count = 0
                    else:
                        player_anim_count += 2
                    if step_s == 0:
                        step_sound.play()
                    if step_s == 14:
                        step_s = 0
                    else:
                        step_s += 1
                    Player.set_x(player, Player.get_x(player) - 5)
                    try:
                        screen.blit(walk_left[player_anim_count], (Player.get_x(player) - 8, Player.get_y(player)))
                    except IndexError:
                        player_anim_count = 0
                        screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
                    end_frame = 'left'
                else:
                    if player_anim_count == 11:
                        player_anim_count = 0
                    else:
                        player_anim_count += 1
                    if step_s == 0:
                        step_sound.play()
                    if step_s == 26:
                        step_s = 0
                    else:
                        step_s += 1
                    Player.set_x(player, Player.get_x(player) - 5)
                    try:
                        screen.blit(walk_left[player_anim_count], (Player.get_x(player) - 8, Player.get_y(player)))
                    except IndexError:
                        player_anim_count = 0
                        screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
                    end_frame = 'left'
            else:
                screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
                if Player.get_energy(player) < 100:
                    Player.set_eat(player, Player.get_eat(player) - 0.1)
                    Player.set_energy(player, Player.get_energy(player) + 1)
        elif keys[pg.K_d] and keys[pg.K_LSHIFT] and Player.get_x(player) < 1920:
            if generation_dict.get(str(int((Player.get_x(player) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) == None:
                if Player.get_energy(player) >= 0.5:
                    Player.set_energy(player, Player.get_energy(player) - 0.5)
                    if player_anim_count == 10:
                        player_anim_count = 0
                    else:
                        player_anim_count += 2
                    if step_s == 0:
                        step_sound.play()
                    if step_s == 14:
                        step_s = 0
                    else:
                        step_s += 1
                    Player.set_x(player, Player.get_x(player) + 7)
                    try:
                        screen.blit(walk_right[player_anim_count], (Player.get_x(player) - 22, Player.get_y(player)))
                    except IndexError:
                        player_anim_count = 0
                        screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
                    end_frame = 'right'
                else:
                    if player_anim_count == 11:
                        player_anim_count = 0
                    else:
                        player_anim_count += 1
                    if step_s == 0:
                        step_sound.play()
                    if step_s == 26:
                        step_s = 0
                    else:
                        step_s += 1
                    Player.set_x(player, Player.get_x(player) + 5)
                    try:
                        screen.blit(walk_right[player_anim_count],
                                    (Player.get_x(player) - 22, Player.get_y(player)))
                    except IndexError:
                        player_anim_count = 0
                        screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
                    end_frame = 'right'
            elif generation_dict.get(str(int((Player.get_x(player) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) != None and generation_dict.get(str(int(((Player.get_x(player) + 6) // 32) * 32)) + ',' + str(int((Player.get_y(player) // 32) * 32))) == None:
                if Player.get_energy(player) >= 0.5:
                    Player.set_energy(player, Player.get_energy(player) - 0.5)
                    if player_anim_count == 10:
                        player_anim_count = 0
                    else:
                        player_anim_count += 2
                    if step_s == 0:
                        step_sound.play()
                    if step_s == 14:
                        step_s = 0
                    else:
                        step_s += 1
                    Player.set_x(player, Player.get_x(player) + 5)
                    try:
                        screen.blit(walk_right[player_anim_count], (Player.get_x(player) - 22, Player.get_y(player)))
                    except IndexError:
                        player_anim_count = 0
                        screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
                    end_frame = 'right'
                else:
                    if player_anim_count == 11:
                        player_anim_count = 0
                    else:
                        player_anim_count += 1
                    if step_s == 0:
                        step_sound.play()
                    if step_s == 26:
                        step_s = 0
                    else:
                        step_s += 1
                    Player.set_x(player, Player.get_x(player) + 5)
                    try:
                        screen.blit(walk_right[player_anim_count],
                                    (Player.get_x(player) - 22, Player.get_y(player)))
                    except IndexError:
                        player_anim_count = 0
                        screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
                    end_frame = 'right'
            else:
                screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
                if Player.get_energy(player) < 100:
                    Player.set_eat(player, Player.get_eat(player) - 0.1)
                    Player.set_energy(player, Player.get_energy(player) + 1)
        else:
            player_anim_count = 0
            if end_frame == 'left':
                screen.blit(walk_left[1], (Player.get_x(player) - 8, Player.get_y(player)))
            else:
                screen.blit(walk_right[1], (Player.get_x(player) - 22, Player.get_y(player)))
            if Player.get_energy(player) < 100:
                Player.set_eat(player, Player.get_eat(player) - 0.1)
                Player.set_energy(player, Player.get_energy(player) + 1)

        try:
            if inventory.get(Player.get_hand(player)) == '1,Меч_Вправо':
                slot_1 = True
                slot_2 = False
                slot_3 = False
                slot_4 = False
            elif inventory.get(Player.get_hand(player)) == '1,Кирка_Вправо':
                slot_1 = False
                slot_2 = True
                slot_3 = False
                slot_4 = False
            elif inventory.get(Player.get_hand(player)) == '1,Топор_Вправо':
                slot_1 = False
                slot_2 = False
                slot_3 = True
                slot_4 = False
            elif inventory.get(Player.get_hand(player)) == '1,Лопата_Вправо':
                slot_1 = False
                slot_2 = False
                slot_3 = False
                slot_4 = True
            else:
                slot_1 = False
                slot_2 = False
                slot_3 = False
                slot_4 = False
        except IndexError:
            pass

        if dis_things:
            try:
                screen.blit(pg.transform.scale(pg.image.load(f'images/blocks/whole/{inventory[Player.get_hand(player)].split(',')[1]}32.png').convert_alpha(),(20, 20)), (Player.get_x(player) - 8, Player.get_y(player) + 30))
            except KeyError:
                pass
            except FileNotFoundError:
                if end_frame == 'left':
                    new_th = ''
                    for th in inventory[Player.get_hand(player)].split(',')[1]:
                        if th != '_':
                            new_th += th
                        else:
                            break
                    screen.blit(pg.image.load(f'images/things/{new_th + '_Влево'}.png').convert_alpha(),(Player.get_x(player) - 28, Player.get_y(player) + 10))
                else:
                    screen.blit(pg.image.load(f'images/things/{inventory[Player.get_hand(player)].split(',')[1]}.png').convert_alpha(),(Player.get_x(player) - 4, Player.get_y(player) + 10))

    else:
        screen.blit(label_other.render(f'Вы умерли от {dead}', True, 'white'), (720, 400))
        screen.blit(restart_label, restart_label_rect)

        if restart_label_rect.collidepoint(pg.mouse.get_pos()) and pg.mouse.get_pressed()[0]:
            Player.set_HP(player, 100)
            Player.set_eat(player, 100)

    for event in pg.event.get():
        if event.type == pg.QUIT:
            run = False
            pg.quit()
        elif event.type == pg.KEYDOWN:
            if event.key == pg.K_y:
                if inv:
                    inv = False
                else:
                    inv = True
            if event.key == pg.K_1:
                Player.set_hand(player, '31,640,896')
            elif event.key == pg.K_2:
                Player.set_hand(player, '32,704,896')
            elif event.key == pg.K_3:
                Player.set_hand(player, '33,768,896')
            elif event.key == pg.K_4:
                Player.set_hand(player, '34,832,896')
            elif event.key == pg.K_5:
                Player.set_hand(player, '35,896,896')
            elif event.key == pg.K_6:
                Player.set_hand(player, '36,960,896')
            elif event.key == pg.K_7:
                Player.set_hand(player, '37,1024,896')
            elif event.key == pg.K_8:
                Player.set_hand(player, '38,1088,896')
            elif event.key == pg.K_9:
                Player.set_hand(player, '39,1152,896')
            elif event.key == pg.K_0:
                Player.set_hand(player, '40,1216,896')
            if event.key == pg.K_ESCAPE:
                workbench = False

    screen.blit(font.render(f'{int(clock.get_fps())} fps', 1, (255, 255, 255)), (1820, 30))

    clock.tick(fps)

    pg.display.flip()