Bedrock Snippets

Custom Trees

View Source

custom_trees > bp > blocks > custom_sapling.json

{
  "format_version": "1.20.30",
  "minecraft:block": {
    "description": {
      "identifier": "wiki:custom_sapling",
      "states": {
        // Sapling's growth stage
        "wiki:growth_stage": [0, 1, 2]
      }
    },
    "components": {
      "minecraft:collision_box": false,
      "minecraft:selection_box": {
        "origin": [-6, 0, -6],
        "size": [12, 13, 12]
      },
      "minecraft:light_dampening": 0,
      "minecraft:geometry": "geometry.custom_sapling",
      "minecraft:material_instances": {
        "*": {
          "texture": "custom_sapling",
          "render_method": "alpha_test",
          "face_dimming": false,
          "ambient_occlusion": false
        }
      },
      // Add loot component so it will drop sapling placer item
      "minecraft:loot": "loot_tables/blocks/custom_sapling.json",
      // Allows to place block only on these blocks
      "minecraft:placement_filter": {
        "conditions": [
          {
            "allowed_faces": ["up"],
            "block_filter": ["minecraft:dirt", "minecraft:grass", "minecraft:podzol"]
          }
        ]
      },
      // Trigger growth on each random tick
      "minecraft:random_ticking": {
        "on_tick": {
          "event": "wiki:grow"
        }
      },
      // Trigger growth when bone meal is used
      "minecraft:on_interact": {
        "condition": "q.is_item_name_any('slot.weapon.mainhand', 'minecraft:bone_meal')",
        "event": "wiki:fertilize"
      }
    },
    "events": {
      "wiki:grow": {
        "sequence": [
          {
            "condition": "q.block_state('wiki:growth_stage') < 2",
            "set_block_state": {
              "wiki:growth_stage": "q.block_state('wiki:growth_stage') + 1"
            }
          },
          {
            "condition": "q.block_state('wiki:growth_stage') == 2",
            "run_command": {
              "command": "structure load custom_tree ~-2~~-2"
            }
          }
        ]
      },
      "wiki:fertilize": {
        // Removes item that was used to interact
        "decrement_stack": {},
        // Trigger growth
        "trigger": {
          "event": "wiki:grow"
        },
        // Trigger effects
        "run_command": {
          "command": ["particle minecraft:crop_growth_emitter ~~~", "playsound item.bone_meal.use @a ~~~"]
        }
      }
    }
  }
}
Copied to Clipboard