Skip to content

Commit

Permalink
Magnet v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SirGavith committed Aug 21, 2020
1 parent 08dd2f5 commit 3f66720
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions magnet.sc
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,42 @@ __config()-> {'stay_loaded' -> true,'scope'->'global'};
//change this value to adjust the radius that blocks start moving toward you
global_pickup_radius = 7;

global_magnet_status = true;

__on_tick()->(
magnet_slot = inventory_find(player(), 'nether_star');
if(magnet_slot != null,
has_magnet = true;
if(global_magnet_status == true,
magnet_slot = inventory_find(player(), 'nether_star');
magnet_info = inventory_get(player(),magnet_slot);
//magnet_info:2 is the item NBT data
if( magnet_info:2 != null, //if item has NBT (a name)
item_name = split('"',split('text":"',split('Name:\'',magnet_info:2):1):1):0; //gets the name from the json
if(lower(item_name) == 'magnet', _magnetize());
if(
magnet_slot != null && __is_magnet('nether_star',magnet_info:2),
_magnetize();
);
);
);
);

__is_magnet(item_name,item_nbt) -> (
if(
//item_name == 'nether_star' && lower(split('"',split('":"',parse_nbt(item_nbt):'display':'Name'):1):0) == 'magnet',
item_name == 'nether_star' && lower(parse_nbt(parse_nbt(item_nbt):'display':'Name'):'text') == 'magnet',

return(true),
);
);

_display_title(target,location,title) -> run('title '+target+' '+location+' '+title);

__on_player_uses_item(player, item_tuple, hand)->(
if(
__is_magnet(item_tuple:0,item_tuple:2) == true,
if(
global_magnet_status == true,
global_magnet_status = false; _display_title(player(),'actionbar','"Magnet toggled off"'),
global_magnet_status = true; _display_title(player(),'actionbar','"Magnet toggled on"');
);
);
);


_magnetize() -> (
nearby_items = entity_selector('@e[type=item]');
for(nearby_items,
Expand Down

0 comments on commit 3f66720

Please sign in to comment.