Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cbscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def compile_all(self):
if type != 'program':
self.log('Script does not contain a full program.')
return False

self.global_context = global_context.global_context(self.namespace)
global_environment = environment(self.global_context)
global_environment.set_dollarid('namespace', self.namespace)
Expand Down Expand Up @@ -142,6 +142,7 @@ def compile_all(self):
world.write_loot_tables(self.global_context.loot_tables)
world.write_predicates(self.global_context.predicates)
world.write_item_modifiers(self.global_context.item_modifiers)
world.write_data(parsed['data'])
world.write_zip()

self.dependencies = [source_file(d) for d in self.global_context.dependencies]
Expand Down
17 changes: 16 additions & 1 deletion mcworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_latest_log_file(self):
logfile = os.path.join(logsdir, 'latest.log')

return logfile

def write_functions(self, functions):
function_dir = f'data/{self.namespace}/functions/'

Expand Down Expand Up @@ -113,6 +113,21 @@ def write_mcmeta(self, desc):

self.zip.writestr(mcmeta_file, json.dumps({'pack':{'pack_format':1, 'description':desc}}, indent=4))

def write_data(self, data):
data_dir = 'data'
if data is not None:
for subdir, dirs, files in os.walk(data):
for file in files:
data_copy_path = os.path.join(subdir, file)

data_raw_path = os.path.relpath(data_copy_path, data)
data_zip_path = os.path.join(data_dir, data_raw_path)
if data_zip_path.replace(os.sep, '/') not in self.zip.namelist():
with open(data_copy_path, "rb") as file:
file_bytes = file.read()
self.zip.writestr(data_zip_path, file_bytes)


def write_zip(self):
self.zip.close()

Expand Down
2 changes: 1 addition & 1 deletion scriptlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'reset', 'clock', 'function', 'if', 'unless', 'then', 'do', 'else', 'switch', 'case', 'default',
'return', 'while', 'macro', 'block', 'block_data', 'block_tag', 'entity_tag', 'item_tag', 'define', 'array', 'remove', 'success', 'result',
'shaped', 'recipe', 'keys', 'eyes', 'feet', 'advancement', 'loot_table', 'predicate', "item_modifier",
'push', 'pop', 'true', 'false',
'push', 'pop', 'true', 'false', 'data'
)

tokens = keywords + (
Expand Down
19 changes: 14 additions & 5 deletions scriptparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,16 @@ def p_parsed_expr(p):

#### Program
def p_program(p):
'''program : optcomments dir string newlines optdesc file_params top_level_blocks'''
'''program : optcomments dir string newlines optdesc optdata file_params top_level_blocks'''
p[0] = {}
p[0]['dir'] = p[3]
p[0]['desc'] = p[5]
p[0]['data'] = p[6]

for param_name in p[6]:
p[0][param_name] = p[6][param_name]
for param_name in p[7]:
p[0][param_name] = p[7][param_name]

p[0]['lines'] = p[7]
p[0]['lines'] = p[8]

### Lib
def p_lib(p):
Expand Down Expand Up @@ -162,7 +163,15 @@ def p_file_param(p):
raise SyntaxError(f'Unknown file parameter: "{p[1]}" at line {p.lineno(1)}')

p[0] = (p[1], int(p[2]))


def p_optdata(p):
'''optdata : data string newlines
| empty'''
if len(p) < 4:
p[0] = None
else:
p[0] = p[2]

#### Sections
def p_section_commented(p):
'''section_commented : optcomments section'''
Expand Down