mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2024-11-11 01:27:35 +08:00
革命尚未成功?也许是库的问题,但是没时间检查了,先走了(((
This commit is contained in:
parent
acb347b491
commit
48f5a975db
@ -155,6 +155,7 @@ class midiConvert:
|
|||||||
[
|
[
|
||||||
self._toCmdList_withDelay_m1,
|
self._toCmdList_withDelay_m1,
|
||||||
self._toCmdList_withDelay_m2,
|
self._toCmdList_withDelay_m2,
|
||||||
|
self._toCmdList_withDelay_m3,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1457,7 +1458,6 @@ class midiConvert:
|
|||||||
speed: float = 1.0,
|
speed: float = 1.0,
|
||||||
progressbar: Union[bool, tuple] = False,
|
progressbar: Union[bool, tuple] = False,
|
||||||
player: str = "@a",
|
player: str = "@a",
|
||||||
author: str = "Eilles",
|
|
||||||
max_height: int = 64,
|
max_height: int = 64,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@ -1480,8 +1480,13 @@ class midiConvert:
|
|||||||
if not os.path.exists(self.outputPath):
|
if not os.path.exists(self.outputPath):
|
||||||
os.makedirs(self.outputPath)
|
os.makedirs(self.outputPath)
|
||||||
|
|
||||||
|
struct, size = to_structure(cmdlist,max_height-1)
|
||||||
|
|
||||||
|
with open(
|
||||||
|
os.path.abspath(os.path.join(self.outputPath, f"{self.midFileName}.mcstructure")),
|
||||||
|
"wb+",
|
||||||
|
) as f:
|
||||||
|
struct.dump(f)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,13 +106,14 @@ def form_command_block_in_BDX_bytes(
|
|||||||
lastOutput: `str`
|
lastOutput: `str`
|
||||||
上次输出字符串,注意此处需要留空
|
上次输出字符串,注意此处需要留空
|
||||||
:param executeOnFirstTick: `bool`
|
:param executeOnFirstTick: `bool`
|
||||||
执行第一个已选项(循环指令方块是否激活后立即执行,若为False,则从激活时起延迟后第一次执行)
|
首刻执行(循环指令方块是否激活后立即执行,若为False,则从激活时起延迟后第一次执行)
|
||||||
:param trackOutput: `bool`
|
:param trackOutput: `bool`
|
||||||
是否输出
|
是否输出
|
||||||
|
|
||||||
:return:str
|
:return:str
|
||||||
"""
|
"""
|
||||||
block = b"\x24" + particularValue.to_bytes(2, byteorder="big", signed=False)
|
block = b"\x24" + \
|
||||||
|
particularValue.to_bytes(2, byteorder="big", signed=False)
|
||||||
|
|
||||||
for i in [
|
for i in [
|
||||||
impluse.to_bytes(4, byteorder="big", signed=False),
|
impluse.to_bytes(4, byteorder="big", signed=False),
|
||||||
@ -147,7 +148,9 @@ def to_BDX_bytes(
|
|||||||
:return 成功与否,成功返回(True,未经过压缩的源,结构占用大小),失败返回(False,str失败原因)
|
:return 成功与否,成功返回(True,未经过压缩的源,结构占用大小),失败返回(False,str失败原因)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_sideLength = bottem_side_length_of_smallest_square_bottom_box(len(commands), max_height)
|
_sideLength = bottem_side_length_of_smallest_square_bottom_box(
|
||||||
|
len(commands), max_height
|
||||||
|
)
|
||||||
_bytes = b""
|
_bytes = b""
|
||||||
|
|
||||||
y_forward = True
|
y_forward = True
|
||||||
@ -196,7 +199,7 @@ def to_BDX_bytes(
|
|||||||
|
|
||||||
now_z += 1 if z_forward else -1
|
now_z += 1 if z_forward else -1
|
||||||
|
|
||||||
if ((now_z > _sideLength) and z_forward) or (
|
if ((now_z >= _sideLength) and z_forward) or (
|
||||||
(now_z < 0) and (not z_forward)
|
(now_z < 0) and (not z_forward)
|
||||||
):
|
):
|
||||||
now_z -= 1 if z_forward else -1
|
now_z -= 1 if z_forward else -1
|
||||||
@ -224,10 +227,11 @@ def to_BDX_bytes(
|
|||||||
|
|
||||||
def form_command_block_in_NBT_struct(
|
def form_command_block_in_NBT_struct(
|
||||||
command: str,
|
command: str,
|
||||||
|
coordinate: tuple,
|
||||||
particularValue: int,
|
particularValue: int,
|
||||||
impluse: int = 0,
|
impluse: int = 0,
|
||||||
condition: bool = False,
|
condition: bool = False,
|
||||||
needRedstone: bool = True,
|
alwaysRun: bool = True,
|
||||||
tickDelay: int = 0,
|
tickDelay: int = 0,
|
||||||
customName: str = "",
|
customName: str = "",
|
||||||
executeOnFirstTick: bool = False,
|
executeOnFirstTick: bool = False,
|
||||||
@ -237,6 +241,8 @@ def form_command_block_in_NBT_struct(
|
|||||||
使用指定项目返回指定的指令方块结构
|
使用指定项目返回指定的指令方块结构
|
||||||
:param command: `str`
|
:param command: `str`
|
||||||
指令
|
指令
|
||||||
|
:param coordinate: `tuple[int,int,int]`
|
||||||
|
此方块所在之相对坐标
|
||||||
:param particularValue:
|
:param particularValue:
|
||||||
方块特殊值,即朝向
|
方块特殊值,即朝向
|
||||||
:0 下 无条件
|
:0 下 无条件
|
||||||
@ -262,28 +268,54 @@ def form_command_block_in_NBT_struct(
|
|||||||
0脉冲 1循环 2连锁
|
0脉冲 1循环 2连锁
|
||||||
:param condition: `bool`
|
:param condition: `bool`
|
||||||
是否有条件
|
是否有条件
|
||||||
:param needRedstone: `bool`
|
:param alwaysRun: `bool`
|
||||||
是否需要红石
|
是否始终执行
|
||||||
:param tickDelay: `int`
|
:param tickDelay: `int`
|
||||||
执行延时
|
执行延时
|
||||||
:param customName: `str`
|
:param customName: `str`
|
||||||
悬浮字
|
悬浮字
|
||||||
lastOutput: `str`
|
|
||||||
上次输出字符串,注意此处需要留空
|
|
||||||
:param executeOnFirstTick: `bool`
|
:param executeOnFirstTick: `bool`
|
||||||
执行第一个已选项(循环指令方块是否激活后立即执行,若为False,则从激活时起延迟后第一次执行)
|
首刻执行(循环指令方块是否激活后立即执行,若为False,则从激活时起延迟后第一次执行)
|
||||||
:param trackOutput: `bool`
|
:param trackOutput: `bool`
|
||||||
是否输出
|
是否输出
|
||||||
|
|
||||||
:return:str
|
:return:str
|
||||||
"""
|
"""
|
||||||
from TrimMCStruct import Block
|
from TrimMCStruct import Block, TAG_Long
|
||||||
block = Block("minecraft","command_block")
|
block = Block(
|
||||||
|
"minecraft",
|
||||||
|
"command_block" if impluse == 0 else (
|
||||||
|
"repeating_command_block" if impluse == 1 else "chain_command_block"),
|
||||||
|
states={"conditional_bit": condition,
|
||||||
|
"facing_direction": particularValue},
|
||||||
|
extra_data={
|
||||||
|
'Command': command,
|
||||||
|
'CustomName': customName,
|
||||||
|
'ExecuteOnFirstTick': executeOnFirstTick,
|
||||||
|
'LPCommandMode': 0,
|
||||||
|
'LPCondionalMode': False,
|
||||||
|
'LPRedstoneMode': False,
|
||||||
|
'LastExecution': TAG_Long(0),
|
||||||
|
'LastOutput': '',
|
||||||
|
'LastOutputParams': [],
|
||||||
|
'SuccessCount': 0,
|
||||||
|
'TickDelay': tickDelay,
|
||||||
|
'TrackOutput': trackOutput,
|
||||||
|
'Version': 25,
|
||||||
|
'auto': alwaysRun,
|
||||||
|
'conditionMet': False, # 是否已经满足条件
|
||||||
|
'conditionalMode': condition,
|
||||||
|
'id': 'CommandBlock',
|
||||||
|
'isMovable': True,
|
||||||
|
'powered': False, # 是否已激活
|
||||||
|
'x': coordinate[0],
|
||||||
|
'y': coordinate[1],
|
||||||
|
'z': coordinate[2],
|
||||||
|
}
|
||||||
|
)
|
||||||
return block
|
return block
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def to_structure(
|
def to_structure(
|
||||||
commands: list,
|
commands: list,
|
||||||
max_height: int = 64,
|
max_height: int = 64,
|
||||||
@ -291,12 +323,14 @@ def to_structure(
|
|||||||
"""
|
"""
|
||||||
:param commands: 指令列表(指令, 延迟)
|
:param commands: 指令列表(指令, 延迟)
|
||||||
:param max_height: 生成结构最大高度
|
:param max_height: 生成结构最大高度
|
||||||
:return 成功与否,成功返回(True,未经过压缩的源,结构占用大小),失败返回(False,str失败原因)
|
:return 成功与否,成功返回(结构类,结构占用大小),失败返回(False,str失败原因)
|
||||||
"""
|
"""
|
||||||
# 导入库
|
# 导入库
|
||||||
from TrimMCStruct import Block, Structure
|
from TrimMCStruct import Structure
|
||||||
|
|
||||||
_sideLength = bottem_side_length_of_smallest_square_bottom_box(len(commands), max_height)
|
_sideLength = bottem_side_length_of_smallest_square_bottom_box(
|
||||||
|
len(commands), max_height
|
||||||
|
)
|
||||||
|
|
||||||
struct = Structure(
|
struct = Structure(
|
||||||
(_sideLength, max_height, _sideLength), # 声明结构大小
|
(_sideLength, max_height, _sideLength), # 声明结构大小
|
||||||
@ -310,34 +344,30 @@ def to_structure(
|
|||||||
now_x = 0
|
now_x = 0
|
||||||
|
|
||||||
for cmd, delay in commands:
|
for cmd, delay in commands:
|
||||||
impluse = 2
|
coordinate = (now_x, now_y, now_z)
|
||||||
condition = False
|
struct.set_block(coordinate,
|
||||||
needRedstone = False
|
form_command_block_in_NBT_struct(
|
||||||
tickDelay = delay
|
command=cmd,
|
||||||
customName = ""
|
coordinate=coordinate,
|
||||||
executeOnFirstTick = False
|
particularValue=(1 if y_forward else 0)
|
||||||
trackOutput = True
|
if (
|
||||||
_bytes += form_command_block_in_BDX_bytes(
|
((now_y != 0) and (not y_forward))
|
||||||
cmd,
|
or (y_forward and (now_y != (max_height - 1)))
|
||||||
(1 if y_forward else 0)
|
)
|
||||||
if (
|
else (3 if z_forward else 2)
|
||||||
((now_y != 0) and (not y_forward))
|
if (
|
||||||
or (y_forward and (now_y != (max_height - 1)))
|
((now_z != 0) and (not z_forward))
|
||||||
)
|
or (z_forward and (now_z != _sideLength))
|
||||||
else (3 if z_forward else 2)
|
)
|
||||||
if (
|
else 5,
|
||||||
((now_z != 0) and (not z_forward))
|
impluse=2,
|
||||||
or (z_forward and (now_z != _sideLength))
|
condition=False,
|
||||||
)
|
alwaysRun=True,
|
||||||
else 5,
|
tickDelay=delay,
|
||||||
impluse=impluse,
|
customName="",
|
||||||
condition=condition,
|
executeOnFirstTick=False,
|
||||||
needRedstone=needRedstone,
|
trackOutput=True,
|
||||||
tickDelay=tickDelay,
|
))
|
||||||
customName=customName,
|
|
||||||
executeOnFirstTick=executeOnFirstTick,
|
|
||||||
trackOutput=trackOutput,
|
|
||||||
)
|
|
||||||
|
|
||||||
now_y += 1 if y_forward else -1
|
now_y += 1 if y_forward else -1
|
||||||
|
|
||||||
@ -348,27 +378,18 @@ def to_structure(
|
|||||||
|
|
||||||
now_z += 1 if z_forward else -1
|
now_z += 1 if z_forward else -1
|
||||||
|
|
||||||
if ((now_z > _sideLength) and z_forward) or (
|
if ((now_z >= _sideLength) and z_forward) or (
|
||||||
(now_z < 0) and (not z_forward)
|
(now_z < 0) and (not z_forward)
|
||||||
):
|
):
|
||||||
now_z -= 1 if z_forward else -1
|
now_z -= 1 if z_forward else -1
|
||||||
z_forward = not z_forward
|
z_forward = not z_forward
|
||||||
_bytes += key[x][1]
|
|
||||||
now_x += 1
|
now_x += 1
|
||||||
else:
|
|
||||||
|
|
||||||
_bytes += key[z][int(z_forward)]
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
_bytes += key[y][int(y_forward)]
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
_bytes,
|
struct,
|
||||||
[
|
[
|
||||||
now_x + 1,
|
now_x + 1,
|
||||||
max_height if now_x or now_z else now_y,
|
max_height if now_x or now_z else now_y,
|
||||||
_sideLength if now_x else now_z,
|
_sideLength if now_x else now_z,
|
||||||
],
|
],
|
||||||
[now_x, now_y, now_z],
|
)
|
||||||
)
|
|
||||||
|
6
example_mcstructure.py
Normal file
6
example_mcstructure.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
from Musicreater import midiConvert
|
||||||
|
|
||||||
|
conversion = midiConvert()
|
||||||
|
conversion.convert(input("midi path:"),input("out path:"))
|
||||||
|
conversion.to_mcstructure_file_with_delay(3,)
|
@ -1,3 +1,3 @@
|
|||||||
Brotli>=1.0.9
|
Brotli>=1.0.9
|
||||||
mido>=1.2.10
|
mido>=1.2.10
|
||||||
TrimMCStruct>=0.0.2
|
TrimMCStruct>=0.0.5
|
Loading…
Reference in New Issue
Block a user