├── .gitattributes
├── README.md
├── libraries
└── survival_unobtainables.scl
├── programs
├── botteam.sc
├── cartlog.sc
├── compdisplay.sc
├── emoticons.sc
├── fill_level.sc
├── getallitems.sc
├── getfullbox.sc
├── gradient.sc
├── itemlayout.sc
├── k.sc
├── period.sc
├── pulselength.sc
├── randomizer.sc
├── stat.sc
├── stx.sc
└── update.sc
└── resources
├── stat
├── combined
│ ├── concrete_placed.txt
│ ├── ores_mined.txt
│ ├── slimestone.txt
│ └── stones_mined.txt
└── display_names
│ ├── 16.json
│ ├── 17.json
│ ├── 18.json
│ ├── 19.json
│ ├── 20.json
│ └── 21.json
└── stx
└── stx_modules.json
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.sc linguist-language=Python
2 | *.scl linguist-language=Python
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CommandLeo's Scarpet Scripts
2 |
3 | Name|Script|Description
4 | ---|---|---
5 | Statistic Display|[stat.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/stat.sc)|Easily display statistics on the scoreboard.
[How to install](https://github.com/CommandLeo/scarpet/wiki/Statistic-Display#how-to-install)
[Docs](https://github.com/CommandLeo/scarpet/wiki/Statistic-Display)
6 | StorageTechX|[stx.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/stx.sc)|A suite of tools for storage tech.
[Docs](https://github.com/CommandLeo/scarpet/wiki/StorageTechX)
7 | Item Randomizer|[randomizer.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/randomizer.sc)|Insert random items inside containers in a variety of ways.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Item-Randomizer)
8 | Get All Items|[getallitems.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/getallitems.sc)|Get all (survival-obtainable) items inside shulker boxes.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Get-All-Items)
9 | Item Layout|[itemlayout.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/itemlayout.sc)|Save a layout of items from a row of blocks and item frames to a file.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Item-Layout)
10 | PulseLength|[pulselength.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/pulselength.sc)|Measure for how long a redstone component has been powered for.
[Docs](https://github.com/CommandLeo/scarpet/wiki/PulseLength)
11 | Period|[period.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/period.sc)|Measure how often a redstone component is activated.
Credits go to [Firigion](https://github.com/Firigion) for part of the main code.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Period)
12 | Fill Level Utilities|[fill_level.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/fill_level.sc)|Get or set the fill level of a container.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Fill-Level-Utilities)
13 | Gradient Generator|[gradient.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/gradient.sc)|Generate gradient texts.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Gradient-Generator)
14 | Emoticons|[emoticons.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/emoticons.sc)|Get emoticon player heads.
15 | Block Updater|[update.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/update.sc)|Send block updates to one or more blocks.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Block-Updater)
16 | Quick Killing|[k.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/k.sc)|Quickly kill items and xp orbs (within a certain distance).
[Docs](https://github.com/CommandLeo/scarpet/wiki/Quick-Killing)
17 | Cartlog|[cartlog.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/cartlog.sc)|Visualise data of minecarts, similarly to MendedMinecarts.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Cartlog)
18 | Full Shulker Box Generator|[getfullbox.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/getfullbox.sc)|Get a shulker box full of a certain item.
[Docs](https://github.com/CommandLeo/scarpet/wiki/Full-Shulker-Box-Generator)
19 | Bot Team|[botteam.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/botteam.sc)|Makes fake players join a dedicated team while preserving the former team in case they ever join back as real players.
20 | Comparator Signal Strength Display|[compdisplay.sc](https://raw.githubusercontent.com/CommandLeo/scarpet/main/programs/compdisplay.sc)|Display the signal strength of a comparator above it.
21 |
--------------------------------------------------------------------------------
/libraries/survival_unobtainables.scl:
--------------------------------------------------------------------------------
1 | game_version = system_info('game_major_target');
2 | global_survival_unobtainables = [
3 | 'bedrock',
4 | 'suspicious_sand',
5 | 'suspicious_gravel',
6 | 'budding_amethyst',
7 | 'petrified_oak_slab',
8 | 'chorus_plant',
9 | 'spawner', // for 1.19.2-
10 | 'monster_spawner', // for 1.19.3+
11 | 'farmland',
12 | ...filter(item_list(), _~'infested' != null),
13 | 'reinforced_deepslate',
14 | 'end_portal_frame',
15 | 'command_block',
16 | 'barrier',
17 | 'light',
18 | 'grass_path', // for 1.16-
19 | 'dirt_path', // for 1.17+
20 | 'repeating_command_block',
21 | 'chain_command_block',
22 | 'structure_void',
23 | 'structure_block',
24 | 'jigsaw',
25 | 'bundle',
26 | ...filter(item_list(), _~'spawn_egg' != null),
27 | 'player_head',
28 | 'command_block_minecart',
29 | 'knowledge_book',
30 | 'debug_stick',
31 | 'frogspawn'
32 | ];
33 | if(game_version < 18, global_survival_unobtainables += 'spore_blossom');
34 | if(game_version < 19, global_survival_unobtainables += 'sculk_sensor');
35 |
--------------------------------------------------------------------------------
/programs/botteam.sc:
--------------------------------------------------------------------------------
1 | // Bot Team by CommandLeo
2 |
3 | global_team_name = 'bots';
4 |
5 | __on_start() -> (
6 | if(team_list()~global_team_name == null,
7 | team_add(global_team_name);
8 | team_property(global_team_name, 'color', 'gray');
9 | team_property(global_team_name, 'prefix', '[BOT] ');
10 | );
11 | );
12 |
13 | __on_player_connects(player) -> (
14 | data = load_app_data() || {};
15 | team = player~'team';
16 |
17 | if(player~'player_type' == 'fake',
18 | if(team,
19 | if(team != global_team_name, data:str(player) = team),
20 | delete(data, str(player))
21 | );
22 | store_app_data(data);
23 | team_add(global_team_name, player),
24 | team == global_team_name,
25 | previous_team = data:str(player);
26 | if(previous_team && team_list()~previous_team != null,
27 | team_add(previous_team, player),
28 | team_leave(player)
29 | );
30 | );
31 | );
--------------------------------------------------------------------------------
/programs/cartlog.sc:
--------------------------------------------------------------------------------
1 | __config() -> {
2 | 'commands' -> {
3 | '' -> 'toggle_visibility',
4 | 'pos' -> ['toggle_setting', 'pos'],
5 | 'speed' -> ['toggle_setting', 'speed'],
6 | 'fall_distance' -> ['toggle_setting', 'fall_distance'],
7 | 'fill_level' -> ['toggle_setting', 'fill_level'],
8 | 'locked' -> ['toggle_setting', 'locked'],
9 | 'fuse' -> ['toggle_setting', 'fuse'],
10 | 'hitbox' -> ['toggle_setting', 'hitbox'],
11 | },
12 | 'scope' -> 'player'
13 | };
14 |
15 | toggle_visibility() -> global_on = !global_on;
16 |
17 | toggle_setting(setting) -> global_settings:setting = !global_settings:setting;
18 |
19 | __on_start() -> (
20 | global_settings = {
21 | 'pos' -> true,
22 | 'speed' -> true,
23 | 'fall_distance' -> false,
24 | 'fill_level' -> true,
25 | 'locked' -> true,
26 | 'fuse' -> true,
27 | 'hitbox' -> true
28 | };
29 | );
30 |
31 | __on_tick() -> (
32 | if(!global_on, return());
33 | for(entity_list('minecarts'),
34 | i = 0;
35 | cart = _;
36 |
37 | if(global_settings:'fuse' && cart~'type' == 'tnt_minecart',
38 | fuse = query(cart, 'nbt', 'TNTFuse');
39 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Fuse: %d', fuse)})
40 | );
41 | if(global_settings:'locked' && cart~'type' == 'hopper_minecart',
42 | locked = !query(cart, 'nbt', 'Enabled');
43 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Locked: %b', locked)})
44 | );
45 | if(global_settings:'fill_level' && inventory_has_items(cart) != null,
46 | fill_level = if(inventory_has_items(cart), floor(1 + reduce(inventory_get(cart), _a + if(_ , _:1 / stack_limit(_:0), 0), 0) / inventory_size(cart) * 14), 0);
47 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Fill Level: %d', fill_level)})
48 | );
49 |
50 | if(global_settings:'fall_distance',
51 | fall_distance = query(cart, 'nbt', 'FallDistance');
52 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Fall Distance: %.2f', fall_distance)})
53 | );
54 | if(global_settings:'speed',
55 | speed_x = max(-8, min(8, cart~'motion_z' * 20 + 1e-10));
56 | speed_y = cart~'motion_y' * 20 + 1e-10;
57 | speed_z = max(-8, min(8, cart~'motion_x' * 20 + 1e-10));
58 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Speed Z: %.2f bps', speed_x)});
59 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Speed Y: %.2f bps', speed_y)});
60 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Speed X: %.2f bps', speed_z)});
61 | );
62 | if(global_settings:'pos',
63 | x = cart~'x';
64 | y = cart~'y';
65 | z = cart~'z';
66 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Z: %.2f', z)});
67 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('Y: %.2f', y)});
68 | draw_shape('label', 1, {'player' -> player(), 'pos' -> [0, 1, 0], 'follow' -> _, 'height' -> i+=1, 'text' -> '', 'value' -> str('X: %.2f', x)});
69 | );
70 |
71 | if(global_settings:'hitbox', draw_shape('box', 1, {'player' -> player(), 'from' -> pos(cart) - [0.98/2, 0, 0.98/2], 'to' -> pos(cart) + [0.98/2, 0.7, 0.98/2], 'fill' -> 0x9b59b688}));
72 | );
73 | )
--------------------------------------------------------------------------------
/programs/compdisplay.sc:
--------------------------------------------------------------------------------
1 | // Comparator Signal Strength Display by CommandLeo
2 |
3 | __config() -> {
4 | 'commands' -> {
5 | '' -> 'toggle'
6 | },
7 | 'scope'-> 'player'
8 | };
9 |
10 | toggle() -> (
11 | print(player(), format('f »', 'g Comparator Signal Strength Display ', if(global_enabled = !global_enabled, 'l enabled', 'r disabled')));
12 | );
13 |
14 | displayComparatorSignalStrength() -> (
15 | if(global_enabled,
16 | trace = player()~'trace';
17 | if(trace == 'comparator', draw_shape('label', 2, {'pos' -> pos(trace) + 0.5, 'text' -> block_data(trace):'OutputSignal', 'player'-> player(), 'color' -> 0xff4757ff}));
18 | );
19 | schedule(1, 'displayComparatorSignalStrength');
20 | );
21 |
22 | __on_start() -> displayComparatorSignalStrength();
--------------------------------------------------------------------------------
/programs/emoticons.sc:
--------------------------------------------------------------------------------
1 | // Emoticons by CommandLeo
2 |
3 | global_emoticons = {
4 | 'Raised Eyebrow' -> 'd12e74a1194e731ffcd4dff02570009f5b4a947de30df5cd220c04d326f0eb87',
5 | 'Neutral' -> 'cb80600254ae8a6b65e2c26dca71d1fea5cf01679232d26ae658e64d6c3a0212',
6 | 'Expressionless' -> '1b497d21df087f4092ae3ef9249452dfc126bf3e7f295583910b19381ae9eb85',
7 | 'No Mouth' -> 'bf1e03da7e1e1eb2a12a4f991b06dffb3be4a7fcc7ab33fe7dbe7ebf9283a65a',
8 | 'Smirking' -> 'b62bbc5f291b1968b86155444f4961e9b963506d7f25c9af3de7d871fdb50f0f',
9 | 'Unamused' -> '574aee6e8726947c4a9355e5897585f48ae8bf00e261d78e5769c975eddb9462',
10 | 'Rolling Eyes' -> 'd7255504f5d9a4aa26ce89b28428e72cc6d9459c100ba22fc4ccc3a1b169b8a0',
11 | 'Grimacing' -> '3ebc1c39e87166f4507459a61f2fba2c62ef03b8ecdfa30db09345525745f199',
12 | 'Exhaling' -> '40da627f52be9536c1ba7daf722bd51db585343689a4627f5fba95712a35693e',
13 | 'Lying' -> '82e2063d7470ab811cc9073d9d0cb270f0a760db01fcbb87b1908d5e395070ed',
14 | 'Relieved' -> 'bc8277af4e7f965b17c4369fe680d3fe88b94269b52496c09a1cf5016f7f516e',
15 | 'Pensive' -> '6910b22b5f29eef94ab4207484281bb69c5286c161753a154510342a114d718c',
16 | 'Sleepy' -> 'f8ce9f566b2431e19ce39f933e32b914d45cd9c5afeea254b0e4ea2afd869101',
17 | 'Drooling' -> 'd8e2d0d0c4f1191899edb2403959b5b60842ce39ba3664a9303205fdeacb34bd',
18 | 'Sleeping' -> '5c819a42c0b1c25b9e2e0bc1ebb574b4d6690777d3e831d82d3c932116c02bdc',
19 | 'Facemask' -> '7f2893e2621986135b4129ed01237b8327e75a56824c57d881c3d22071d2b074',
20 | 'Thermometer' -> '7fda21825065916df7cec47e54b9db9c91ae56404d7e274863acbac013042c7c',
21 | 'Bandaged' -> '44753c60cb0bb0c30ad2ff73a2329a7d9d9e4f209a833cfbe17dfcafec0cef3c',
22 | 'Sick' -> '23b14109b80edcc51c4f1081d765bbc48003159dce6cb6b7c9655687a5e3db87',
23 | 'Vomiting' -> '7b2818b6f378acb1cfabbb11cc4f9ac697af8faaf00c36a601b849fa2c1d9f5c',
24 | 'Sneezing' -> 'ab03827d1f029ddb4d0932508b375b72c04afac8c4ad60ad87b15c9dc60ba3b6',
25 | 'Woozy' -> '1fc76918a21955820153cae8aa1cf163890eca79be5276264f2321bfef4c1a3b',
26 | 'Dead' -> '326bd2c90a58da1068eeae185e190b72437dd361fd6d39943b23a29a72fdac8d',
27 | 'Spiral Eyes' -> 'e94c1a01bc1210f874c81efe756208fa2e69987838fa5e77f45db1eeddbaf172',
28 | 'Exploding Head' -> 'f4367b9220c7c0df371e4ea05b86e771c8be2643b39513513f5407146e16e2a3',
29 | 'Cowboy' -> 'ffd39646e24e6a4e62d0cc8a22b6a8f952bef8ce9bae274bf2d11a82c2e7cd3a',
30 | 'Sad Cowboy' -> '4476b4bead71e84d080cebd405dc31d8b4aea740feac1b7224814052f260dd4d',
31 | 'Partying' -> '525eed8fb447e481c011511062da8b77a228d8fc59a68213f84d63af10e7b53a',
32 | 'Disguised' -> 'b9c9e8d96f11220d5f30c91941317c0b22b566f823243af6f91b169d5ce7b4',
33 | 'Sunglasses' -> '71a11a03d6bc75b144be85848556a15f358ee6a65e0466f6c8b706e7f9bcf14',
34 | 'Nerd' -> '8d394fec5275b584ce6877a273600d04e06c4abbd480bbabb655c81a6ddb1723',
35 | 'Monocle' -> '858f5b1fbfe7395787fcf833b0b5832e74368fe539c9e59e494ede1536794fc2',
36 | 'Confused' -> '8c16b33a589f8881a65222e1c52f32dc7bca335a7c7305b41ae33cd5925f973d',
37 | 'Diagonal' -> 'e8eb9bf1de3e37b5fd9fd5f92dfaa0603de9f0bafcdee0348b2729be71cc0141',
38 | 'Worried' -> '4e3075b6e592e42e3007d4325a51aa593d91f46dc23f1059aa2c319cf385a605',
39 | 'Frowning' -> '72484eaa4b947825efe87c14d752aa64604a94c08b238f29d6f384ac5fc08186',
40 | 'Slightly Frowning' -> '3c26d4e12e8955339e719aebddd23b1d1cc7367426e7be8c1cd0f073f3eeb51d',
41 | 'Open Mouth' -> '35732e461f5e51c7b2b8ff1a853fdfdb833b3992d3985b0aade74d0c724a8596',
42 | 'Hushed' -> 'bcca0b9961e7806d0d3aa0d0a26b29952ca2638d9949b40df641d99eaf7eb66',
43 | 'Astonished' -> 'f40eb7298cd58a0e9edd8595ca3fcf9f0095c4c645d77d234f050c274f0ac4cf',
44 | 'Flushed' -> '679d722bf836318fd11eec260fa9fd32e28f19f503d669f2591877d8285eb6c3',
45 | 'Pleading' -> '7fe4be5ac79baaf26ef02af0ec84096271b807d5b04f139693455e1843ff60f0',
46 | 'Holding Back Tears' -> 'f4f5c69169f5d651abd27d624e0d02065a8d9e9a0dfffdaec323a3f2c6800327',
47 | 'Open Mouth Frowning' -> '93904f070fcf4a954f74fd3a1bc2ef8fa72aef00b2eee31dd0326bf9d4418de6',
48 | 'Anguished' -> 'f90ae4ea93ce6f81fc0920ebefc18d296b8137943a9a1fbbbe8c51c982425f0d',
49 | 'Fearful' -> 'd437661731132e87dbf5358920ea1925fa7f526e52c37ffc3090a183450826d6',
50 | 'Anxious' -> 'a81a2c7af057ee78544aa5a81657dfc05f20834eb8c76fd8b7f7a77a6a8b5bc6',
51 | 'Sad but Relieved' -> '9c140c1baabf29fb5de4a620d5dbf79fa877f584e3ef93919e91ff91b3642441',
52 | 'Crying' -> '150fc33f30791ec06a52f19869e051f32bab183787a34fdc1ff038b9946c9f7f',
53 | 'Sobbing' -> 'e8feeca56cc0aabaac46ad4036690cdc66da3c9f2c85c371b67952fe73898f04',
54 | 'Screaming' -> '8ac2472f011785092152071e82150269a16633b907bd100fc7fe30cd431c63a0',
55 | 'Confounded' -> '87ef8f9f9bcf8352127276eab45a050ea5850a9698c05f140cf57cbd60c5cc95',
56 | 'Persevering' -> '470a5739f9030a9b5657755c3ec121d636949113304d3974a45c6b9272c728ed',
57 | 'Disappointed' -> '63fb3a62ec6bf481aa35e7d2450afe9e7cf80a039854a97ac655e7a5ed76dd55',
58 | 'Downcast Sweat' -> '4ce58fe0e6aa494a202df3446f03d3b9c85febcb73ed4935949b15e1adf45363',
59 | 'Weary' -> 'fd60200a52687fc8af137c6b969cbf894abf240b942a2f4967155afa413afc6b',
60 | 'Tired' -> '5751e703b33e7d90a553e59011cf341ca71ad50bc35a4f9c5afe59ebebc77140',
61 | 'Triumph' -> '3a4bd22473a17eb832feaf8ace8f7461b56a597848b134c8af1b8d521dc3e4f0',
62 | 'Angry' -> 'a79812621484cd2f0b0158d83ca39fef48024f0be588a5a5d23238b3afe90d99',
63 | 'Grinning' -> '551c8e23ddf916cf15e69615dea1dce20e697b9bbf9f28840c42ab929745128e',
64 | 'Grinning Big Eyes' -> 'd1207ffe69f06f7b8173bf5b924c4d8f7976383c7e59dce538ffa63af84d7595',
65 | 'Smiling Closed Eyes' -> '408ffac078376cfd47de892904d014a8e0c56f4924575d400264a7c62607df65',
66 | 'Laughing' -> '72cdc8bc85e0bd034de2b0ebc4f207afd82c782665460412da98e6deeafc254f',
67 | 'Beaming' -> '2d0613b34b6bd90a7192eba424d38a55bfa6dbde44501c1fffe25c7ce3a2ba11',
68 | 'Sweating Smiling' -> '2274eec9cab2710eb225f53d6053a0913b143fa42dbec24e7c99ed0008124daf',
69 | 'ROFL' -> 'b003750d959cd5685ce4697ff6d3ff6b1d8f2f40afbf1ff625393fa071b4681a',
70 | 'Laughing Crying' -> 'f6f9ac4d15c7905e1f96d14e86d53dad89e690d1dcb1072f4e1d987c2d88bfd3',
71 | 'Laughing Crying (Open Eyes)' -> '67bf4532a532c2933d61dc02cc72386829716893441a47330d8258f3046a713a',
72 | 'Slight Smile' -> '3c5aca29950e5b05ea81932f90bc52e8d14757b7e0eeb3909ab79ad98151ba7e',
73 | 'Smile' -> 'a9d977c57ba7543990ed289aa2d0e0e9aca846056d52491079c63c5dc756d0b0',
74 | 'Upside Down' -> '39fee8acaee2e327c0077d6c0a44b4817575f370ea0c41844d04af213aba4916',
75 | 'Melting' -> 'ad88eb70318eb7fb8f486674014d4ccd1c27ffc37e804c0f6e23ead81a561dd7',
76 | 'Winking' -> 'bbdaf6d8469dd476db3c2a7e66e7bd511d852d4a242e3c9e5a2256b4498bf84b',
77 | 'Smiling Blush' -> 'dfeb3f8484e811d40b57e1463b14bde0ae5e1fcfc4153d61e1f7ee813252c7da',
78 | 'Angel' -> 'c48d16aaea9214641cc69a0d2d26367ac3ef75a47decfdfff7c7db5864e6c14f',
79 | 'Smiling Hearts' -> 'b0bd22c2f95b648fee0003241f4eb5f22b5779f99eefc847e984916a4be99ace',
80 | 'Heart Eyes' -> '1d0f2925df37fbd5f80829cafb3e9e9ac00f75a991b2131c26e0b2198e300018',
81 | 'Starstruck' -> 'e9e30866ea82f30b0c15691deacfc6311fdd4cb8740fc4aa8f4302ffe0e8dc5a',
82 | 'Blowing Kiss' -> '47b7a9c64f7aa04c46a596003b145113494877ecbf656ea97320e624d25680f',
83 | 'Kissing' -> 'fc16c51ef7bd2c1a558a941d46a19b8e2a91a53817603de382ac8462da46d13f',
84 | 'Smiling' -> '1d0018edadc58ee8dbd120a17f1e9a985bd52fb45998a6a6479eff8ff767b768',
85 | 'Kissing Blush' -> '4595e2302700452dc1ac990ba61bcdf89331998a896989dd659e3a6039aabae2',
86 | 'Kissing Closed Eyes' -> '3c4ef82732d8d8b1824436227fce10fbb57e6faa1ba976ad0cb8e369ef52ff74',
87 | 'Smiling Tear' -> '624711f6b9792b104d29992e93d1431d90e804026cdb52234d4463f05db0123b',
88 | 'Yummy' -> '7a63d49d8a9f0f03e6a6a2296ceb6f45c740dfcee71f236705b8b6409253a9f7',
89 | 'Tongue' -> 'b044971538922eff82349882517b334ffbefb86480e7f65a73c15d2738d998f9',
90 | 'Winking Tongue' -> '9cef234b3fe6b492ee9b8f1e26341e30036f8a51dd89cdc86e8173481eac8003',
91 | 'Tongue Closed Eyes' -> '79d064dfa577d2b0661b24499fb3b2d8f6cab50571fcc61c79ee5532f00e1e1e',
92 | 'Zany' -> 'ca5ed182bd9cec8ad7c0797cab7c3776d3d7f4fa800a89359fc6f3fffa9c1255',
93 | 'Money Mouth' -> '406ac74d3270e4813efc3d4bd235ce4daeb790d02b1e61a7c29768fcb96890ea',
94 | 'Shushing' -> 'cf78f252cec21eb4e6ae8d70b89faf617d1e9fc92eb6949050542c500028ffd',
95 | 'Thinking' -> 'd070b22e255702d3252ff57aadb7432c2f41fd516f500e3715567f8e0d6618af',
96 | 'Zipper' -> '92ebe9ade5c6640f84c38dba4690d21d05a169efce52792a4e97d2fdfb4f0bbc',
97 | };
98 | global_emoticons = sort(pairs(global_emoticons));
99 |
100 | __config() -> {
101 | 'commands' -> {
102 | '' -> 'emoticonMenu',
103 | '' -> 'equipEmoticon',
104 | 'random' -> 'randomEmoticon'
105 | },
106 | 'arguments' -> {
107 | 'emoticon' -> {
108 | 'type' -> 'term',
109 | 'options' -> map(global_emoticons, lower(replace(replace(_:0, '\\(|\\)', ''), ' ', '_'))),
110 | 'case_sensitive' -> false
111 | }
112 | },
113 | 'requires' -> {
114 | 'carpet' -> '>=1.4.57'
115 | },
116 | 'scope' -> 'player'
117 | };
118 |
119 | _getHeadNbt(name, hash) -> (
120 | head_name = str('{"text":"%s","italic":false}', name);
121 | value = encode_b64(encode_json({'textures' -> {'SKIN' -> {'url' -> str('http://textures.minecraft.net/texture/%s', hash)}}}));
122 | return(if(system_info('game_pack_version') >= 33,
123 | {
124 | 'custom_name' -> head_name,
125 | 'profile' -> {'properties' -> [{'name' -> 'textures', 'value' -> value}]}
126 | },
127 | {
128 | 'display' -> {'Name' -> head_name},
129 | 'SkullOwner' -> {'Properties' -> {'textures' -> [{'Value' -> value}]}}
130 | }
131 | );
132 | ));
133 |
134 | emoticonMenu() -> (
135 | pages = map(range(length(global_emoticons) / 45), slice(global_emoticons, _i * 45, min(length(global_emoticons), (_i + 1) * 45)));
136 |
137 | _setMenuInfo(screen, pages_length) -> (
138 | name = str('\'{"text":"Page %d/%d","color":"gold","italic":false}\'', global_page % pages_length + 1, pages_length);
139 | lore = [str('\'{"text":"%s entries","color":"gray","italic":false}\'', length(global_emoticons))];
140 | inventory_set(screen, 49, 1, 'paper', if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> name, 'lore' -> lore}, 'id' -> 'paper'}, {'display' -> {'Name' -> name, 'Lore' -> lore}}));
141 | );
142 |
143 | _setMenuItems(screen, page) -> (
144 | loop(45, inventory_set(screen, _, , if(_ < length(page), 1, 0), 'player_head', if(system_info('game_pack_version') >= 33, {'components' -> encode_nbt(_getHeadNbt(...page:_)), 'id' -> 'player_head'}, encode_nbt(_getHeadNbt(...page:_)))));
145 | );
146 |
147 | global_page = 0;
148 | screen = create_screen(player(), 'generic_9x6', 'Emoticons', _(screen, player, action, data, outer(pages)) -> (
149 | if(length(pages) > 1 && action == 'pickup' && (data:'slot' == 48 || data:'slot' == 50),
150 | page = if(data:'slot' == 48, pages:(global_page += -1), data:'slot' == 50, pages:(global_page += 1));
151 | _setMenuInfo(screen, length(pages));
152 | _setMenuItems(screen, page);
153 | );
154 | if(action == 'pickup' && data:'slot' == 53, randomEmoticon());
155 | if(action == 'pickup' && 0 <= data:'slot' <= 45,
156 | i = inventory_get(screen, data:'slot');
157 | if(i,
158 | inventory_set(player, 39, 1, 'player_head', i:2);
159 | run('playsound block.note_block.pling master @s');
160 | );
161 | );
162 | if(action == 'pickup_all' || action == 'quick_move' || (action != 'clone' && data:'slot' != null && 0 <= data:'slot' <= 44) || (45 <= data:'slot' <= 53), return('cancel'));
163 | ));
164 |
165 | _setMenuItems(screen, pages:0);
166 |
167 | for(range(45, 54), inventory_set(screen, _, 1, 'gray_stained_glass_pane', if(system_info('game_pack_version') >= 33, {'components' -> {'hide_tooltip' -> {}}, 'id' -> 'gray_stained_glass_pane'}, {'display' -> {'Name' -> '\'{"text":""}\''}})));
168 | _setMenuInfo(screen, length(pages));
169 | random_emoticon_head_nbt = _getHeadNbt('Random Emoticon', 'da99b05b9a1db4d29b5e673d77ae54a77eab66818586035c8a2005aeb810602a');
170 | inventory_set(screen, 53, 1, 'player_head', if(system_info('game_pack_version') >= 33, {'components' -> encode_nbt(random_emoticon_head_nbt), 'id' -> 'player_head'}, encode_nbt(random_emoticon_head_nbt)));
171 | if(length(pages) > 1,
172 | previous_page_name = '\'{"text":"Previous page","color":"gold","italic":false}\'';
173 | next_page_name = '\'{"text":"Next page","color":"gold","italic":false}\'';
174 | inventory_set(screen, 48, 1, 'arrow', if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> previous_page_name}, 'id' -> 'arrow'}, {'display' -> {'Name' -> previous_page_name}}));
175 | inventory_set(screen, 50, 1, 'arrow', if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> next_page_name}, 'id' -> 'arrow'}, {'display' -> {'Name' -> next_page_name}}));
176 | );
177 | );
178 |
179 | equipEmoticon(name) -> (
180 | emoticon = first(global_emoticons, lower(replace(replace(_:0, '\\(|\\)', ''), ' ', '_')) == name);
181 | if(!emoticon, exit(print(format('r No emoticon found'))));
182 | inventory_set(player(), 39, 1, 'player_head', if(system_info('game_pack_version') >= 33, {'components' -> encode_nbt(_getHeadNbt(...emoticon)), 'id' -> 'player_head'}, encode_nbt(_getHeadNbt(...emoticon))));
183 | run('playsound block.note_block.pling master @s');
184 | );
185 |
186 | randomEmoticon() -> (
187 | head_nbt = _getHeadNbt(...rand(global_emoticons));
188 | inventory_set(player(), 39, 1, 'player_head', if(system_info('game_pack_version') >= 33, {'components' -> encode_nbt(head_nbt), 'id' -> 'player_head'}, encode_nbt(head_nbt)));
189 | run('playsound block.note_block.pling master @s');
190 | );
--------------------------------------------------------------------------------
/programs/fill_level.sc:
--------------------------------------------------------------------------------
1 | // Fill Level Utilities by CommandLeo
2 |
3 | global_color = '#E67E22';
4 |
5 | global_stackable_dummy_item = global_default_stackable_dummy_item = ['structure_void', null];
6 | global_unstackable_dummy_item = global_default_unstackable_dummy_item = ['shulker_box', null];
7 |
8 | __config() -> {
9 | 'commands' -> {
10 | '' -> 'help',
11 |
12 | 'get' -> ['printFillLevel', null],
13 | 'get ' -> 'printFillLevel',
14 | 'set ' -> ['setFillLevel', null],
15 | 'set ' -> 'setFillLevel',
16 |
17 | 'dummy_item stackable' -> 'printStackableDummyItem',
18 | 'dummy_item stackable print' -> 'printStackableDummyItem',
19 | 'dummy_item stackable give' -> 'giveStackableDummyItem',
20 | 'dummy_item stackable set item - ' -> 'setStackableDummyItem',
21 | 'dummy_item stackable set hand' -> 'setStackableDummyItemFromHand',
22 | 'dummy_item stackable reset' -> ['setStackableDummyItem', null],
23 | 'dummy_item unstackable' -> 'printUnstackableDummyItem',
24 | 'dummy_item unstackable print' -> 'printUnstackableDummyItem',
25 | 'dummy_item unstackable give' -> 'giveUnstackableDummyItem',
26 | 'dummy_item unstackable set item
- ' -> 'setUnstackableDummyItem',
27 | 'dummy_item unstackable set hand' -> 'setUnstackableDummyItemFromHand',
28 | 'dummy_item unstackable reset' -> ['setUnstackableDummyItem', null]
29 | },
30 | 'arguments' -> {
31 | 'fill_level' -> {
32 | 'type' -> 'int',
33 | 'min' -> 0,
34 | 'max' -> if(system_info('game_pack_version') < 33, 897, 15),
35 | 'suggest' -> []
36 | },
37 | 'item' -> {
38 | 'type' -> 'item'
39 | }
40 | },
41 | 'scope' -> 'global'
42 | };
43 |
44 | // HELPER FUNCTIONS
45 |
46 | _error(error) -> exit(print(format(str('r %s', error))));
47 |
48 | _checkVersion(version) -> (
49 | regex = '(\\d+)\.(\\d+)\.(\\d+)';
50 | target_version = map(version~regex, number(_));
51 | scarpet_version = map(system_info('scarpet_version')~regex, number(_));
52 | return(scarpet_version >= target_version);
53 | );
54 |
55 | _giveCommand(item, nbt) -> (
56 | return('give @s ' + item + if(nbt, if(system_info('game_pack_version') >= 33, '[' + join(',', map(nbt, _ + '=' + encode_nbt(nbt:_, true))) + ']', encode_nbt(nbt, true)), ''));
57 | );
58 |
59 | _getReadingComparators(pos) -> (
60 | comparators = [];
61 | map(['north', 'east', 'south', 'west'],
62 | block1 = block(pos_offset(pos, _, -1));
63 | if(block1 == 'comparator' && block_state(block1, 'facing') == _, continue(comparators += block1));
64 | if(solid(block1) && inventory_has_items(block1) == null,
65 | block2 = block(pos_offset(block1, _, -1));
66 | if(block2 == 'comparator' && block_state(block2, 'facing') == _, comparators += block2);
67 | );
68 | );
69 | return(comparators);
70 | );
71 |
72 | // MAIN
73 |
74 | help() -> (
75 | texts = [
76 | 'fs ' + ' ' * 80, ' \n',
77 | '%color%b Fill Level Utilities ', if(_checkVersion('1.4.57'), ...['@https://github.com/CommandLeo/scarpet/wiki/Fill-Level-Utilities', '^g Click to visit the wiki']), 'g by ', '%color%b CommandLeo', '^g https://github.com/CommandLeo', if(_checkVersion('1.4.57'), '@https://github.com/CommandLeo'), ' \n\n',
78 | '%color% /%app_name% get []', 'f |', 'g Gets the fill level of the block you are looking at or at the specified position', ' \n',
79 | '%color% /%app_name% set []', 'f |', 'g Sets the fill level of the block you are looking at or at the specified position', ' \n',
80 | '%color% /%app_name% dummy_item stackable [get|set|reset|give]', 'f |', 'g Gets, sets, resets or gives the stackable dummy item', ' \n',
81 | '%color% /%app_name% dummy_item unstackable [get|set|reset|give]', 'f |', 'g Gets, sets, resets or gives the unstackable dummy item', ' \n',
82 | 'fs ' + ' ' * 80
83 | ];
84 | replacement_map = {'%app_name%' -> system_info('app_name'), '%color%' -> global_color};
85 | print(format(map(texts, reduce(pairs(replacement_map), replace(_a, ..._), _))));
86 | );
87 |
88 | // FILL LEVEL
89 |
90 | getFillLevel(target) -> (
91 | fill_level = if(
92 | target == 'composter' || target == 'cauldron' || target == 'water_cauldron' || target == 'powder_snow_cauldron',
93 | block_state(pos(target), 'level') || 0,
94 | inventory_has_items(target) != null,
95 | if(
96 | inventory_has_items(target),
97 | floor(1 + reduce(inventory_get(target), _a + if(_ , _:1 / stack_limit(_:0), 0), 0) / inventory_size(target) * 14),
98 | // else
99 | 0
100 | )
101 | );
102 | return(fill_level);
103 | );
104 |
105 | printFillLevel(position) -> (
106 | target = if(position, block(position), player()~'trace');
107 | if(!target || target~'type' == 'player', _error('You are not looking at any block'));
108 |
109 | fill_level = getFillLevel(target);
110 | if(fill_level == null, _error('Invalid block'));
111 | print(format('f » ', str('gi %s', target), '^g ' + pos(target), 'g has a fill level of ', str('%s %d', global_color, fill_level)));
112 | );
113 |
114 | setFillLevel(fill_level, position) -> (
115 | target = if(position, block(position), player()~'trace');
116 | if(!target || target~'type' == 'player', _error('You are not looking at any block'));
117 |
118 | if(
119 | target == 'composter',
120 | setComposterFillLevel(target, fill_level),
121 | target == 'cauldron' || target == 'water_cauldron',
122 | setCauldronFillLevel(target, fill_level),
123 | inventory_has_items(target) != null,
124 | setContainerFillLevel(target, fill_level),
125 | // else
126 | _error('Invalid block')
127 | );
128 |
129 | for(_getReadingComparators(pos(target)), update(_));
130 |
131 | actual_fill_level = getFillLevel(target);
132 | print(format('f » ', 'g Filled ', str('gi %s', target), '^g ' + pos(target), 'g with fill level ', str('%s %d', global_color, actual_fill_level), if(actual_fill_level != fill_level, str('g (instead of %s)', fill_level)))),
133 | );
134 |
135 | setComposterFillLevel(composter, fill_level) -> (
136 | if(fill_level > 8 || fill_level < 0, _error('Invalid fill level'));
137 | set(composter, 'composter', {'level' -> fill_level});
138 | );
139 |
140 | setCauldronFillLevel(cauldron, fill_level) -> (
141 | if(fill_level > 3 || fill_level < 0, _error('Invalid fill level'));
142 | if(fill_level == 0,
143 | set(cauldron, 'cauldron'),
144 | set(cauldron, if(system_info('game_major_target') >= 17, 'water_cauldron', 'cauldron'), {'level' -> fill_level})
145 | );
146 | );
147 |
148 | setContainerFillLevel(block, fill_level) -> (
149 | slots = inventory_size(block);
150 | items = if(fill_level == 1, 1, ceil(slots * 64 / 14 * (fill_level - 1)));
151 | [dummy_item, dummy_nbt] = global_stackable_dummy_item;
152 | [unstackable_dummy_item, unstackable_dummy_nbt] = global_unstackable_dummy_item;
153 | if(fill_level <= 15,
154 | loop(slots,
155 | amount = min(items, 64);
156 | items += -amount;
157 | inventory_set(block, _, amount, dummy_item, if(system_info('game_pack_version') >= 33, {'components' -> dummy_nbt, 'id' -> dummy_item}, dummy_nbt));
158 | ),
159 | loop(slots,
160 | amount = min(64, items / 64);
161 | items += -if(amount < 1, amount, floor(amount)) * 64;
162 | if(amount < 1,
163 | inventory_set(block, _, amount * 64, dummy_item, if(system_info('game_pack_version') >= 33, {'components' -> dummy_nbt, 'id' -> dummy_item}, dummy_nbt)),
164 | inventory_set(block, _, if(_ == slots - 1, ceil(amount), floor(amount)), unstackable_dummy_item, if(system_info('game_pack_version') >= 33, {'components' -> unstackable_dummy_nbt, 'id' -> unstackable_dummy_item}, unstackable_dummy_nbt))
165 | );
166 | )
167 | );
168 | );
169 |
170 | // DUMMY ITEM
171 |
172 | printStackableDummyItem() -> (
173 | [item, nbt] = global_stackable_dummy_item;
174 | print(format('f » ', 'g The current stackable dummy item is ', if(nbt, ...[str('%s %s*', global_color, item), str('^g %s', nbt)], str('%s %s', global_color, item)))),
175 | );
176 |
177 | setStackableDummyItemFromHand() -> (
178 | holds = player()~'holds';
179 | if(!holds, _error('You are not holding any item'));
180 |
181 | setStackableDummyItem(holds);
182 | );
183 |
184 | setStackableDummyItem(item_tuple) -> (
185 | if(
186 | !item_tuple,
187 | global_stackable_dummy_item = global_default_stackable_dummy_item;
188 | print(format('f » ', 'g The stackable dummy item has been reset')),
189 | // else
190 | [item, count, nbt] = item_tuple;
191 | if(stack_limit(item) == 1, _error('You can use only stackable items'));
192 | if(system_info('game_pack_version') >= 33, nbt = nbt:'components');
193 | global_stackable_dummy_item = [item, nbt];
194 | print(format('f » ', 'g The stackable dummy item has been set to ', str('%s %s', global_color, item), if(nbt, str('^g %s', nbt)))),
195 | );
196 | );
197 |
198 | giveStackableDummyItem() -> (
199 | [item, nbt] = global_stackable_dummy_item;
200 | run(_giveCommand(item, nbt));
201 | );
202 |
203 | printUnstackableDummyItem() -> (
204 | [item, nbt] = global_unstackable_dummy_item;
205 | print(format('f » ', 'g The current unstackable dummy item is ', if(nbt, ...[str('%s %s*', global_color, item), str('^g %s', nbt)], str('%s %s', global_color, item)))),
206 | );
207 |
208 | setUnstackableDummyItemFromHand() -> (
209 | holds = player()~'holds';
210 | if(!holds, _error('You are not holding any item'));
211 |
212 | setUnstackableDummyItem(holds);
213 | );
214 |
215 | setUnstackableDummyItem(item_tuple) -> (
216 | if(
217 | !item_tuple,
218 | global_unstackable_dummy_item = global_default_unstackable_dummy_item;
219 | print(format('f » ', 'g The unstackable dummy item has been reset')),
220 | // else
221 | [item, count, nbt] = item_tuple;
222 | if(stack_limit(item) != 1, _error('You can use only unstackable items'));
223 | if(system_info('game_pack_version') >= 33, nbt = nbt:'components');
224 | global_unstackable_dummy_item = [item, nbt];
225 | print(format('f » ', 'g The unstackable dummy item has been set to ', str('%s %s', global_color, item), if(nbt, str('^g %s', nbt)))),
226 | );
227 | );
228 |
229 | giveUnstackableDummyItem() -> (
230 | [item, nbt] = global_unstackable_dummy_item;
231 | run(_giveCommand(item, nbt));
232 | );
233 |
--------------------------------------------------------------------------------
/programs/getallitems.sc:
--------------------------------------------------------------------------------
1 | // Get All Items by CommandLeo
2 |
3 | global_color = '#E84393';
4 | global_items = item_list();
5 | global_sort_alphabetically = false;
6 |
7 | global_obtainabilities = {'everything' -> 'Everything', 'main_storage' -> 'Main Storage', 'survival_obtainables' -> 'Survival Obtainables'};
8 | global_stackabilities = {'stackables' -> [16, 64], '64_stackables' -> [64], '16_stackables' -> [16], 'unstackables' -> [1]};
9 |
10 | global_survival_unobtainable_items = [
11 | 'bedrock',
12 | 'budding_amethyst',
13 | 'petrified_oak_slab',
14 | 'chorus_plant',
15 | 'spawner', // for 1.19.2-
16 | 'monster_spawner', // for 1.19.3+
17 | 'farmland',
18 | ...filter(global_items, _~'infested' != null),
19 | 'reinforced_deepslate',
20 | 'end_portal_frame',
21 | 'command_block',
22 | 'barrier',
23 | 'light',
24 | 'grass_path', // for 1.16-
25 | 'dirt_path', // for 1.17+
26 | 'repeating_command_block',
27 | 'chain_command_block',
28 | 'structure_void',
29 | 'structure_block',
30 | 'jigsaw',
31 | 'bundle',
32 | ...filter(global_items, _~'spawn_egg' != null),
33 | 'player_head',
34 | 'command_block_minecart',
35 | 'knowledge_book',
36 | 'debug_stick',
37 | 'frogspawn',
38 | 'trial_spawner',
39 | 'vault',
40 | 'test_block',
41 | 'test_instance_block'
42 | ];
43 | if(system_info('game_data_version') < 2825, global_survival_unobtainable_items += 'spore_blossom'); // 1.18 Experimental 1
44 | if(system_info('game_data_version') < 3066, global_survival_unobtainable_items += 'sculk_sensor'); // Deep Dark Experimental Snapshot 1
45 | global_junk_items = ['filled_map', 'written_book', 'tipped_arrow', 'firework_star', 'firework_rocket'];
46 | system_variable_set('survival_unobtainable_items', global_survival_unobtainable_items);
47 | system_variable_set('junk_items', global_junk_items);
48 |
49 | _checkVersion(version) -> (
50 | regex = '(\\d+)\.(\\d+)\.(\\d+)';
51 | target_version = map(version~regex, number(_));
52 | scarpet_version = map(system_info('scarpet_version')~regex, number(_));
53 | return(scarpet_version >= target_version);
54 | );
55 |
56 | __config() -> {
57 | 'commands' -> {
58 | '' -> 'menu',
59 | 'chests' -> ['giveChests', 'main_storage', 'stackables'],
60 | 'chests ' -> ['giveChests', null],
61 | 'chests ' -> 'giveChests',
62 |
63 | 'screen' -> ['showScreen', 'main_storage', 'stackables'],
64 | 'screen ' -> ['showScreen', null],
65 | 'screen ' -> 'showScreen'
66 | },
67 | 'arguments' -> {
68 | 'obtainability' -> {
69 | 'type' -> 'term',
70 | 'options' -> keys(global_obtainabilities)
71 | },
72 | 'stackability' -> {
73 | 'type' -> 'term',
74 | 'options' -> keys(global_stackabilities)
75 | }
76 | },
77 | 'requires' -> {
78 | 'carpet' -> '>=1.4.57'
79 | },
80 | 'scope' -> 'player'
81 | };
82 |
83 | menu() -> (
84 | texts = [
85 | 'fs ' + ' ' * 80, ' \n',
86 | str('%sb Get All Items', global_color), if(_checkVersion('1.4.57'), ...['@https://github.com/CommandLeo/scarpet/wiki/Get-All-Items', '^g Click to visit the wiki']), 'g by ', str('%sb CommandLeo', global_color), '^g https://github.com/CommandLeo', if(_checkVersion('1.4.57'), '@https://github.com/CommandLeo'),' \n\n',
87 | 'g A script to get all items in the game inside shulker boxes.', ' \n',
88 | 'g Run ', str('%s /%s screen', global_color, system_info('app_name')), str('!/%s screen', system_info('app_name')), '^g Click to run the command', 'g to view the shulker boxes in a screen or ', str('%s /%s chests', global_color, system_info('app_name')), str('!/%s chests', system_info('app_name')), '^g Click to run the command', 'g to get them in chests.', ' \n',
89 | 'fs ' + ' ' * 80
90 | ];
91 | print(format(texts));
92 | );
93 |
94 | getItems(category, stackability) -> (
95 | items = map(global_items, [_, null]);
96 | firework_rockets = map(range(3), ['firework_rocket', if(system_info('game_pack_version') >= 33, {'fireworks' -> {'flight_duration' -> _ + 1}}, {'Fireworks' -> {'Flight' -> _ + 1}})]);
97 | if(category == 'main_storage', put(items, items~['firework_rocket', null], firework_rockets, 'extend'));
98 | items = filter(items,
99 | [item, nbt] = _;
100 | category_check = if(
101 | category == 'main_storage',
102 | global_survival_unobtainable_items~item == null && (global_junk_items~item == null || nbt != null) && item~'shulker_box' == null,
103 | category == 'survival_obtainables',
104 | global_survival_unobtainable_items~item == null,
105 | true
106 | );
107 | stackability_check = !stackability || global_stackabilities:stackability~stack_limit(item) != null;
108 | item != 'air' && category_check && stackability_check;
109 | );
110 | if(!_checkVersion('1.4.113') || global_sort_alphabetically, items = sort_key(items, _:0));
111 | return(items);
112 | );
113 |
114 | giveChests(category, stackability) -> (
115 | items = getItems(category, stackability);
116 | shulker_boxes = map(range(ceil(length(items) / 27)), map(slice(items, _ * 27, min(length(items), (_ + 1) * 27)), [item, nbt] = _; if(system_info('game_pack_version') >= 33, {'slot' -> _i, 'item' -> {'id' -> item, 'components' -> nbt || {}}}, {'Slot' -> _i, 'id' -> item, 'Count' -> 1, ...if(nbt, {'tag' -> nbt}, {})})));
117 | loop(ceil(length(items) / 27 / 27),
118 | chest_contents = map(slice(shulker_boxes, _ * 27, min(ceil(length(items) / 27), (_ + 1) * 27)), if(system_info('game_pack_version') >= 33, {'slot' -> _i, 'item' -> {'id' -> 'white_shulker_box', 'components' -> {'container' -> _}}}, {'Slot' -> _i, 'id' -> 'white_shulker_box', 'Count' -> 1, 'tag' -> {'BlockEntityTag' -> {'Items' -> _}}}));
119 | run('/give @s chest' + if(system_info('game_pack_version') >= 33, str('[container=%s]', encode_nbt(chest_contents)), encode_nbt({'BlockEntityTag' -> {'Items' -> chest_contents}})));
120 | );
121 | );
122 |
123 | showScreen(category, stackability) -> (
124 | items = getItems(category, stackability);
125 | screen = create_screen(player(), 'generic_9x6', str('%s | %d items', global_obtainabilities:category, length(items)));
126 | loop(ceil(length(items) / 27),
127 | shulker_box_items = slice(items, _ * 27, min(length(items), (_ + 1) * 27));
128 | shulker_box_contents = map(shulker_box_items, [item, nbt] = _; if(system_info('game_pack_version') >= 33, {'slot' -> _i, 'item' -> {'id' -> item, 'components' -> nbt || {}}}, {'Slot' -> _i, 'id' -> item, 'Count' -> 1, ...if(nbt, {'tag' -> nbt}, {})}));
129 | inventory_set(screen, _, 1, 'white_shulker_box', if(system_info('game_pack_version') >= 33, {'components' -> {'container' -> shulker_box_contents}, 'id' -> 'white_shulker_box'}, {'BlockEntityTag' -> {'Items' -> shulker_box_contents}}));
130 | );
131 | );
--------------------------------------------------------------------------------
/programs/getfullbox.sc:
--------------------------------------------------------------------------------
1 | // Full Shulker Box Generator by CommandLeo
2 |
3 | global_colors = ['white', 'orange', 'magenta', 'light_blue', 'yellow', 'lime', 'pink', 'gray', 'light_gray', 'cyan', 'purple', 'blue', 'brown', 'green', 'red', 'black'];
4 |
5 | __config() -> {
6 | 'commands' -> {
7 | '
- ' -> ['getFullBox', null],
8 | '
- ' -> 'getFullBox'
9 | },
10 | 'arguments' -> {
11 | 'item' -> {
12 | 'type' -> 'item'
13 | },
14 | 'box_color' -> {
15 | 'type' -> 'term',
16 | 'options' -> global_colors
17 | }
18 | }
19 | };
20 |
21 | getFullBox(item_tuple, box_color) -> (
22 | slot = inventory_find(player(), 'air');
23 | if(slot < 0 || slot >= 36, exit(print(format('r No space left in your inventory'))));
24 | [item, count, nbt] = item_tuple;
25 | shulker_box = if(box_color, str('%s_shulker_box', box_color), 'shulker_box');
26 | box_content = map(range(27), if(system_info('game_pack_version') >= 33, {'slot' -> _, 'item' -> {'id' -> item, 'count' -> stack_limit(item), 'components' -> nbt:'components' || {}}}, {'id' -> item, 'Count' -> stack_limit(item), 'Slot' -> _, 'tag' -> nbt}));
27 | inventory_set(player(), slot, 1, shulker_box, if(system_info('game_pack_version') >= 33, {'components' -> {'container' -> box_content}, 'id' -> shulker_box}, {'BlockEntityTag' -> {'Items' -> box_content}}));
28 | );
29 |
--------------------------------------------------------------------------------
/programs/gradient.sc:
--------------------------------------------------------------------------------
1 | // Gradient Generator by CommandLeo
2 |
3 | global_charset = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
4 |
5 | __config() -> {
6 | 'commands' -> {
7 | '' -> 'help',
8 | 'print ' -> ['printGradient', false],
9 | 'print bold' -> ['printGradient', true],
10 | 'team ' -> ['teamGradient', false],
11 | 'team bold' -> ['teamGradient', true]
12 | },
13 | 'arguments' -> {
14 | 'text' -> {
15 | 'type' -> 'string',
16 | 'suggest' -> []
17 | },
18 | 'start_color' -> {
19 | 'type' -> 'string',
20 | 'suggester' -> _(args) -> (
21 | color = upper(args:'start_color' || '');
22 | if(!color || (length(color) < 6 && all(split(color), global_charset~_ != null)), map(global_charset, color + _));
23 | ),
24 | 'case_sensitive' -> false
25 | },
26 | 'end_color' -> {
27 | 'type' -> 'string',
28 | 'suggester' -> _(args) -> (
29 | color = upper(args:'end_color' || '');
30 | if(!color || (length(color) < 6 && all(split(color), global_charset~_ != null)), map(global_charset, color + _));
31 | ),
32 | 'case_sensitive' -> false
33 | }
34 | }
35 | };
36 |
37 | // HELPER FUNCTIONS
38 |
39 | _error(error) -> exit(print(format(str('r %s', error))));
40 |
41 | validateHex(string) -> (
42 | hex = upper(string)~'^#?([0-9A-F]{6}|[0-9A-F]{3})$';
43 | if(length(hex) == 3, hex = replace(hex, '(.)', '$1$1'));
44 | return(hex);
45 | );
46 |
47 | rgbToHex(rgb) -> upper(str('#%02x%02x%02x', rgb));
48 |
49 | hexToRgb(hex) -> (
50 | values = map(split(hex), global_charset~_);
51 | r = values:0 * 16 + values:1;
52 | g = values:2 * 16 + values:3;
53 | b = values:4 * 16 + values:5;
54 | return([r, g, b]);
55 | );
56 |
57 | generateGradient(text, start_color, end_color, bold) -> (
58 | input = split(text);
59 | l = length(filter(input, _ != ' ')) - 1;
60 |
61 | start_color = validateHex(start_color);
62 | end_color = validateHex(end_color);
63 | if(!start_color, _error('The start color is not a valid hex color'));
64 | if(!end_color, _error('The end color is not a valid hex color'));
65 |
66 | start_rgb = hexToRgb(start_color);
67 | end_rgb = hexToRgb(end_color);
68 | increment = (end_rgb - start_rgb) / l;
69 |
70 | i = -1;
71 | output = map(input, if(_ == ' ', ' \ ', str('%s%s %s', if(bold, 'b', ''), rgbToHex(start_rgb + increment * (i += 1)), _)));
72 | return(output);
73 | );
74 |
75 | // MAIN
76 |
77 | help() -> (
78 | texts = [
79 | 'fs ' + ' ' * 80, ' \n',
80 | ...generateGradient('Gradient Generator', '#6AB04C', '#22A6B3', true), 'g by ', '#1ABC9Cb CommandLeo', '^g https://github.com/CommandLeo', ' \n\n',
81 | '#1ABC9C /app_name print [bold] ', 'f | ', 'g Prints to chat a [bold] text colored with a gradient from to ', ' \n',
82 | '#1ABC9C /app_name team [bold] ', 'f | ', 'g Sets as the prefix of the team you belong to a [bold] text colored with a gradient from to ', ' \n',
83 | 'fs ' + ' ' * 80
84 | ];
85 | print(format(map(texts, replace(_, 'app_name', system_info('app_name')))));
86 | );
87 |
88 | printGradient(text, start_color, end_color, bold) -> (
89 | gradient = generateGradient(text, start_color, end_color, bold);
90 | print(format(gradient));
91 | );
92 |
93 | teamGradient(text, start_color, end_color, bold) -> (
94 | team = player()~'team';
95 | if(!team, _error('You must be in a team!'));
96 | team_property(team, 'prefix', format(generateGradient(text, start_color, end_color, bold)) + ' ');
97 | );
--------------------------------------------------------------------------------
/programs/itemlayout.sc:
--------------------------------------------------------------------------------
1 | // Item Layout by CommandLeo
2 |
3 | global_color = '#26DE81';
4 | global_directions = ['down', 'up', 'north', 'south', 'west', 'east'];
5 |
6 | global_default_block = load_app_data():'default_block' || 'gray_concrete';
7 | global_error_messages = {
8 | 'FILE_DELETION_ERROR' -> 'There was an error while deleting the file',
9 | 'FILE_WRITING_ERROR' -> 'There was an error while writing the file',
10 | 'ITEM_LAYOUT_ALREADY_EXISTS' -> 'A item layout with that name already exists',
11 | 'ITEM_LAYOUT_DOESNT_EXIST' -> 'The item layout %s doesn\'t exist',
12 | 'ITEM_LAYOUT_EMPTY' -> 'The %s item layout is empty',
13 | 'NOT_A_ROW_OF_BLOCKS' -> 'The area must be a row of blocks',
14 | 'NO_DEFAULT_BLOCK' -> 'There is no default block',
15 | 'NO_ITEM_LAYOUTS' -> 'There are no item layouts saved'
16 | };
17 |
18 | global_current_page = {};
19 |
20 | _checkVersion(version) -> (
21 | regex = '(\\d+)\.(\\d+)\.(\\d+)';
22 | target_version = map(version~regex, number(_));
23 | scarpet_version = map(system_info('scarpet_version')~regex, number(_));
24 | return(scarpet_version >= target_version);
25 | );
26 |
27 | __config() -> {
28 | 'commands' -> {
29 | '' -> 'menu',
30 | 'help' -> 'help',
31 |
32 | 'save ' -> 'saveItemLayout',
33 | 'paste ' -> ['pasteItemLayout', false],
34 | 'paste ' -> 'pasteItemLayout',
35 | 'delete ' -> ['deleteItemLayout', false],
36 | 'delete confirm' -> ['deleteItemLayout', true],
37 | 'list' -> 'listItemLayouts',
38 | ...if(_checkVersion('1.4.57'), {'view ' -> 'viewItemLayout'}, {}),
39 | 'default_block' -> 'getDefaultBlock',
40 | 'default_block get' -> 'getDefaultBlock',
41 | 'default_block set ' -> 'setDefaultBlock',
42 | 'default_block reset' -> ['setDefaultBlock', null],
43 | },
44 | 'arguments' -> {
45 | 'from_pos' -> {
46 | 'type' -> 'pos',
47 | 'loaded' -> true
48 | },
49 | 'to_pos' -> {
50 | 'type' -> 'pos',
51 | 'loaded' -> true
52 | },
53 | 'direction' -> {
54 | 'type' -> 'term',
55 | 'options' -> global_directions,
56 | 'case_sensitive' -> false
57 | },
58 | 'facing' -> {
59 | 'type' -> 'term',
60 | 'options' -> global_directions,
61 | 'case_sensitive' -> false
62 | },
63 | 'item_frames_only' -> {
64 | 'type' -> 'bool'
65 | },
66 | 'name' -> {
67 | 'type' -> 'term',
68 | 'suggest' -> [],
69 | 'case_sensitive' -> false
70 | },
71 | 'item_layout' -> {
72 | 'type' -> 'term',
73 | 'suggester' -> _(args) -> map(list_files('item_layouts', 'shared_text'), slice(_, length('item_layouts') + 1)),
74 | 'case_sensitive' -> false
75 | }
76 | },
77 | 'requires' -> {
78 | 'carpet' -> '>=1.4.44'
79 | },
80 | 'scope' -> 'global'
81 | };
82 |
83 | // HELPER FUNCTIONS
84 |
85 | _error(error) -> (
86 | print(format(str('r %s', error)));
87 | run(str('playsound block.note_block.didgeridoo master %s', player()~'command_name'));
88 | exit();
89 | );
90 |
91 | // UTILITY FUNCTIONS
92 |
93 | _scanStrip(from_pos, to_pos) -> (
94 | [x1, y1, z1] = from_pos;
95 | [x2, y2, z2] = to_pos;
96 | [dx, dy, dz] = map(to_pos - from_pos, if(_ < 0, -1, 1));
97 |
98 | if(
99 | x1 != x2,
100 | return(map(range(x1, x2 + dx, dx), block([_, y1, z1]))),
101 | y1 != y2,
102 | return(map(range(y1, y2 + dy, dy), block([x1, _, z1]))),
103 | z1 != z2,
104 | return(map(range(z1, z2 + dz, dz), block([x1, y1, _])))
105 | );
106 | return([block(from_pos)]);
107 | );
108 |
109 | _getItemAtPos(pos, direction) -> (
110 | pos1 = pos_offset(pos, direction);
111 | if(!air(pos1), return(_getItemFromBlock(block(pos1))));
112 |
113 | item_frame = entity_area('item_frame', pos1 + [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]):0 || entity_area('glow_item_frame', pos1 + [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]):0;
114 | if(item_frame, return(query(item_frame, 'item'):0 || replace(query(item_frame, 'nbt', 'Item.id'), '.+:', '')));
115 |
116 | return(_getItemFromBlock(block(pos)));
117 | );
118 |
119 | _getItemFromBlock(block) -> (
120 | if(!block || block == global_default_block, return('air'));
121 | if(item_list()~block != null, return(str(block)));
122 |
123 | return(
124 | if(
125 | block == 'bamboo_sapling', 'bamboo',
126 | block == 'beetroots', 'beetroot',
127 | block == 'big_dripleaf_stem', 'big_dripleaf',
128 | block == 'carrots', 'carrot',
129 | block == 'cocoa', 'cocoa_beans',
130 | block == 'pitcher_crop', 'pitcher_plant',
131 | block == 'potatoes', 'potato',
132 | block == 'powder_snow', 'powder_snow_bucket',
133 | block == 'redstone_wire', 'redstone',
134 | block == 'sweet_berry_bush', 'sweet_berries',
135 | block == 'tall_seagrass', 'seagrass',
136 | block == 'torchflower_crop', 'torchflower',
137 | block == 'tripwire', 'string',
138 | block~'cake', 'cake',
139 | block~'cauldron', 'cauldron',
140 | block~'cave_vine', 'glow_berries',
141 | block~'melon', 'melon_seeds',
142 | block~'pumpkin', 'pumpkin_seeds',
143 | block~'azalea_bush', replace(replace(block, '_bush', ''), 'potted_', ''),
144 | block~'plant', replace(block, '_plant', ''),
145 | block~'potted', replace(block, 'potted_', ''),
146 | block~'wall', replace(block, 'wall_', ''),
147 | 'air'
148 | )
149 | );
150 | );
151 |
152 | // MAIN
153 |
154 | menu() -> (
155 | texts = [
156 | 'fs ' + ' ' * 80, ' \n',
157 | str('%sb Item Layout', global_color), if(_checkVersion('1.4.57'), ...['@https://github.com/CommandLeo/scarpet/wiki/Item-Layout', '^g Click to visit the wiki']), 'g by ', str('%sb CommandLeo', global_color), '^g https://github.com/CommandLeo', if(_checkVersion('1.4.57'), '@https://github.com/CommandLeo'),' \n\n',
158 | 'g A tool to save a layout of items from a row of blocks and item frames to a file.', ' \n',
159 | 'g Run ', str('%s /%s help', global_color, system_info('app_name')), str('!/%s help', system_info('app_name')), '^g Click to run the command', 'g to see a list of all the commands.', ' \n',
160 | 'fs ' + ' ' * 80
161 | ];
162 | print(format(texts));
163 | );
164 |
165 | help() -> (
166 | texts = [
167 | 'fs ' + ' ' * 80, ' \n',
168 | '%color% /%app_name% save ', 'f |', 'g Saves an item layout from a row of blocks, looking for extra blocks or item frames in the specified direction', ' \n',
169 | '%color% /%app_name% paste []', 'f |', 'g Pastes an item layout starting from your current position toward the specified direction, with the item frames facing the specified direction', ' \n',
170 | '%color% /%app_name% delete ', 'f |', 'g Deletes an item layout', ' \n',
171 | '%color% /%app_name% list', 'f |', 'g Lists all item layouts', ' \n',
172 | if(_checkVersion('1.4.57'), ...['%color% /%app_name% view ', 'f |', 'g Displays the contents of an item layout inside a fancy menu', ' \n']),
173 | '%color% /%app_name% default_block [get|set|reset]', 'f |', 'g Gets, sets or resets the default block, the block type that will be ignored when saving an item layout', ' \n',
174 | 'fs ' + ' ' * 80
175 | ];
176 | replacement_map = {'%app_name%' -> system_info('app_name'), '%color%' -> global_color};
177 | print(format(map(texts, reduce(pairs(replacement_map), replace(_a, ..._), _))));
178 | );
179 |
180 | saveItemLayout(from_pos, to_pos, direction, name) -> (
181 | item_layout_path = str('item_layouts/%s', name);
182 | if(list_files('item_layouts', 'shared_text')~item_layout_path != null, _error(global_error_messages:'ITEM_LAYOUT_ALREADY_EXISTS'));
183 | if(length(filter(to_pos - from_pos, _ == 0)) != 2, _error(global_error_messages:'NOT_A_ROW_OF_BLOCKS'));
184 |
185 | items = map(_scanStrip(from_pos, to_pos), _getItemAtPos(_, direction));
186 | success = write_file(item_layout_path, 'shared_text', items);
187 |
188 | if(!success, _error(global_error_messages:'FILE_WRITING_ERROR'));
189 | print(format('f » ', 'g Successfully saved the ', str('%s %s', global_color, name), str('^g /%s view %s', system_info('app_name'), name), str('!/%s view %s', system_info('app_name'), name), 'g item layout'));
190 | run(str('playsound block.note_block.pling master %s', player()~'command_name'));
191 | );
192 |
193 | deleteItemLayout(item_layout, confirmation) -> (
194 | item_layout_path = str('item_layouts/%s', item_layout);
195 | if(list_files('item_layouts', 'shared_text')~item_layout_path == null, _error(str(global_error_messages:'ITEM_LAYOUT_DOESNT_EXIST', item_layout)));
196 |
197 | if(!confirmation, exit(print(format('f » ', 'g Click ', str('%sbu here', global_color), str('^g /%s delete %s confirm', system_info('app_name'), item_layout), str('!/%s delete %s confirm', system_info('app_name'), item_layout),'g to confirm the deletion of the ', str('%s %s', global_color, item_layout), 'g item layout'))));
198 |
199 | success = delete_file(item_layout_path, 'shared_text');
200 |
201 | if(!success, _error(global_error_messages:'FILE_DELETION_ERROR'));
202 | print(format('f » ', 'g Successfully deleted the ', str('%s %s', global_color, item_layout), 'g item layout'));
203 | run(str('playsound item.shield.break master %s', player()~'command_name'));
204 | );
205 |
206 | listItemLayouts() -> (
207 | files = list_files('item_layouts', 'shared_text');
208 | if(!files, _error(global_error_messages:'NO_ITEM_LAYOUTS'));
209 |
210 | item_layouts = map(files, slice(_, length('item_layouts') + 1));
211 |
212 | texts = reduce(item_layouts,
213 | [..._a, if(_i == 0, '', 'g , '), str('%s %s', global_color, _), if(_checkVersion('1.4.57'), ...[str('^g /%s view %s', system_info('app_name'), _), str('?/%s view %s', system_info('app_name'), _)])],
214 | ['f » ', 'g Saved item layouts: ']
215 | );
216 | print(format(texts));
217 | );
218 |
219 | viewItemLayout(item_layout) -> (
220 | item_layout_path = str('item_layouts/%s', item_layout);
221 | if(list_files('item_layouts', 'shared_text')~item_layout_path == null, _error(str(global_error_messages:'ITEM_LAYOUT_DOESNT_EXIST', item_layout)));
222 |
223 | entries = read_file(item_layout_path, 'shared_text');
224 | items = filter(entries, _ != 'air' && item_list()~_ != null);
225 | if(!items, _error(str(global_error_messages:'ITEM_LAYOUT_EMPTY', item_layout)));
226 |
227 | pages = map(range(length(items) / 45), slice(items, _i * 45, min(length(items), (_i + 1) * 45)));
228 |
229 | _setMenuInfo(screen, page_count, pages_length, items_length) -> (
230 | name = str('\'{"text":"Page %d/%d","color":"%s","italic":false}\'', page_count % pages_length + 1, pages_length, global_color);
231 | lore = [str('\'{"text":"%s entries","color":"gray","italic":false}\'', items_length)];
232 | nbt = if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> name, 'lore' -> lore}, 'id' -> 'paper'}, {'display' -> {'Name' -> name, 'Lore' -> lore}});
233 | inventory_set(screen, 49, 1, 'paper', nbt);
234 | );
235 |
236 | _setMenuItems(screen, page) -> (
237 | loop(45, inventory_set(screen, _, if(_ < length(page), 1, 0), page:_));
238 | );
239 |
240 | global_current_page:player() = 0;
241 |
242 | screen = create_screen(player(), 'generic_9x6', item_layout, _(screen, player, action, data, outer(pages), outer(items)) -> (
243 | if(length(pages) > 1 && action == 'pickup' && (data:'slot' == 48 || data:'slot' == 50),
244 | page = if(data:'slot' == 48, pages:(global_current_page:player += -1), data:'slot' == 50, pages:(global_current_page:player += 1));
245 | _setMenuInfo(screen, global_current_page:player, length(pages), length(items));
246 | _setMenuItems(screen, page);
247 | );
248 | if(action == 'pickup_all' || action == 'quick_move' || (action != 'clone' && data:'slot' != null && 0 <= data:'slot' <= 44) || (45 <= data:'slot' <= 53), return('cancel'));
249 | ));
250 |
251 | _setMenuItems(screen, pages:0);
252 |
253 | for(range(45, 54), inventory_set(screen, _, 1, 'gray_stained_glass_pane', if(system_info('game_pack_version') >= 33, {'components' -> {'hide_tooltip' -> {}}, 'id' -> 'gray_stained_glass_pane'}, {'display' -> {'Name' -> '\'{"text":""}\''}})));
254 | _setMenuInfo(screen, global_current_page:player(), length(pages), length(items));
255 | if(length(pages) > 1,
256 | inventory_set(screen, 48, 1, 'arrow', if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> str('\'{"text":"Previous page","color":"%s","italic":false}\'', global_color)}, 'id' -> 'arrow'}, {'display' -> {'Name' -> str('\'{"text":"Previous page","color":"%s","italic":false}\'', global_color)}}));
257 | inventory_set(screen, 50, 1, 'arrow', if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> str('\'{"text":"Next page","color":"%s","italic":false}\'', global_color)}, 'id' -> 'arrow'}, {'display' -> {'Name' -> str('\'{"text":"Next page","color":"%s","italic":false}\'', global_color)}}));
258 | );
259 | );
260 |
261 | pasteItemLayout(item_layout, direction, item_frame_direction, item_frames_only) -> (
262 | item_layout_path = str('item_layouts/%s', item_layout);
263 | if(list_files('item_layouts', 'shared_text')~item_layout_path == null, _error(str(global_error_messages:'ITEM_LAYOUT_DOESNT_EXIST', item_layout)));
264 |
265 | items = read_file(item_layout_path, 'shared_text');
266 | if(!items, _error(global_error_messages:'ITEM_LAYOUT_EMPTY'));
267 |
268 | origin_pos = player()~'pos';
269 | for(items,
270 | pos = pos_offset(origin_pos, direction, _i);
271 | set(pos, 'air');
272 | print(_);
273 | if(item_list()~_ == null, continue());
274 | if(!item_frames_only,
275 | if(block_list()~_ != null, continue(set(pos, _)));
276 | if(place_item(_, pos), continue());
277 | );
278 | if(global_default_block, set(pos, global_default_block));
279 | spawn('item_frame', pos_offset(pos, item_frame_direction), {'Facing' -> global_directions~item_frame_direction, 'Fixed' -> true, 'Item' -> {'id' -> _, 'Count' -> 1}});
280 | );
281 |
282 | print(format('f » ', 'g The ', str('%s %s', global_color, item_layout), 'g item layout has been pasted'));
283 | );
284 |
285 | // DEFAULT BLOCK
286 |
287 | getDefaultBlock() -> (
288 | if(global_default_block,
289 | print(format('f » ', 'g The default block is currently set to ', str('%s %s', global_color, global_default_block))),
290 | _error(global_error_messages:'NO_DEFAULT_BLOCK')
291 | );
292 | );
293 |
294 | setDefaultBlock(block) -> (
295 | global_default_block = block;
296 | if(block,
297 | print(format('f » ', 'g The default block has been set to ', str('%s %s', global_color, block))),
298 | print(format('f » ', 'g The default block has been reset'))
299 | );
300 | );
301 |
302 | // EVENTS
303 |
304 | __on_close() -> (
305 | if(global_default_block, store_app_data({'default_block' -> global_default_block}));
306 | );
--------------------------------------------------------------------------------
/programs/k.sc:
--------------------------------------------------------------------------------
1 | // Quick Killing by CommandLeo
2 |
3 | __config() -> {
4 | 'commands' -> {
5 | '' -> ['kill', 0],
6 | '' -> 'kill'
7 | },
8 | 'arguments' -> {
9 | 'distance' -> {
10 | 'type' -> 'int',
11 | 'suggest' -> []
12 | }
13 | },
14 | 'requires' -> {
15 | 'carpet' -> '>=1.4.57'
16 | },
17 | 'scope' -> 'global'
18 | };
19 |
20 | kill(distance) -> (
21 | killed_count = 0;
22 | for(['item', 'experience_orb'],
23 | entities = if(distance > 0, entity_area(_, system_info('source_position'), [distance, distance, distance]), entity_list(_));
24 | for(entities,
25 | modify(_, 'kill');
26 | killed_count += 1;
27 | );
28 | );
29 | print(format('f » ', 'g Killed ', str('d %d', killed_count), str('g entit%s', if(killed_count != 1, 'ies', 'y'))));
30 | );
31 |
--------------------------------------------------------------------------------
/programs/period.sc:
--------------------------------------------------------------------------------
1 | // Period by CommandLeo & Firigion
2 |
3 | global_color = '#3498DB';
4 | global_valid_blockstates = {'powered', 'power', 'extended', 'triggered', 'enabled'};
5 | global_littables = {'redstone_torch', 'redstone_wall_torch', 'redstone_lamp', 'redstone_ore'};
6 | global_highlight_color = 0x3498DB88;
7 |
8 | global_monitored = {};
9 | global_data = {};
10 |
11 | _checkVersion(version) -> (
12 | regex = '(\\d+)\.(\\d+)\.(\\d+)';
13 | target_version = map(version~regex, number(_));
14 | scarpet_version = map(system_info('scarpet_version')~regex, number(_));
15 | return(scarpet_version >= target_version);
16 | );
17 |
18 | __config() -> {
19 | 'commands' -> {
20 | '' -> 'help',
21 | 'monitor' -> ['monitor', null],
22 | 'monitor ' -> 'monitor',
23 | 'unmonitor' -> ['unmonitor', null],
24 | 'unmonitor ' -> 'unmonitor',
25 | 'clear' -> 'clear',
26 | 'list' -> 'list',
27 | 'highlight' -> 'highlightAll',
28 | 'highlight ' -> 'highlight',
29 | },
30 | 'arguments' -> {
31 | 'position' -> {
32 | 'type' -> 'pos',
33 | 'loaded' -> true
34 | }
35 | },
36 | 'scope' -> 'player'
37 | };
38 |
39 | _error(error) -> (
40 | print(format(str('r %s', error)));
41 | run(str('playsound block.note_block.didgeridoo master %s', player()));
42 | exit();
43 | );
44 |
45 | help() -> (
46 | texts = [
47 | 'fs ' + ' ' * 80, ' \n',
48 | '#2980B9b Period', if(_checkVersion('1.4.57'), '@https://github.com/CommandLeo/scarpet/wiki/Period'), 'g by ', '#%color%b CommandLeo', '^g https://github.com/CommandLeo', if(_checkVersion('1.4.57'), '@https://github.com/CommandLeo'), ' \n\n',
49 | '%color% /%app_name% monitor []', 'f |', 'g Starts monitoring the block you are looking at or at the specified position', ' \n',
50 | '%color% /%app_name% unmonitor []', 'f |', 'g Unmonitors the block you are looking at or at the specified position', ' \n',
51 | '%color% /%app_name% clear', 'f |', 'g Unmonitors all blocks', ' \n',
52 | '%color% /%app_name% list', 'f |', 'g Lists all monitored blocks', ' \n',
53 | '%color% /%app_name% highlight', 'f |', 'g Highlights all monitored blocks', ' \n',
54 | 'fs ' + ' ' * 80
55 | ];
56 | replacement_map = {'%app_name%' -> system_info('app_name'), '%color%' -> global_color};
57 | print(format(map(texts, reduce(pairs(replacement_map), replace(_a, ..._), _))));
58 | );
59 |
60 | isValid(block) -> (
61 | return(
62 | block~'command_block' != null // isCommandBlock
63 | || has(global_littables, str(block)) // isLittable
64 | || first(global_valid_blockstates, block_state(block, _)) != null // isRedstoneComponent
65 | );
66 | );
67 |
68 | isActive(block) -> (
69 | return(
70 | bool(block_state(block, 'extended')) // isExtendedPiston
71 | || bool(block_state(block, 'triggered')) // isTriggered
72 | || block == 'hopper' && !bool(block_state(block, 'enabled')) // isDisabledHopper
73 | || block_state(str(block), 'lit') != block_state(block, 'lit') // isLit
74 | || bool(block_state(block, 'powered')) || block_state(block, 'power') > 0 || bool(block_data(block):'powered') // isPowered
75 | );
76 | );
77 |
78 | monitor(position) -> (
79 | target = if(position, block(position), query(player(), 'trace', 5, 'blocks'));
80 | if(!target, _error('You must be looking at a block'));
81 | if(!isValid(target), _error('Invalid block'));
82 |
83 | dimension = current_dimension();
84 | data = {'position' -> pos(target), 'dimension' -> dimension};
85 | if(has(global_monitored, data), _error('That block is already being monitored'));
86 | global_monitored += data;
87 |
88 | run(str('playsound minecraft:block.note_block.pling master %s', player()));
89 | print(format('f » ', 'g Started monitoring ', str('gi %s', target), 'g at ', str('%s %s', global_color, str(pos(target))), str('^g %s', dimension), str('!/%s highlight %d %d %d %s', system_info('app_name'), ...pos(target), dimension)));
90 | );
91 |
92 | unmonitor(position) -> (
93 | target = if(position, block(position), query(player(), 'trace', 5, 'blocks'));
94 | if(!target, _error('You must be looking at a block'));
95 |
96 | dimension = current_dimension();
97 | data = {'position' -> pos(target), 'dimension' -> dimension};
98 | if(!has(global_monitored, data), _error('That block is not being monitored'));
99 | delete(global_monitored, data);
100 | delete(global_data, data);
101 |
102 | run(str('playsound minecraft:item.shield.break master %s', player()));
103 | print(format('f » ', 'g Successfully unmonitored ', str('gi %s', target), 'g at ', str('%s %s', global_color, str(pos(target))), str('^g %s', dimension)));
104 | );
105 |
106 | clear() -> (
107 | l = length(global_monitored);
108 | if(!l, _error('No blocks are being monitored'));
109 |
110 | global_monitored = {};
111 | global_data = {};
112 | print(format('f » ', 'g Unmonitored ', str('%s %s ', global_color, l), str('g block%s', if(l == 1, '', 's'))));
113 | );
114 |
115 | list() -> (
116 | l = length(global_monitored);
117 | if(!l, _error('No blocks are being monitored'));
118 | run(str('playsound minecraft:block.note_block.pling master %s', player()));
119 | texts = reduce(global_monitored, dimension = _:'dimension';
120 | position = _:'position';
121 | block = in_dimension(dimension, block(position));
122 | [..._a, ' \n', str('%s %s', global_color, str(position)), str('^g %s', dimension), str('!/execute in %s run tp @s %d %d %d', dimension, ...position), str('g %s ', block), '#EB4D4Bb ❌', '^g Click to unmonitor', str('!/execute in %s run %s unmonitor %d %d %d', dimension, system_info('app_name'), ...position), 'f |', '#8E44ADb ⚜', '^g Click to teleport', str('!/execute in %s run tp @s %d %d %d', dimension, ...position), 'f |', '#FBC531b ☀', '^g Click to highlight', str('!/%s highlight %d %d %d %s', system_info('app_name'), ...position, dimension)],
123 | ['f » ', 'g Monitoring ', str('%s %s ', global_color, l), str('g block%s:', if(l == 1, '', 's'))]
124 | );
125 | print(format(texts));
126 | );
127 |
128 | highlightAll() -> (
129 | l = length(global_monitored);
130 | if(l < 1, _error('There are no blocks to highlight'));
131 |
132 | for(global_monitored, in_dimension(_:'dimension', draw_shape('box', 100, {'player' -> player(), 'from' -> _:'position', 'to' -> _:'position' + 1, 'fill' -> global_highlight_color, 'color' -> 0})));
133 |
134 | run(str('playsound minecraft:entity.evoker.cast_spell master %s', player()));
135 | print(format('f » ', 'g Highlighted ', str('%s %s ', global_color, l), str('g blocks%s', if(l == 1, '', 's'))));
136 | );
137 |
138 | highlight(position, dimension) -> (
139 | if(!has(global_monitored, {'position' -> position, 'dimension' -> dimension}), _error('That block is not being monitored'));
140 |
141 | in_dimension(dimension, draw_shape('box', 100, {'player' -> player(), 'from' -> position, 'to' -> position + 1, 'fill' -> global_highlight_color, 'color' -> 0}));
142 | run(str('playsound minecraft:entity.evoker.cast_spell master %s', player()));
143 | );
144 |
145 | period() -> (
146 | for(global_monitored,
147 | dimension = _:'dimension';
148 | position = _:'position';
149 | block = in_dimension(dimension, block(position));
150 | if(!isValid(block) && block != 'moving_piston',
151 | delete(global_monitored, _);
152 | delete(global_data, _),
153 |
154 | if(isActive(block),
155 | if(!global_data:_:'was_active', (
156 | global_data:_ = global_data:_ || {};
157 | global_data:_:'was_active' = true;
158 | global_data:_:'on_tick' = tick_time() - 1
159 | ),
160 |
161 | global_data:_:'was_inactive',
162 | period_and_durations = [
163 | tick_time() - global_data:_:'on_tick',
164 | global_data:_:'off_tick'-global_data:_:'on_tick',
165 | tick_time() - global_data:_:'off_tick'
166 | ];
167 | if(global_data:_:'period' != period_and_durations,
168 | global_data:_:'period' = period_and_durations;
169 | if(player(), print(player(), format('#2980B9b Period', 'f » ', str('gi %s', block), 'g at ', str('%s %s', global_color, str(position)), str('^g %s', dimension), str('!/%s highlight %d %d %d %s', system_info('app_name'), ...position, dimension), 'f » ', str('%s %dgt', global_color, period_and_durations:0), str('^g Frequency: §3%.2fHz§7|On time: §3%dgt§7|Off time: §3%dgt', 20 / period_and_durations:0, period_and_durations:1, period_and_durations:2))));
170 | );
171 | global_data:_:'was_active' = false;
172 | global_data:_:'was_inactive' = false
173 | ),
174 | global_data:_:'was_active' && !global_data:_:'was_inactive',
175 | global_data:_:'off_tick' = tick_time();
176 | global_data:_:'was_inactive' = true
177 | )
178 | )
179 | );
180 | schedule(1, 'period');
181 | );
182 |
183 | __on_start() -> period();
--------------------------------------------------------------------------------
/programs/pulselength.sc:
--------------------------------------------------------------------------------
1 | // PulseLength by CommandLeo
2 |
3 | global_color = '#E74C3C';
4 | global_valid_blockstates = {'powered', 'power', 'extended', 'triggered', 'enabled'};
5 | global_littables = {'redstone_torch', 'redstone_wall_torch', 'redstone_lamp', 'redstone_ore'};
6 | global_highlight_color = 0xE74C3C88;
7 |
8 | global_monitored = {};
9 |
10 | _checkVersion(version) -> (
11 | regex = '(\\d+)\.(\\d+)\.(\\d+)';
12 | target_version = map(version~regex, number(_));
13 | scarpet_version = map(system_info('scarpet_version')~regex, number(_));
14 | return(scarpet_version >= target_version);
15 | );
16 |
17 | __config() -> {
18 | 'commands' -> {
19 | '' -> 'help',
20 | 'monitor' -> ['monitor', null],
21 | 'monitor ' -> 'monitor',
22 | 'unmonitor' -> ['unmonitor', null],
23 | 'unmonitor ' -> 'unmonitor',
24 | 'clear' -> 'clear',
25 | 'list' -> 'list',
26 | 'highlight' -> 'highlightAll',
27 | 'highlight ' -> 'highlight',
28 | },
29 | 'arguments' -> {
30 | 'position' -> {
31 | 'type' -> 'pos',
32 | 'loaded' -> true
33 | }
34 | },
35 | 'scope' -> 'player'
36 | };
37 |
38 | _error(error) -> (
39 | print(format(str('r %s', error)));
40 | run(str('playsound block.note_block.didgeridoo master %s', player()));
41 | exit();
42 | );
43 |
44 | help() -> (
45 | texts = [
46 | 'fs ' + ' ' * 80, ' \n',
47 | '#C0392Bb PulseLength', if(_checkVersion('1.4.57'), '@https://github.com/CommandLeo/scarpet/wiki/PulseLength'), 'g by ', '#%color%b CommandLeo', '^g https://github.com/CommandLeo', if(_checkVersion('1.4.57'), '@https://github.com/CommandLeo'), ' \n\n',
48 | '%color% /%app_name% monitor []', 'f |', 'g Starts monitoring the block you are looking at or at the specified position', ' \n',
49 | '%color% /%app_name% unmonitor []', 'f |', 'g Unmonitors the block you are looking at or at the specified position', ' \n',
50 | '%color% /%app_name% clear', 'f |', 'g Unmonitors all blocks', ' \n',
51 | '%color% /%app_name% list', 'f |', 'g Lists all monitored blocks', ' \n',
52 | '%color% /%app_name% highlight', 'f |', 'g Highlights all monitored blocks', ' \n',
53 | 'fs ' + ' ' * 80
54 | ];
55 | replacement_map = {'%app_name%' -> system_info('app_name'), '%color%' -> global_color};
56 | print(format(map(texts, reduce(pairs(replacement_map), replace(_a, ..._), _))));
57 | );
58 |
59 | isValid(block) -> (
60 | return(
61 | block~'command_block' != null // isCommandBlock
62 | || has(global_littables, str(block)) // isLittable
63 | || first(global_valid_blockstates, block_state(block, _)) != null // isRedstoneComponent
64 | );
65 | );
66 |
67 | isActive(block) -> (
68 | return(
69 | bool(block_state(block, 'extended')) // isExtendedPiston
70 | || bool(block_state(block, 'triggered')) // isTriggered
71 | || block == 'hopper' && !bool(block_state(block, 'enabled')) // isDisabledHopper
72 | || block_state(str(block), 'lit') != block_state(block, 'lit') // isLit
73 | || bool(block_state(block, 'powered')) || block_state(block, 'power') > 0 || bool(block_data(block):'powered') // isPowered
74 | );
75 | );
76 |
77 | monitor(position) -> (
78 | target = if(position, block(position), query(player(), 'trace', 5, 'blocks'));
79 | if(!target, _error('You must be looking at a block'));
80 | if(!isValid(target), _error('Invalid block'));
81 |
82 | dimension = current_dimension();
83 | data = {'position' -> pos(target), 'dimension' -> dimension};
84 | if(has(global_monitored, data), _error('That block is already being monitored'));
85 | global_monitored += data;
86 |
87 | run(str('playsound minecraft:block.note_block.pling master %s', player()));
88 | print(format('f » ', 'g Started monitoring ', str('gi %s', target), 'g at ', str('%s %s', global_color, str(pos(target))), str('^g %s', dimension), str('!/%s highlight %d %d %d %s', system_info('app_name'), ...pos(target), dimension)));
89 | );
90 |
91 | unmonitor(position) -> (
92 | target = if(position, block(position), query(player(), 'trace', 5, 'blocks'));
93 | if(!target, _error('You must be looking at a block'));
94 |
95 | dimension = current_dimension();
96 | data = {'position' -> pos(target), 'dimension' -> dimension};
97 | if(!has(global_monitored, data), _error('That block is not being monitored'));
98 | delete(global_monitored, data);
99 |
100 | run(str('playsound minecraft:item.shield.break master %s', player()));
101 | print(format('f » ', 'g Successfully unmonitored ', str('gi %s', target), 'g at ', str('%s %s', global_color, str(pos(target))), str('^g %s', dimension)));
102 | );
103 |
104 | clear() -> (
105 | l = length(global_monitored);
106 | if(!l, _error('No blocks are being monitored'));
107 |
108 | global_monitored = {};
109 | print(format('f » ', 'g Unmonitored ', str('%s %s ', global_color, l), str('g block%s', if(l == 1, '', 's'))));
110 | );
111 |
112 | list() -> (
113 | l = length(global_monitored);
114 | if(!l, _error('No blocks are being monitored'));
115 | run(str('playsound minecraft:block.note_block.pling master %s', player()));
116 | texts = reduce(global_monitored, dimension = _:'dimension';
117 | position = _:'position';
118 | block = in_dimension(dimension, block(position));
119 | [..._a, ' \n', str('%s %s', global_color, str(position)), str('^g %s', dimension), str('!/execute in %s run tp @s %d %d %d', dimension, ...position), str('g %s ', block), '#EB4D4Bb ❌', '^g Click to unmonitor', str('!/execute in %s run %s unmonitor %d %d %d', dimension, system_info('app_name'), ...position), 'f |', '#8E44ADb ⚜', '^g Click to teleport', str('!/execute in %s run tp @s %d %d %d', dimension, ...position), 'f |', '#FBC531b ☀', '^g Click to highlight', str('!/%s highlight %d %d %d %s', system_info('app_name'), ...position, dimension)],
120 | ['f » ', 'g Monitoring ', str('%s %s ', global_color, l), str('g block%s:', if(l == 1, '', 's'))]
121 | );
122 | print(format(texts));
123 | );
124 |
125 | highlightAll() -> (
126 | l = length(global_monitored);
127 | if(l < 1, _error('There are no blocks to highlight'));
128 |
129 | for(global_monitored, in_dimension(_:'dimension', draw_shape('box', 100, {'player' -> player(), 'from' -> _:'position', 'to' -> _:'position' + 1, 'fill' -> global_highlight_color, 'color' -> 0})));
130 |
131 | run(str('playsound minecraft:entity.evoker.cast_spell master %s', player()));
132 | print(format('f » ', 'g Highlighted ', str('%s %s ', global_color, l), str('g blocks%s', if(l == 1, '', 's'))));
133 | );
134 |
135 | highlight(position, dimension) -> (
136 | if(!has(global_monitored, {'position' -> position, 'dimension' -> dimension}), _error('That block is not being monitored'));
137 |
138 | in_dimension(dimension, draw_shape('box', 100, {'player' -> player(), 'from' -> position, 'to' -> position + 1, 'fill' -> global_highlight_color, 'color' -> 0}));
139 | run(str('playsound minecraft:entity.evoker.cast_spell master %s', player()));
140 | );
141 |
142 | pulselength() -> (
143 | for(global_monitored,
144 | dimension = _:'dimension';
145 | position = _:'position';
146 | block = in_dimension(dimension, block(position));
147 | if(!(isValid(block) || block == 'moving_piston'), delete(global_monitored, _),
148 | isActive(block), global_monitored:_ += 1,
149 | global_monitored:_ > 0, (
150 | if(player(), print(player(), format('#C0392Bb PulseLength', 'f » ', str('gi %s', block), 'g at ', str('%s %s', global_color, str(position)), str('^g %s', dimension), str('!/%s highlight %d %d %d %s', system_info('app_name'), ...position, dimension), 'f » ', str('%s %dgt', global_color, global_monitored:_))));
151 | global_monitored:_ = 0
152 | )
153 | );
154 | );
155 | schedule(1, 'pulselength');
156 | );
157 |
158 | __on_start() -> pulselength();
--------------------------------------------------------------------------------
/programs/randomizer.sc:
--------------------------------------------------------------------------------
1 | // Item Randomizer by CommandLeo
2 |
3 | global_color = '#9B59B6';
4 | global_containers = [...filter(item_list(), _~'shulker_box' != null), 'chest', 'barrel', 'hopper', 'dropper', 'dispenser'];
5 | global_modes = {
6 | 'single',
7 | 'single_random',
8 | 'single_stack',
9 | 'random',
10 | 'random_stacks',
11 | 'full',
12 | 'box_single',
13 | 'box_single_random',
14 | 'box_single_stack',
15 | 'box_random',
16 | 'box_random_stacks',
17 | 'box_full'
18 | };
19 | global_obtainabilities = {
20 | 'everything' -> 'Everything',
21 | 'main_storage' -> 'Main Storage',
22 | 'survival_obtainables' -> 'Survival Obtainables'
23 | };
24 | global_stackabilities = {
25 | 'stackables' -> [16, 64],
26 | '64_stackables' -> [64],
27 | '16_stackables' -> [16],
28 | 'unstackables' -> [1]
29 | };
30 | global_error_messages = {
31 | 'ALLITEMS_NOT_INSTALLED' -> 'You must install the allitems script to use this feature',
32 | 'FILE_DELETION_ERROR' -> 'There was an error while deleting the file',
33 | 'FILE_WRITING_ERROR' -> 'There was an error while writing the file',
34 | 'INVALID_INDEX' -> 'Invalid index',
35 | 'INVALID_ITEMS' -> 'Invalid items: %s',
36 | 'ITEM_LIST_DOESNT_EXIST' -> 'The item list %s doesn\'t exist',
37 | 'ITEM_LIST_EMPTY' -> 'The %s item list is empty',
38 | 'NOT_A_CONTAINER' -> 'That block is not a container',
39 | 'NOT_LOOKING_AT_ANY_BLOCK' -> 'You are not looking at any block',
40 | 'NO_CONTAINER_FOUND' -> 'No container was found',
41 | 'NO_ENTRIES_TO_REMOVE' -> 'No entries to remove from the table',
42 | 'NO_ITEMS_FOUND' -> 'No items were found',
43 | 'NO_ITEMS_PROVIDED' -> 'No items were provided',
44 | 'NO_ITEMS_TO_ADD' -> 'No items to add to the item list',
45 | 'NO_TABLES' -> 'There are no tables saved',
46 | 'SELECTED_AREA_EMPTY' -> 'The selected area is empty',
47 | 'TABLE_ALREADY_EXISTS' -> 'A table with that name already exists',
48 | 'TABLE_DOESNT_EXIST' -> 'The table %s doesn\'t exist',
49 | 'TABLE_EMPTY' -> 'The %s table is empty'
50 | };
51 |
52 | global_current_page = {};
53 |
54 | _checkVersion(version) -> (
55 | regex = '(\\d+)\.(\\d+)\.(\\d+)';
56 | target_version = map(version~regex, number(_));
57 | scarpet_version = map(system_info('scarpet_version')~regex, number(_));
58 | return(scarpet_version >= target_version);
59 | );
60 |
61 | __config() -> {
62 | 'strict' -> true,
63 | 'commands' -> {
64 | '' -> 'menu',
65 | 'help' -> 'help',
66 |
67 | 'create items ' -> 'createTableFromItems',
68 | 'create item_list ' -> 'createTableFromItemList',
69 | 'create all_items ' -> ['createTableFromAllItems', null],
70 | 'create all_items ' -> 'createTableFromAllItems',
71 | 'create containers' -> ['createTableFromContainers', null, null],
72 | 'create containers ' -> ['createTableFromContainers', null],
73 | 'create containers ' -> 'createTableFromContainers',
74 | 'create area ' -> 'createTableFromArea',
75 | 'rename
' -> 'renameTable',
76 | 'clone ' -> 'cloneTable',
77 | 'delete ' -> ['deleteTable', false],
78 | 'delete confirm' -> ['deleteTable', true],
79 | 'edit ' -> 'editTable',
80 | 'edit add items ' -> 'addEntriesToTableFromItems',
81 | 'edit add table ' -> 'addEntriesToTableFromTable',
82 | 'edit add containers' -> ['addEntriesToTableFromContainers', null, null],
83 | 'edit add containers ' -> ['addEntriesToTableFromContainers', null],
84 | 'edit add containers ' -> 'addEntriesToTableFromContainers',
85 | 'edit add area ' -> 'addEntriesToTableFromArea',
86 | 'edit remove items ' -> 'removeEntriesFromTableFromItems',
87 | 'edit remove table ' -> 'removeEntriesFromTableFromTable',
88 | 'edit remove index ' -> 'removeEntriesFromTableWithIndex',
89 | 'list' -> 'listTables',
90 | 'info ' -> 'infoTable',
91 | ...if(_checkVersion('1.4.57'), {'view ' -> 'viewTable'}, {}),
92 |
93 | 'insert ' -> ['insert', null, null],
94 | 'insert ' -> ['insert', null],
95 | 'insert ' -> 'insert',
96 |
97 | 'give ' -> 'giveContainer'
98 | },
99 | 'arguments' -> {
100 | 'name' -> {
101 | 'type' -> 'term',
102 | 'suggest' -> [],
103 | 'case_sensitive' -> false
104 | },
105 | 'table' -> {
106 | 'type' -> 'term',
107 | 'suggester' -> _(args) -> list_files('', 'text'),
108 | 'case_sensitive' -> false
109 | },
110 | 'other_table' -> {
111 | 'type' -> 'term',
112 | 'suggester' -> _(args) -> list_files('', 'text'),
113 | 'case_sensitive' -> false
114 | },
115 | 'index' -> {
116 | 'type' -> 'int',
117 | 'min' -> 0,
118 | 'suggester' -> _(args) -> (
119 | table = args:'table';
120 | items = _readTable(table);
121 | if(items, return([range(length(items))]));
122 | )
123 | },
124 | 'entries' -> {
125 | 'type' -> 'text',
126 | 'suggester' -> _(args) -> (
127 | table = args:'table';
128 | input = args:'entries';
129 | entries = split(' ', input);
130 | items = filter(map(_readTable(table), _:0), entries~_ == null);
131 | if(entries && slice(input, -1) != ' ', delete(entries, -1));
132 | return(if(entries, map(items, str('%s %s', join(' ', entries), _)), items));
133 | ),
134 | 'case_sensitive' -> false
135 | },
136 | 'items' -> {
137 | 'type' -> 'text',
138 | 'suggester' -> _(args) -> (
139 | input = args:'items';
140 | items = split(' ', input);
141 | if(items && slice(input, -1) != ' ', delete(items, -1));
142 | return(if(items, map(item_list(), str('%s %s', join(' ', items), _)), item_list()));
143 | ),
144 | 'case_sensitive' -> false
145 | },
146 | 'mode' -> {
147 | 'type' -> 'term',
148 | 'options' -> keys(global_modes),
149 | 'case_sensitive' -> false
150 | },
151 | 'container' -> {
152 | 'type' -> 'term',
153 | 'options' -> global_containers,
154 | 'case_sensitive' -> false
155 | },
156 | 'from_pos' -> {
157 | 'type' -> 'pos',
158 | 'loaded' -> true
159 | },
160 | 'to_pos' -> {
161 | 'type' -> 'pos',
162 | 'loaded' -> true
163 | },
164 | 'item_list' -> {
165 | 'type' -> 'term',
166 | 'suggester' -> _(args) -> map(list_files('item_lists', 'shared_text'), slice(_, length('item_lists') + 1)),
167 | 'case_sensitive' -> false
168 | },
169 | 'obtainability' -> {
170 | 'type' -> 'term',
171 | 'options' -> keys(global_obtainabilities)
172 | },
173 | 'stackability' -> {
174 | 'type' -> 'term',
175 | 'options' -> keys(global_stackabilities)
176 | }
177 | },
178 | 'requires' -> {
179 | 'carpet' -> '>=1.4.44'
180 | },
181 | 'scope' -> 'global'
182 | };
183 |
184 | // HELPER FUNCTIONS
185 |
186 | _error(error) -> (
187 | print(format(str('r %s', error)));
188 | run('playsound block.note_block.didgeridoo master @s');
189 | exit();
190 | );
191 |
192 | _removeDuplicates(list) -> filter(list, list~_ == _i);
193 |
194 | // UTILITY FUNCTIONS
195 |
196 | _readTable(table) -> (
197 | regex = '(\\w+)(\\{.+\\})?';
198 | entries = map(read_file(table, 'text'), results = _~regex; [lower(results:0), results:1 || null]);
199 | return(filter(entries, _ && _:0 != 'air' && item_list()~(_:0) != null));
200 | );
201 |
202 | _readItemList(item_list) -> (
203 | item_list_path = str('item_lists/%s', item_list);
204 | regex = '(\\w+)(\\{.+\\})?';
205 | entries = map(filter(read_file(item_list_path, 'shared_text'), _), results = _~regex; [lower(results:0), results:1 || null]);
206 | return(entries);
207 | );
208 |
209 | _itemToString(item_duple) -> (
210 | [item, nbt] = item_duple;
211 | return(item + (nbt || ''));
212 | );
213 |
214 | _itemToMap(slot, item, count, nbt) -> (
215 | if(
216 | system_info('game_pack_version') >= 33,
217 | {'slot' -> slot, 'item' -> {'id' -> item, 'count' -> count, 'components' -> if(nbt, parse_nbt(nbt), {})}},
218 | // else
219 | {'Slot' -> slot, 'id' -> item, 'Count' -> count, ...if(nbt, {'tag' -> parse_nbt(nbt)}, {})}
220 | );
221 | );
222 |
223 | _giveCommand(item, nbt) -> (
224 | return('give @s ' + item + if(nbt, if(system_info('game_pack_version') >= 33, '[' + join(',', map(nbt, _ + '=' + encode_nbt(nbt:_, true))) + ']', encode_nbt(nbt, true)), ''));
225 | );
226 |
227 | _getItemFromBlock(block) -> (
228 | if(item_list()~block != null, return(str(block)));
229 |
230 | return(
231 | if(
232 | block == 'bamboo_sapling', 'bamboo',
233 | block == 'beetroots', 'beetroot',
234 | block == 'big_dripleaf_stem', 'big_dripleaf',
235 | block == 'carrots', 'carrot',
236 | block == 'cocoa', 'cocoa_beans',
237 | block == 'pitcher_crop', 'pitcher_plant',
238 | block == 'potatoes', 'potato',
239 | block == 'powder_snow', 'powder_snow_bucket',
240 | block == 'redstone_wire', 'redstone',
241 | block == 'sweet_berry_bush', 'sweet_berries',
242 | block == 'tall_seagrass', 'seagrass',
243 | block == 'torchflower_crop', 'torchflower',
244 | block == 'tripwire', 'string',
245 | block~'cake', 'cake',
246 | block~'cauldron', 'cauldron',
247 | block~'cave_vine', 'glow_berries',
248 | block~'melon', 'melon_seeds',
249 | block~'pumpkin', 'pumpkin_seeds',
250 | block~'azalea_bush', replace(replace(block, '_bush', ''), 'potted_', ''),
251 | block~'plant', replace(block, '_plant', ''),
252 | block~'potted', replace(block, 'potted_', ''),
253 | block~'wall', replace(block, 'wall_', '')
254 | )
255 | );
256 | );
257 |
258 | _getReadingComparators(pos) -> (
259 | comparators = [];
260 | map(['north', 'east', 'south', 'west'],
261 | block1 = block(pos_offset(pos, _, -1));
262 | if(
263 | block1 == 'comparator' && block_state(block1, 'facing') == _,
264 | comparators += block1,
265 | solid(block1) && inventory_has_items(block1) == null,
266 | block2 = block(pos_offset(block1, _, -1));
267 | if(block2 == 'comparator' && block_state(block2, 'facing') == _, comparators += block2);
268 | );
269 | );
270 | return(comparators);
271 | );
272 |
273 | _updateComparators(block) -> (
274 | for(_getReadingComparators(block), update(_));
275 | );
276 |
277 | _getRandomContents(mode, items, size) -> (
278 | if(!items, return([]));
279 | [item, nbt] = rand(items);
280 |
281 | return(if(
282 | mode == 'single',
283 | [[item, 1, nbt]],
284 | mode == 'single_random',
285 | [[item, ceil(rand(stack_limit(item))), nbt]],
286 | mode == 'single_stack',
287 | [[item, stack_limit(item), nbt]],
288 | mode == 'random',
289 | map(range(size), [item, nbt] = rand(items); [item, ceil(rand(stack_limit(item))), nbt]),
290 | mode == 'random_stacks',
291 | map(range(size), [item, nbt] = rand(items); [item, stack_limit(item), nbt]),
292 | mode == 'full',
293 | map(range(size), [item, stack_limit(item), nbt]),
294 | mode~'box',
295 | map(range(size), item_maps = map(_getRandomContents(mode~'box_(.+)', items, 27), [item, count, nbt] = _; _itemToMap(_i, item, count, nbt)); ['white_shulker_box', 1, encode_nbt(if(system_info('game_pack_version') >= 33, {'container' -> item_maps}, {'BlockEntityTag' -> {'Items' -> item_maps}}), true)])
296 | ));
297 | );
298 |
299 | // MAIN
300 |
301 | menu() -> (
302 | texts = [
303 | 'fs ' + ' ' * 80, ' \n',
304 | str('%sb Item Randomizer', global_color), if(_checkVersion('1.4.57'), ...['@https://github.com/CommandLeo/scarpet/wiki/Item-Randomizer', '^g Click to visit the wiki']), 'g by ', str('%sb CommandLeo', global_color), '^g https://github.com/CommandLeo', if(_checkVersion('1.4.57'), '@https://github.com/CommandLeo'),' \n\n',
305 | 'g A tool to easily insert random items inside containers.', ' \n',
306 | 'g Run ', str('%s /%s help', global_color, system_info('app_name')), str('!/%s help', system_info('app_name')), '^g Click to run the command', 'g to see a list of all the commands.', ' \n',
307 | 'fs ' + ' ' * 80
308 | ];
309 | print(format(texts));
310 | );
311 |
312 | help() -> (
313 | texts = [
314 | 'fs ' + ' ' * 80, ' \n',
315 | '%color% /%app_name% create items ', 'f |', 'g Creates a table from a list of items', ' \n',
316 | '%color% /%app_name% create item_list ', 'f |', 'g Creates a table from an item list', ' \n',
317 | '%color% /%app_name% create container []', 'f |', 'g Creates a table from the items inside the container you are looking at or at the specified coords', ' \n',
318 | '%color% /%app_name% create area ', 'f |', 'g Creates a table from the blocks within the specified coordinates', ' \n',
319 | '%color% /%app_name% delete ', 'f |', 'g Deletes a table', ' \n',
320 | '%color% /%app_name% clone ', 'f |', 'g Creates a new table with the content of another table', ' \n',
321 | '%color% /%app_name% list', 'f |', 'g Lists all existing tables', ' \n',
322 | '%color% /%app_name% info ', 'f |', 'g Displays information about a table', ' \n',
323 | if(_checkVersion('1.4.57'), ...['%color% /%app_name% view ', 'f |', 'g Displays the content of a table inside a fancy GUI', ' \n']),
324 | '%color% /%app_name% edit ', 'f |', 'g Prints a menu to edit a table', ' \n',
325 | '%color% /%app_name% edit add items ', 'f |', 'g Adds items to a table', ' \n',
326 | '%color% /%app_name% edit add table ', 'f |', 'g Adds items to a table from another table', ' \n',
327 | '%color% /%app_name% edit remove items ', 'f |', 'g Removes items from a table', ' \n',
328 | '%color% /%app_name% edit remove index ', 'f |', 'g Removes a specific item from a table', ' \n',
329 | '%color% /%app_name% edit remove table ', 'f |', 'g Remove from a table the items contained in another table', ' \n',
330 | '%color% /%app_name% insert []', 'f |', 'g Inserts the table in the container you are looking at or at the specified coords', ' \n',
331 | '%color% /%app_name% export ', 'f |', 'g Exports the table as a loot table in a datapack', ' \n',
332 | 'fs ' + ' ' * 80
333 | ];
334 | replacement_map = {'%app_name%' -> system_info('app_name'), '%color%' -> global_color};
335 | print(format(map(texts, reduce(pairs(replacement_map), replace(_a, ..._), _))));
336 | );
337 |
338 | // TABLES
339 |
340 | createTableFromItems(name, item_string) -> (
341 | items = map(split(' ', item_string), [lower(_), null]);
342 |
343 | createTable(name, items);
344 | );
345 |
346 | createTableFromItemList(name, item_list) -> (
347 | item_list_path = str('item_lists/%s', item_list);
348 | if(list_files('item_lists', 'shared_text')~item_list_path == null, _error(str(global_error_messages:'ITEM_LIST_DOESNT_EXIST', item_list)));
349 |
350 | items = _readItemList(item_list);
351 | if(!items, _error(str(global_error_messages:'ITEM_LIST_EMPTY', item_list)));
352 |
353 | createTable(name, items);
354 | );
355 |
356 | createTableFromAllItems(name, category, stackability) -> (
357 | items = map(item_list(), [_, null]);
358 | survival_unobtainable_items = system_variable_get('survival_unobtainable_items');
359 | junk_items = system_variable_get('junk_items');
360 | firework_rockets = map(range(3), ['firework_rocket', if(system_info('game_pack_version') >= 33, {'fireworks' -> {'flight_duration' -> _ + 1}}, {'Fireworks' -> {'Flight' -> _ + 1}})]);
361 | if((category == 'main_storage' || category == 'survival_obtainables') && (!survival_unobtainable_items || !junk_items), _error(global_error_messages:'ALLITEMS_NOT_INSTALLED'));
362 | if(category == 'main_storage', put(items, items~['firework_rocket', null], firework_rockets, 'extend'));
363 | items = filter(items,
364 | [item, nbt] = _;
365 | category_check = if(
366 | category == 'main_storage',
367 | survival_unobtainable_items~item == null && (junk_items~item == null || nbt != null) && item~'shulker_box' == null,
368 | category == 'survival_obtainables',
369 | survival_unobtainable_items~item == null,
370 | true
371 | );
372 | stackability_check = !stackability || global_stackabilities:stackability~stack_limit(item) != null;
373 | item != 'air' && category_check && stackability_check;
374 | );
375 |
376 | createTable(name, items);
377 | );
378 |
379 | createTableFromContainers(name, from_pos, to_pos) -> (
380 | trace = query(player(), 'trace', 5, 'blocks');
381 | if(!from_pos,
382 | if(!trace, _error(global_error_messages:'NOT_LOOKING_AT_ANY_BLOCK'));
383 | from_pos = trace;
384 | );
385 | if(!to_pos,
386 | if(inventory_has_items(from_pos) == null, _error(global_error_messages:'NOT_A_CONTAINER'));
387 | to_pos = from_pos;
388 | );
389 |
390 | items = [];
391 | container_found = false;
392 |
393 | volume(from_pos, to_pos,
394 | block = _;
395 |
396 | if(inventory_has_items(from_pos),
397 | container_found = true;
398 | loop(inventory_size(block), item_tuple = inventory_get(block, _); if(item_tuple, [item, count, nbt] = item_tuple; items += [item, if(system_info('game_pack_version') >= 33, nbt:'components', nbt)]));
399 | );
400 | );
401 |
402 | if(!container_found, _error(global_error_messages:'NO_CONTAINER_FOUND'));
403 | if(!items, _error(global_error_messages:'NO_ITEMS_FOUND'));
404 |
405 | createTable(name, _removeDuplicates(items));
406 | );
407 |
408 | createTableFromArea(name, from_pos, to_pos) -> (
409 | items = {};
410 | ignored_blocks = {};
411 | volume(from_pos, to_pos, item = _getItemFromBlock(_); if(item, items += [item, null], ignored_blocks += str(_)));
412 |
413 | if(ignored_blocks, print(format('f » ', str('g The following blocks were ignored: %s', join(', ', keys(ignored_blocks))))));
414 | if(!items, _error(global_error_messages:'SELECTED_AREA_EMPTY'));
415 |
416 | createTable(name, keys(items));
417 | );
418 |
419 | createTable(name, items) -> (
420 | if(list_files('', 'text')~name != null, _error(global_error_messages:'TABLE_ALREADY_EXISTS'));
421 | if(!items, _error(global_error_messages:'NO_ITEMS_PROVIDED'));
422 |
423 | invalid_items = filter(map(items, _:0), item_list()~_ == null);
424 | if(invalid_items, _error(str(global_error_messages:'INVALID_ITEMS', join(', ', sort(_removeDuplicates(invalid_items))))));
425 |
426 | success = write_file(name, 'text', map(items, _itemToString(_)));
427 |
428 | if(!success, _error(global_error_messages:'FILE_WRITING_ERROR'));
429 | print(format('f » ', 'g Successfully created the ', str('%s %s', global_color, name), str('^g /%s %s %s', system_info('app_name'), if(_checkVersion('1.4.57'), 'view', 'info'), name), str('!/%s %s %s', system_info('app_name'), if(_checkVersion('1.4.57'), 'view', 'info'), name), 'g table'));
430 | run('playsound block.note_block.pling master @s');
431 | );
432 |
433 | renameTable(table, name) -> (
434 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
435 | if(list_files('', 'text')~name != null, _error(global_error_messages:'TABLE_ALREADY_EXISTS'));
436 |
437 | success1 = write_file(name, 'text', read_file(table, 'text'));
438 | if(!success1, _error(global_error_messages:'FILE_WRITING_ERROR'));
439 | success2 = delete_file(table, 'text');
440 | if(!success2, _error(global_error_messages:'FILE_DELETION_ERROR'));
441 |
442 | print(format('f » ', 'g Successfully renamed the ', str('%s %s', global_color, table), 'g table to ', str('%s %s', global_color, name)));
443 | run('playsound block.note_block.pling master @s');
444 | );
445 |
446 | cloneTable(table, name) -> (
447 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
448 | if(list_files('', 'text')~name != null, _error(global_error_messages:'TABLE_ALREADY_EXISTS'));
449 |
450 | success = write_file(name, 'text', read_file(table, 'text'));
451 | if(!success, _error(global_error_messages:'FILE_WRITING_ERROR'));
452 | print(format('f » ', 'g Successfully cloned the ', str('%s %s', global_color, table), 'g table'));
453 | run('playsound block.note_block.pling master @s');
454 | );
455 |
456 | deleteTable(table, confirmation) -> (
457 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
458 |
459 | if(!confirmation, exit(print(format('f » ', 'g Click ', str('%sbu here', global_color), str('^g /%s delete %s confirm', system_info('app_name'), table), str('!/%s delete %s confirm', system_info('app_name'), table),'g to confirm the deletion of the ', str('%s %s', global_color, table), 'g table'))));
460 | success = delete_file(table, 'text');
461 |
462 | if(!success, _error(global_error_messages:'FILE_DELETION_ERROR'));
463 | print(format('f » ', 'g Successfully deleted the ', str('%s %s', global_color, table), 'g table'));
464 | run('playsound minecraft:item.shield.break master @s');
465 | );
466 |
467 | editTable(table) -> (
468 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
469 |
470 | items = _readTable(table);
471 | if(!items, _error(str(global_error_messages:'TABLE_EMPTY', table)));
472 |
473 | print(format(reduce(items, [item, nbt] = _; [..._a, ' \n ', '#EB4D4Bb ❌', '^r Remove the item', str('?/%s edit %s remove index %d', system_info('app_name'), table, _i), ' ', str('g%s %s%s', if(item_list()~item == null, 's', ''), item, if(nbt, '*', '')), str('!/%s', _giveCommand(item, nbt)), if(item_list()~item == null, '^g Invalid item', nbt, str('^g %s', nbt), ''), str('!/%s', _giveCommand(item, nbt))], ['f » ', 'g Edit the ', str('%s %s', global_color, table), 'g item list: ', '#26DE81b (+)', '^#26DE81 Add more items', str('?/%s edit %s add', system_info('app_name'), table)])));
474 | );
475 |
476 | addEntriesToTableFromItems(table, item_string) -> (
477 | items = map(split(' ', item_string), [lower(_), null]);
478 |
479 | addEntriesToTable(table, items);
480 | );
481 |
482 | addEntriesToTableFromTable(table, other_table) -> (
483 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
484 | if(list_files('', 'text')~other_table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', other_table)));
485 |
486 | addEntriesToTable(table, _readTable(other_table));
487 | );
488 |
489 | addEntriesToTableFromContainers(table, from_pos, to_pos) -> (
490 | trace = query(player(), 'trace', 5, 'blocks');
491 | if(!from_pos,
492 | if(!trace, _error(global_error_messages:'NOT_LOOKING_AT_ANY_BLOCK'));
493 | from_pos = trace;
494 | );
495 | if(!to_pos,
496 | if(inventory_has_items(from_pos) == null, _error(global_error_messages:'NOT_A_CONTAINER'));
497 | to_pos = from_pos;
498 | );
499 |
500 | items = [];
501 | container_found = false;
502 |
503 | volume(from_pos, to_pos,
504 | block = _;
505 |
506 | if(inventory_has_items(from_pos),
507 | container_found = true;
508 | loop(inventory_size(block), item_tuple = inventory_get(block, _); if(item_tuple, [item, count, nbt] = item_tuple; items += [item, if(system_info('game_pack_version') >= 33, nbt:'components', nbt)]));
509 | );
510 | );
511 |
512 | if(!container_found, _error(global_error_messages:'NO_CONTAINER_FOUND'));
513 | if(!items, _error(global_error_messages:'NO_ITEMS_FOUND'));
514 |
515 | addEntriesToTable(table, _removeDuplicates(items));
516 | );
517 |
518 | addEntriesToTableFromArea(table, from_pos, to_pos) -> (
519 | items = {};
520 | ignored_blocks = {};
521 | volume(from_pos, to_pos, item = _getItemFromBlock(_); if(item, items += [item, null], ignored_blocks += str(_)));
522 |
523 | if(ignored_blocks, print(format('f » ', str('g The following blocks were ignored: %s', join(', ', keys(ignored_blocks))))));
524 | if(!items, _error(global_error_messages:'SELECTED_AREA_EMPTY'));
525 |
526 | addEntriesToTable(table, keys(items));
527 | );
528 |
529 | addEntriesToTable(table, entries) -> (
530 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
531 |
532 | items = _readTable(table);
533 | if(!items, _error(global_error_messages:'NO_ITEMS_TO_ADD'));
534 |
535 | invalid_items = filter(map(items, _:0), item_list()~_ == null);
536 | if(invalid_items, _error(str(global_error_messages:'INVALID_ITEMS', join(', ', sort(_removeDuplicates(invalid_items))))));
537 |
538 | success = write_file(table, 'text', map(entries, _itemToString(_)));
539 |
540 | if(!success, _error(global_error_messages:'FILE_WRITING_ERROR'));
541 | print(format('f » ', 'g Successfully added the items to the ', str('%s %s', global_color, table), 'g table'));
542 | run('playsound block.note_block.pling master @s');
543 | );
544 |
545 | removeEntriesFromTableFromItems(table, item_string) -> (
546 | items = map(split(' ', item_string), [lower(_), null]);
547 |
548 | removeEntriesFromTable(table, items);
549 | );
550 |
551 | removeEntriesFromTableFromTable(table, other_table) -> (
552 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
553 | if(list_files('', 'text')~other_table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', other_table)));
554 |
555 | removeEntriesFromTable(table, _readTable(other_table));
556 | );
557 |
558 | removeEntriesFromTable(table, entries) -> (
559 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
560 |
561 | items = _readTable(table);
562 |
563 | l1 = length(items);
564 | items = filter(items, [item, nbt] = _; entries~[item, nbt] == null && entries~[item, null] == null);
565 | l2 = length(items);
566 | if(l2 == l1, _error(global_error_messages:'NO_ENTRIES_TO_REMOVE'));
567 |
568 | delete_file(table, 'text');
569 | success = write_file(table, 'text', map(items, _itemToString(_)));
570 |
571 | if(!success, _error(global_error_messages:'FILE_WRITING_ERROR'));
572 | print(format('f » ', 'g Successfully removed the items from the ', str('%s %s', global_color, table), 'g table'));
573 | run('playsound block.note_block.pling master @s');
574 | );
575 |
576 | removeEntriesFromTableWithIndex(table, index) -> (
577 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
578 |
579 | items = _readTable(table);
580 | if(index < 0 || index >= length(items), _error(global_error_messages:'INVALID_INDEX'));
581 |
582 | delete(items:index);
583 |
584 | delete_file(table, 'text');
585 | success = write_file(table, 'text', map(items, _itemToString(_)));
586 |
587 | if(!success, _error(global_error_messages:'FILE_WRITING_ERROR'));
588 | print(format('f » ', 'g Successfully removed the item from the ', str('%s %s', global_color, table), 'g table'));
589 | run('playsound block.note_block.pling master @s');
590 | );
591 |
592 | listTables() -> (
593 | tables = list_files('', 'text');
594 | if(!tables, _error(global_error_messages:'NO_TABLES'));
595 |
596 | texts = reduce(tables,
597 | [..._a, if(_i == 0, '', 'g , '), str('%s %s', global_color, _), str('^g /%s %s %s', system_info('app_name'), if(_checkVersion('1.4.57'), 'view', 'info'), _), str('?/%s %s %s', system_info('app_name'), if(_checkVersion('1.4.57'), 'view', 'info'), _)],
598 | ['f » ', 'g Saved tables: ']
599 | );
600 | print(format(texts));
601 | );
602 |
603 | infoTable(table) -> (
604 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
605 |
606 | items = _readTable(table);
607 | if(!items, _error(str(global_error_messages:'TABLE_EMPTY', table)));
608 |
609 | texts = reduce(items, [item, nbt] = _; [..._a, if(length(items) < 12, ' \n', if(_i == 0, '', 'g , ')), str('g %s', if(length(items) < 12, ' ', '')), str('g%s %s%s', if(item_list()~item == null, 's', ''), item, if(nbt, '*', '')), str('!/%s', _giveCommand(item, nbt)), if(item_list()~item == null, '^g Invalid item', nbt, str('^g %s', nbt), '')], ['f » ', 'g The ', str('%s %s', global_color, table), 'g table contains the following items: ']);
610 | print(format(texts));
611 | );
612 |
613 | viewTable(table) -> (
614 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
615 |
616 | entries = _readTable(table);
617 | items = filter(entries, [item, nbt] = _; item != 'air' && item_list()~item != null);
618 | if(!items, _error(str(global_error_messages:'TABLE_EMPTY', table)));
619 |
620 | pages = map(range(length(items) / 45), slice(items, _i * 45, min(length(items), (_i + 1) * 45)));
621 |
622 | _setMenuInfo(screen, page_count, pages_length, items_length) -> (
623 | name = str('\'{"text":"Page %d/%d","color":"%s","italic":false}\'', page_count % pages_length + 1, pages_length, global_color);
624 | lore = [str('\'{"text":"%s entries","color":"gray","italic":false}\'', items_length)];
625 | nbt = if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> name, 'lore' -> lore}, 'id' -> 'paper'}, {'display' -> {'Name' -> name, 'Lore' -> lore}});
626 | inventory_set(screen, 49, 1, 'paper', nbt);
627 | );
628 |
629 | _setMenuItems(screen, page) -> (
630 | loop(45, [item, nbt] = page:_; inventory_set(screen, _, if(_ < length(page), 1, 0), item, if(system_info('game_pack_version') >= 33, {'components' -> nbt, 'id' -> item}, nbt)));
631 | );
632 |
633 | global_current_page:player() = 0;
634 |
635 | screen = create_screen(player(), 'generic_9x6', table, _(screen, player, action, data, outer(pages), outer(items)) -> (
636 | if(length(pages) > 1 && action == 'pickup' && (data:'slot' == 48 || data:'slot' == 50),
637 | page = if(data:'slot' == 48, pages:(global_current_page:player += -1), data:'slot' == 50, pages:(global_current_page:player += 1));
638 | _setMenuInfo(screen, global_current_page:player, length(pages), length(items));
639 | _setMenuItems(screen, page);
640 | );
641 | if(action == 'pickup_all' || action == 'quick_move' || (action != 'clone' && data:'slot' != null && 0 <= data:'slot' <= 44) || (45 <= data:'slot' <= 53), return('cancel'));
642 | ));
643 |
644 | _setMenuItems(screen, pages:0);
645 |
646 | for(range(45, 54), inventory_set(screen, _, 1, 'gray_stained_glass_pane', if(system_info('game_pack_version') >= 33, {'components' -> {'hide_tooltip' -> {}}, 'id' -> 'gray_stained_glass_pane'}, {'display' -> {'Name' -> '\'{"text":""}\''}})));
647 | _setMenuInfo(screen, global_current_page:player(), length(pages), length(items));
648 | if(length(pages) > 1,
649 | inventory_set(screen, 48, 1, 'arrow', if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> str('\'{"text":"Previous page","color":"%s","italic":false}\'', global_color)}, 'id' -> 'arrow'}, {'display' -> {'Name' -> str('\'{"text":"Previous page","color":"%s","italic":false}\'', global_color)}}));
650 | inventory_set(screen, 50, 1, 'arrow', if(system_info('game_pack_version') >= 33, {'components' -> {'custom_name' -> str('\'{"text":"Next page","color":"%s","italic":false}\'', global_color)}, 'id' -> 'arrow'}, {'display' -> {'Name' -> str('\'{"text":"Next page","color":"%s","italic":false}\'', global_color)}}));
651 | );
652 | );
653 |
654 | // INSERTION
655 |
656 | insert(mode, table, from_pos, to_pos) -> (
657 | trace = query(player(), 'trace', 5, 'blocks');
658 | if(!from_pos,
659 | if(!trace, _error(global_error_messages:'NOT_LOOKING_AT_ANY_BLOCK'));
660 | from_pos = trace;
661 | );
662 | if(!to_pos,
663 | if(inventory_has_items(from_pos) == null, _error(global_error_messages:'NOT_A_CONTAINER'));
664 | to_pos = from_pos;
665 | );
666 |
667 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
668 |
669 | items = _readTable(table);
670 | if(!items, _error(str(global_error_messages:'TABLE_EMPTY', table)));
671 |
672 | last_block = null;
673 | affected_blocks = volume(from_pos, to_pos,
674 | block = _;
675 |
676 | if(inventory_has_items(block) != null,
677 | size = inventory_size(block);
678 | loop(size, inventory_set(block, _, 0));
679 | for(_getRandomContents(mode, items, size), [item, count, nbt] = _; inventory_set(block, _i, count, item, if(system_info('game_pack_version') >= 33, {'components' -> nbt, 'id' -> item}, nbt)));
680 | _updateComparators(block);
681 | last_block = block;
682 | );
683 | );
684 |
685 | if(
686 | affected_blocks == 0,
687 | _error(global_error_messages:'NO_CONTAINER_FOUND'),
688 | affected_blocks == 1,
689 | print(format('f » ', 'g Inserted the ', str('%s %s', global_color, table), 'g table in ', str('gi %s', last_block), 'g at ' + pos(last_block))),
690 | // else
691 | print(format('f » ', 'g Inserted the ', str('%s %s', global_color, table), 'g table in ', str('%s %s', global_color, affected_blocks), str('g container%s', if(affected_blocks == 1, '', 's'))));
692 | );
693 | run('playsound block.note_block.pling master @s');
694 | );
695 |
696 | giveContainer(container, mode, table) -> (
697 | if(list_files('', 'text')~table == null, _error(str(global_error_messages:'TABLE_DOESNT_EXIST', table)));
698 |
699 | items = _readTable(table);
700 | if(!items, _error(str(global_error_messages:'TABLE_EMPTY', table)));
701 |
702 |
703 | item_maps = map(_getRandomContents(mode, items, 27), _itemToMap(_i, ..._));
704 | run(_giveCommand(container, if(system_info('game_pack_version') >= 33, {'container' -> item_maps}, {'BlockEntityTag' -> {'Items' -> item_maps}})));
705 | );
--------------------------------------------------------------------------------
/programs/stat.sc:
--------------------------------------------------------------------------------
1 | // Statistic Display by CommandLeo
2 |
3 | global_total_text = ' §lTotal';
4 | global_block_list = block_list();
5 | global_item_list = item_list();
6 | global_entity_list = entity_types('*');
7 | global_server_whitelisted = system_info('server_whitelisted') || length(system_info('server_whitelist')) > 0;
8 | global_app_name = system_info('app_name');
9 | global_hex_charset = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
10 |
11 | pickaxes = filter(global_item_list, _~'_pickaxe');
12 | axes = filter(global_item_list, _~'_axe');
13 | shovels = filter(global_item_list, _~'_shovel');
14 | hoes = filter(global_item_list, _~'_hoe');
15 |
16 | display_names = read_file('display_names', 'json');
17 | global_misc_stats = display_names:'misc';
18 | global_block_names = display_names:'blocks';
19 | global_item_names = display_names:'items';
20 | global_entity_names = display_names:'entities';
21 | global_categories = {'mined' -> '%s Mined', 'crafted' -> '%s Crafted', 'used' -> '%s Used', 'broken' -> '%s Broken', 'picked_up' -> '%s Picked Up', 'dropped' -> '%s Dropped', 'killed' -> '%s Killed', 'killed_by' -> 'Killed by %s', 'custom' -> '%s', 'extra' -> '%s', 'digs' -> 'Digs [%s]'};
22 | global_extra_stats = {'bedrock_removed' -> 'Bedrock Removed', 'ping' -> 'Ping', 'health' -> 'Health', 'xp_level' -> 'Levels of Experience', 'hunger' -> 'Hunger', 'saturation' -> 'Saturation', 'air' -> 'Remaining Air'};
23 | global_dig_data = {'combined_blocks' -> ['Combined Blocks', null], 'total' -> ['Total', [...pickaxes, ...shovels, ...axes, ...hoes, 'shears']], 'pick' -> ['Pickaxe', pickaxes], 'shovel' -> ['Shovel', shovels], 'pickshovel' -> ['Pickaxe & Shovel', [...pickaxes, ...shovels]], 'axe' -> ['Axe', axes], 'hoe' -> ['Hoe', hoes]};
24 |
25 | global_bedrock_removed = read_file('bedrock_removed', 'json') || {};
26 | global_digs = {};
27 | for(list_files('digs', 'json'), global_digs:slice(_, length('digs') + 1) = read_file(_, 'json'));
28 | global_carousel_data = read_file('carousel', 'json') || {'interval' -> 200, 'entries' -> []};
29 |
30 | settings = read_file('settings', 'json');
31 | global_stat = settings:'stat' || [];
32 | global_bots_included = settings:'bots_included';
33 | global_offline_digs = if(settings:'offline_digs' != null, settings:'offline_digs', true);
34 | global_total_enabled = if(settings:'total_enabled' != null, settings:'total_enabled', true);
35 | global_dig_display = settings:'dig_display' || {};
36 | global_dig_display_color = settings:'dig_display_color' || {};
37 | global_stat_color = settings:'stat_color' || 'FFEE44';
38 | global_default_dig = settings:'default_dig' || 'combined_blocks';
39 |
40 | global_help_pages = [
41 | [
42 | '%color% /%app_name% mined ', 'f | ', 'g Amount of mined', ' \n',
43 | '%color% /%app_name% used - ', 'f | ', 'g Amount of
- used or placed', ' \n',
44 | '%color% /%app_name% crafted
- ', 'f | ', 'g Amount of
- crafted', ' \n',
45 | '%color% /%app_name% dropped
- ', 'f | ', 'g Amount of
- dropped', ' \n',
46 | '%color% /%app_name% picked_up
- ', 'f | ', 'g Amount of
- picked up', ' \n',
47 | '%color% /%app_name% broken
- ', 'f | ', 'g Amount of
- broken', '^g (that ran out of durability)', ' \n',
48 | '%color% /%app_name% killed ', 'f | ', 'g Amount of killed', ' \n',
49 | '%color% /%app_name% killed_by ', 'f | ', 'g Amount of times killed you', ' \n',
50 | '%color% /%app_name% misc ', 'f | ', 'g Misc statistics, e.g. play_time, deaths, mob_kills, aviate_one_cm', ' \n',
51 | '%color% /%app_name% extra ', 'f | ', 'g Extra statistics that are not normally in the game, e.g. xp_level, ping, health, hunger', ' \n',
52 | '%color% /%app_name% bedrock_removed ', 'f | ', 'g Amount of bedrock removed by hand using pistons and tnt', ' \n',
53 | '%color% /%app_name% digs ', 'f | ', 'g Amount of digs (%default_dig% by default)', ' \n',
54 | '%color% /%app_name% combined ', 'f | ', 'g Multiple statistics combined together', ' \n'
55 | ],
56 | [
57 | '%color% /%app_name% print [] ', 'f | ', 'g Prints the value of a stat of a player', ' \n',
58 | '%color% /%app_name% hide ', 'f | ', 'g Hides the scoreboard', ' \n',
59 | '%color% /%app_name% show ', 'f | ', 'g Shows the scoreboard', ' \n',
60 | '%color% /%app_name% settings bots_included [on|off|toggle] ', 'f | ', 'g Includes or excludes bots in the scoreboard', ' \n',
61 | '%color% /%app_name% bots [on|off|toggle] ', 'f | ', 'g Shortcut for the command above', ' \n',
62 | '%color% /%app_name% settings default_dig ', 'f | ', 'g Sets the default dig type ', 'f *', '^g For server operators only', ' \n',
63 | '%color% /%app_name% settings offline_digs [on|off|toggle] ', 'f | ', 'g Includes or excludes digs of offline whitelisted players in the scoreboard', ' \n',
64 | '%color% /%app_name% settings total [on|off|toggle] ', 'f | ', 'g Enables or disables the total in the scoreboard', ' \n',
65 | '%color% /%app_name% settings dig_display [on|off|toggle] ', 'f | ', 'g Shows or hides digs in the player list footer', ' \n',
66 | '%color% /%app_name% settings dig_display_color ', 'f | ', 'g Changes the color of digs display for yourself; leave empty to reset', ' \n',
67 | '%color% /%app_name% settings stat_color ', 'f | ', 'g Changes the color of the scoreboard name for everyone; leave empty to reset ', 'f *', '^g For server operators only', ' \n'
68 | ],
69 | [
70 | '%color% /%app_name% settings combined_stats list ', 'f | ', 'g Lists combined statistics ', ' \n',
71 | '%color% /%app_name% settings combined_stats info ', 'f | ', 'g Prints the entries of a combined statistic ', ' \n',
72 | '%color% /%app_name% settings combined_stats create ', 'f | ', 'g Creates a combined statistic ', 'f *', '^g For server operators only', ' \n',
73 | '%color% /%app_name% settings combined_stats delete ', 'f | ', 'g Deletes a combined statistic ', 'f *', '^g For server operators only', ' \n\n',
74 | '%color% /%app_name% carousel start ', 'f | ', 'g Starts a carousel of statistics', ' \n',
75 | '%color% /%app_name% carousel stop ', 'f | ', 'g Stops the carousel', ' \n',
76 | '%color% /%app_name% carousel interval [] ', 'f | ', 'g Gets or sets the interval of the carousel', ' \n',
77 | '%color% /%app_name% carousel list ', 'f | ', 'g Lists carousel entries', ' \n',
78 | '%color% /%app_name% carousel add ', 'f | ', 'g Adds an entry to the carousel', ' \n',
79 | '%color% /%app_name% carousel remove ', 'f | ', 'g Removes an entry from the carousel', ' \n',
80 | ]
81 | ];
82 |
83 | __config() -> {
84 | 'resources' -> [
85 | {
86 | 'source' -> str('https://raw.githubusercontent.com/CommandLeo/scarpet/main/resources/stat/display_names/%d.json', system_info('game_major_target')),
87 | 'target' -> 'display_names.json'
88 | }
89 | ],
90 | 'commands' -> {
91 | '' -> 'menu',
92 | 'hide' -> 'hide',
93 | 'show' -> 'show',
94 | 'help' -> ['help', 1],
95 | 'help ' -> 'help',
96 |
97 | 'bots' -> ['toggleBots', null],
98 | 'bots on' -> ['toggleBots', true],
99 | 'bots off' -> ['toggleBots', false],
100 | 'bots toggle' -> ['toggleBots', null],
101 | 'settings bots_included' -> ['toggleBots', null],
102 | 'settings bots_included on' -> ['toggleBots', true],
103 | 'settings bots_included off' -> ['toggleBots', false],
104 | 'settings bots_included toggle' -> ['toggleBots', null],
105 | 'settings offline_digs' -> ['toggleOfflineDigs', null],
106 | 'settings offline_digs on' -> ['toggleOfflineDigs', true],
107 | 'settings offline_digs off' -> ['toggleOfflineDigs', false],
108 | 'settings offline_digs toggle' -> ['toggleOfflineDigs', null],
109 | 'settings total' -> ['toggleTotal', null],
110 | 'settings total on' -> ['toggleTotal', true],
111 | 'settings total off' -> ['toggleTotal', false],
112 | 'settings total toggle' -> ['toggleTotal', null],
113 | 'settings dig_display' -> ['toggleDigDisplay', null],
114 | 'settings dig_display on' -> ['toggleDigDisplay', true],
115 | 'settings dig_display off' -> ['toggleDigDisplay', false],
116 | 'settings dig_display toggle' -> ['toggleDigDisplay', null],
117 | 'settings dig_display_color' -> ['setDigDisplayColor', null],
118 | 'settings dig_display_color ' -> 'setDigDisplayColor',
119 | 'settings stat_color' -> ['setStatColor', null],
120 | 'settings stat_color ' -> 'setStatColor',
121 | 'settings default_dig ' -> 'setDefaultDig',
122 |
123 | 'settings combined_stats list' -> 'listCombinedStats',
124 | 'settings combined_stats info ' -> 'combinedStatInfo',
125 | 'settings combined_stats create mined blocks ' -> ['createCombinedStatFromBlocks', 'mined'],
126 | 'settings combined_stats create mined tag ' -> ['createCombinedStatFromBlockTag', 'mined'],
127 | 'settings combined_stats create crafted items ' -> ['createCombinedStatFromItems', 'crafted'],
128 | 'settings combined_stats create crafted tag ' -> ['createCombinedStatFromItemTag', 'crafted'],
129 | 'settings combined_stats create used items ' -> ['createCombinedStatFromItems', 'used'],
130 | 'settings combined_stats create used tag ' -> ['createCombinedStatFromItemTag', 'used'],
131 | 'settings combined_stats create broken items ' -> ['createCombinedStatFromItems', 'broken'],
132 | 'settings combined_stats create broken tag ' -> ['createCombinedStatFromItemTag', 'broken'],
133 | 'settings combined_stats create picked_up items ' -> ['createCombinedStatFromItems', 'picked_up'],
134 | 'settings combined_stats create picked_up tag ' -> ['createCombinedStatFromItemTag', 'picked_up'],
135 | 'settings combined_stats create dropped items ' -> ['createCombinedStatFromItems', 'dropped'],
136 | 'settings combined_stats create dropped tag ' -> ['createCombinedStatFromItemTag', 'dropped'],
137 | 'settings combined_stats create killed entities ' -> ['createCombinedStatFromEntities', 'killed'],
138 | 'settings combined_stats create killed_by entities ' -> ['createCombinedStatFromEntities', 'killed_by'],
139 | 'settings combined_stats create misc misc_entries ' -> 'createCombinedStatFromMiscEntries',
140 | 'settings combined_stats delete ' -> ['deleteCombinedStat', false],
141 | 'settings combined_stats delete