blob: 772fc203ea58bbca3ebe5497b403d7b62359d6f0 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package gregtech.api.util.shutdown;
import java.util.Objects;
import javax.annotation.Nonnull;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.StatCollector;
import org.jetbrains.annotations.NotNull;
import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils;
/**
* Simple implementation of {@link ShutDownReason}. You can create new object without registering it.
*/
public class SimpleShutDownReason implements ShutDownReason {
private String key;
private boolean wasCritical;
public SimpleShutDownReason(String key, boolean isCritical) {
this.key = key;
this.wasCritical = isCritical;
}
@NotNull
@Override
public String getID() {
return "simple_result";
}
@NotNull
@Override
public String getDisplayString() {
return Objects.requireNonNull(StatCollector.translateToLocal("GT5U.gui.text." + key));
}
@Override
public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) {
tag.setString("key", key);
tag.setBoolean("wasCritical", wasCritical);
return tag;
}
@Override
public void readFromNBT(@NotNull NBTTagCompound tag) {
key = tag.getString("key");
wasCritical = tag.getBoolean("wasCritical");
}
@NotNull
@Override
public ShutDownReason newInstance() {
return new SimpleShutDownReason("", false);
}
@Override
public void encode(@NotNull PacketBuffer buffer) {
buffer.writeBoolean(wasCritical);
NetworkUtils.writeStringSafe(buffer, key);
}
@Override
public void decode(PacketBuffer buffer) {
wasCritical = buffer.readBoolean();
key = NetworkUtils.readStringSafe(buffer);
}
@Override
public boolean wasCritical() {
return wasCritical;
}
/**
* Creates new reason with critical state. Add your localized description with `GT5U.gui.text.{key}`.
* This is already registered to registry.
*/
@Nonnull
public static ShutDownReason ofCritical(String key) {
return new SimpleShutDownReason(key, true);
}
/**
* Creates new reason with normal state. Add your localized description with `GT5U.gui.text.{key}`.
* This is already registered to registry.
*/
@Nonnull
public static ShutDownReason ofNormal(String key) {
return new SimpleShutDownReason(key, false);
}
}
|