forked from BisUmTo/scarpet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlodestonebuttons.sc
41 lines (37 loc) · 1.55 KB
/
lodestonebuttons.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//////
// lodestonebuttons by BisUmTo (idea by Demi-Wrath)
// Place a button on a lodestone and link a compass to the lodestone
// Right click holding a lodestone compass will activate the button on the linked lodestone
//////
__on_player_uses_item(player, item_tuple, hand)->(
if(!item_tuple || item_tuple:0 != 'compass' || player~'trace' == 'lodestone', return());
[item, count, nbt] = item_tuple;
if(!nbt || !(pos = nbt:'LodestonePos'), return());
dimension = nbt:'LodestoneDimension';
pos = [pos:'X', pos:'Y', pos:'Z'];
modify(player,'swing',hand);
in_dimension(dimension,
pos_button = pos_offset(pos,'up');
if((block = block(pos_button)) ~ '_button$' == null,
sound('block.stone_button.click_off', pos(player), 1, 0.7);
return()
);
state = block_state(block);
if(state:'face' != 'floor' || state:'powered' == 'true',
sound('block.stone_button.click_off', pos(player), 1, 0.7);
return()
);
state:'powered' = 'true';
set(pos_button, block, state);
for(diamond(pos_button,2,2), update(_));
sound('block.stone_button.click_on', pos(player), 1, 1.2);
schedule(20, _(outer(block),outer(pos_button),outer(state),outer(player))->(
if(block(pos_button) == block,
state:'powered' = 'false';
set(pos_button, block, state);
for(diamond(pos_button,2,2), update(_));
sound('block.stone_button.click_off', pos(player));
)
))
)
)