From bd329082c24d377a5c59d56b75b53f2baec4934b Mon Sep 17 00:00:00 2001 From: EillesWan Date: Sun, 5 Mar 2023 18:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99=E4=B8=8D=E6=98=AF=E6=9C=80=E7=BB=88?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E8=AF=B7=E4=B8=8D=E8=A6=81=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Musicreater/__init__.py | 8 ++-- Musicreater/exceptions.py | 14 +++--- Musicreater/main.py | 32 +++++++++----- Musicreater/utils.py | 91 ++++++++++++++++++++++++++++++++++++++- README.md | 4 +- requirements.txt | 3 +- 6 files changed, 126 insertions(+), 26 deletions(-) diff --git a/Musicreater/__init__.py b/Musicreater/__init__.py index 6473b31..b13efda 100644 --- a/Musicreater/__init__.py +++ b/Musicreater/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """一个简单的我的世界音频转换库 -音·创 库版 (Musicreater) +音·创 (Musicreater) 是一款免费开源的针对《我的世界》的midi音乐转换库 Musicreater(音·创) A free open source library used for convert midi file into formats that is suitable for **Minecraft**. @@ -12,14 +12,14 @@ Copyright © 2023 all the developers of Musicreater Terms & Conditions: ../License.md """ -# 音·创 开发交流群 861684859 -# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com +# 睿穆组织 开发交流群 861684859 +# Email TriM-Organization@hotmail.com # 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon") # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md from .main import * -__version__ = "0.3.2" +__version__ = "0.3.3" __all__ = [] __author__ = (("金羿", "Eilles Wan"), ("诸葛亮与八卦阵", "bgArray")) diff --git a/Musicreater/exceptions.py b/Musicreater/exceptions.py index bc68d22..9db92b9 100644 --- a/Musicreater/exceptions.py +++ b/Musicreater/exceptions.py @@ -1,17 +1,17 @@ # -*- coding: utf-8 -*- -# 音·创 开发交流群 861684859 -# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com +# 睿穆组织 开发交流群 861684859 +# Email TriM-Organization@hotmail.com # 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon") # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md -""" -音·创 库版 (Musicreater Package Version) -是一款免费开源的针对《我的世界:基岩版》的midi音乐转换库 -Musicreater pkgver (Package Version 音·创 库版) -A free open source library used for convert midi file into formats that is suitable for **Minecraft: Bedrock Edition**. +"""一个简单的我的世界音频转换库 +音·创 (Musicreater) +是一款免费开源的针对《我的世界》的midi音乐转换库 +Musicreater(音·创) +A free open source library used for convert midi file into formats that is suitable for **Minecraft**. 版权所有 © 2023 音·创 开发者 Copyright © 2023 all the developers of Musicreater diff --git a/Musicreater/main.py b/Musicreater/main.py index 6fc6d40..d1d3bd7 100644 --- a/Musicreater/main.py +++ b/Musicreater/main.py @@ -2,7 +2,7 @@ # 音·创 开发交流群 861684859 -# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com +# Email TriM-Organization@hotmail.com # 版权所有 金羿("Eilles Wan") & 诸葛亮与八卦阵("bgArray") & 鸣凤鸽子("MingFengPigeon") # 若需转载或借鉴 许可声明请查看仓库目录下的 License.md @@ -1471,7 +1471,17 @@ class midiConvert: :param player: 玩家选择器,默认为`@a` :return 成功与否,成功返回(True,未经过压缩的源,结构占用大小),失败返回(False,str失败原因) """ - pass + cmdlist, max_delay = self.methods_byDelay[method - 1]( + volume, + speed, + player, + ) + + if not os.path.exists(self.outputPath): + os.makedirs(self.outputPath) + + + def to_BDX_file( self, @@ -1552,9 +1562,9 @@ class midiConvert: max_height - 1, ) _bytes += pgbBytes - _bytes += move(y, -pgbNowPos[1]) - _bytes += move(z, -pgbNowPos[2]) - _bytes += move(x, 2) + _bytes += bdx_move(y, -pgbNowPos[1]) + _bytes += bdx_move(z, -pgbNowPos[2]) + _bytes += bdx_move(x, 2) size[0] += 2 + pgbSize[0] size[1] = max(size[1], pgbSize[1]) @@ -1632,14 +1642,14 @@ class midiConvert: 1, customName="初始化进度条", ) - _bytes += move(z, 2) + _bytes += bdx_move(z, 2) _bytes += form_command_block_in_BDX_bytes( r"scoreboard players add {} {} 1".format(player, scb_name), 1, 1, customName="显示进度条并加分", ) - _bytes += move(y, 1) + _bytes += bdx_move(y, 1) pgbBytes, pgbSize, pgbNowPos = to_BDX_bytes( [ (i, 0) @@ -1648,15 +1658,15 @@ class midiConvert: max_height - 1, ) _bytes += pgbBytes - _bytes += move(y, -1 - pgbNowPos[1]) - _bytes += move(z, -2 - pgbNowPos[2]) - _bytes += move(x, 2) + _bytes += bdx_move(y, -1 - pgbNowPos[1]) + _bytes += bdx_move(z, -2 - pgbNowPos[2]) + _bytes += bdx_move(x, 2) _bytes += form_command_block_in_BDX_bytes( r"scoreboard players reset {} {}".format(player, scb_name), 1, customName="置零进度条", ) - _bytes += move(y, 1) + _bytes += bdx_move(y, 1) size[0] += 2 + pgbSize[0] size[1] = max(size[1], pgbSize[1]) size[2] = max(size[2], pgbSize[2]) diff --git a/Musicreater/utils.py b/Musicreater/utils.py index 229d99b..434eeea 100644 --- a/Musicreater/utils.py +++ b/Musicreater/utils.py @@ -14,7 +14,7 @@ y = "y" z = "z" -def move(axis: str, value: int): +def bdx_move(axis: str, value: int): if value == 0: return b"" if abs(value) == 1: @@ -220,3 +220,92 @@ def to_BDX_bytes( ], [now_x, now_y, now_z], ) + +def to_structure( + commands: list, + max_height: int = 64, +): + """ + :param commands: 指令列表(指令, 延迟) + :param max_height: 生成结构最大高度 + :return 成功与否,成功返回(True,未经过压缩的源,结构占用大小),失败返回(False,str失败原因) + """ + # 导入库 + from mcstructure import Block, Structure + + _sideLength = bottem_side_length_of_smallest_square_bottom_box(len(commands), max_height) + + struct = Structure( + (_sideLength, max_height, _sideLength), # 声明结构大小 + ) + + y_forward = True + z_forward = True + + now_y = 0 + now_z = 0 + now_x = 0 + + for cmd, delay in commands: + impluse = 2 + condition = False + needRedstone = False + tickDelay = delay + customName = "" + executeOnFirstTick = False + trackOutput = True + _bytes += form_command_block_in_BDX_bytes( + cmd, + (1 if y_forward else 0) + if ( + ((now_y != 0) and (not y_forward)) + or (y_forward and (now_y != (max_height - 1))) + ) + else (3 if z_forward else 2) + if ( + ((now_z != 0) and (not z_forward)) + or (z_forward and (now_z != _sideLength)) + ) + else 5, + impluse=impluse, + condition=condition, + needRedstone=needRedstone, + tickDelay=tickDelay, + customName=customName, + executeOnFirstTick=executeOnFirstTick, + trackOutput=trackOutput, + ) + + now_y += 1 if y_forward else -1 + + if ((now_y >= max_height) and y_forward) or ((now_y < 0) and (not y_forward)): + now_y -= 1 if y_forward else -1 + + y_forward = not y_forward + + now_z += 1 if z_forward else -1 + + if ((now_z > _sideLength) and z_forward) or ( + (now_z < 0) and (not z_forward) + ): + now_z -= 1 if z_forward else -1 + z_forward = not z_forward + _bytes += key[x][1] + now_x += 1 + else: + + _bytes += key[z][int(z_forward)] + + else: + + _bytes += key[y][int(y_forward)] + + return ( + _bytes, + [ + now_x + 1, + max_height if now_x or now_z else now_y, + _sideLength if now_x else now_z, + ], + [now_x, now_y, now_z], + ) \ No newline at end of file diff --git a/README.md b/README.md index 345157b..e9c34ba 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@

-[![][Bilibili: 凌云金羿]](https://space.bilibili.com/397369002/) +[![][Bilibili: 金羿ELS]](https://space.bilibili.com/397369002/) [![][Bilibili: 诸葛亮与八卦阵]](https://space.bilibili.com/604072474) [![CodeStyle: black]](https://github.com/psf/black) [![][python]](https://www.python.org/) @@ -103,7 +103,7 @@ NOT APPROVED BY OR ASSOCIATED WITH MOJANG OR MICROSOFT. -[Bilibili: 凌云金羿]: https://img.shields.io/badge/Bilibili-%E5%87%8C%E4%BA%91%E9%87%91%E7%BE%BF-00A1E7?style=for-the-badge +[Bilibili: 金羿ELS]: https://img.shields.io/badge/Bilibili-%E5%87%8C%E4%BA%91%E9%87%91%E7%BE%BF-00A1E7?style=for-the-badge [Bilibili: 诸葛亮与八卦阵]: https://img.shields.io/badge/Bilibili-%E8%AF%B8%E8%91%9B%E4%BA%AE%E4%B8%8E%E5%85%AB%E5%8D%A6%E9%98%B5-00A1E7?style=for-the-badge [CodeStyle: black]: https://img.shields.io/badge/code%20style-black-121110.svg?style=for-the-badge [python]: https://img.shields.io/badge/python-3.6-AB70FF?style=for-the-badge diff --git a/requirements.txt b/requirements.txt index 70abd76..68153c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Brotli>=1.0.9 -mido>=1.2.10 \ No newline at end of file +mido>=1.2.10 +mcstructure \ No newline at end of file