[Feature Request] IAction validation check
Darkhax opened this issue ยท 3 comments
Feature request name
IAction validation check
Feature request description
I would like a new method to be added to IAction which allows the action to perform validation checks before the action has been applied. Ideally this check would be done before the action has been applied and if the check fails the action will not be applied.
Feature request reason
Currently there is no officially stated way to do validation with an IAction. Initially I was doing validation in my ZenMethod or my Action's constructor, however this would cause an issue where failed actions would not provide the user with a script line number. The best way I have seen to do this is to run the validation at the start of apply, however this leads to an additional code block at the start of the method which has semi-unrelated logic to the rest of the method. For organizational purposes having a separate method dedicated to checking the validity of an action would be very useful.
Depending on how this is implemented into CraftTweaker, this may also allow CraftTweaker to safely ignore invalid actions before they are executed, and skip to the next one without the need to error out an entire script file. All errored actions could then be reported at the end. While not required, I think this change would help pack makers out a lot because they could see all of the errors right away without having to restart the game once for each one. This would also allow for things like the syntax command to have better coverage.
Feature request dependencies
This feature would be useful in general, and not specific to any mod. Since IAction is an interface, a default method which defaults to true would allow backwards compat, although in 1.13 I would recommend making this a required method.
Adding a new method to IAction might have an impact on binary compatibility to other mods that use IAction.
Why not just derive an abstract ActionVerifiable class from IAction that has a validate method that you can then apply at will?
Making it a default Method returning true should keep binary compat just fine
Edit: didn't mean to close.
Close in 53dce6a