Last active
July 29, 2023 02:14
-
-
Save szdytom/1c1ab414e06c69a701688896a8a1ba0b to your computer and use it in GitHub Desktop.
[Minecraft] Store items in the "cloud"!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__config -> {}; | |
__on_start() -> ( | |
if(nbt_storage('cloud_storage:item_data'):'Barrels' == null, ( | |
nbt_storage('cloud_storage:item_data', '{Barrels: []}'); | |
)) | |
); | |
upload_items(myself, bpos, name) -> ( | |
barrel = block(bpos); | |
if(barrel != 'barrel', ( | |
print('Barrel Removed'); | |
return(false); | |
)); | |
ename = escape_nbt(name); | |
if(nbt_storage('cloud_storage:item_data'):str('Barrels[{Name: "%s"}]', ename), ( | |
print('Name Conflict'); | |
return(false); | |
)); | |
run(str('data modify storage cloud_storage:item_data Barrels append value {Name: "%s"}', ename)); | |
run(str('data modify storage cloud_storage:item_data Barrels[{Name: "%s"}].Items set from block %d %d %d Items', | |
ename, bpos:0, bpos:1, bpos:2)); | |
c_for(i = 0, i < 27, i += 1, inventory_set(barrel, i, 0)); | |
print('OK'); | |
true | |
); | |
download_items(myself, bpos, name) -> ( | |
barrel = block(bpos); | |
if(barrel != 'barrel', ( | |
print('Barrel Removed'); | |
return(false); | |
)); | |
ename = escape_nbt(name); | |
items = nbt_storage('cloud_storage:item_data'):str('Barrels[{Name: "%s"}].Items', ename); | |
if(items == null, ( | |
print('Not Found'); | |
return(false); | |
)); | |
c_for(i = 0, has(items, '['+i+']'), i += 1, ( | |
items_i = items:('['+i+']'); | |
drop_item(barrel, items_i:'Slot'); | |
inventory_set(barrel, items_i:'Slot', items_i:'Count', items_i:'id', items_i:'tag'); | |
)); | |
put(block_data(bpos), '') | |
delete(nbt_storage('cloud_storage:item_data'):str('Barrels[{Name: "%s"}]', ename)); | |
print('OK'); | |
true | |
); | |
__on_player_clicks_block(myself, barrel, face) -> ( | |
if(barrel == 'barrel', ( | |
sslot = query(myself, 'selected_slot'); | |
handitem = inventory_get(myself, sslot); | |
if(handitem:0 == 'amethyst_shard', ( | |
bpos = pos(barrel); | |
is_upload = inventory_has_items(barrel); | |
pmt_scr = create_screen(myself, 'anvil', if(is_upload, 'Upload to:', 'Download from:'), _( | |
outer(bpos), outer(is_upload), | |
screen, myself, action, data) -> ( | |
if(action == 'pickup' && data:'slot' == 2, ( | |
renamed_item = inventory_get(screen, 2); | |
v = renamed_item:2; | |
name = decode_json(v:'display.Name'):'text'; | |
if(!name, return('cancel')); | |
if(is_upload, upload_items(myself, bpos, name)); | |
close_screen(screen); | |
), action == 'close', ( | |
return(null); | |
)); | |
'cancel' | |
)); | |
inventory_set(pmt_scr, 0, 1, 'amethyst_shard', '{display:{Name:\'{"text":""}\'}}'); | |
return('cancel'); | |
)); | |
)); | |
null | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment