# +----------
# | Replacer Tool (requires Denizen build #1300 or higher)
# | Use '/replacer' to get the replacer tool
# | Use '/replacer <material>' to set the replace material
# | Use '/replacer reset' to reset the history (and leave no trace behind!)
Replacer tool:
type: world
# Use some world events to handle interaction with the block replacer and the /replacer command.
events:
# A right click will change the material the block replacer uses.
# Crouching while right clicking will simply show the material it is currently set to (or m@stone if null).
on player right clicks with i@block replacer:
- if !<player.is_op> determine fulfilled
- if <player.is_sneaking> {
- narrate "Block replacer is currently set to '<player.flag[block_replacer_material] || m@stone>'."
} else {
- flag <player> block_replacer_material:<player.location.cursor_on.block.material>
- narrate "Block replacer material set to '<player.flag[block_replacer_material]>'."
}
- determine cancelled
# A left click will do the replacement, and store the replacement in history using dual flag arrays.
# A shift-left click will undo the last replacement. By default, it handles 30 undo levels.
on player left clicks with i@block replacer:
- if !<player.is_op> determine fulfilled
- if <player.is_sneaking> {
- modifyblock <player.flag[block_replacer_undo_location]> material:<player.flag[block_replacer_undo_material]>
- flag <player> block_replacer_undo_material[<player.flag[block_replacer_undo_material].size>]:<-
- flag <player> block_replacer_undo_location[<player.flag[block_replacer_undo_location].size>]:<-
- narrate 'Undone. <player.flag[block_replacer_undo_location].size> undos left.'
} else {
- flag <player> block_replacer_undo_material:->:<player.location.cursor_on.block.material>
- flag <player> block_replacer_undo_location:->:<player.location.cursor_on.simple>
- modifyblock '<player.location.cursor_on>' 'material:<player.flag[block_replacer_material] || m@stone>'
- if <player.flag[block_replacer_undo_material].size> > 30 {
- flag <player> block_replacer_undo_material[1]:<-
- flag <player> block_replacer_undo_location[1]:<-
}
}
- determine cancelled
# The replacer command handles a few usages, as described in the description of this script.
on replacer command:
- if <c.raw_args> == 'reset' {
- flag <player> block_replacer_undo_material:!
- flag <player> block_replacer_undo_location:!
- flag <player> block_replacer_material:!
- narrate 'Reset flags for replacer tool.'
} else if <c.args.size> > 0 && <m@<c.raw_args.replace[m@]>.is_block> {
- flag <player> block_replacer_material:<c.raw_args>
- narrate "Block replacer material set to '<player.flag[block_replacer_material]>'."
} else if <c.args.size> == 0 {
- drop 'i@block replacer' <player.location>
} else narrate 'Invalid material.'
- determine fulfilled
# Item script for the block replacer item. Use '/replacer' or '/ex give "i@block replacer"' to obtain it.
Block Replacer:
type: item
material: gold_spade
display name: <gold>Block Replacer
lore:
- <light_purple>Easily replace blocks!
- <white>-------------------------------
- <yellow>right click a block to set the material
- <yellow>shift-right click to see the material set
- <yellow>left click a block to replace
- <yellow>shift-left click to undo the replacement