Ghoulboy78 / Scarpet-edit

A useful tool for developing decorative builds etc in scarpet.
Creative Commons Zero v1.0 Universal
22 stars 4 forks source link

Added angel block and framework to handle new items with actions #55

Closed Firigion closed 3 years ago

Firigion commented 3 years ago

This is built on the drain branch, because it modifies some of the same parts of the code that feature doe,s and it would have been a pain to merge them separately to master. If i should do this some other way, tell be and I'll make another PR.

It adds a single command (tree), namely /world-edit angel [new|clear]. Called with new, it will register the held item as the angel block tool. Holding it will highlight the targeted (air) block, and clicking with it will place a stone block in mid air. Calling it with clear will deregister the current angel block tool, and calling it without arguments will give the player the current angel block tool item.

Writing this code was a bit of a foreshadowing for how much of a pain it will be to add new commands that add arbitrary functionality to items (like currently brushes, wand and now angel block tool). Since stuff like building wands and tools from pixel sniper are listed as stuff that is gonna be added at some point, I thought it would be a good idea to write some code to wrap the addition of new items with actions. Before doing this, stuff like registering a new brush had to manually check if the item was not already a wand or an angel block tool, and angel block had to check for wand and brush, and so on.

To avoid needing to edit all existing commands when creating a new action associated to an item, there's now a global map of items with the actions associated to them. The contributor should use new_action_item when adding a new item, which will handle the checks for them. The actions in the map are only used in the error messages, to tell the user what's that item currently doing, if it's doing something. Since now adding something new that registers items to do stuff is a bit more involved, I updated CONTRIBUTING.md with the detailed instructions of what people need to do in order to add such a thing. Here's a dirty little video showing how the error messages are handled (and also how the angel block works): https://youtu.be/sKWqZOIE7sA

I also fixed an unreported bug with the wand command.