blob: 40ebcea0f4fda316a4d52f3aafdd2b0d7f317c07 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package gregtech.api.gui.modularui;
import com.gtnewhorizons.modularui.api.widget.Widget;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.util.ISerializableObject;
import gregtech.common.gui.modularui.widget.DataControllerWidget;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* Widget whose state is controlled by specific data.
* Data can be anything, e.g. {@link ISerializableObject} or machine recipe mode.
* <br> No widgets implementing this interface should not sync;
* Instead, {@link DataControllerWidget} will sync data, either when this widget triggers update on client
* or data update is detected on server.
* @param <T> Data type stored in the parent widget
* @param <U> State type stored in this widget
* @see DataControllerWidget
*/
@SuppressWarnings("UnusedReturnValue")
public interface IDataFollowerWidget<T, U> {
/**
* Sets function to get widget state from provided data. This function will be called when client receives data
* from server and {@link DataControllerWidget} updates all children, including this widget.
*/
Widget setDataToStateGetter(Function<T, U> dataToStateGetter);
/**
* Sets setter called when this widget gets action from player.
* Basically the same functionality with widgets that have getter/setter.
*/
Widget setStateSetter(Consumer<U> setter);
/**
* Updates state of this widget with provided data.
* On server {@link DataControllerWidget} won't propagate data update to this widget,
* so this method is client-only.
*/
@SideOnly(Side.CLIENT)
void updateState(T data);
/**
* Called on {@link Widget#onPostInit}.
*/
default void onPostInit() {}
}
|