aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/gui/modularui/widget/ShutDownReasonSyncer.java
blob: 21c19e524c3ac40ad582a844387e14429adeb232 (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
package gregtech.common.gui.modularui.widget;

import java.util.function.Consumer;
import java.util.function.Supplier;

import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;

import gregtech.api.util.shutdown.ShutDownReason;
import gregtech.api.util.shutdown.ShutDownReasonRegistry;

public class ShutDownReasonSyncer extends FakeSyncWidget<ShutDownReason> {

    public ShutDownReasonSyncer(Supplier<ShutDownReason> getter, Consumer<ShutDownReason> setter) {
        super(getter, setter, (buffer, result) -> {
            NetworkUtils.writeStringSafe(buffer, result.getID());
            result.encode(buffer);
        }, buffer -> {
            String id = NetworkUtils.readStringSafe(buffer);
            ShutDownReason result = ShutDownReasonRegistry.getSampleFromRegistry(id)
                .newInstance();
            result.decode(buffer);
            return result;
        });
    }
}