modernize chunk_display.sc

This commit is contained in:
gnembon committed 2023-02-19 00:58:27 +01:00
1 parent 65de5492ac
commit 2bf6d638d7
1 file changed
+93 -86
@@ -1,100 +1,105 @@
global_update_interval = 100;
global_chunk_colors = m(
global_chunk_colors = {
// loaded ticking
l(3, l(0xAAdd0000, 0x66990000)), // lime, green
l(2, l(0xFF000000, 0x88000000)), // red
l(1, l(0xFFcc0000, 0xbbaa0000)), // yellowish
3 -> [0xAAdd0000, 0x66990000], // lime, green
2 -> [0xFF000000, 0x88000000], // red
1 -> [0xFFcc0000, 0xbbaa0000], // yellowish
// 'unloaded' (in memory, so rather 'inaccessible')
l(0, l(0xcccccc00, 0x11111100)), // gray / hi constast
0 -> [0xcccccc00, 0x11111100], // gray / hi constast
// stable full generation (for '0's, all 1,2,3 are always 'full')
l('full', l(0xbbbbbb00, 0x88888800)), // gray
'full' -> [0xbbbbbb00, 0x88888800], // gray
// unstable final bits
l('heightmaps', l(0x33333300, 0x22222200)), // checker
l('spawn', l(0x00333300, 0x00222200)), // checker
l('light_gen', l(0x55550000, 0x44440000)), // checker
'heightmaps' -> [0x33333300, 0x22222200], // checker
'spawn' -> [0x00333300, 0x00222200], // checker
'light_gen' -> [0x55550000, 0x44440000], // checker
// stable features
l('features', l(0x88bb2200, 0x66882200)), // green muddled
'features' -> [0x88bb2200, 0x66882200], // green muddled
//stable terrain
l('liquid_carvers', l(0x65432100, 0x54321000)), // browns
'liquid_carvers' -> [0x65432100, 0x54321000], // browns
//unstable terrain - not generated yet
l('carvers', l(0x33003300, 0x22002200)), // checker
l('surface', l(0x33330000, 0x22220000)), // checker
l('noise', l(0x33000000, 0x22000000)), // checker
l('biomes', l(0x00330000, 0x00220000)), // checker
l('structure_references', l(0x00003300, 0x00002200)), // checker
'carvers' -> [0x33003300, 0x22002200], // checker
'surface' -> [0x33330000, 0x22220000], // checker
'noise' -> [0x33000000, 0x22000000], // checker
'biomes' -> [0x00330000, 0x00220000], // checker
'structure_references' -> [0x00003300, 0x00002200], // checker
// stable
l('structure_starts', l(0x66666600, 0x22222200)), // darkgrey
'structure_starts' -> [0x66666600, 0x22222200], // darkgrey
// not stated yet
l('empty', l(0xFF888800, 0xDD444400)), // pink
'empty' -> [0xFF888800, 0xDD444400], // pink
// proper not in memory
l(null , l(0xFFFFFF00, 0xFFFFFF00)), // hwite
null -> [0xFFFFFF00, 0xFFFFFF00], // hwite
// ticket types
l('player', l(0x0000DD00, 0x00008800)), // blue
l('portal', l(0xAA00AA00, 0xAA00AA00)), // purple
l('dragon', l(0xAA008800, 0xAA008800)), // purple
l('forced', l(0xAABBFF00, 0x8899AA00)), // blue
l('light', l(0xFFFF0000, 0xBBBB0000)), // yellow
l('post_teleport', l(0xAA00AA00, 0xAA00AA00)), // purple
l('start', l(0xDDFF0000, 0xDDFF0000)), // lime, green
'player' -> [0x0000DD00, 0x00008800], // blue
'portal' -> [0xAA00AA00, 0xAA00AA00], // purple
'dragon' -> [0xAA008800, 0xAA008800], // purple
'forced' -> [0xAABBFF00, 0x8899AA00], // blue
'light' -> [0xFFFF0000, 0xBBBB0000], // yellow
'post_teleport' -> [0xAA00AA00, 0xAA00AA00], // purple
'start' -> [0xDDFF0000, 0xDDFF0000], // lime, green
// recent chunk requests
l('unknown', l(0xFF55FF00, 0xff99ff00)) // pink purple
);
'unknown' -> [0xFF55FF00, 0xff99ff00] // pink purple
};
// map representing current displayed chunkloading setup
global_current_setup = null;
// which blocks in the inventory represent which dimension
global_block_markers = m(
l('netherrack', 'the_nether'),
l('grass_block', 'overworld'),
l('end_stone', 'the_end')
);
__config() -> {
'commands' -> {
'<dimension> <radius>' -> ['__setup_tracker', null],
'<dimension> <radius> <center>' -> '__setup_tracker',
'clear' -> '__remove_previous_setup'
},
'arguments' -> {
'radius' -> {
'type' -> 'int',
'suggest' -> [16],
'min' -> 8,
'max' -> 64
},
'center' -> {
'type' -> 'columnpos'
},
}
};
// for legacy support
__on_player_uses_item(player, item_tuple, hand) ->
(
// which blocks in the inventory represent which dimension
global_block_markers = {
'netherrack' -> 'the_nether',
'grass_block' -> 'overworld',
'end_stone' -> 'the_end'
};
if (hand != 'mainhand', return());
if (!has(global_block_markers, item_tuple:0), return());
if (item_tuple:1%16 != 0, return());
new_setup = true;
if (global_current_setup,
new_setup = __remove_previous_setup(player)
);
if (!new_setup, return());
tag = nbt('{}');
put(tag:'Enchantments','[]');
put(tag:'Enchantments', '{lvl:1s,id:"minecraft:protection"}', 0);
inventory_set(player, player~'selected_slot', item_tuple:1, item_tuple:0, tag);
__setup_tracker(player, item_tuple);
print('setting chunkloading via item does not work anymore, use /chunk_display instead');
);
__remove_previous_setup(new_player) ->
__remove_previous_setup() ->
(
if (!global_current_setup, return());
global_running = false;
p = player();
if (p &&
global_block_markers:((item = inventory_get(p, global_current_setup:'inventory_slot')):0)==global_current_setup:'source_dimension' &&
item:1 == global_current_setup:'radius' &&
item:2,
inventory_set(p, global_current_setup:'inventory_slot', item:1, item:0, null); // disenchant
if( new_player == p && new_player~'selected_slot' == global_current_setup:'inventory_slot',
disabled = true
);
);
global_current_setup = null;
!disabled
global_status_cache = {};
);
__setup_tracker(player, item) ->
__setup_tracker(dimension, radius, columnpos) ->
(
setup = m();
setup:'player_name' = str(player);
setup:'inventory_slot' = player ~ 'selected_slot';
setup:'plot_dimension' = player ~ 'dimension';
setup:'plot_center' = map(pos(player), floor(_))-l(0,1,0);
setup:'radius' = item:1;
setup:'source_dimension' = global_block_markers:(item:0);
//player = player();
if (global_current_setup,
__remove_previous_setup()
);
setup = {};
setup:'plot_dimension' = current_dimension();// player ~ 'dimension';
setup:'plot_center' = map(pos(player()), floor(_))-[0,1,0];
setup:'radius' = radius;
setup:'source_dimension' = dimension;
multiplier = 1;
if (setup:'source_dimension' != setup:'plot_dimension',
multiplier = if (
@@ -102,48 +107,50 @@ __setup_tracker(player, item) ->
setup:'source_dimension' == 'the_end', 0,
8);
);
setup:'source_center' = setup:'plot_center' * multiplier;
setup:'source_center' = if (columnpos, [columnpos:0, 0, columnpos:1], setup:'plot_center' * multiplier);
print(setup:'source_dimension'+' around '+setup:'source_center'+' with '+setup:'radius'+' radius ('+ (2*setup:'radius'+1)^2 +' chunks)');
l(sx, sy, sz) = setup:'source_center';
global_status_cache = m();
[sx, sy, sz] = setup:'source_center';
global_status_cache = {};
loop( 2*setup:'radius'+1, dx = _ - setup:'radius';
loop( 2*setup:'radius'+1, dz = _ - setup:'radius';
source_pos = l(sx+16*dx,sy,sz+16*dz);
global_status_cache:source_pos = l(null, 0);
source_pos = [sx+16*dx,sy,sz+16*dz];
global_status_cache:source_pos = [null, 0];
)
);
global_current_setup = setup;
global_running = true;
schedule(0, '__chunk_visualizer_tick', player);
schedule(0, '__chunk_visualizer_tick');
);
global_status_cache = m();
global_status_cache = {};
__chunk_visualizer_tick(p) ->
__chunk_visualizer_tick() ->
(
setup = global_current_setup;
if(!setup, return());
if (!global_running, return());
show_activity = (p~'holds':0 == 'redstone_torch');
player = player();
show_activity = (player~'holds':0 == 'redstone_torch');
yval = setup:'plot_center':1+16;
base_update = global_update_interval;
random_component = ceil(0.4*base_update);
duration_max = ceil(1.5*base_update);
in_dimension( setup:'plot_dimension',
l(sx, sy, sz) = setup:'source_center';
l(px, py, pz) = setup:'plot_center';
[sx, sy, sz] = setup:'source_center';
[px, py, pz] = setup:'plot_center';
source_center = setup:'source_center';
radius = setup:'radius';
source_dimension = setup:'source_dimension';
shapes = l();
shapes = [];
now = tick_time();
loop( 2*radius+1, dx = _ - radius;
loop( 2*radius+1, dz = _ - radius;
changed = false;
source_pos = l(sx+16*dx,sy,sz+16*dz);
source_pos = [sx+16*dx,sy,sz+16*dz];
status = in_dimension( source_dimension,
loaded_status = loaded_status(source_pos);
if (loaded_status > 0, loaded_status, generation_status(source_pos))
@@ -155,29 +162,29 @@ __chunk_visualizer_tick(p) ->
if (loaded_status > 0,
tickets = in_dimension( source_dimension, chunk_tickets(source_pos));
for(tickets,
l(type, level) = _;
[type, level] = _;
if (show_activity || type != 'unknown',
status = type;
);
);
);
l(cached_status, expiry) = global_status_cache:source_pos;
[cached_status, expiry] = global_status_cache:source_pos;
changed = (status != cached_status);
if ( changed || (expiry < now),
global_status_cache:source_pos = l(status, now+base_update+floor(rand(random_component)));
bpos = l(dx/2, yval, dz/2);
global_status_cache:source_pos = [status, now+base_update+floor(rand(random_component))];
bpos = [dx/2, yval, dz/2];
bcol = global_chunk_colors:status:((dx+dz)%2);
shapes += l('box', duration_max, 'from', bpos, 'to', bpos + l(0.5,0,0.5),
'color', 0xffffff00, 'fill', bcol+128, 'follow', p, 'snap', 'xz');
shapes += ['box', duration_max, 'from', bpos, 'to', bpos + [0.5,0,0.5],
'color', 0xffffff00, 'fill', bcol+128, 'follow', player, 'snap', 'xz'];
if (changed,
pbcol = global_chunk_colors:cached_status:((dx+dz)%2);
shapes += l('box', 0, 'from', bpos, 'to', bpos + l(0.5,0,0.5),
'color', 0xffffff00, 'fill', pbcol+128, 'follow', p, 'snap', 'xz');
shapes += ['box', 0, 'from', bpos, 'to', bpos + [0.5,0,0.5],
'color', 0xffffff00, 'fill', pbcol+128, 'follow', player, 'snap', 'xz'];
);
);
);
);
draw_shape(shapes);
);
schedule(1, '__chunk_visualizer_tick', p)
schedule(1, '__chunk_visualizer_tick')
)