diff --git a/magnet.sc b/magnet.sc index 3dda827..18e200d 100644 --- a/magnet.sc +++ b/magnet.sc @@ -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,