Scarpet additions
Adds some miscellaneous new functions like http requests to the scarpet language
介绍
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 支持哪些 Minecraft 版本?
Scarpet additions 支持 Minecraft Java 版 1.19–26.3,共 22 个版本,可用的加载器:Fabric。下载时注意选择和你游戏版本一致的文件。
Scarpet additions 怎么安装?
先用 PCL2 或 HMCL 启动器安装对应版本的 Fabric,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。运行环境:仅服务端。
replaceitem 的其他作品
查看全部 →
Symbol Chat
一款客户端模组,添加了符号/表情菜单,还能用不同的 Unicode 字体书写。
Integrated circuit
Adds integrated circuits to compact your redstone circuits into one block
Dynamic App Icon
Simple mod that changes the application icon of Minecraft to that of a world or server when joining
Secret Spectator
Serverside mod that prevents non-spectators from seeing spectators grayed out in the tab player list.
评论
登录后评论和评分