mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2024-11-11 01:27:35 +08:00
0.2.0前的预备更新
This commit is contained in:
parent
ebfaeafcda
commit
392e74d8d9
@ -71,14 +71,16 @@ def operation(
|
|||||||
):
|
):
|
||||||
print(f'正在操作{i}')
|
print(f'正在操作{i}')
|
||||||
convertion.convert(midipath + '/' + i, outpath)
|
convertion.convert(midipath + '/' + i, outpath)
|
||||||
convertion.toBDXfile_withDelay(
|
print(
|
||||||
1,
|
convertion.toBDXfile_withDelay(
|
||||||
authorname if authorname != '' else input('请输入作者:'),
|
1,
|
||||||
isProgress,
|
authorname if authorname != '' else input('请输入作者:'),
|
||||||
heightmax if heightmax != '' else int(input('请输入指令结构最大生成高度:')),
|
isProgress,
|
||||||
volume if volume != '' else float(input('请输入音量(0-1]:')),
|
heightmax if heightmax != '' else int(input('请输入指令结构最大生成高度:')),
|
||||||
speed if speed != '' else float(input('请输入速度倍率:')),
|
volume if volume != '' else float(input('请输入音量(0-1]:')),
|
||||||
player if player != '' else input('请输入玩家选择器:'),
|
speed if speed != '' else float(input('请输入速度倍率:')),
|
||||||
|
player if player != '' else input('请输入玩家选择器:'),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -90,12 +92,14 @@ if os.path.isdir(midipath):
|
|||||||
threading.Thread(target=operation, args=(i,)).start()
|
threading.Thread(target=operation, args=(i,)).start()
|
||||||
else:
|
else:
|
||||||
convertion.convert(midipath, outpath)
|
convertion.convert(midipath, outpath)
|
||||||
convertion.toBDXfile_withDelay(
|
print(
|
||||||
1,
|
convertion.toBDXfile_withDelay(
|
||||||
authorname if authorname != '' else input('请输入作者:'),
|
1,
|
||||||
isProgress,
|
authorname if authorname != '' else input('请输入作者:'),
|
||||||
heightmax if heightmax != '' else int(input('请输入指令结构最大生成高度:')),
|
isProgress,
|
||||||
volume if volume != '' else float(input('请输入音量(0-1]:')),
|
heightmax if heightmax != '' else int(input('请输入指令结构最大生成高度:')),
|
||||||
speed if speed != '' else float(input('请输入速度倍率:')),
|
volume if volume != '' else float(input('请输入音量(0-1]:')),
|
||||||
player if player != '' else input('请输入玩家选择器:'),
|
speed if speed != '' else float(input('请输入速度倍率:')),
|
||||||
|
player if player != '' else input('请输入玩家选择器:'),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
@ -143,9 +143,10 @@
|
|||||||
|
|
||||||
## 第三部分 关于其他问题
|
## 第三部分 关于其他问题
|
||||||
|
|
||||||
如果你在仔细阅读以上内容之后,仍然感觉有所困惑,可以加我们的[QQ群](https://jq.qq.com/?_wv=1027&k=hpeRxrYr)来提问,但是请注意,**由于开发者们都很忙,群友们的耐心也都有限,所以恳请大家提出有意义的问题。**如果您在使用过程中遇到报错,希望你能够把完整的报错内容复制给我们,而不是截一半的屏幕或者在群内大呼小叫。以下两张图给了你很好的解释说明。
|
如果你在仔细阅读以上内容之后,仍然感觉有所困惑,可以加我们的[QQ群](https://jq.qq.com/?_wv=1027&k=hpeRxrYr)来提问,但是请注意,**由于开发者们都很忙,群友们的耐心也都有限,所以恳请大家提出有意义的问题。**
|
||||||
|
如果您在使用过程中遇到报错,希望你能够把完整的报错内容复制给我们,而不是截一半的屏幕或者在群内大呼小叫。以下两张图给了你很好的解释说明。
|
||||||
|
|
||||||
*图片暂无。*
|
<table><tr><td><img src=https://foruda.gitee.com/images/1673053210913625261/37197693_9911226.png></td><td><img src=https://foruda.gitee.com/images/1673052430511255221/6a279fae_9911226.png></td></tr></table>
|
||||||
|
|
||||||
这里附一个关于[智慧地提问](https://github.com/tvvocold/How-To-Ask-Questions-The-Smart-Way)的文章,大家可以看看。
|
这里附一个关于[智慧地提问](https://github.com/tvvocold/How-To-Ask-Questions-The-Smart-Way)的文章,大家可以看看。
|
||||||
|
|
||||||
|
171
magicDemo.py
171
magicDemo.py
@ -35,12 +35,14 @@ languages = {
|
|||||||
"WhetherArgEntering": "是否为文件夹内文件的转换统一参数[是(1) 或 否(0)]",
|
"WhetherArgEntering": "是否为文件夹内文件的转换统一参数[是(1) 或 否(0)]",
|
||||||
"EnterArgs": "请输入转换参数",
|
"EnterArgs": "请输入转换参数",
|
||||||
"noteofArgs": "注:文件夹内的全部midi将统一以此参数转换",
|
"noteofArgs": "注:文件夹内的全部midi将统一以此参数转换",
|
||||||
"ChooseSbReset": "是否自动重置计分板[是(1) 或 否(0)]",
|
"EnterVolume": "请输入音量大小(0~1)",
|
||||||
|
"EnterSpeed": "请输入速度倍率",
|
||||||
|
"WhetherPgb": "是否自动生成进度条[是(1) 或 否(0)]",
|
||||||
"WhetherCstmProgressBar": "是否自定义进度条[是(1) 或 否(0)]",
|
"WhetherCstmProgressBar": "是否自定义进度条[是(1) 或 否(0)]",
|
||||||
"EnterProgressBarStyle": "请输入进度条样式",
|
"EnterProgressBarStyle": "请输入进度条样式",
|
||||||
"EnterSbName": "请输入计分板名称",
|
"EnterSbName": "请输入计分板名称",
|
||||||
"EnterVolume": "请输入音量大小(0~1)",
|
"EnterSelecter": "请输入播放者选择器",
|
||||||
"EnterSpeed": "请输入速度倍率",
|
"WhetherSbReset": "是否自动重置计分板[是(1) 或 否(0)]",
|
||||||
"EnterAuthor": "请输入作者",
|
"EnterAuthor": "请输入作者",
|
||||||
"EnterMaxHeight": "请输入指令结构最大生成高度",
|
"EnterMaxHeight": "请输入指令结构最大生成高度",
|
||||||
"ErrEnter": "输入错误",
|
"ErrEnter": "输入错误",
|
||||||
@ -48,8 +50,13 @@ languages = {
|
|||||||
"Dealing": "正在处理",
|
"Dealing": "正在处理",
|
||||||
"FileNotFound": "文件(夹)不存在",
|
"FileNotFound": "文件(夹)不存在",
|
||||||
"ChooseOutPath": "请输入结果输出路径",
|
"ChooseOutPath": "请输入结果输出路径",
|
||||||
"EnterSelecter": "请输入播放者选择器",
|
|
||||||
"Saying": "言·论",
|
"Saying": "言·论",
|
||||||
|
"Failed": "失败",
|
||||||
|
"CmdLength": "指令数量",
|
||||||
|
"MaxDelay": "曲目时间(游戏刻)",
|
||||||
|
"PlaceSize": "结构占用大小",
|
||||||
|
"LastPos": "最末方块坐标",
|
||||||
|
"PressEnterExit": "请按下回车键退出。",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,20 +128,50 @@ MainConsole.rule(
|
|||||||
title="[bold #AB70FF]Welcome to Independent Musicreater Convernter", characters="-"
|
title="[bold #AB70FF]Welcome to Independent Musicreater Convernter", characters="-"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
nowYang = datetime.datetime.now()
|
||||||
|
nowYin = zhdate.ZhDate.from_datetime(nowYang)
|
||||||
|
|
||||||
# 显示箴言部分
|
if nowYang.month == 8 and nowYang.day == 6:
|
||||||
MainConsole.print(
|
# 诸葛八卦生日
|
||||||
"[#121110 on #F0F2F4]"
|
MainConsole.print(
|
||||||
+ random.choice(
|
"[#7DB5F0 on #121110]今天可不是催更的日子!\n诸葛亮与八卦阵{}岁生日快乐!".format(nowYang.year - 2009),
|
||||||
requests.get(
|
style="#7DB5F0 on #121110",
|
||||||
"https://gitee.com/EillesWan/Musicreater/raw/master/resources/myWords.txt"
|
justify="center",
|
||||||
)
|
)
|
||||||
.text.strip("\r\n")
|
elif nowYang.month == 4 and nowYang.day == 3:
|
||||||
.split("\r\n")
|
# 金羿生日快乐
|
||||||
),
|
MainConsole.print(
|
||||||
style="#121110 on #F0F2F4",
|
"[#0089F2 on #F0F2F4]今天就不要催更啦!\n金羿{}岁生日快乐!".format(nowYang.year - 2006),
|
||||||
justify="center",
|
style="#0089F2 on #F0F2F4",
|
||||||
)
|
justify="center",
|
||||||
|
)
|
||||||
|
elif nowYin.lunar_month == 12 and nowYin.lunar_day == 30:
|
||||||
|
MainConsole.print(
|
||||||
|
"[#FF3432 on #121110]除夕到了,你是否与家人共处,融融其乐?",
|
||||||
|
style="#FF3432 on #121110",
|
||||||
|
justify="center",
|
||||||
|
)
|
||||||
|
elif nowYin.leap_month == 1 and nowYin.lunar_day in range(1, 9):
|
||||||
|
MainConsole.print(
|
||||||
|
"[#FFF642 on #FF3432]春节快乐!\n在你使用音·创的时候,是不是也要去感受一下喜庆的氛围呢?",
|
||||||
|
style="#FFF642 on #FF3432",
|
||||||
|
justify="center",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# 显示箴言部分
|
||||||
|
MainConsole.print(
|
||||||
|
"[#121110 on #F0F2F4]{}".format(
|
||||||
|
random.choice(
|
||||||
|
requests.get(
|
||||||
|
'https://gitee.com/EillesWan/Musicreater/raw/master/resources/myWords.txt'
|
||||||
|
)
|
||||||
|
.text.strip('\r\n')
|
||||||
|
.split('\r\n')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
style="#121110 on #F0F2F4",
|
||||||
|
justify="center",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
from typing import Any, Literal, Optional, TextIO
|
from typing import Any, Literal, Optional, TextIO
|
||||||
@ -262,7 +299,12 @@ def ipt(
|
|||||||
return MainConsole.input("", password=password, stream=stream)
|
return MainConsole.input("", password=password, stream=stream)
|
||||||
|
|
||||||
|
|
||||||
def formatipt(notice: str, fun, errnote: str = "", *extraArg):
|
def formatipt(
|
||||||
|
notice: str,
|
||||||
|
fun,
|
||||||
|
errnote: str = f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}",
|
||||||
|
*extraArg,
|
||||||
|
):
|
||||||
'''循环输入,以某种格式
|
'''循环输入,以某种格式
|
||||||
notice: 输入时的提示
|
notice: 输入时的提示
|
||||||
fun: 格式函数
|
fun: 格式函数
|
||||||
@ -306,7 +348,7 @@ outpath = formatipt(
|
|||||||
f"{_('ChooseOutPath')}{_(':')}",
|
f"{_('ChooseOutPath')}{_(':')}",
|
||||||
os.path.exists,
|
os.path.exists,
|
||||||
f"{_('FileNotFound')}{_(',')}{_('Re-Enter')}{_('.')}",
|
f"{_('FileNotFound')}{_(',')}{_('Re-Enter')}{_('.')}",
|
||||||
).lower()
|
)[0].lower()
|
||||||
|
|
||||||
|
|
||||||
# 选择输出格式
|
# 选择输出格式
|
||||||
@ -314,17 +356,16 @@ while True:
|
|||||||
fileFormat = ipt(f"{_('ChooseFileFormat')}{_(':')}").lower()
|
fileFormat = ipt(f"{_('ChooseFileFormat')}{_(':')}").lower()
|
||||||
if fileFormat in ('0', 'mcpack'):
|
if fileFormat in ('0', 'mcpack'):
|
||||||
fileFormat = 0
|
fileFormat = 0
|
||||||
prt(_("EnterArgs"))
|
playerFormat = 1
|
||||||
if len(midis) > 1:
|
break
|
||||||
prt(_("noteofArgs"))
|
|
||||||
|
|
||||||
elif fileFormat in ('1', 'bdx'):
|
elif fileFormat in ('1', 'bdx'):
|
||||||
fileFormat = 1
|
fileFormat = 1
|
||||||
while True:
|
while True:
|
||||||
playerFormat = ipt(f"{_('ChoosePlayer')}{_(':')}").lower()
|
playerFormat = ipt(f"{_('ChoosePlayer')}{_(':')}").lower()
|
||||||
if playerFormat in ('0', '延迟'):
|
if playerFormat in ('0', '延迟', 'delay'):
|
||||||
playerFormat = 0
|
playerFormat = 0
|
||||||
elif playerFormat in ('1', '计分板'):
|
elif playerFormat in ('1', '计分板', 'scoreboard'):
|
||||||
playerFormat = 1
|
playerFormat = 1
|
||||||
else:
|
else:
|
||||||
prt(f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}")
|
prt(f"{_('ErrEnter')}{_(',')}{_('Re-Enter')}{_('.')}")
|
||||||
@ -336,8 +377,84 @@ while True:
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
if fileFormat == 0:
|
# 真假字符串判断
|
||||||
pass
|
def boolstr(sth: str) -> bool:
|
||||||
|
try:
|
||||||
|
return bool(int(sth))
|
||||||
|
except:
|
||||||
|
if str(sth).lower() == 'true':
|
||||||
|
return True
|
||||||
|
elif str(sth).lower() == 'false':
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
raise "布尔字符串啊?"
|
||||||
|
|
||||||
|
|
||||||
MainConsole.input()
|
prompts = []
|
||||||
|
# 提示语 检测函数 错误提示语
|
||||||
|
for args in [
|
||||||
|
(
|
||||||
|
f'{_("EnterVolume")}{_(":")}',
|
||||||
|
float,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
f'{_("EnterSpeed")}{_(":")}',
|
||||||
|
float,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
f'{_("WhetherPgb")}{_(":")}',
|
||||||
|
boolstr,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
f'{_("EnterSbName")}{_(":")}',
|
||||||
|
str,
|
||||||
|
)
|
||||||
|
if playerFormat == 1
|
||||||
|
else (
|
||||||
|
f'{_("EnterSelecter")}{_(":")}',
|
||||||
|
str,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
f'{_("WhetherSbReset")}{_(":")}',
|
||||||
|
boolstr,
|
||||||
|
)
|
||||||
|
if playerFormat == 1
|
||||||
|
else (),
|
||||||
|
(
|
||||||
|
f'{_("EnterAuthor")}{_(":")}',
|
||||||
|
str,
|
||||||
|
)
|
||||||
|
if fileFormat == 1
|
||||||
|
else (),
|
||||||
|
(
|
||||||
|
f'{_("EnterMaxHeight")}{_(":")}',
|
||||||
|
int,
|
||||||
|
)
|
||||||
|
if fileFormat == 1
|
||||||
|
else (),
|
||||||
|
]:
|
||||||
|
if args:
|
||||||
|
prompts.append(formatipt(*args)[1])
|
||||||
|
|
||||||
|
|
||||||
|
newLine = '\n'
|
||||||
|
conversion = midiConvert()
|
||||||
|
for singleMidi in midis:
|
||||||
|
conversion.convert(singleMidi, outpath)
|
||||||
|
conversion_result = (
|
||||||
|
conversion.tomcpack(2, *prompts)
|
||||||
|
if fileFormat == 0
|
||||||
|
else (
|
||||||
|
conversion.toBDXfile(2, *prompts)
|
||||||
|
if playerFormat == 1
|
||||||
|
else conversion.toBDXfile_withDelay(1, *prompts)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if conversion_result[0]:
|
||||||
|
prt(
|
||||||
|
f"{newLine}{_('Dealing')} {singleMidi} {_(':')}{newLine} {_('CmdLength')}{_(':')}{conversion_result[1]}{_(',')}{_('MaxDelay')}{_(':')}{conversion_result[2]}{f'''{_(',')}{_('PlaceSize')}{_(':')}{conversion_result[3]}{_(',')}{_('LastPos')}{_(':')}{conversion_result[4]}''' if fileFormat == 1 else ''}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
prt(f"{_('Failed')}")
|
||||||
|
|
||||||
|
ipt(_("PressEnterExit"))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""一个简单的基于音·创的我的世界音频操作工具"""
|
"""一个简单的我的世界音频转换库"""
|
||||||
|
|
||||||
# 音·创 开发交流群 861684859
|
# 音·创 开发交流群 861684859
|
||||||
# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com
|
# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com
|
||||||
|
File diff suppressed because it is too large
Load Diff
209
msctPkgver/utils.py
Normal file
209
msctPkgver/utils.py
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
|
key = {
|
||||||
|
"x": [b"\x0f", b"\x0e", b"\x1c", b"\x14", b"\x15"],
|
||||||
|
"y": [b"\x11", b"\x10", b"\x1d", b"\x16", b"\x17"],
|
||||||
|
"z": [b"\x13", b"\x12", b"\x1e", b"\x18", b"\x19"],
|
||||||
|
}
|
||||||
|
"""key存储了方块移动指令的数据,其中可以用key[x|y|z][0|1]来表示xyz的减或增
|
||||||
|
而key[][2+]是用来增加指定数目的"""
|
||||||
|
|
||||||
|
x = "x"
|
||||||
|
y = "y"
|
||||||
|
z = "z"
|
||||||
|
|
||||||
|
|
||||||
|
def move(axis: str, value: int):
|
||||||
|
if value == 0:
|
||||||
|
return b''
|
||||||
|
if abs(value) == 1:
|
||||||
|
return key[axis][0 if value == -1 else 1]
|
||||||
|
|
||||||
|
pointer = sum(
|
||||||
|
[
|
||||||
|
1 if i else 0
|
||||||
|
for i in (
|
||||||
|
value != -1,
|
||||||
|
value < -1 or value > 1,
|
||||||
|
value < -128 or value > 127,
|
||||||
|
value < -32768 or value > 32767,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
return key[axis][pointer] + value.to_bytes(2 ** (pointer - 2), 'big', signed=True)
|
||||||
|
|
||||||
|
|
||||||
|
def makeZip(sourceDir, outFilename, compression=8, exceptFile=None):
|
||||||
|
"""使用compression指定的算法打包目录为zip文件\n
|
||||||
|
默认算法为DEFLATED(8),可用算法如下:\n
|
||||||
|
STORED = 0\n
|
||||||
|
DEFLATED = 8\n
|
||||||
|
BZIP2 = 12\n
|
||||||
|
LZMA = 14\n
|
||||||
|
"""
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
zipf = zipfile.ZipFile(outFilename, "w", compression)
|
||||||
|
pre_len = len(os.path.dirname(sourceDir))
|
||||||
|
for parent, dirnames, filenames in os.walk(sourceDir):
|
||||||
|
for filename in filenames:
|
||||||
|
if filename == exceptFile:
|
||||||
|
continue
|
||||||
|
pathfile = os.path.join(parent, filename)
|
||||||
|
arcname = pathfile[pre_len:].strip(os.path.sep) # 相对路径
|
||||||
|
zipf.write(pathfile, arcname)
|
||||||
|
zipf.close()
|
||||||
|
|
||||||
|
|
||||||
|
def formCMDblk(
|
||||||
|
command: str,
|
||||||
|
particularValue: int,
|
||||||
|
impluse: int = 0,
|
||||||
|
condition: bool = False,
|
||||||
|
needRedstone: bool = True,
|
||||||
|
tickDelay: int = 0,
|
||||||
|
customName: str = "",
|
||||||
|
executeOnFirstTick: bool = False,
|
||||||
|
trackOutput: bool = True,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
使用指定项目返回指定的指令方块放置指令项
|
||||||
|
:param command: `str`
|
||||||
|
指令
|
||||||
|
:param particularValue:
|
||||||
|
方块特殊值,即朝向
|
||||||
|
:0 下 无条件
|
||||||
|
:1 上 无条件
|
||||||
|
:2 z轴负方向 无条件
|
||||||
|
:3 z轴正方向 无条件
|
||||||
|
:4 x轴负方向 无条件
|
||||||
|
:5 x轴正方向 无条件
|
||||||
|
:6 下 无条件
|
||||||
|
:7 下 无条件
|
||||||
|
|
||||||
|
:8 下 有条件
|
||||||
|
:9 上 有条件
|
||||||
|
:10 z轴负方向 有条件
|
||||||
|
:11 z轴正方向 有条件
|
||||||
|
:12 x轴负方向 有条件
|
||||||
|
:13 x轴正方向 有条件
|
||||||
|
:14 下 有条件
|
||||||
|
:14 下 有条件
|
||||||
|
注意!此处特殊值中的条件会被下面condition参数覆写
|
||||||
|
:param impluse: `int 0|1|2`
|
||||||
|
方块类型
|
||||||
|
0脉冲 1循环 2连锁
|
||||||
|
:param condition: `bool`
|
||||||
|
是否有条件
|
||||||
|
:param needRedstone: `bool`
|
||||||
|
是否需要红石
|
||||||
|
:param tickDelay: `int`
|
||||||
|
执行延时
|
||||||
|
:param customName: `str`
|
||||||
|
悬浮字
|
||||||
|
lastOutput: `str`
|
||||||
|
上次输出字符串,注意此处需要留空
|
||||||
|
:param executeOnFirstTick: `bool`
|
||||||
|
执行第一个已选项(循环指令方块是否激活后立即执行,若为False,则从激活时起延迟后第一次执行)
|
||||||
|
:param trackOutput: `bool`
|
||||||
|
是否输出
|
||||||
|
|
||||||
|
:return:str
|
||||||
|
"""
|
||||||
|
block = b"\x24" + particularValue.to_bytes(2, byteorder="big", signed=False)
|
||||||
|
|
||||||
|
for i in [
|
||||||
|
impluse.to_bytes(4, byteorder="big", signed=False),
|
||||||
|
bytes(command, encoding="utf-8") + b"\x00",
|
||||||
|
bytes(customName, encoding="utf-8") + b"\x00",
|
||||||
|
bytes("", encoding="utf-8") + b"\x00",
|
||||||
|
tickDelay.to_bytes(4, byteorder="big", signed=True),
|
||||||
|
executeOnFirstTick.to_bytes(1, byteorder="big"),
|
||||||
|
trackOutput.to_bytes(1, byteorder="big"),
|
||||||
|
condition.to_bytes(1, byteorder="big"),
|
||||||
|
needRedstone.to_bytes(1, byteorder="big"),
|
||||||
|
]:
|
||||||
|
block += i
|
||||||
|
return block
|
||||||
|
|
||||||
|
|
||||||
|
def __fillSquareSideLength(total: int, maxHeight: int):
|
||||||
|
"""给定总方块数量和最大高度,返回所构成的图形外切正方形的边长
|
||||||
|
:param total: 总方块数量
|
||||||
|
:param maxHeight: 最大高度
|
||||||
|
:return: 外切正方形的边长 int"""
|
||||||
|
return math.ceil(math.sqrt(math.ceil(total / maxHeight)))
|
||||||
|
|
||||||
|
|
||||||
|
def toBDXbytes(
|
||||||
|
commands: list,
|
||||||
|
maxheight: int = 64,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
:param commands: 指令列表(指令, 延迟)
|
||||||
|
:param maxheight: 生成结构最大高度
|
||||||
|
:return 成功与否,成功返回(True,未经过压缩的源,结构占用大小),失败返回(False,str失败原因)
|
||||||
|
"""
|
||||||
|
|
||||||
|
_sideLength = __fillSquareSideLength(len(commands), maxheight)
|
||||||
|
_bytes = b''
|
||||||
|
|
||||||
|
yforward = True
|
||||||
|
zforward = True
|
||||||
|
|
||||||
|
nowy = 0
|
||||||
|
nowz = 0
|
||||||
|
nowx = 0
|
||||||
|
|
||||||
|
for cmd, delay in commands:
|
||||||
|
_bytes += formCMDblk(
|
||||||
|
cmd,
|
||||||
|
(1 if yforward else 0)
|
||||||
|
if (
|
||||||
|
((nowy != 0) and (not yforward))
|
||||||
|
or ((yforward) and (nowy != (maxheight - 1)))
|
||||||
|
)
|
||||||
|
else (3 if zforward else 2)
|
||||||
|
if (
|
||||||
|
((nowz != 0) and (not zforward))
|
||||||
|
or ((zforward) and (nowz != _sideLength))
|
||||||
|
)
|
||||||
|
else 5,
|
||||||
|
impluse=2,
|
||||||
|
condition=False,
|
||||||
|
needRedstone=False,
|
||||||
|
tickDelay=delay,
|
||||||
|
customName="",
|
||||||
|
executeOnFirstTick=False,
|
||||||
|
trackOutput=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
nowy += 1 if yforward else -1
|
||||||
|
|
||||||
|
if ((nowy >= maxheight) and (yforward)) or ((nowy < 0) and (not yforward)):
|
||||||
|
nowy -= 1 if yforward else -1
|
||||||
|
|
||||||
|
yforward = not yforward
|
||||||
|
|
||||||
|
nowz += 1 if zforward else -1
|
||||||
|
|
||||||
|
if ((nowz > _sideLength) and (zforward)) or ((nowz < 0) and (not zforward)):
|
||||||
|
nowz -= 1 if zforward else -1
|
||||||
|
zforward = not zforward
|
||||||
|
_bytes += key[x][1]
|
||||||
|
nowx += 1
|
||||||
|
else:
|
||||||
|
|
||||||
|
_bytes += key[z][int(zforward)]
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
_bytes += key[y][int(yforward)]
|
||||||
|
|
||||||
|
return (
|
||||||
|
_bytes,
|
||||||
|
[nowx + 1, maxheight if nowx or nowz else nowy, _sideLength if nowx else nowz],
|
||||||
|
[nowx, nowy, nowz],
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user