{
  "format_version": "1.21.80",
  "minecraft:block": {
    "description": {
      "identifier": "mnp_ci:palm_fence_gate", // The identifier of your custom fence gate
      "menu_category": {
        "category": "none"
      },
      "traits": {
        "minecraft:placement_direction": {
          "enabled_states": ["minecraft:cardinal_direction"] // Block trait used to rotate the fence gate
        }
      },
      "states": {
        "mnp_ci:gate_open": [false, true],
        "mnp_ci:gate_in_wall_bit": [false, true], // Wheter the fence gate is connected to a wall or not
        "mnp_ci:gate_invisible": [false, true], // When true, the fence gate is invisible, this is made to add an extra block in top of our fence gate, which results in a 1.5y collision box.
        "mnp_ci:gate_direction": [false, true] // When true, minecraft:cardinal_direction is south. This block state is the real 'south' value of our fence gate.
      }
    },
    "permutations": [
      {
        "condition": "query.block_state('minecraft:cardinal_direction') == 'north'",
        "components": {
          "minecraft:transformation": {
            "rotation": [0, -90, 0]
          }
        }
      },
      // This permutation is only used to render the block in the inventory with the proper rotation. This rotation is never seen in the world, just the inventory.
      {
        "condition": "query.block_state('minecraft:cardinal_direction') == 'south'",
        "components": {
          "minecraft:transformation": {
            "rotation": [0, 180, 0]
          }
        }
      },
      {
        "condition": "query.block_state('minecraft:cardinal_direction') == 'east'",
        "components": {
          "minecraft:transformation": {
            "rotation": [0, -180, 0]
          }
        }
      },
      {
        "condition": "query.block_state('minecraft:cardinal_direction') == 'west'",
        "components": {
          "minecraft:transformation": {
            "rotation": [0, -180, 0]
          }
        }
      },
      // The true rotation of 'south'.
      {
        "condition": "q.block_state('mnp_ci:gate_direction')",
        "components": {
          "minecraft:transformation": {
            "rotation": [0, -90, 0]
          }
        }
      },
      {
        "condition": "q.block_state('mnp_ci:gate_open')",
        "components": {
          "minecraft:collision_box": false
        }
      },
      {
        "condition": "!q.block_state('mnp_ci:gate_invisible')",
        "components": {
          "minecraft:custom_components": [
            // Custom components that add the main functionalities to our fence gate.
            "mnp_ci:on_gate_interact",
            "mnp_ci:on_gate_tick",
            "mnp_ci:on_gate_player_placed",
            "mnp_ci:on_gate_player_destroy"
          ]
        }
      },
      // This permutation is the other half of our fence gate. Should always be invisible.
      {
        "condition": "q.block_state('mnp_ci:gate_invisible') && !q.block_state('mnp_ci:gate_open')",
        "components": {
          "minecraft:selection_box": false,
          "minecraft:collision_box": {
            "origin": [-2, 0, -8],
            "size": [4, 8, 16]
          },
          "minecraft:geometry": {
            "identifier": "geometry.mnp_ci.fence_gate",
            "bone_visibility": {
              "fence_gate_closed": false,
              "fence_gate_open": false,
              "fence_gate_open_inverted": false,
              "post": false,
              "fence_gate_closed_wall": false,
              "fence_gate_open_wall": false,
              "fence_gate_open_inverted_wall": false,
              "post_wall": false
            }
          }
        }
      },
      {
        "condition": "q.block_state('mnp_ci:gate_invisible') && q.block_state('mnp_ci:gate_open')",
        "components": {
          "minecraft:selection_box": false,
          "minecraft:collision_box": false,
          "minecraft:geometry": {
            "identifier": "geometry.mnp_ci.fence_gate",
            "bone_visibility": {
              "fence_gate_closed": false,
              "fence_gate_open": false,
              "fence_gate_open_inverted": false,
              "post": false,
              "fence_gate_closed_wall": false,
              "fence_gate_open_wall": false,
              "fence_gate_open_inverted_wall": false,
              "post_wall": false
            }
          }
        }
      }
    ],
    "components": {
      "minecraft:geometry": {
        "identifier": "geometry.mnp_ci.fence_gate", // Our fence gate geometry.
        "bone_visibility": {
          "fence_gate_closed": "!q.block_state('mnp_ci:gate_open') && !q.block_state('mnp_ci:gate_in_wall_bit')",
          "fence_gate_open": "q.block_state('mnp_ci:gate_open') && ((q.block_state('minecraft:cardinal_direction') == 'south' && q.block_state('mnp_ci:gate_direction')) || q.block_state('minecraft:cardinal_direction') == 'west') && !q.block_state('mnp_ci:gate_in_wall_bit')",
          "fence_gate_open_inverted": "q.block_state('mnp_ci:gate_open') && (q.block_state('minecraft:cardinal_direction') == 'north' || q.block_state('minecraft:cardinal_direction') == 'east') && !q.block_state('mnp_ci:gate_in_wall_bit')",
          "post": "!q.block_state('mnp_ci:gate_in_wall_bit')",
          "fence_gate_closed_wall": "!q.block_state('mnp_ci:gate_open') && q.block_state('mnp_ci:gate_in_wall_bit')",
          "fence_gate_open_wall": "q.block_state('mnp_ci:gate_open') && ((q.block_state('minecraft:cardinal_direction') == 'south' && q.block_state('mnp_ci:gate_direction')) || q.block_state('minecraft:cardinal_direction') == 'west') && q.block_state('mnp_ci:gate_in_wall_bit')",
          "fence_gate_open_inverted_wall": "q.block_state('mnp_ci:gate_open') && (q.block_state('minecraft:cardinal_direction') == 'north' || q.block_state('minecraft:cardinal_direction') == 'east') && q.block_state('mnp_ci:gate_in_wall_bit')",
          "post_wall": "q.block_state('mnp_ci:gate_in_wall_bit')"
        }
      },
      "minecraft:liquid_detection": {
        "detection_rules": [
          {
            "liquid_type": "water",
            "can_contain_liquid": true, // Waterloggable
            "on_liquid_touches": "no_reaction" // Water flows through the block like air
          }
        ]
      },
      "minecraft:collision_box": {
        "origin": [-2, 0, -8],
        "size": [4, 16, 16]
      },
      "minecraft:selection_box": {
        "origin": [-2, 0, -8],
        "size": [4, 16, 16]
      },
      "minecraft:flammable": {
        "catch_chance_modifier": 5,
        "destroy_chance_modifier": 20
      },
      "minecraft:tick": {
        // Allows onTick to work.
        "interval_range": [3, 3]
      },
      "minecraft:destructible_by_mining": {
        "seconds_to_destroy": 3,
        "item_specific_speeds": [
          {
            "destroy_speed": 1.5,
            "item": {
              "tags": "q.all_tags('minecraft:is_axe', 'minecraft:wooden_tier')"
            }
          },
          {
            "destroy_speed": 0.75,
            "item": {
              "tags": "q.all_tags('minecraft:is_axe', 'minecraft:stone_tier')"
            }
          },
          {
            "destroy_speed": 0.5,
            "item": {
              "tags": "q.all_tags('minecraft:is_axe', 'minecraft:iron_tier')"
            }
          },
          {
            "destroy_speed": 0.25,
            "item": {
              "tags": "q.all_tags('minecraft:is_axe', 'minecraft:golden_tier')"
            }
          },
          {
            "destroy_speed": 0.4,
            "item": {
              "tags": "q.all_tags('minecraft:is_axe', 'minecraft:diamond_tier')"
            }
          },
          {
            "destroy_speed": 0.35,
            "item": {
              "tags": "q.all_tags('minecraft:is_axe', 'minecraft:netherite_tier')"
            }
          }
        ]
      },
      "minecraft:loot": "loot_tables/mnp_ci/palm_tree/palm_fence_gate.json", // Drops the inventory fence block when the block is destroyed.
      "tag:fence_gate": {},
      "minecraft:material_instances": {
        "*": {
          "texture": "mnp_ci:palm_tree_planks",
          "render_method": "alpha_test_to_opaque"
        }
      }
    }
  }
}
