Skip to content

Commit 1b32f22

Browse files
committed
add 1.21.6 to versions
add experimental semicolon feature
1 parent d894065 commit 1b32f22

13 files changed

Lines changed: 63 additions & 4 deletions

File tree

packscript.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# /// script
44
# requires-python = ">=3.12"
55
# ///
6-
__version__ = '0.2.3'
6+
__version__ = '0.2.4'
77
__v_type__ = 'release'
88
__author__ = 'Slackow'
99
__license__ = 'MIT'
@@ -13,7 +13,7 @@
1313
modified_by = ''
1414
# # # # # # # # # # # # # # # # # # # # # #
1515

16-
latest_mc_version = '1.21.5'
16+
latest_mc_version = '1.21.6'
1717

1818
import textwrap, argparse, json, re, sys, shutil, tempfile
1919
from os import chdir
@@ -26,6 +26,7 @@ def ver(base_version, start, end, *, pf):
2626

2727
pack_formats = {
2828
'future': 9001,
29+
'1.21.6': 80,
2930
'1.21.5': 71,
3031
'1.21.4': 61,
3132
'1.21.3': 57, '1.21.2': 57,
@@ -122,6 +123,9 @@ def __enter__(self):
122123
def __exit__(self, exc_type, exc_val, exc_tb):
123124
func_stack.pop()
124125

126+
def replace(self):
127+
func_stack[-1] = self.func_name
128+
125129
def __function__(func_name: str) -> FuncContext:
126130
return FuncContext(func_name)
127131

@@ -219,15 +223,17 @@ def comp_file(output_folder: Path, parent: Path, filename: Path, globals: dict[s
219223
# It's basically grabbing from either the first or second group, since they're mutually exclusive
220224
contents = interpolation_re.sub(r'{\1\2}', contents)
221225
extra_line = None
222-
if contents.endswith(':'):
226+
if (end_chr := contents[-1:]) in (':', ';'):
223227
func_def_start = right_most_function(contents)
224228
# print('func: ', line)
225229
if func_def_start is None:
226-
raise ValueError(f'Command {contents!r} ends with colon but does not contain function')
230+
raise ValueError(f'Command {contents!r} ends with colon/semicolon but does not contain function')
227231
func_def = contents[func_def_start:-1].strip()
228232
code.append(f'{indent}__f, __extra = __function_name__(f"{func_def}")')
229233
contents = f'{contents[:func_def_start]} {{__f}}{{__extra}}'
230234
extra_line = f'{indent}with __function__(__f):'
235+
if end_chr == ';':
236+
extra_line = f'{indent}__function__(__f).replace()'
231237
code.append(f'{indent}__line__(rf""" {contents} """[1:-1])')
232238
if extra_line:
233239
code.append(extra_line)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/function tick [tick]:
2+
/execute as @a at @s run function:
3+
/execute if items @s weapon.mainhand cookie run function:
4+
/execute store result storage args length int 1 if data storage s items[]
5+
/function [] with storage args;
6+
/$execute store result storage args index int 1 run random value 1..$(length)
7+
/function [] with storage args;
8+
/$data modify storage args item set from storage s items[-$(index)]
9+
/function [] with storage args;
10+
/$give @p $(item)
11+
/function load [load]:
12+
/tellraw @a "Loaded BasicTest"
13+
/data modify storage s items set value [diamond, iron_ingot, gold_ingot]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"pack": {
3+
"pack_format": 41,
4+
"description": "Datapack 'BasicTest' for version 1.20.5"
5+
}
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"values": [
3+
"test:load"
4+
]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"values": [
3+
"test:tick"
4+
]
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated by PackScript 0.2.3-release by Slackow
2+
execute if items @s weapon.mainhand cookie run function test:anon/function_1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Generated by PackScript 0.2.3-release by Slackow
2+
execute store result storage args length int 1 if data storage s items[]
3+
function test:anon/function_2 with storage args
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Generated by PackScript 0.2.3-release by Slackow
2+
$execute store result storage args index int 1 run random value 1..$(length)
3+
function test:anon/function_3 with storage args
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Generated by PackScript 0.2.3-release by Slackow
2+
$data modify storage args item set from storage s items[-$(index)]
3+
function test:anon/function_4 with storage args
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated by PackScript 0.2.3-release by Slackow
2+
$give @p $(item)

0 commit comments

Comments
 (0)