Date: 2020/01/27 11:58:57 UTC-08:00
Type: Denizen 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
path_selector:
debug: false
type: item
material: blaze_rod
mechanisms:
flags: HIDE_ENCHANTS
nbt: way/0|id/<player.flag[npc_id]>
display_name: "<green>Path Selector"
enchantments:
- thorns:1
path_selection_effect:
debug: false
type: task
definitions: item
script:
- if <[item].has_nbt[way]>:
- if <[item].nbt[way]> != null || <[item].nbt[way]> != 0:
- while <player.has_flag[path_selection]>:
- define path:<[item].nbt[way].unescaped.as_list.get_sub_items[2].deduplicate>
- foreach <[path]> as:point:
- playeffect effect:redstone at:<[point].add[0,1,0]> quantity:20 data:0 special_data:1.2|orange offset:0.0 visibility:15 target:<player>
- wait 3t
path_selection_waypoint:
debug: true
type: task
definitions: item
script:
- define path_list:<[item].nbt[way].unescaped.as_list>
- define location_order:<[path_list].get_sub_items[1]>
- narrate "<aqua>Location Order :<[location_order]>"
- define npc_id:<[item].nbt[id].as_npc>
- narrate "<aqua>NPC ID :<[npc_id]>"
- foreach <[location_order]> as:order:
- define location:<[path_list].map_get[<[order]>]>
- narrate "<red><[location]>"
- yaml id:<player.uuid> set npc.id.<[npc_id].id>.path.0.<[order]>:<[location]>
- narrate <green><yaml[<player.uuid>].list_deep_keys[npc.id]>
npc_path_menu:
debug: true
type: inventory
inventory: chest
title: "NPC Path Menu"
size: 36
definitions:
get_wand: blaze_rod[display_name=<gold>Path selector;lore=<gray>Click to get;nbt=inv/0]
back: grass_path[display_name=<gold>Path;lore=<gray>Click to go back;nbt=inv/0]
slots:
- "[get_wand] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] []"
- "[] [] [] [] [] [] [] [] [back]"
npc_path_menu_handler:
debug: true
type: world
events:
on player clicks in npc_path_menu priority:2 :
- determine cancelled
on player drags in npc_path_menu priority:2 :
- determine cancelled
# on player opens npc_path_menu:
# - if <player.has_flag[npc_id]>:
# - define health_menu <context.inventory>
# - define npc_health <player.flag[npc_id].as_npc.health>
# - define npc_max_health <player.flag[npc_id].as_npc.health_max>
# Change the name of the beetroot to match how much life does the NPC have
# - if <[npc_health]> < <[npc_max_health]>:
# - inventory adjust d:<[health_menu]> slot:23 "display_name:<gold>Health <red><[npc_health]><gold>/<green><[npc_max_health]>"
# - else:
# - inventory adjust d:<[health_menu]> slot:23 "display_name:<gold>Health <green><[npc_health]><gold>/<green><[npc_max_health]>"
# Fill with poppies the amount of health it have
# - repeat <[npc_health].mul[7].div[<[npc_max_health]>].round_down> as:slot:
# - inventory set d:<[health_menu]> o:poppy slot:<[slot].add_int[10]>
# - define slot_filled <[slot].add_int[10]>
# Fill with wither_roses how much health does it lose
# - repeat <[npc_health].mul[7].div[<[npc_max_health]>].sub[7].abs.round> as:slot:
# - inventory set d:<[health_menu]> o:wither_rose slot:<[slot].add_int[<[slot_filled]>]>
on player clicks grass_path in npc_path_menu priority:1 :
- if <context.item.has_nbt[inv]>:
- inventory open d:npc_editor
on player clicks blaze_rod in npc_path_menu priority:1 :
- if <context.item.has_nbt[inv]>:
- if !<player.has_flag[npc_id]>:
- narrate "<red>Select an NPC to use it."
- stop
- narrate "<yellow>Use the <green>Right Click <yellow>to mark one point path and the <green>Left Click <yellow>to remove it."
- narrate "<yellow>When you are done you may drop the <aqua>Path Selector<yellow>."
- give path_selector
- inventory close
waypoint_yes_no_inv:
debug: true
type: inventory
inventory: chest
title: Do you want to end the selection ?
size: 27
definitions:
yup: LIME_STAINED_GLASS_PANE[display_name=<green>YES;lore=<gray>Click to select;nbt=inv/0]
nope: RED_STAINED_GLASS_PANE[display_name=<red>NO;lore=<gray>Click to select;nbt=inv/0]
slots:
- "[] [] [] [] [] [] [] [] []"
- "[] [] [yup] [] [] [] [nope] [] []"
- "[] [] [] [] [] [] [] [] []"
waypoint_yes_no_inv_handler:
type: world
events:
on player clicks in waypoint_yes_no_inv priority:2:
- determine cancelled
on player drags in waypoint_yes_no_inv priority:2:
- determine cancelled
on player closes waypoint_yes_no_inv:
- if <player.has_flag[path_selector_backup]>:
- define path_selector_backup <player.flag[path_selector_backup].as_item>
- flag <player> path_selector_backup:!
- give <[path_selector_backup]>
- inventory close
- else:
- inventory close
on player clicks LIME_STAINED_GLASS_PANE in waypoint_yes_no_inv:
- if <context.item.has_nbt[inv]>:
- define path_selector_backup <player.flag[path_selector_backup].as_item>
- flag <player> path_selector_backup:!
- flag <player> path_selection:!
- run path_selection_waypoint def:<[path_selector_backup]>
- inventory close
on player clicks RED_STAINED_GLASS_PANE in waypoint_yes_no_inv priority:0 :
- if <context.item.has_nbt[inv]>:
- if <player.has_flag[path_selector_backup]>:
- define path_selector_backup <player.flag[path_selector_backup].as_item>
- flag <player> path_selector_backup:!
- give <[path_selector_backup]>
- inventory close
- else:
- inventory close
path_selector_handle:
debug: false
type: world
events:
on player right clicks with path_selector:
# Avoiding setting a null place to the selector
- if <context.location.block.material||air> == air:
- determine cancelled
- determine passively cancelled
# Basic definitions
- define held_item:<context.item||null>
- define place:<context.location.block.center||null>
# If the item has the way
- if <[held_item].has_nbt[way]>:
# Which slot the item is
- define slot:<player.inventory.find.scriptname[path_selector]>
- if <[held_item].nbt[way].unescaped.as_list.get_sub_items[2].contains[<[place]>]>:
- narrate "<red>You can't put two points on the same place."
- stop
- if <[held_item].nbt[way]> == 0:
- narrate "<yellow>Point <green>0 <yellow>selected."
- inventory adjust slot:<[slot]> nbt:way/<list[0/<[place]>].escaped>
# Setting Definitions
- define held_item:<player.inventory.slot[<[slot]>]>
# Playing Effects
- flag player path_selection:0
- run path_selection_effect def:<[held_item]>
- else:
- define last_key:<[held_item].nbt[way].unescaped.as_list.get_sub_items[1].highest.add[1]>
- narrate "<yellow>Point <green><[last_key]> <yellow>selected."
# Setting the new NBT
- define new_nbt:<list[<[held_item].nbt[way].unescaped.as_list>|<[last_key]>/<[place]>].escaped>
# Inserting NBT data
- inventory adjust slot:<[slot]> nbt:way/<[new_nbt]>
# Setting definitions
- define held_item:<player.inventory.slot[<[slot]>]>
# Playing effects
- flag player path_selection:0
- run path_selection_effect def:<[held_item]>
on player left clicks with path_selector:
# Avoiding setting a null place to the selector
- if <context.location.block.material||air> == air:
- determine cancelled
- determine passively cancelled
- ratelimit <player> 20t
# Basic definitions
- define held_item:<context.item||null>
- define place:<context.location.block.center||null>
# If the item has the way
- if <[held_item].has_nbt[way]>:
# Which slot the item is
- define slot:<player.inventory.find.scriptname[path_selector]>
- if <[held_item].nbt[way]> == 0:
- narrate "<yellow>There's no point selected."
- stop
- else:
- define path:<[held_item].nbt[way].unescaped.as_list>
- if <[path].get_sub_items[2].contains[<[place]>]>:
- define the_point:<[path].map_find_key[<[place]>]>
#Check if is the first point or not
- if <[path].size> != 1:
# Setting the new NBT
- narrate "The Point: <green><[the_point]>"
# Hacky way to delete a map entry
- define new_nbt:<list[<[path].filter[starts_with[<[the_point]>/].not]>].escaped>
# Inserting NBT data
- inventory adjust slot:<[slot]> nbt:way/<[new_nbt]>
- narrate "<yellow>Point <green><[the_point]> <red>removed<yellow>."
- define held_item:<player.inventory.slot[<[slot]>]>
- flag player path_selection:!
- wait 15t
- flag player path_selection:0
- run path_selection_effect def:<[held_item]>
- stop
- else:
# Correcting NBT data
- inventory adjust slot:<[slot]> nbt:way/0
- narrate "<yellow>Point <green><[the_point]> <red>removed<yellow>."
- flag player path_selection:!
- stop
- else:
- narrate "<red>No point to remove."
- stop
# on player holds item item:path_selector:
# - narrate "Hi there"
on player clicks path_selector in inventory:
- inject locally abuse_prevention_click
on player drags path_selector in inventory:
- inject locally abuse_prevention_click
on player drops path_selector:
- inventory open d:waypoint_yes_no_inv
- flag player path_selector_backup:<context.item>
- remove <context.entity>
# Copied from the cuboid_selection_tool script made by mcmonkey
abuse_prevention_click:
- if <context.inventory.inventory_type> == player:
- stop
- if <context.inventory.inventory_type> == crafting:
- if <context.raw_slot||<context.raw_slots.numerical_first>> >= 6:
- stop
- determine passively cancelled
- inventory update