-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Regarding this API usage:
builder.putElement(slot, new ActionableElement(
new RunnableAction(container, ActionType.NONE, "", context -> {}),
item
));
This is messy for a number of reasons:
- There is no reason to provide the
StateContainerto anAction- context can be passed when necessary. - Even if the
ActionTypeisNONE, you still have to pass agoalState. Even though this could be made a default property of anAction, such that if only the container and effective consumer (context -> {}) is passed, it still isn't as clean as it could be. In reality,goalStatelogic is just another consumer permanently attached to theAction, when they could easily be merged together.
I propose:
ActionableElement::new(ItemStack, Consumer<ActionContext>)
Here, ActionContext replaces what was initially RunnableAction and replaces the functionality of the consumer, however here it is not the RunnableAction passed into the anonymous function - it is an object specifically for the runnable's context.
To replace the functionality of goalState transition being easily requested with ActionType I propose Actions.GO and Actions.BACK, where Actions is an interface consisting of static default Consumer<ActionContext which automatically change the state.
Actions.GO could be defined as state -> context -> context.setState(state), which allows the use of Actions.GO("some_state").
Actions.BACK could be defined context -> context.setState(context.getParent()) or just context -> context.back(). It is useful to shorten this, because of the following scenario.
new ActionableElement(item, context -> {
context.getObserver().sendMessage(...);
context.back();
});
This allows for the previous functionality where a runnable can be executed AND the state can be changed at once.