Decorator Tool (Testers Wanted!)

Share scripts you wrote for Denizen-Bukkit here!
Post Reply
Berufeng
New
New
Posts: 7
Joined: January 29th, 2020, 4:40 pm

Decorator Tool (Testers Wanted!)

Post by Berufeng » May 21st, 2020, 2:09 am

This script is for developers who like to use interactable blocks in their builds but don't want players to utilize them for their intended purpose. For example, maybe you are using vertical trapdoors as a fence line, or you want a strictly cosmetic chest or anvil or enchanting table? Or maybe you just want to make your pressure plate table-tops stop clicking when folks get too close?

To use this script, type /decorate. You'll get a special stick you can whack things with to make them decorative, because who doesn't like whacking things with a stick? It's fun AND user-friendly!

To Do:
- Identify any missed blocks that ought to be "decoratable."
- Identify any blocks that incorrectly trigger the "attached block" protocol-- ie, blocks that occupy one block's space but return true for <material.is_bisected>. (Like trapdoors.)

***LOOKING FOR TESTERS!***
There may have been blocks I missed, or something I overlooked. Feedback is welcomed and greatly appreciated!

Here's a link to a haste: https://one.denizenscript.com/haste/69595

Or click Show to show the script in this post.
Spoiler!

Code: Select all

Decorator_Tool:
  type: item
  material: stick
  display name: <blue>Decorator Tool
  lore:
  - Right-click to mark location as decorative.
  - Left-click to unmark location.
  - Shift-right-click to toggle block state.

Decorate_Command:
  type: command
  name: decorate
  usage: /decorate
  permission: beruscripts.decorator
  description: Gives the player a Decorator Tool.
  script:
      - if !<player.inventory.contains[decorator_tool]>:
        - give decorator_tool
        - narrate "<aqua>You received a <blue>[Decorator Tool]<aqua>."
        - narrate "<gray>Right-click to decorate, left-click to un-decorate."
        - narrate "<gray>Right-click while sneaking to toggle open/closed."
      - else:
        - take scriptname:decorator_tool
        - narrate "<red>Removed your <blue>[Decorator Tool]<red>."

Decorative_Blocks:
  type: world
  debug: false
  misc_blocks:
  - loom
  - crafting_table
  - cartography_table
  - anvil
  - chipped_anvil
  - damaged_anvil
  - enchanting_table
  - grindstone
  - smithing_table
  - stonecutter
  - fletching_table
  events:
    on player right clicks block priority:1:
      - if <server.has_flag[decorative_block.<context.location.simple>]>:
        - determine cancelled
    on player stands on material:
      - if <server.has_flag[decorative_block.<context.location.simple>]>:
        - determine cancelled
    # Decorator tool functionality.
    on player clicks block with decorator_tool:
      - determine passively cancelled
      - if <player.is_sneaking> && <context.click_type> == right_click_block:
        - switch <context.location>
        - stop
      - choose <context.click_type>:
        - case right_click_block:
          - if !<context.location.material.is_switchable> && !<context.location.has_inventory> && !<script.yaml_key[misc_blocks].contains[<context.location.material.name>]> && !<context.location.material.name.ends_with[_bed]>:
            - narrate "<dark_gray>You cannot make <context.location.material.item.formatted> decorative."
            - stop
          - if <server.has_flag[decorative_block.<context.location.simple>]>:
            - narrate "<dark_gray>This <gray><context.location.material.translated_name> <dark_gray>is already decorative!"
            - stop
          - narrate "<aqua>Made this <gray><context.location.material.translated_name> <aqua>decorative."
          - flag server decorative_block.<context.location.simple>
          - if <context.location.material.is_bisected> && !<context.location.material.name.ends_with[_trapdoor]>:
            - narrate "<aqua>(Also added adjacent block.)"
            - flag server decorative_block.<context.location.other_block.simple>
        - case left_click_block:
          - if !<server.has_flag[decorative_block.<context.location.simple>]>:
            - narrate "<dark_gray>This <gray><context.location.material.translated_name> <dark_gray>is not decorative!"
            - stop
          - narrate "<red>This <gray><context.location.material.translated_name> <red>is no longer decorative."
          - flag server decorative_block.<context.location.simple>:!
          - if <context.location.material.is_bisected> && !<context.location.material.name.ends_with[_trapdoor]>:
            - narrate "<red>(Also removed adjacent block.)"
            - flag server decorative_block.<context.location.other_block.simple>:!
    # Item protection. (Prevents decorator tool from being transfered to another inventory.)
    on player drops decorator_tool:
      - determine cancelled
    on player clicks in inventory with decorator_tool:
      - if <context.clicked_inventory.inventory_type> != PLAYER:
        - determine cancelled
    on player clicks decorator_tool in inventory:
      - if <context.is_shift_click> && <context.inventory.inventory_type> != PLAYER:
        - determine cancelled
    on player drags decorator_tool in inventory:
      - if <context.clicked_inventory.inventory_type> != PLAYER:
        - determine cancelled
    # If any player breaks a decorative block, alerts them and removes decoration flag.
    on player breaks block priority:1:
      - if <server.has_flag[decorative_block.<context.location.simple>]>:
        - narrate "<red>You broke a decorative <context.location.material.translated_name.to_lowercase>."
        - flag server decorative_block.<context.location.simple>:!
        - if <context.location.material.is_bisected> && !<context.location.material.name.ends_with[_trapdoor]>:
          - narrate "<red>(Also removed adjacent block.)"
          - flag server decorative_block.<context.location.other_block.simple>:!
Last edited by Berufeng on May 25th, 2020, 10:39 am, edited 10 times in total.

User avatar
mcmonkey
Site Admin
Site Admin
Posts: 267
Joined: August 5th, 2016, 7:27 pm
Location: Los Angeles, California, USA
Contact:

Re: Decorator Tool (Testers Wanted!)

Post by mcmonkey » May 21st, 2020, 2:15 am

(reviewing https://one.denizenscript.com/haste/69318 )
- - give <player> decorator_tool is invalid, and will error in your console. Watch your debug console!
- Use a command script, not the event
- that decorating flag seems redundant... get rid of it.
- consider using priorities on your events to deconflict them.
- Use a map-style flag for the locations instead of a flag list. That is, like, decoration_location.<context.location.simple> as a flag name. This is just more performant with large numbers of decorative blocks in use.
Denizen lead developer. On Discord as mcmonkey#6666.

Berufeng
New
New
Posts: 7
Joined: January 29th, 2020, 4:40 pm

Re: Decorator Tool (Testers Wanted!)

Post by Berufeng » May 21st, 2020, 11:40 am

Updated to incorporate all of mcmonkey's suggestions.

Also added functionality:
- Beds of all types are now valid decorative block options.
- Right click with decorator_tool while sneaking to toggle on/off state of applicable blocks, regardless of their "decorative" status.

User avatar
mcmonkey
Site Admin
Site Admin
Posts: 267
Joined: August 5th, 2016, 7:27 pm
Location: Los Angeles, California, USA
Contact:

Re: Decorator Tool (Testers Wanted!)

Post by mcmonkey » May 22nd, 2020, 5:35 am

(reviewing https://one.denizenscript.com/haste/69389 )
- Remove the "allowed help" section
- Add a permission node. Just make one up, like berufeng.decorator or something.
- - take decorator_tool this is bad as I mentioned on Discord. Use the scriptname: argument.
- All the stuff about "Decorator mode" and "toggling" seems off. It's just a decorator wand item, there's no "mode" and there's no need to have a "mode".
- <context.location.material.item.formatted.after[ ]> this is some kind of wild hack. Use the MaterialTag.translated_name tag if anything.
Denizen lead developer. On Discord as mcmonkey#6666.

Berufeng
New
New
Posts: 7
Joined: January 29th, 2020, 4:40 pm

Re: Decorator Tool (Testers Wanted!)

Post by Berufeng » May 22nd, 2020, 6:33 pm

Updated to add planned functionality, and to fix according to mcmonkey's new suggestions.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests