portal renderer

This commit is contained in:
gnembon committed 2020-09-09 01:58:36 -03:00
1 parent 3105d5bb71
commit 224ce8d671
1 file changed
+128 -2
@@ -19,7 +19,12 @@ global_renderers = m(
l('handler', '__shape_renderer'),
l('tasks', m()),
l('range', 8)
))
)),
'portals' -> {
'active' -> false,
'handler' -> '__portal_renderer',
'tasks' -> {}
}
);
__command() -> '';
@@ -45,6 +50,10 @@ ruined_portal() -> __toggle('ruined_portal', 'structures');
slime_chunks() -> __toggle('slime_chunks', 'chunks');
portal_coordinates() -> __toggle('coords', 'portals');
portal_links() -> __toggle('links', 'portals');
clear() -> for(global_renderers, global_renderers:_:'tasks' = m() );
@@ -151,4 +160,121 @@ __chunk_renderer(player_name) ->
)
);
schedule(10, '__chunk_renderer', player_name);
)
);
__portal_renderer(player_name) ->
(
l(p, config) = __should_run('portals', player_name);
if (!p, return());
dim = p~'dimension';
shapes = [];
shape_duration = 6;
ppos = pos(p);
py = ppos:1;
if (dim == 'overworld',
//
nether_pos = [ppos:0/8, py, ppos:2/8];
if (has(config:'tasks':'coords'),
ow_x = 8*floor(nether_pos:0);
ow_z = 8*floor(nether_pos:2);
for (range(-5,6), dx = _;
for (range(-5,6), dz = _;
x = ow_x + 8*dx;
z = ow_z + 8*dz;
nx = x / 8;
nz = z / 8;
shapes += ['line', shape_duration, 'from', [x,0,z], 'to', [x,255,z], 'line', 5];
shapes += ['box', shape_duration, 'from', [x,0,z], 'to', [x+8,255,z+8], 'color', 0x00000000, 'fill', 0xffffff05];
shapes += ['label', shape_duration, 'pos', [x+4, 1,z+4], 'text', [nx, floor(py), nz], 'follow', p, 'snap', 'y'];
)
);
);
if (has(config:'tasks':'links'),
in_dimension('the_nether',
portals = map(poi(nether_pos, 16, 'nether_portal', 'any', true), [x,y,z]=_:2; [[x,y,z], [8*x,y,8*z]]);
if (portals,
sorted_portals = __sort_portals(nether_pos, portals);
offset = p~'look' + [0,p~'eye_height',0];
for(sorted_portals,
[pos, display] = _;
color = if(_i, 0x00999999, 0x990099ff);
to_rel = display-ppos;
shapes += ['line', shape_duration, 'line', 5, 'from', [0,0.5,0], 'to', to_rel, 'color', color,'follow', p];
to_dist = _euclidean([0,0,0],to_rel);
if (to_dist > 3,
direction = to_rel / to_dist;
shapes += ['label', shape_duration, 'pos', [0,0.5,0]+(2+1*_i)*direction, 'text', pos, 'color', color, 'follow', p];
)
)
)
)
);
, dim == 'the_nether',
look = query(p, 'trace', 10, 'blocks', 'exact');
if (look,
ly = look:1;
ow_pos = [8*look:0, look:1, 8*look:2];
nx = floor(8*look:0)/8;
nz = floor(8*look:2)/8;
shapes += ['box', shape_duration, 'from', [nx, ly-1, nz], 'to', [nx+0.125, ly+1, nz+0.125]];
if (has(config:'tasks':'coords'),
shapes += ['label', shape_duration, 'pos', look-ppos+[0,0.25,0], 'follow', p, 'text', map(ow_pos,floor(_))];
);
if (has(config:'tasks':'links'),
in_dimension('overworld',
portals = map(poi(ow_pos, 128, 'nether_portal', 'any', true), [x,y,z]=_:2; [[x,y,z], [x/8,y,z/8]]);
if (portals,
sorted_portals = __sort_portals(ow_pos, portals);
for(sorted_portals,
[pos, display] = _;
color = if(_i, 0x00999999, 0x990099ff);
to_rel = display-ppos;
shapes += ['line', shape_duration, 'line', 5, 'from', look-ppos+[0,1.0,0], 'to', to_rel, 'color', color, 'follow', p];
to_dist = _euclidean([0,0,0],to_rel);
if (to_dist > 3,
direction = to_rel / to_dist;
shapes += ['label', shape_duration, 'pos', look-ppos+[0,1.1,0]+(0.2+0.5*_i)*direction, 'text', pos, 'color', color, 'follow', p]
);
)
)
)
)
)
);
if (shapes, in_dimension(p, draw_shape(shapes)));
schedule(5, '__portal_renderer', player_name);
);
__sort_portals(ref_pos, portals) ->
(
point_map = {};
for (portals, point_map:(_:0) = _:1);
sorted_portals = sort_key(keys(point_map), _euclidean_sq(ref_pos, _)+0.0001*(_:1));
output_locations = [];
seen_portals = {};
for (sorted_portals,
[x,y,z] = _;
if ( !has(seen_portals, [x,y+1,z]) && !has(seen_portals, [x,y-1,z]),
output_locations += _;
);
seen_portals += _;
);
base_portals = [];
seen_bases = {};
for (output_locations,
[x,y,z] = _;
while(has(seen_portals, [x,y,z]), 256, y += -1);
y += 1;
seen_bases += [x,y,z];
if (!has(seen_bases, [x-1,y,z]) && !has(seen_bases, [x+1,y,z])
&& !has(seen_bases, [x,y,z-1]) && !has(seen_bases, [x,y,z+1]),
base_portals += [x,y,z];
)
);
map(base_portals, [_, point_map:_]);
);