- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register








The script repo is an archive of historical scripts. For modern scripts, or to post your own, please use the Scripts forum section.





Staff Pick: Schematic checker with notable storage


By Wahrheit
Created: 2018/08/04 14:03:03 UTC-07:00 (6 years and 140 days ago)
Edited: 2018/08/04 14:40:31 UTC-07:00 (6 years and 140 days ago)
Likes: 0

Staff pick as of: 2018/11/06 19:49:05 UTC-08:00 (6 years and 46 days ago)
Denizen Version: 1.0.2
Script Version: 1.0
Description:

Allows definition and checking of schematics to create notable cuboids for usage in other scripts. Cuboids will be created upon placement of a defined trigger block if surrounding blocks conform to the schematic. Cuboids will be removed if a block is destroyed in their areas. Scripts can be defined to run upon creation and deletion.

Written by suspic and mcmonkey. Throw your love (and support questions) in their direction.


Download script | View raw script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
8900

schematic_data:
    type: yaml data
    triggers:
        # Material names to check on block place
        # Each schematic entry for that material will be checked each time the trigger block is placed
        #- 'SCHEMATIC_NAME/IGNORE_AIR(Boolean)(/Creation Script(/Deletion Script))'
        dirt:
        - 'example_schematic/false'
        diamond_block:
        # Checks against schematic 'altar_example' and requires air blocks to match the schematic
        - 'altar_example/false/altar_created/altar_deleted'

altar_created:
    type: task
    speed: 0
    script:
    - narrate "Created!"

alter_deleted:
    type: task
    speed: 0
    script:
    - narrate "Deleted!"

# Handles creation and removal of notable cuboids when a player places a schematic listed in 'schematic_data'.

# Will save schematics in form "schematic_<LOCATION>_<SCHEMATIC NAME>"
# For example, "schematic_1,2,3,world_examplename"
schematic_check_evt:
    type: world
    events:
        # Checks for a trigger block, then checks for a matching schamatic, and notes if found
        on player places block:
        - if <s@schematic_data.list_keys[triggers].contains[<context.material.name>]> {
            - foreach <s@schematic_data.yaml_key[triggers.<context.material.name>]> {
                - if !<schematic[<def[value].before[/]>].exists> {
                    - queue clear
                }
                - run schematic_checker def:<context.location>|<def[value].before[/]>|<def[value].after[/]>
                - if <server.flag[schem_check]> {
                    - note <schematic[<def[value].before[/]>].cuboid[<context.location>]> as:schematic_<context.location.simple.replace[l@]>_<def[value].before[/]>
                }
                - flag server schem_check:!
                - if <def[value].split_by[/].size> >= 3 {
                    - run <def[value].split_by[/].get[3]>
                }
                - if <def[value].split_by[/].size> == 4 {
                    - flag server schem_deletion_scripts.schematic_<context.location.simple.replace[l@]>_<def[value].before[/]>:<def[value].after_last[/]>
                }
            }
        }
        on player breaks block in notable cuboid:
        - foreach <context.location.cuboids.filter[notable_name.starts_with[schematic_]]> {
            - note remove as:<def[value].notable_name>
            - if <server.has_flag[schem_deletion_scripts.<def[value].notable_name>]> {
                - run <server.flag[schem_deletion_scripts.<def[value].notable_name>]>
                - flag server schem_deletion_scripts.<def[value].notable_name>:!
            }
        }

# Checks if a schematic matches the placed blocks around a location
# USAGE SAMPLE:
# - run schematic_checker def:<LOCATION>|<SCHEMATIC>|<IGNORE_AIR(Boolean)>
# - if <server.flag[schem_check]> { ... }
# - flag server schem_check:!
schematic_checker:
    type: procedure
    debug: true
    definitions: location|schematic|ignore_air
    speed: 0
    script:
    - define cuboid <schematic[<def[schematic]>].cuboid[<def[location]>]>
    - define adjusted_location <def[location].sub[<schematic[<def[schematic]>].origin>]>
    - inject locally <tern[<def[ignore_air]>]:ignore_air||with_air>
    - flag server schem_check:true
    with_air:
    - foreach <def[cuboid].blocks>:
        - define schem_mat <schematic[<def[schematic]>].block[<def[value].sub[<def[adjusted_location]>]>].name>
        - if <def[schem_mat]> != air && <def[schem_mat]> != <def[value].material.name> {
            - flag server schem_check:false
        }
    ignore_air:
    - foreach <def[cuboid].blocks>:
        - define schem_mat <schematic[<def[schematic]>].block[<def[value].sub[<def[adjusted_location]>]>].name>
        - if <def[schem_mat]> != <def[value].material.name> {
            - flag server schem_check:false
        }






View History