Interface IAction
- All Known Subinterfaces:
IRuntimeAction,IUndoableAction
- All Known Implementing Classes:
ActionAddRecipe,ActionAddShiftedTooltip,ActionAddTooltip,ActionAddTrade,ActionAddWanderingTrade,ActionClearTooltip,ActionKnownTag,ActionKnownTagAdd,ActionKnownTagClear,ActionKnownTagCreate,ActionKnownTagModify,ActionKnownTagRemove,ActionLootModifier,ActionModifyAttribute,ActionModifyShiftedTooltip,ActionModifyTooltip,ActionRecipeBase,ActionRegisterLootModifier,ActionRemoveAll,ActionRemoveAllGenericRecipes,ActionRemoveGenericRecipeBase,ActionRemoveGenericRecipeByModId,ActionRemoveGenericRecipeByName,ActionRemoveGenericRecipeByOutput,ActionRemoveGenericRecipeByRegex,ActionRemoveLootModifier,ActionRemoveRecipe,ActionRemoveRecipeByModid,ActionRemoveRecipeByName,ActionRemoveRecipeByOutput,ActionRemoveRecipeByOutputInput,ActionRemoveRecipeByRegex,ActionRemoveRegexTooltip,ActionRemoveTrade,ActionRemoveWanderingTrade,ActionReplaceRecipe,ActionSetBlockProperty,ActionSetBurnTime,ActionSetCauldronInteraction,ActionSetCompostable,ActionSetFood,ActionSetItemProperty,ActionTag,ActionTooltipBase,ActionTradeBase,ActionUnknownTag,ActionUnknownTagAdd,ActionUnknownTagClear,ActionUnknownTagCreate,ActionUnknownTagModify,ActionUnknownTagRemove,ActionWholeRegistryBase,ReplacerAction
All methods that are exposed to ZenCode should use classes that implement this interface or one of its sub-interfaces as required by semantics to ensure proper logging and rollback if necessary.
If an action should be executed on every game reload and not only during the first run of a
loader, refer to IRuntimeAction instead. If the action requires some additional
code to be run to correctly rollback changes, refer to IUndoableAction.
- Since:
- 9.1.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidapply()Applies the action, executing all code necessary.default booleanassertLoader(IScriptLoader loader) Ensures that an action is only applied on a certain loader.describe()Gets a human-readable description of the action.default CodePositionRetrieves the position in the script file where the action was created.default booleanshouldApplyOn(IScriptLoadSource source) Determines whether an action should be applied for scripts loading in the givenIScriptLoadSource.default booleanvalidate(org.apache.logging.log4j.Logger logger) Validates the action, ensuring no erroneous information is present.
-
Method Details
-
apply
void apply()Applies the action, executing all code necessary.- Since:
- 9.1.0
-
describe
String describe()Gets a human-readable description of the action.This message is used for logging and to surface information to the user when something goes wrong. It is thus customary to describe the action as accurately as possible without being too verbose.
It is not allowed to return a
nullor otherwise empty description for the action: doing so will raise an error at runtime.- Returns:
- A description of the current action.
- Since:
- 9.1.0
-
validate
default boolean validate(org.apache.logging.log4j.Logger logger) Validates the action, ensuring no erroneous information is present.Implementations should validate all action information and log errors using the provided
Loggerif anything is incorrect. It is highly suggested to specify exactly what is wrong in the most precise yet brief way possible, to ensure script writers know why their actions are not being applied.If validation fails for whatever reason,
apply()will not be called.- Parameters:
logger- Logger object on which to log errors or warnings.- Returns:
- Whether the action is valid (
true) or not (false). - Since:
- 9.1.0
-
shouldApplyOn
Determines whether an action should be applied for scripts loading in the givenIScriptLoadSource.- Parameters:
source- TheIScriptLoadSourceresponsible for loading the scripts.- Returns:
- If the action should be applied.
- Since:
- 9.1.0
-
getDeclaredScriptPosition
Retrieves the position in the script file where the action was created.The created
CodePositionwill always be a virtual position, meaning that its contents cannot be accessed.- Returns:
- The
CodePositionwhere the action was created on, orCodePosition.UNKNOWNif the information cannot be retrieved. - Since:
- 9.1.0
-
assertLoader
Ensures that an action is only applied on a certain loader.This method is not meant to be overridden, but rather used as an additional check in
shouldApplyOn(IScriptLoadSource)if needed.If the check fails, this method will also log a warning stating the script position where the error occurred if possible (see
getDeclaredScriptPosition()) and which loader is the one the action is supposed to be ran on.- Parameters:
loader- THeIScriptLoaderthe action should be only applied on.- Returns:
- If this loader matches the one specified as a parameter.
- Since:
- 9.1.0
-