Skip to content

Commit ffc8d17

Browse files
committed
Add blingedit header
1 parent b8eb631 commit ffc8d17

File tree

6 files changed

+118
-10
lines changed

6 files changed

+118
-10
lines changed

assembler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def jump_after_next(self, dest):
124124
self.jump_later = dest
125125

126126
def local_to_func_name(self, local_name):
127-
return self.sub_to_func_name(self.curr_sub) + '_local_' + local_name
127+
return self.sub_to_func_name(self.curr_sub) + '/' + local_name
128128

129129
def sub_to_func_name(self, sub_name):
130130
return 'sub_' + sub_name
@@ -145,10 +145,10 @@ def symbol_to_func(self, symbol):
145145
return self.sub_to_func_name(symbol)
146146

147147
def unique_func(self, hint):
148-
name = self.curr_func + '_' + hint
148+
name = self.curr_func + '/' + hint
149149
i = 1
150150
while name in self.function_subsequences:
151-
name = '%s_%s_%d' % (self.curr_func, hint, i)
151+
name = '%s/%s_%d' % (self.curr_func, hint, i)
152152
i += 1
153153
return name
154154

compiler_main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
parser.add_argument('-S', action='store_true',
2121
help="Don't run assembler. Outputs ASM to stdout")
2222
parser.add_argument('--world-dir', help="World Directory")
23-
parser.add_argument('--as_zip', action='store_true', help="Write datapack as zip file")
23+
parser.add_argument('--as-zip', action='store_true', help="Write datapack as zip file")
2424
parser.add_argument('--namespace', help="Function namespace", default='c_generated')
2525
parser.add_argument('--rem-existing', help="Remove existing functions in namespace",
2626
action='store_true')
@@ -36,6 +36,7 @@
3636
parser.add_argument('--spawn-location', default='~ ~2 ~',
3737
help="Location to spawn hidden armor stand")
3838
parser.add_argument('--pack-description', help="Datapack description")
39+
parser.add_argument('--extern', action='append', help="Specify external symbol")
3940

4041
args = parser.parse_args()
4142

@@ -97,7 +98,7 @@ def __iter__(self):
9798
page_size = 0
9899
session = CompilerSession((x, y, z), writer, args.namespace, stack_size=args.stack,
99100
args=sargs, setup_on_load=args.setup_on_load, debug=args.debug,
100-
page_size=page_size)
101+
page_size=page_size, extern=args.extern)
101102
assembler.write_to_session(session)
102103
setup, cleanup = session.create_up_down_functions(args.spawn_location)
103104
writer.close()

examples/blingedit.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#ifndef __BLING_EDIT_H
2+
#define __BLING_EDIT_H
3+
4+
#include <entity.h>
5+
#include <text.h>
6+
#include <mclib.h>
7+
8+
entity_local disp_plugins;
9+
10+
// Strange syntax, but this allows the entity_local to be attached to the player named "Global"
11+
entity_local plugin_can_run = "Global";
12+
entity_local loaded = "Global";
13+
14+
entity_local box_xmin = "Global";
15+
entity_local box_ymin = "Global";
16+
entity_local box_zmin = "Global";
17+
entity_local box_xmax = "Global";
18+
entity_local box_ymax = "Global";
19+
entity_local box_zmax = "Global";
20+
21+
entity_local box_center_x = "Global";
22+
entity_local box_center_y = "Global";
23+
entity_local box_center_z = "Global";
24+
25+
entity_local box_size_x = "Global";
26+
entity_local box_size_y = "Global";
27+
entity_local box_size_z = "Global";
28+
29+
entity_local rx1 = "Global";
30+
entity_local ry1 = "Global";
31+
entity_local rz1 = "Global";
32+
entity_local rx2 = "Global";
33+
entity_local ry2 = "Global";
34+
entity_local rz2 = "Global";
35+
36+
void run_plugin();
37+
38+
int blingedit_plugin_can_run()
39+
{
40+
CMD(function blingedit:plugin_can_run);
41+
return plugin_can_run;
42+
}
43+
44+
int blingedit_check_loaded()
45+
{
46+
CMD(function blingedit:check_loaded);
47+
return loaded;
48+
}
49+
50+
void click_handler()
51+
{
52+
if (blingedit_plugin_can_run()) {
53+
run_plugin();
54+
}
55+
CMD(gamerule sendCommandFeedback false);
56+
}
57+
58+
EVENT(minecraft:tick,, tick_handler)
59+
{
60+
select_players(sel_variable(disp_plugins >= 1)) {
61+
text_begin();
62+
text_begin();
63+
text_set_text(__str_quote([PLUGIN_NAME]));
64+
text_set_color("aqua");
65+
text_set_click_run(click_handler);
66+
text_end(TEXT_APPEND_PARENT);
67+
text_begin();
68+
text_set_text(" - by ");
69+
text_set_color("white");
70+
text_end(TEXT_APPEND_PARENT);
71+
text_begin();
72+
text_set_text(__str_quote(PLUGIN_AUTHOR));
73+
text_set_color("red");
74+
#ifdef PLUGIN_URL
75+
text_set_click_url(__str_quote(PLUGIN_URL));
76+
#endif
77+
text_end(TEXT_APPEND_PARENT);
78+
text_end(TEXT_TELLRAW);
79+
}
80+
}
81+
82+
#endif /* __BLING_EDIT_H */

examples/blingedit_test.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
3+
#define PLUGIN_NAME Test Plugin
4+
#define PLUGIN_AUTHOR Simon816
5+
#define PLUGIN_URL https://github.com/simon816/Command-Block-Assembly
6+
7+
#include "blingedit.h"
8+
9+
void run_plugin()
10+
{
11+
// Use static for performance improvement. (Only possible if not recursive)
12+
static int x, y, z;
13+
for (x = box_xmin; x <= box_xmax; ++x) {
14+
for (y = box_ymin; y <= box_ymax; y++) {
15+
for (z = box_zmin; z <= box_zmax; z++) {
16+
printf("(%d, %d, %d)", x, y, z);
17+
}
18+
}
19+
}
20+
}

main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
parser = argparse.ArgumentParser()
1010
parser.add_argument('file', help="ASM File", type=argparse.FileType('r'))
1111
parser.add_argument('--world-dir', help="World Directory")
12-
parser.add_argument('--as_zip', action='store_true', help="Write datapack as zip file")
12+
parser.add_argument('--as-zip', action='store_true', help="Write datapack as zip file")
1313
parser.add_argument('--namespace', help="Function namespace", default='asm_generated')
1414
parser.add_argument('--rem-existing', help="Remove existing functions in namespace",
1515
action='store_true')
@@ -25,6 +25,7 @@
2525
parser.add_argument('--spawn-location', default='~ ~2 ~',
2626
help="Location to spawn hidden armor stand")
2727
parser.add_argument('--pack-description', help="Datapack description")
28+
parser.add_argument('--extern', action='append', help="Specify external symbol")
2829

2930
args = parser.parse_args()
3031

@@ -54,7 +55,8 @@
5455
writer.open()
5556

5657
session = Session((x, y, z), writer, args.namespace, stack_size=args.stack,
57-
args=sargs, setup_on_load=args.setup_on_load, debug=args.debug)
58+
args=sargs, setup_on_load=args.setup_on_load, debug=args.debug,
59+
extern=args.extern)
5860
assembler.write_to_session(session)
5961
setup, cleanup = session.create_up_down_functions(args.spawn_location)
6062
writer.close()

session.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
from placer import CommandPlacer
55

66
class Scope:
7-
def __init__(self, namespace, tag_name, variables, args={}):
7+
def __init__(self, namespace, tag_name, variables, args={}, extern=[]):
88
self.entity_tag = namespace + '_' + tag_name
99
self.namespace = namespace
1010
self.variables = variables
1111
self.mem_locs = {}
1212
self.tags = {}
1313
self.args = args
1414
self.func_names = set()
15+
self.extern = set(extern or [])
1516

1617
def variable(self, name, args=()):
1718
var = self.variables[name]
@@ -20,6 +21,8 @@ def variable(self, name, args=()):
2021
return self.trim(self.namespace + '_' + var % args)
2122

2223
def entity_local(self, name):
24+
if name in self.extern:
25+
return name
2326
name = 'el_%s' % name
2427
self.variables[name] = name
2528
return self.variable(name)
@@ -80,7 +83,7 @@ def cmd_arg(self, param, val):
8083
class Session:
8184

8285
def __init__(self, pos, writer, namespace, stack_size=16, args={},
83-
setup_on_load=False, debug=False):
86+
setup_on_load=False, debug=False, extern=[]):
8487
self.placer = CommandPlacer(pos)
8588
self.writer = writer
8689
self.stack_size = stack_size
@@ -94,7 +97,7 @@ def __init__(self, pos, writer, namespace, stack_size=16, args={},
9497
'success_tracker': 'st',
9598
'sync_trigger': 'sy',
9699
'lookup_pointer': 'lk'
97-
}, args)
100+
}, args, extern)
98101
self.print_debug = debug
99102
self.setup_hook = None
100103
self.setup_on_load = setup_on_load

0 commit comments

Comments
 (0)