{
    "format_version": "1.20.50",
    "minecraft:block": {
        "description": {
            "identifier": "rc:mechanical_piston",
            "menu_category": {
                "category": "items",
                "group": "itemGroup.name.create",
                "is_hidden_in_commands": false
            },
            "states": {
                "rc:expanded": [false, true],
                "rc:speed": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
                "rc:direcao": [ "null", "x", "y", "z" ],
                "rc:sentido": [ "estatico", "horario", "antihorario" ]
            },
            "traits": {
                "minecraft:placement_direction": {
                    "enabled_states": ["minecraft:facing_direction", "minecraft:cardinal_direction"], 
                    "y_rotation_offset": 180.0 
                  }
            }
        },
        "components": {
            "minecraft:material_instances": {
                "*": {
                    "render_method": "alpha_test",
                    "texture": "andesite_casing_piston"
                },
                "piston_bottom": {
                    "render_method": "alpha_test",
                    "texture": "mechanical_piston_bottom"
                },
                "piston_inner": {
                    "render_method": "alpha_test",
                    "texture": "mechanical_piston_inner"
                },
                "piston_side": {
                    "render_method": "alpha_test",
                    "texture": "piston_side"
                },
                "piston_top": {
                    "render_method": "alpha_test",
                    "texture": "piston_top_normal"
                },
                "andesite_casing_piston":{
                    "render_method": "alpha_test",
                    "texture": "andesite_casing_piston"
                },
                "gearbox":{
                    "render_method": "alpha_test",
                    "texture": "piston_gearbox"
                },
                "pole_end": {
                    "render_method": "alpha_test",
                    "texture": "pole_end"
                },
                "shaft_h": {
                    "render_method": "alpha_test",
                    "texture": "shaft"
                },
                "shaft_a": {
                    "render_method": "alpha_test",
                    "texture": "shaft"
                }
            },
            "minecraft:geometry":{
                "identifier": "geometry.mechanical_piston",
                "bone_visibility": {
                    "top": "!q.block_state('rc:expanded')",
                    "pole": "q.block_state('rc:expanded')",
                    "shaft_h": "q.block_state('rc:sentido') == 'estatico' || q.block_state('rc:sentido') == 'horario'",
                    "shaft_a": "q.block_state('rc:sentido') == 'antihorario'"
                }
            },
            "minecraft:collision_box": true,
            "minecraft:selection_box": true,
            "minecraft:map_color": "#FFFFFF",
            "minecraft:on_placed": {
                "event": "placed"
            },
            "minecraft:queued_ticking": {
                "looping": true,
                "interval_range": [0, 0],
                "on_tick": {
                    "event": "update"
                }
            }
        },
        "events": {
            "placed": {
                "sequence": [
                    {
                        "condition": " (q.block_state('minecraft:facing_direction') == 'north' || q.block_state('minecraft:facing_direction') == 'south')",
                        "set_block_state":{
                            "rc:direcao": "'x'"
                        }
                    },
                    {
                        "condition": "(q.block_state('minecraft:facing_direction') == 'west' || q.block_state('minecraft:facing_direction') == 'east')",
                        "set_block_state":{
                            "rc:direcao": "'z'"
                        }
                    },
                    {
                        "condition": "(q.block_state('minecraft:facing_direction') == 'down') && (q.block_state('minecraft:cardinal_direction') == 'west' || q.block_state('minecraft:cardinal_direction') == 'east')",
                        "set_block_state":{
                            "rc:direcao": "'x'"
                        }
                    },
                    {
                        "condition": "(q.block_state('minecraft:facing_direction') == 'down') && (q.block_state('minecraft:cardinal_direction') == 'north' || q.block_state('minecraft:cardinal_direction') == 'south')",
                        "set_block_state":{
                            "rc:direcao": "'z'"
                        }
                    },
                    {
                        "condition": "(q.block_state('minecraft:facing_direction') == 'up') && (q.block_state('minecraft:cardinal_direction') == 'west' || q.block_state('minecraft:cardinal_direction') == 'east')",
                        "set_block_state":{
                            "rc:direcao": "'x'"
                        }
                    },
                    {
                        "condition": "(q.block_state('minecraft:facing_direction') == 'up') && (q.block_state('minecraft:cardinal_direction') == 'north' || q.block_state('minecraft:cardinal_direction') == 'south')",
                        "set_block_state":{
                            "rc:direcao": "'z'"
                        }
                    }
                ]
            },
            "connect": {
               "sequence": [
                {
                    "run_command":{
                        "command": ["scriptevent rc:pistonConnect"]
                    }
                },
                {
                    "condition": "q.block_state('rc:speed') > 0",
                    "run_command":{
                        "command": ["scriptevent rc:pistonActivate"]
                    }
                }
               ]
            },
            "update": {
                "sequence": [
                  {
                    "trigger": "connect"
                  },
                  {
                      "condition": "q.block_state('minecraft:facing_direction') == 'north'",
                      "set_block_state":{
                          "rc:expanded": "q.block_neighbor_has_any_tag(0,0,-1,'piston_pole:north')"
                      }
                  },
                  {
                      "condition": "q.block_state('minecraft:facing_direction') == 'south'",
                      "set_block_state":{
                          "rc:expanded": "q.block_neighbor_has_any_tag(0,0,1,'piston_pole:south')"
                      }
                  },
                  {
                      "condition": "q.block_state('minecraft:facing_direction') == 'west'",
                      "set_block_state":{
                          "rc:expanded": "q.block_neighbor_has_any_tag(-1,0,0,'piston_pole:west')"
                      }
                  },
                  {
                      "condition": "q.block_state('minecraft:facing_direction') == 'east'",
                      "set_block_state":{
                          "rc:expanded": "q.block_neighbor_has_any_tag(1,0,0,'piston_pole:east')"
                      }
                  },
                  {
                      "condition": "q.block_state('minecraft:facing_direction') == 'up'",
                      "set_block_state":{
                          "rc:expanded": "q.block_neighbor_has_any_tag(0,-1,0,'piston_pole:down')"
                      }
                  },
                  {
                      "condition": "q.block_state('minecraft:facing_direction') == 'down'",
                      "set_block_state":{
                          "rc:expanded": "q.block_neighbor_has_any_tag(0,1,0,'piston_pole:up')"
                      }
                  }
                ]
            }
        },
        "permutations": [
            {
                "condition": "q.block_state('rc:expanded') == true",
                "components": {
                    "minecraft:destructible_by_explosion": true,
                    "minecraft:destructible_by_mining": true
                }
            },
            {
                "condition": "q.block_state('rc:expanded') == false",
                "components": {
                    "minecraft:destructible_by_explosion": false,
                    "minecraft:destructible_by_mining": false
                }
            },
            {
                "condition": "q.block_state('minecraft:facing_direction') == 'north'",
                "components": {
                    "minecraft:transformation": {
                        "rotation": [270, 0, 90]
                    },
                    "minecraft:geometry":{
                        "identifier": "geometry.mechanical_piston",
                        "bone_visibility": {
                            "top": "!q.block_state('rc:expanded')",
                            "pole": "q.block_state('rc:expanded')",
                            "shaft_a": "q.block_state('rc:sentido') == 'estatico' || q.block_state('rc:sentido') == 'horario'",
                            "shaft_h": "q.block_state('rc:sentido') == 'antihorario'"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('minecraft:facing_direction') == 'south'",
                "components": {
                    "minecraft:transformation": {
                        "rotation": [90, 0, 90]
                    }
                }
            },
            {
                "condition": "q.block_state('minecraft:facing_direction') == 'west'",
                "components": {
                    "minecraft:transformation": {
                        "rotation": [0, 0, 90]
                    }
                }
            },
            {
                "condition": "q.block_state('minecraft:facing_direction') == 'east'",
                "components": {
                    "minecraft:transformation": {
                        "rotation": [180, 0, 90]
                    }
                },
                "minecraft:geometry":{
                    "identifier": "geometry.mechanical_piston",
                    "bone_visibility": {
                        "top": "!q.block_state('rc:expanded')",
                        "pole": "q.block_state('rc:expanded')",
                        "shaft_a": "q.block_state('rc:sentido') == 'estatico' || q.block_state('rc:sentido') == 'horario'",
                        "shaft_h": "q.block_state('rc:sentido') == 'antihorario'"
                    }
                }
            },
            {
                "condition": "q.block_state('minecraft:facing_direction') == 'down' && (q.block_state('minecraft:cardinal_direction') == 'north' || q.block_state('minecraft:cardinal_direction') == 'south')",
                "components": {
                    "minecraft:transformation": {
                        "rotation": [0, 0, 0]
                    }
                }
            },
            {
                "condition": "q.block_state('minecraft:facing_direction') == 'down' && (q.block_state('minecraft:cardinal_direction') == 'west' || q.block_state('minecraft:cardinal_direction') == 'east')",
                "components": {
                    "minecraft:transformation": {
                        "rotation": [0, 90, 0]
                    }
                }
            },
            {
                "condition": "q.block_state('minecraft:facing_direction') == 'up' && (q.block_state('minecraft:cardinal_direction') == 'north' ||  q.block_state('minecraft:cardinal_direction') == 'south')",
                "components": {
                    "minecraft:transformation": {
                        "rotation": [180, 0, 0]
                    }
                }
            },
            {
                "condition": "q.block_state('minecraft:facing_direction') == 'up' && (q.block_state('minecraft:cardinal_direction') == 'west' || q.block_state('minecraft:cardinal_direction') == 'east')",
                "components": {
                    "minecraft:transformation": {
                        "rotation": [180, 90, 0]
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 1",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_1"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_1"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 2",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_2"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_2"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 3",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_3"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_3"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 4",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_4"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_4"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 5",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_5"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_5"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 6",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_6"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_6"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 7",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_7"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_7"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 8",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_8"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_8"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 9",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_9"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_9"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 10",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_10"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_10"
                        }
                    }
                }
            },
            {
                "condition": "q.block_state('rc:speed') == 11",
                "components": {
                    "minecraft:material_instances": {
                        "*": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "piston_bottom": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_bottom"
                        },
                        "piston_inner": {
                            "render_method": "alpha_test",
                            "texture": "mechanical_piston_inner"
                        },
                        "piston_side": {
                            "render_method": "alpha_test",
                            "texture": "piston_side"
                        },
                        "piston_top": {
                            "render_method": "alpha_test",
                            "texture": "piston_top_normal"
                        },
                        "andesite_casing_piston": {
                            "render_method": "alpha_test",
                            "texture": "andesite_casing_piston"
                        },
                        "gearbox": {
                            "render_method": "alpha_test",
                             "texture": "piston_gearbox"
                        },
                        "pole_end": {
                            "render_method": "alpha_test",
                            "texture": "pole_end"
                        },
                        "shaft_h": {
                            "render_method": "alpha_test",
                            "texture": "shaft_h_11"
                        },
                        "shaft_a": {
                            "render_method": "alpha_test",
                            "texture": "shaft_a_11"
                        }
                    }
                }
            }            
        ]
    }
}