scarpet-additions
![]()
Carpet mod 的扩展,用于提供额外的 scarpet 函数
需要 Carpet mod
函数
convert_color(color,model,output)
将一种 model 格式的颜色转换为另一种。
color -> List: 根据指定的 model 而定
model -> String: 输入颜色模型,可以是 RGB、RGBA 或 HSB
- RGB: 红色、绿色和蓝色值的列表
- RGBA: 红色、绿色、蓝色和透明度值的列表
- HSB: 色相、饱和度和亮度值的列表
output -> String: 输出颜色模型,可以是 RGB、RGBA、HEX 或 NUM
- RGB: 红色、绿色和蓝色值的列表
- RGBA: 红色、绿色、蓝色和透明度值的列表
- HEX: 十六进制字符组成的字符串(不含前导 '#')。可用于
format() - NUM: 表示为 4 个字节颜色的数字:0xRRGGBBAA。可用于
draw_shape()中的'color'参数
示例:
convert_color([255,128,0],'rgb','hex'); -> 'FF8000'
convert_color([255,128,0],'rgb','num'); -> 0xff7f00ff
convert_color([0,255,255],'hsb','hex'); -> 'FF0000'
convert_color([120,255,255],'hsb','hex'); -> '00FF00'
示例代码:
__on_tick() -> (
if((tick_time() % 2) == 0,
headerHue = tick_time()%360;
headerGlossIndex = (floor(tick_time()/3)%40)-10;
header = [];
title = 'MinecraftServer';
for(range(length(title)),
if(abs(_-headerGlossIndex) < 3,
c = convert_color([headerHue,abs(_-headerGlossIndex)/3*255,255],'hsb','hex');
,
if(_ < 7,
c = convert_color([headerHue,255,190],'hsb','hex');
,
c = convert_color([headerHue,255,255],'hsb','hex');
);
);
put(header,null,str('b#%s %s',c,slice(title,_,_+1)));
);
header = format(header);
footer = format('r to the server!');
set_tab_text(header,footer);
)
);
http_request(options)
执行由给定 options 指定的 HTTP 请求。
此调用是阻塞的,因此应在 task() 中使用!
options 参数是一个映射值,包含以下键:
uri(String): 要请求的 URImethod(String, optional): HTTP 请求方法。例如GET、POST、DELETE... 默认为GETheaders(Map, optional): 每个映射项都是指向字符串或字符串列表的字符串键body(String):POST或其他请求的请求体
该函数返回一个包含以下条目的映射:
status_code(number): 请求的状态码body(String): 从请求中返回的主体headers(Map: string -> [strings]): 接收到的响应头uri(String): 最初请求的 URI
请注意,响应主体不会解析为 JSON 或 HTML 转义。
请使用 escape_html 和 unescape_html 函数,
以及 Scarpet 内置的 encode_json 和 decode_json 函数。
用法示例:
// simple get request and parsing
response = http_request({
'uri'->'https://opentdb.com/api.php?amount=1'
});
print('Response: ' + response);
if(response:'status_code' != 200,
print('Request failed: ' + response:'status_code');
,
body = decode_json(response:'body');
print('\n\nBody: ' + body);
question_data = body:'results':0;
question = unescape_html(question_data:'question');
answer = unescape_html(question_data:'correct_answer');
print('\n\n\n' + question + '\n' + answer);
);
escape_html(html)
返回转义的 HTML 字符串(例如 " -> ")
unescape_html(html)
返回未转义的 HTML 字符串(例如 " -> ")
list_text(header, footer, player?)
设置所有玩家的标签菜单中的页眉和页脚,或者如果提供了 player?,则更改单个玩家的页眉和页脚。
set_motd(motd)
设置服务器的每日消息(Message of the Day)。
scarpet-additions
![]()
A Carpet mod extension for some additional scarpet functions
Reqires Carpet mod
Functions
convert_color(color,model,output)
Converts a color from one model to another.
color -> List: Depending on specified model
model -> String: Input color model, can be RGB, RGBA or HSB
- RGB: List of a red, green and blue value
- RGBA: List of a red, green, blue and alpha value
- HSB: List of a hue, saturation and brightnes value
output -> String: Output color model, can be RGB, RGBA, HEX or NUM
- RGB: List of a red, green and blue value
- RGBA: List of a red, green, blue and alpha value
- HEX: String of hex characters (without leading '#') Can be used for
format() - NUM: Number representing the color as 4 bytes: 0xRRGGBBAA. Can be used for
'color'parameter indraw_shape()
Examples:
convert_color([255,128,0],'rgb','hex'); -> 'FF8000'
convert_color([255,128,0],'rgb','num'); -> 0xff7f00ff
convert_color([0,255,255],'hsb','hex'); -> 'FF0000'
convert_color([120,255,255],'hsb','hex'); -> '00FF00'
Example:
__on_tick() -> (
if((tick_time() % 2) == 0,
headerHue = tick_time()%360;
headerGlossIndex = (floor(tick_time()/3)%40)-10;
header = [];
title = 'MinecraftServer';
for(range(length(title)),
if(abs(_-headerGlossIndex) < 3,
c = convert_color([headerHue,abs(_-headerGlossIndex)/3*255,255],'hsb','hex');
,
if(_ < 7,
c = convert_color([headerHue,255,190],'hsb','hex');
,
c = convert_color([headerHue,255,255],'hsb','hex');
);
);
put(header,null,str('b#%s %s',c,slice(title,_,_+1)));
);
header = format(header);
footer = format('r to the server!');
set_tab_text(header,footer);
)
);
http_request(options)
Performs a http request specified by the given options.
This call is blocking, so you should use it in a task()!
The options parameter is a map value with the following keys:
uri(String): The URI to request frommethod(String, optional): The http request method. For exampleGET,POST,DELETE,... Defaults toGETheaders(Map, optional): Each map entry is a string key pointing to a string, or list of stringsbody(String): The body forPOSTor other requests
The function returns a map with the following entries:
status_code(number): The status code of the requestbody(String): The body returned from the requestheaders(Map: string -> [strings]): The received response headersuri(String): The originally requested URI
Note that the response body is not parsed as json or html escaped.
Use the escape_html and unescape_html functions,
as well as the scarpet-builtins encode_json and decode_json.
Example usage:
// simple get request and parsing
response = http_request({
'uri'->'https://opentdb.com/api.php?amount=1'
});
print('Response: ' + response);
if(response:'status_code' != 200,
print('Request failed: ' + response:'status_code');
,
body = decode_json(response:'body');
print('\n\nBody: ' + body);
question_data = body:'results':0;
question = unescape_html(question_data:'question');
answer = unescape_html(question_data:'correct_answer');
print('\n\n\n' + question + '\n' + answer);
);
escape_html(html)
Returns the escaped html string (e.g. " -> ")
unescape_html(html)
Returns the unescaped html string (e.g. " -> ")
list_text(header, footer, player?)
Sets header and footer in tab menu of all players, or changes it for one player if player? is given.
set_motd(motd)
Sets the message of the day of the server.
下载 Scarpet additions
下载 Scarpet additions
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Scarpet additions
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Scarpet additions
下载 Scarpet additions
下载 Scarpet additions
下载 Scarpet additions
下载 Scarpet additions
下载 Scarpet additions
下载 Scarpet additions
- 已更新至 MC 26.1
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
AE2:一款流行的自动化与存储模组
评论 0
登录后参与评分
还没有评论,来抢沙发吧