From 81eb8e5376f921dd0167816a20fee95fe2286d8d Mon Sep 17 00:00:00 2001 From: bgArray <474037765@qq.com> Date: Wed, 19 Jan 2022 17:48:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=92=8Cbug=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Musicreater.py | 1 + languages/__pycache__/__init__.cpython-39.pyc | Bin 182 -> 174 bytes languages/__pycache__/zhCN.cpython-39.pyc | Bin 5844 -> 5896 bytes msctspt/__pycache__/__init__.cpython-39.pyc | Bin 180 -> 172 bytes .../__pycache__/bugReporter.cpython-39.pyc | Bin 4363 -> 4386 bytes .../__pycache__/threadOpera.cpython-39.pyc | Bin 1066 -> 1059 bytes nmcsup/__pycache__/__init__.cpython-39.pyc | Bin 179 -> 171 bytes nmcsup/__pycache__/const.cpython-39.pyc | Bin 6713 -> 6705 bytes nmcsup/__pycache__/log.cpython-39.pyc | Bin 820 -> 1492 bytes nmcsup/__pycache__/nmcreader.cpython-39.pyc | Bin 2701 -> 2719 bytes nmcsup/__pycache__/trans.cpython-39.pyc | Bin 7022 -> 7284 bytes nmcsup/__pycache__/vers.cpython-39.pyc | Bin 2172 -> 2166 bytes nmcsup/const.py | 402 +++++++++--------- nmcsup/log.py | 52 ++- nmcsup/nmcreader.py | 69 ++- nmcsup/trans.py | 267 ++++++------ nmcsup/vers.py | 61 ++- 17 files changed, 433 insertions(+), 419 deletions(-) diff --git a/Musicreater.py b/Musicreater.py index bc1a33b..4f2e0b4 100644 --- a/Musicreater.py +++ b/Musicreater.py @@ -658,6 +658,7 @@ def __main__(): except ValueError: # 测试完为ValueError,故修改语法 tkinter.messagebox.showerror(title=READABLETEXT[0], message=READABLETEXT[117]) continue + break Outdire = tkinter.filedialog.askdirectory(title=READABLETEXT[29], initialdir=r'./') if Outdire is None or Outdire == '': return diff --git a/languages/__pycache__/__init__.cpython-39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J$iN%u-Nbs>PXRBv$nVcxOa&mzr2lH~aBp_Rn`8}I30B%_t4*&oF diff --git a/nmcsup/__pycache__/log.cpython-39.pyc b/nmcsup/__pycache__/log.cpython-39.pyc index 386b007129a7876677a37acbd0d63526f9940542..606b88d7bab021f79fdcf314c21bcfe871e28943 100644 GIT binary patch literal 1492 zcmaJ>-)kI29G}@Ace{IcX?~brjg6;J>>+oJ;zKDSLgA>8L@|-#5?D4jlgnQBc8{68 z#)SAFX-b8rt@sdWq~1ML6vYVDQY$h4$AAxF?vnchd@wKZJ9{C`Q)ig(ulde*zTf$N zcHKH$Js6=ZjL?QaRGKy@28n#IiwnZ&!4kJ57aU)GLO>Fnjp2``DE4?JSfiVJmA59Ts z7{OjY9q7tya;Lu$`!%~>FA)jZxYk?@DPTmIjCw#~Ywp zQ5=bbRfT;Yr5fqgI3ls2 z$Eo`3kaFvnTYJ0B_UGFNyANCU@3eNlYJIWM-h9&8{PkdGr?vj5+i50iT`>z)Xrb(= z!0w9v@oX`F30iH?pcE2lQYQsoodF<+*c8~B&SiuWa-r4SXi+5Sryh^EFskl#N<0Sk zuto!so{88@z)TUseHJX*AkTFB!ZZL>_H$rz2o za2)xyI1U?wL$<+TM}BQWdw;t4ft@OPKE3J&#HY+oE_MZWR=S$SkX79X9>F#jPQ)|> zc)pQ=eo(i15}*_YJoKq;xr7`WSzny&d>Hz1?eT-3BI9z~c&8eYx=-JQKQ7`0Aev_2 dcq-#qQ#8d;EZhS#t;qMZ6a%C#AJWJ5{{ctvvSt7P delta 431 zcmYk2ze~eV5XaxU_mZZ+K*UO`B6ZAQ+UhDI2qNfEv>=2+h zDj=XX{f%IQ&wP4KXM9ekbfyU=_#6ZX?Ez}U)a$&1OrP0V)nrn`38^D8+Iu6ihS_&Jt?<_5rfIdT=5`p3>Vt7T847pgcEf=e zC&Mo8v4-P}VN~ylO9%obTA)>WL^+k~s7;XSI~_BhXb!$2*!jZY!L}p zoPJoT(+lM4sZGsS_oBYyYs~2)eMC6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(Y$5?NaJll(GosfXaR_0o)a3ECSOy3nRC zzXP(P;YR`K){FsZT-{xGC$m}@M{p-N7Lx4$TYNt#KbaAGD|BUrj`=VYL&PtDTU%ahtn#Nt)-D;(;?Q$q+&(?h!%v}b8sRrc);;&4>p5zTdHjCyo_)F{Pp{kR zM-tAg>F1l=V=b5zyZ}J76r5QmRp<;Iq6W38rj%)sX6ZpX4?WPQSnTJ#04%-dQoe@0a;B^Suc5f_)O8f4Db}1PZWaf7X(3@s z7v<>P;6Rh|c>ABl_vnPo8z^UlUj$gsxR>18TIiOKxi4LsU03hBJS%@3ptU~B=fur{ zbH+Tf9~0TqpIQ+%??I4%6w;u*(pE7Y4U3UX0)7QqDuT2asg4FA54!B$ccFz7gXw3y z>SdSz8@NFMfIzHGh`xn!gqHCJJwy3b@%kWNkzPgzS5*Ehc=3}6F?ML3qBsw~VO=i# zZ^bi4Gn;LbU>40FhoG>;d`vtLVguxw4kfr p@4L&K@tX`*IHCX}7y-~UE14TNZPOYoc777kX@!)1!XC~QzXy;oV&(t< diff --git a/nmcsup/__pycache__/vers.cpython-39.pyc b/nmcsup/__pycache__/vers.cpython-39.pyc index 31b6a2573d2dc8b3e59e104019dc9d643fbc8f32..bab8a127caddee89e426a15875a36706b51dec54 100644 GIT binary patch delta 268 zcmew(@J)a(k(ZZ?0SI(1Jx^@rp2%lllfsz7oWmT&oXV8N6vYB0S)#3Rem@P?Rf$d193_qu<88&lnj!Cof?#RL#jxOwrXX zGte{AGl$ylU3`3Sofqw3`M>>4^n0zk1_ z%weuUQJguMNkxf8nW@E5EFcq$_&_>^L4*>BP@U|=q07t2!OX_Y#>%0@!O15M05iuz Ag#Z8m delta 289 zcmew+@JE0zk(ZZ?0SJn{A0__bn#gBhlggCE6vYfAS)y1|m{V9<7^2ux7*kkt*rV7} z*izVme2!G+RMs@66pj?m7RD&f6s{C*peR=g>%=POjr*Q4G6qgw%4DcpW}s)NXP}#x zU!ss(sZd&wl30=$lb4%ZTv`xQmReM-S5SG2Jvl$O0LT%V{F_Og(QmR6^FQ8OEIyu2 z!MB);O7n`iCp&ToPj+NcU=-P$#1hTKC^C5;TM47`WMlS3Hc_C%i^L|+VwdKS0Wvii zi&TKhMJ8Wl7h_bL{DNIW`xbMUYfuztPG(Y3Vo_#lagh*63m=FO01+Y}LK#G;O}63C T list: +# 从格式文本文件读入一个音轨并存入一个列表 +def ReadFile(fn: str): # -> list from nmcsup.trans import note2list - log('打开'+fn+"并读取音符") + log('打开' + fn + "并读取音符") try: nat = open(fn, 'r', encoding='UTF-8').read().split(" ") del fn - except: + except FileNotFoundError: log("找不到读取目标文件") return False Notes = [] - log(str(nat)+"已读取") - for i in range(int(len(nat)/2)): - Notes.append([nat[i*2], float(nat[i*2+1])]) + log(str(nat) + "已读取") + for i in range(int(len(nat) / 2)): + Notes.append([nat[i * 2], float(nat[i * 2 + 1])]) Notes = note2list(Notes) - log('音符数据更新'+str(Notes)) - return [Notes,] + log('音符数据更新' + str(Notes)) + return [Notes, ] -#从midi读入多个音轨,返回多个音轨列表 -def ReadMidi(midfile : str ) -> list: +# 从midi读入多个音轨,返回多个音轨列表 +def ReadMidi(midfile: str): # -> list import mido from msctspt.threadOpera import NewThread Notes = [] try: mid = mido.MidiFile(midfile) - except: - log("找不到文件或无法读取文件"+midfile) + except FileNotFoundError: + log("找不到文件或无法读取文件" + midfile) return False # 解析 ks = list(notes.values()) - def loadMidi(track): + + def loadMidi(track1): datas = [] - for i in track: + for i in track1: if i.is_meta: - log('元信息'+str(i)) + log('元信息' + str(i)) pass # 不处理元信息 elif 'note_on' in str(i): msg = str(i).replace("note=", '').replace("time=", '').split(" ") - log('音符on消息,处理后:'+str(msg)) + log('音符on消息,处理后:' + str(msg)) if msg[4] == '0': - datas.append([ks[int(msg[2])-20][0], 1.0]) - log('延续时间0tick--:添加音符'+str([ks[int(msg[2])-20][0], 1.0])) + datas.append([ks[int(msg[2]) - 20][0], 1.0]) + log('延续时间0tick--:添加音符' + str([ks[int(msg[2]) - 20][0], 1.0])) else: - datas.append([ks[int(msg[2])-20][0], float(msg[4])/480]) - log('延续时间'+msg[4]+'tick--:添加音符' +str([ks[int(msg[2])-20][0], float(msg[4])/480])) + datas.append([ks[int(msg[2]) - 20][0], float(msg[4]) / 480]) + log('延续时间' + msg[4] + 'tick--:添加音符' + str([ks[int(msg[2]) - 20][0], float(msg[4]) / 480])) del msg - log('音符增加'+str(datas)) + log('音符增加' + str(datas)) return datas + for j, track in enumerate(mid.tracks): - th = NewThread(loadMidi,(track,)) + th = NewThread(loadMidi, (track,)) th.start() Notes.append(th.getResult()) del ks return Notes - - -def ReadOldProject(fn:str) -> list: +def ReadOldProject(fn: str): # -> list import json from nmcsup.trans import note2list - log("读取文件:"+fn) + log("读取文件:" + fn) try: with open(fn, 'r', encoding='UTF-8') as c: dataset = json.load(c) - except: - print('找不到文件:'+fn+",请查看您是否输入正确") - log("丢失"+fn) + except FileNotFoundError: + print('找不到文件:' + fn + ",请查看您是否输入正确") + log("丢失" + fn) return False for i in range(len(dataset['musics'])): dataset['musics'][i]['notes'] = note2list(dataset['musics'][i]['notes']) - #返回 音轨列表 选择器 + # 返回 音轨列表 选择器 return dataset - - diff --git a/nmcsup/trans.py b/nmcsup/trans.py index fc712b3..6274c17 100644 --- a/nmcsup/trans.py +++ b/nmcsup/trans.py @@ -1,37 +1,41 @@ - """音创系列的转换功能""" - +# 诸葛亮与八卦阵帮忙修改语法 日期:---2022年1月19日 +# 统计:致命(三级)错误:0个;警告(二级)错误:2个;语法(一级)错误:192个 from nmcsup.log import log - - - +import amulet +import amulet_nbt +from amulet.api.block import Block +from amulet.api.block_entity import BlockEntity +from amulet.utils.world_utils import block_coords_to_chunk_coords +from amulet_nbt import TAG_String, TAG_Compound, TAG_Byte # 输入一个列表 [ [str, float ], [], ... ] 音符str 值为持续时间float -def note2list(Notes : list) -> list: +def note2list(Notes: list) -> list: from nmcsup.const import notes + def change(base): enwo = { - 'a': 'A', - 'b': 'B', - 'c': 'C', - 'd': "D", - "e": "E", - 'f': 'F', - 'g': "G" + 'a': 'A', + 'b': 'B', + 'c': 'C', + 'd': "D", + "e": "E", + 'f': 'F', + 'g': "G" } nuwo = { - '6': 'A', - '7': 'B', - '1': 'C', - '2': "D", - "3": "E", - '4': 'F', - '5': "G" + '6': 'A', + '7': 'B', + '1': 'C', + '2': "D", + "3": "E", + '4': 'F', + '5': "G" } for k, v in enwo.items(): if k in base: @@ -40,193 +44,184 @@ def note2list(Notes : list) -> list: if k in base: base = base.replace(k, v) return base + res = [] log(" === 音符列表=>音调列表") for i in Notes: s2 = change(i[0]) - log(' === 正在操作音符'+i[0]+'->'+s2) + log(' === 正在操作音符' + i[0] + '->' + s2) if s2 in notes.keys(): - log(" === 找到此音符,加入:"+str(notes[s2][0])) + log(" === 找到此音符,加入:" + str(notes[s2][0])) res.append([notes[s2][0], float(i[1])]) else: - log(' === '+s2+'不在音符表内,此处自动替换为 休止符0 ') + log(' === ' + s2 + '不在音符表内,此处自动替换为 休止符0 ') res.append(['0', float(i[1])]) - log(' === 最终反回'+str(res)) + log(' === 最终反回' + str(res)) return res - - def mcnote2freq(Notes): from nmcsup.const import notes mcnback = {} - for i,j in notes.items(): + for i, j in notes.items(): mcnback[j[0]] = i res = [] log(" === 我的世界音调表=>频率列表") for i in Notes: - log(' === 正在操作音符'+i[0]+'->'+mcnback[i[0]]) + log(' === 正在操作音符' + i[0] + '->' + mcnback[i[0]]) res.append([notes[mcnback[i[0]]][1], float(i[1])]) - log(' === 最终反回'+str(res)) + log(' === 最终反回' + str(res)) return res - - - -#MP3文件转midi文件 +# MP3文件转midi文件 def Mp32Mid(mp3File, midFile): from piano_transcription_inference import PianoTranscription, sample_rate, load_audio # 加载 - (audio, _) = load_audio(mp3File, sr=sample_rate, mono=True) + (audio, _) = load_audio(mp3File, sr=sample_rate) # , mono=True # 实例化并转换 PianoTranscription(device="cpu").transcribe(audio, midFile) - - - -#传入一个音符列表转为指令列表 -def Note2Cmd(Notes : list,ScoreboardName:str,Instrument:str, PlayerSelect:str='',isProsess:bool=False) -> list: +# 传入一个音符列表转为指令列表 +def Note2Cmd(Notes: list, ScoreboardName: str, Instrument: str, PlayerSelect: str = '', + isProsess: bool = False) -> list: commands = [] a = 0.0 if isProsess: length = len(Notes) j = 1 - for i in range(len(Notes)): - commands.append("execute @a"+PlayerSelect+" ~ ~ ~ execute @s[scores={"+ScoreboardName+"="+str(int((a+2)*5+int(Notes[i][1]*5)))+"}] ~ ~ ~ playsound "+Instrument+" @s ~ ~ ~ 1000 "+str(Notes[i][0])+" 1000\n") - a += Notes[i][1] - if isProsess: - commands.append("execute @a"+PlayerSelect+" ~ ~ ~ execute @s[scores={"+ScoreboardName+"="+str(int((a+2)*5+int(Notes[i][1]*5)))+"}] ~ ~ ~ title @s actionbar §e▶ 播放中: §a"+str(j)+"/"+str(length)+" || "+str(int(j/length*1000)/10)+"\n") - j+=1 - commands.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI(金羿)\n") + for i in range(len(Notes)): + commands.append("execute @a" + PlayerSelect + " ~ ~ ~ execute @s[scores={" + ScoreboardName + "=" + str( + int((a + 2) * 5 + int(Notes[i][1] * 5))) + "}] ~ ~ ~ playsound " + Instrument + " @s ~ ~ ~ 1000 " + str( + Notes[i][0]) + " 1000\n") + a += Notes[i][1] + if isProsess: + commands.append("execute @a" + PlayerSelect + " ~ ~ ~ execute @s[scores={" + ScoreboardName + "=" + str( + int((a + 2) * 5 + int(Notes[i][1] * 5))) + "}] ~ ~ ~ title @s actionbar §e▶ 播放中: §a" + str( + j) + "/" + str(length) + " || " + str(int(j / length * 1000) / 10) + "\n") + j += 1 + commands.append("\n\n# 凌云我的世界开发团队 x 凌云软件开发团队 : W-YI(金羿)\n") return commands +# 简单载入方块 +# level.set_version_block(posx,posy,posz,"minecraft:overworld",("bedrock", (1, 16, 20)),Block(namespace, name)) - - - - -import amulet -import amulet_nbt -from amulet.api.block import Block -from amulet.api.block_entity import BlockEntity -from amulet.utils.world_utils import block_coords_to_chunk_coords -from amulet_nbt import TAG_String,TAG_Compound,TAG_Byte - - - -#简单载入方块 -#level.set_version_block(posx,posy,posz,"minecraft:overworld",("bedrock", (1, 16, 20)),Block(namespace, name)) - - - -#转入指令列表与位置信息转至世界 -def Cmd2World(cmd:list,world:str,dire:list): - '''将指令以命令链的形式载入世界\n +# 转入指令列表与位置信息转至世界 +def Cmd2World(cmd: list, world: str, dire: list): + """将指令以命令链的形式载入世界\n cmd指令列表位为一个序列,中包含指令字符串\n - world为地图所在位置,需要指向文件夹,dire为指令方块生成之位置''' + world为地图所在位置,需要指向文件夹,dire为指令方块生成之位置""" level = amulet.load_level(world) cdl = [] for i in cmd: + e = True try: - if (i[:i.index('#')].replace(' ','') != '\n') and(i[:i.index('#')].replace(' ','') != ''): + if (i[:i.index('#')].replace(' ', '') != '\n') and (i[:i.index('#')].replace(' ', '') != ''): cdl.append(i[:i.index('#')]) - except: + e = False + except ValueError: cdl.append(i) + finally: + if e is True: + cdl.append(i) i = 0 - #第一个是特殊 - universal_block = Block('universal_minecraft','command_block',{'conditional':TAG_String("false"),'facing':TAG_String('up'),'mode':TAG_String("repeating")}) + # 第一个是特殊 + universal_block = Block('universal_minecraft', 'command_block', + {'conditional': TAG_String("false"), 'facing': TAG_String('up'), + 'mode': TAG_String("repeating")}) cx, cz = block_coords_to_chunk_coords(dire[0], dire[2]) chunk = level.get_chunk(cx, cz, "minecraft:overworld") offset_x, offset_z = dire[0] - 16 * cx, dire[2] - 16 * cz - universal_block_entity = BlockEntity( 'universal_minecraft','command_block',dire[0],dire[1],dire[2],amulet_nbt.NBTFile(TAG_Compound({'utags': TAG_Compound({'auto': TAG_Byte(0),'Command': TAG_String(cdl.pop(0))}) }))) + universal_block_entity = BlockEntity('universal_minecraft', 'command_block', dire[0], dire[1], dire[2], + amulet_nbt.NBTFile(TAG_Compound({'utags': TAG_Compound( + {'auto': TAG_Byte(0), 'Command': TAG_String(cdl.pop(0))})}))) chunk.blocks[offset_x, dire[1], offset_z] = level.block_palette.get_add_block(universal_block) chunk.block_entities[(dire[0], dire[1], dire[2])] = universal_block_entity chunk.changed = True - #集体上移 - dire[1]+=1 - #真正开始 + # 集体上移 + dire[1] += 1 + # 真正开始 down = False for j in cdl: - if dire[1]+i >= 255: - dire[0]+=1 - i=0 + if dire[1] + i >= 255: + dire[0] += 1 + i = 0 down = not down - #定义此方块 - if dire[1]+i == 254 : - universal_block = Block('universal_minecraft','command_block',{'conditional':TAG_String("false"),'facing':TAG_String('east'),'mode':TAG_String("chain")}) + # 定义此方块 + if dire[1] + i == 254: + universal_block = Block('universal_minecraft', 'command_block', + {'conditional': TAG_String("false"), 'facing': TAG_String('east'), + 'mode': TAG_String("chain")}) else: if down: - universal_block = Block('universal_minecraft','command_block',{'conditional':TAG_String("false"),'facing':TAG_String('down'),'mode':TAG_String("chain")}) + universal_block = Block('universal_minecraft', 'command_block', + {'conditional': TAG_String("false"), 'facing': TAG_String('down'), + 'mode': TAG_String("chain")}) else: - universal_block = Block('universal_minecraft','command_block',{'conditional':TAG_String("false"),'facing':TAG_String('up'),'mode':TAG_String("chain")}) + universal_block = Block('universal_minecraft', 'command_block', + {'conditional': TAG_String("false"), 'facing': TAG_String('up'), + 'mode': TAG_String("chain")}) cx, cz = block_coords_to_chunk_coords(dire[0], dire[2]) - #获取区块 + # 获取区块 chunk = level.get_chunk(cx, cz, "minecraft:overworld") offset_x, offset_z = dire[0] - 16 * cx, dire[2] - 16 * cz if down: - #定义方块实体 - universal_block_entity = BlockEntity( 'universal_minecraft','command_block',dire[0],254-i,dire[2],amulet_nbt.NBTFile(TAG_Compound({'utags': TAG_Compound({'auto': TAG_Byte(1),'Command': TAG_String(j)}) }))) - - #将方块加入世界 - chunk.blocks[offset_x, 254-i, offset_z] = level.block_palette.get_add_block(universal_block) - chunk.block_entities[(dire[0], 254-i, dire[2])] = universal_block_entity + # 定义方块实体 + universal_block_entity = BlockEntity('universal_minecraft', 'command_block', dire[0], 254 - i, dire[2], + amulet_nbt.NBTFile(TAG_Compound({'utags': TAG_Compound( + {'auto': TAG_Byte(1), 'Command': TAG_String(j)})}))) + + # 将方块加入世界 + chunk.blocks[offset_x, 254 - i, offset_z] = level.block_palette.get_add_block(universal_block) + chunk.block_entities[(dire[0], 254 - i, dire[2])] = universal_block_entity else: - #定义方块实体 - universal_block_entity = BlockEntity( 'universal_minecraft','command_block',dire[0],dire[1]+i,dire[2],amulet_nbt.NBTFile(TAG_Compound({'utags': TAG_Compound({'auto': TAG_Byte(1),'Command': TAG_String(j)}) }))) - - #将方块加入世界 - chunk.blocks[offset_x, dire[1]+i, offset_z] = level.block_palette.get_add_block(universal_block) - chunk.block_entities[(dire[0], dire[1]+i, dire[2])] = universal_block_entity - #设置为已更新区块 + # 定义方块实体 + universal_block_entity = BlockEntity('universal_minecraft', 'command_block', dire[0], dire[1] + i, dire[2], + amulet_nbt.NBTFile(TAG_Compound({'utags': TAG_Compound( + {'auto': TAG_Byte(1), 'Command': TAG_String(j)})}))) + + # 将方块加入世界 + chunk.blocks[offset_x, dire[1] + i, offset_z] = level.block_palette.get_add_block(universal_block) + chunk.block_entities[(dire[0], dire[1] + i, dire[2])] = universal_block_entity + # 设置为已更新区块 chunk.changed = True - i+=1 + i += 1 del i, cdl - #保存世界并退出 + # 保存世界并退出 level.save() level.close() - - - - - -#音符转成方块再加载到世界里头 -def Blocks2World(world:str,dire:list,Datas:list): +# 音符转成方块再加载到世界里头 +def Blocks2World(world: str, dire: list, Datas: list): from nmcsup.const import Blocks level = amulet.load_level(world) i = 0 - def setblock(block:str,pos:list): - '''pos : list[int,int,int]''' + + def setblock(block: str, pos: list): + """pos : list[int,int,int]""" cx, cz = block_coords_to_chunk_coords(pos[0], pos[2]) chunk = level.get_chunk(cx, cz, "minecraft:overworld") offset_x, offset_z = pos[0] - 16 * cx, pos[2] - 16 * cz - chunk.blocks[offset_x, pos[1], offset_z] = level.block_palette.get_add_block(Block("minecraft",block)) + chunk.blocks[offset_x, pos[1], offset_z] = level.block_palette.get_add_block(Block("minecraft", block)) chunk.changed = True + for j in Datas: - if dire[1]+1 >= 255: + if dire[1] + 1 >= 255: i = 0 - dire[0]+=1 - setblock(Blocks[j[0]],[dire[0],dire[1]+i,dire[2]]) - i = int(i+j[1]+0.5) #四舍五入 + dire[0] += 1 + setblock(Blocks[j[0]], [dire[0], dire[1] + i, dire[2]]) + i = int(i + j[1] + 0.5) # 四舍五入 level.save() level.close() - - - - - - - -#传入音符列表制作播放器指令 -def Notes2Player(Note,dire:list,CmdData:dict): - '''传入音符列表、坐标、指令数据,生成播放器指令''' +# 传入音符列表制作播放器指令 +def Notes2Player(Note, dire: list, CmdData: dict): + """传入音符列表、坐标、指令数据,生成播放器指令""" Notes = {} for i in Note: Notes[i[0]] = '' @@ -234,21 +229,17 @@ def Notes2Player(Note,dire:list,CmdData:dict): from nmcsup.const import Blocks Cmds = [] for j in Notes: - Cmds.append('execute @e[x='+str(dire[0])+',y='+str(dire[1])+',z='+str(dire[2])+',dy='+str(255-dire[1])+',name='+CmdData['Ent']+'] ~ ~ ~ detect ~ ~ ~ '+Blocks[j]+' 0 execute @a '+CmdData['Pls']+' ~ ~ ~ playsound '+CmdData['Ins']+' @s ~ ~ ~ 1000 '+str(j)+' 1000\n') - Cmds+=['#本函数由 金羿 音·创 生成\n','execute @e[y='+str(dire[1])+',dy='+str(255-dire[1])+',name='+CmdData['Ent']+'] ~ ~ ~ tp ~ ~1 ~\n','execute @e[y=255,dy=100,name='+CmdData['Ent']+'] ~ ~ ~ tp ~1 '+str(dire[1])+' ~\n','#音·创 开发交流群 861684859'] + Cmds.append('execute @e[x=' + str(dire[0]) + ',y=' + str(dire[1]) + ',z=' + str(dire[2]) + ',dy=' + str( + 255 - dire[1]) + ',name=' + CmdData['Ent'] + '] ~ ~ ~ detect ~ ~ ~ ' + Blocks[j] + ' 0 execute @a ' + + CmdData['Pls'] + ' ~ ~ ~ playsound ' + CmdData['Ins'] + ' @s ~ ~ ~ 1000 ' + str(j) + ' 1000\n') + Cmds += ['#本函数由 金羿 音·创 生成\n', 'execute @e[y=' + str(dire[1]) + ',dy=' + str(255 - dire[1]) + ',name=' + CmdData[ + 'Ent'] + '] ~ ~ ~ tp ~ ~1 ~\n', + 'execute @e[y=255,dy=100,name=' + CmdData['Ent'] + '] ~ ~ ~ tp ~1 ' + str(dire[1]) + ' ~\n', + '#音·创 开发交流群 861684859'] return Cmds - - - - - - - -#传入音符列表生成方块至世界 -def Datas2BlkWorld(NoteData,world:str,dire:list): +# 传入音符列表生成方块至世界 +def Datas2BlkWorld(NoteData, world: str, dire: list): for i in range(len(NoteData)): - Blocks2World(world,[dire[0],dire[1],dire[2]+i],NoteData[i]) - - + Blocks2World(world, [dire[0], dire[1], dire[2] + i], NoteData[i]) diff --git a/nmcsup/vers.py b/nmcsup/vers.py index 2a524cc..b056231 100644 --- a/nmcsup/vers.py +++ b/nmcsup/vers.py @@ -1,20 +1,19 @@ """音创系列版本号和版本操作函数""" - +# 统计:致命(三级)错误:0个;警告(二级)错误:0个;语法(一级)错误:24个 from msctspt.bugReporter import version +import os - -#以下下两个值请在 msctspt/bugReporter 的version类中修改 +# 以下下两个值请在 msctspt/bugReporter 的version类中修改 VER = version.version -'''当前版本''' +"""当前版本""" LIBS = version.libraries -'''当前所需库''' +"""当前所需库""" - -#判断版本、临时文件与补全库 +# 判断版本、临时文件与补全库 def compver(ver1, ver2): """ 传入不带英文的版本号,特殊情况:"10.12.2.6.5">"10.12.2.6" @@ -39,6 +38,8 @@ def compver(ver1, ver2): return -1 else: return 1 + + # # ———————————————— # 版权声明:上面的函数compver为CSDN博主「基友死得早」的原创文章中的函数,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 @@ -46,44 +47,40 @@ def compver(ver1, ver2): # ———————————————— # -import os -def InstallLibs(now,LIBS): - '''比对库信息并安装库''' +def InstallLibs(now, LIBS1): + """比对库信息并安装库""" from os import system as run - for i in LIBS: - if not i in now: - print("安装库:"+i) - run("python -m pip install "+i+" -i https://pypi.tuna.tsinghua.edu.cn/simple") + for i in LIBS1: + if i not in now: + print("安装库:" + i) + run("python -m pip install " + i + " -i https://pypi.tuna.tsinghua.edu.cn/simple") -def chkver(ver = VER,libs = LIBS): - '''通过文件比对版本信息并安装库''' - if not os.path.exists(os.getenv('APPDATA')+'\\Musicreater\\msct.ActiveDatas.msct'): +def chkver(ver=VER, libs=LIBS): + """通过文件比对版本信息并安装库""" + if not os.path.exists(os.getenv('APPDATA') + '\\Musicreater\\msct.ActiveDatas.msct'): print("新安装库") - os.makedirs(os.getenv('APPDATA')+'\\Musicreater\\') - with open(os.getenv('APPDATA')+'\\Musicreater\\msct.ActiveDatas.msct', 'w') as f: - f.write(ver[0]+'\n') + os.makedirs(os.getenv('APPDATA') + '\\Musicreater\\') + with open(os.getenv('APPDATA') + '\\Musicreater\\msct.ActiveDatas.msct', 'w') as f: + f.write(ver[0] + '\n') for i in libs: - f.write(i+'\n') - InstallLibs([],libs) + f.write(i + '\n') + InstallLibs([], libs) else: - with open(os.getenv('APPDATA')+'\\Musicreater\\msct.ActiveDatas.msct', 'r') as f: + with open(os.getenv('APPDATA') + '\\Musicreater\\msct.ActiveDatas.msct', 'r') as f: v = f.readlines() cp = compver(ver[0], v[0]) if cp != 0: - InstallLibs(v[1:],libs) - with open(os.getenv('APPDATA')+'\\Musicreater\\msct.ActiveDatas.msct', 'w') as f: - f.write(ver[0]+'\n') + InstallLibs(v[1:], libs) + with open(os.getenv('APPDATA') + '\\Musicreater\\msct.ActiveDatas.msct', 'w') as f: + f.write(ver[0] + '\n') for i in libs: - f.write(i+'\n') + f.write(i + '\n') del cp def resetver(): - '''重置版本信息''' + """重置版本信息""" import shutil - shutil.rmtree(os.getenv('APPDATA')+'\\Musicreater\\') - - - + shutil.rmtree(os.getenv('APPDATA') + '\\Musicreater\\')