{
  "format_version": "1.20.50",
  "minecraft:block": {
    "description": {
      "identifier": "rc:handcrank",
      "menu_category": {
        "group": "itemGroup.name.create",
        "category": "Items"
      },
      "states": {
        "rc:lado": [ 0, 1, 2, 3, 4, 5 ],
        "rc:direcao": [ "null", "x", "y", "z" ],
        "rc:sentido": [ "estatico", "horario", "antihorario" ],
        "rc:working": [0,1,2],
        "rc:time": [0, 1, 2, 3],
        "rc:speed": [0,3]
      }
    },
    "components": {
      "minecraft:transformation": {
        "rotation": [0, 0, 0]
      },
      "minecraft:selection_box": {
        "origin": [ -6, 0, -6],
        "size": [ 12, 6, 12 ]
      },
      "minecraft:collision_box": {
        "origin": [ -6, 0, -6],
        "size": [ 12, 6, 12 ]
      },"minecraft:on_player_placing": {
        "event": "placed",
        "target": "self"
      },
      "minecraft:material_instances": {
        "*": {
          "texture": "handcrank",
          "render_method": "alpha_test"
        }
      },
      "minecraft:geometry": { 
         "identifier": "geometry.handcrank"
       },
       "minecraft:queued_ticking": {
         "interval_range": [
           1,
           1
         ],
         "looping": false,
         "on_tick": {
           "event": "stop"
         }
       },
       "minecraft:on_interact":{
         "event":"interacting"
       },
      "minecraft:destructible_by_mining": {
        "seconds_to_destroy": 0.3
      }
    },
    "events": {
      "interacting": {
        "sequence": [
          {
            "run_command":{
              "command":[
                "scoreboard players set world resetAll 0"
              ]
            }
          },
          {
            "condition": "query.block_state('rc:lado') == 0 || query.block_state('rc:lado') == 1",
            "set_block_state": {
              "rc:direcao": "'y'"
                    }
          },
          {
            "condition": "query.block_state('rc:lado') == 4 || query.block_state('rc:lado') == 5",
            "set_block_state": {
              "rc:direcao": "'x'"
                    }
          },
          {
            "condition": "query.block_state('rc:lado') == 2 || query.block_state('rc:lado') == 3",
            "set_block_state": {
              "rc:direcao": "'z'"
                    }
          },
          {
            "condition": "query.block_state('rc:time') < 3",
            "set_block_state": {
              "rc:time": "(query.block_state('rc:time')+1)"
            }
          },
          {
            "condition": "query.block_state('rc:time') == 3",
            "set_block_state": {
              "rc:time": 1
            }
          },
          {
            "condition":"!query.is_sneaking",
            "set_block_state":{
              "rc:working": 1
              }
            },
          {
            "condition":"query.is_sneaking",
            "set_block_state":{
              "rc:working": 2
              }
            },
            {
              "condition":"!query.is_sneaking",
              "set_block_state":{
                "rc:speed": 3
                }
              },
            {
              "condition":"query.is_sneaking",
              "set_block_state":{
                "rc:speed": 3
                }
              },
              {
                "condition":"!query.is_sneaking && ( query.block_state('rc:lado') == 1 || query.block_state('rc:lado') == 3 || query.block_state('rc:lado') == 5 )",
                "set_block_state":{
                  "rc:sentido": "'horario'"
                  }
                },
                {
                  "condition":"!query.is_sneaking && ( query.block_state('rc:lado') == 0 || query.block_state('rc:lado') == 2 || query.block_state('rc:lado') == 4 )",
                  "set_block_state":{
                    "rc:sentido": "'antihorario'"
                    }
                  },
                  {
                    "condition":"query.is_sneaking && ( query.block_state('rc:lado') == 1 || query.block_state('rc:lado') == 3 || query.block_state('rc:lado') == 5 )",
                    "set_block_state":{
                      "rc:sentido": "'antihorario'"
                      }
                    },
                    {
                      "condition":"query.is_sneaking && ( query.block_state('rc:lado') == 0 || query.block_state('rc:lado') == 2 || query.block_state('rc:lado') == 4 )",
                      "set_block_state":{
                        "rc:sentido": "'horario'"
                        }
                      }
        ]
      },
      "stop":{
        "sequence":[
          {"run_command":{
            "command":[
              "execute as @a at @a run scriptevent rc:resetAll"
            ]
          }},
        {
          "set_block_state":{
            "rc:working": 0
            }
            },
            {
              "set_block_state":{
                "rc:speed": 0
                }
                },
                {
                  "set_block_state":{
                    "rc:sentido": "'estatico'"
                    }
                    },
            {
              "set_block_state":{
              "rc:time": 0
              }
            }
          ]
        },
  "placed": {
    "sequence":[
      {
    "set_block_state": {
      "rc:lado": "(query.cardinal_block_face_placed_on)"
            }
          }
        ]
      }
    },
    "permutations": [
      {
          "condition": "query.block_state('rc:lado') == 1",
          "components": {
            "minecraft:transformation": {
              "rotation": [0, 0, 0]
            }
          }
      },
      {
        "condition": "query.block_state('rc:lado') == 3",
        "components": {    
          "minecraft:transformation": {
            "rotation": [90, 0, 0]
          }
        }
    },
    {
        "condition": "query.block_state('rc:lado') == 5",
        "components": {    
          "minecraft:transformation": {
            "rotation": [90, 90, 0]
          }
        }
    },
    {
        "condition": "query.block_state('rc:lado') == 0",
        "components": {
          "minecraft:transformation": {
            "rotation": [180, 0, 0]
          }
        }
    },
    {
      "condition": "query.block_state('rc:lado') == 2",
      "components": {    
        "minecraft:transformation": {
          "rotation": [-90, 0, 0]
        }
      }
  },
  {
      "condition": "query.block_state('rc:lado') == 4",
      "components": {    
        "minecraft:transformation": {
          "rotation": [90, -90, 0]
        }
      }
  },
    {
      "condition": "query.block_state('rc:working') == 0",
      "components": {
        "minecraft:material_instances": {
          "*": {
              "texture": "handcrank",
              "render_method": "alpha_test"
            }
          }
        }
      },
      {
        "condition": "query.block_state('rc:working') == 1",
        "components": {
          "minecraft:material_instances": {
            "*": {
                "texture": "handcrank_1",
                "render_method": "alpha_test"
            }
        }
        }
      },
      {
        "condition": "query.block_state('rc:working') == 2",
        "components": {
          "minecraft:material_instances": {
            "*": {
                "texture": "handcrank_2",
                "render_method": "alpha_test"
            }
        }
        }
      },
      {
        "condition": "query.block_state('rc:time') >= 1",
        "components": {
          "minecraft:queued_ticking": {
            "interval_range": [
              10,
              10
            ],
            "looping": true,
            "on_tick": {
              "event": "stop"
            }
          }
        }
      }
    ]
  }
}