aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bartworks/util/ResultWrongSievert.java
blob: fd1f7ce25b30f8725252b4d94fbac80d620dd62c (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
94
95
96
97
package bartworks.util;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.StatCollector;

import org.jetbrains.annotations.NotNull;

import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.util.GTUtility;

public class ResultWrongSievert implements CheckRecipeResult {

    public enum NeededSievertType {
        EXACTLY,
        MINIMUM
    }

    private NeededSievertType type;
    private int required;

    public ResultWrongSievert(int required, NeededSievertType type) {
        this.required = required;
        this.type = type;
    }

    public @NotNull String getID() {
        return "wrong_sievert";
    }

    @Override
    public boolean wasSuccessful() {
        return false;
    }

    @Override
    public @NotNull String getDisplayString() {
        return switch (this.type) {
            case EXACTLY -> StatCollector.translateToLocalFormatted(
                "GT5U.gui.text.wrong_sievert_exactly",
                GTUtility.formatNumbers(this.required));
            case MINIMUM -> StatCollector
                .translateToLocalFormatted("GT5U.gui.text.wrong_sievert_min", GTUtility.formatNumbers(this.required));
        };
    }

    @Override
    public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) {
        tag.setInteger("required", required);
        tag.setInteger("type", type.ordinal());
        return tag;
    }

    @Override
    public void readFromNBT(@NotNull NBTTagCompound tag) {
        required = tag.getInteger("required");
    }

    @Override
    public @NotNull CheckRecipeResult newInstance() {
        return new ResultWrongSievert(0, NeededSievertType.EXACTLY);
    }

    @Override
    public void encode(@NotNull PacketBuffer buffer) {
        buffer.writeVarIntToBuffer(this.required);
        buffer.writeVarIntToBuffer(this.type.ordinal());
    }

    @Override
    public void decode(PacketBuffer buffer) {
        this.required = buffer.readVarIntFromBuffer();
        this.type = NeededSievertType.values()[buffer.readVarIntFromBuffer()];
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || this.getClass() != o.getClass()) return false;
        ResultWrongSievert that = (ResultWrongSievert) o;
        return this.required == that.required;
    }

    /**
     * Cannot process recipe because the machine doesn't have the minimum amount of sievert
     */
    public static CheckRecipeResult insufficientSievert(int required) {
        return new ResultWrongSievert(required, NeededSievertType.MINIMUM);
    }

    /**
     * Cannot process recipe because the machine doesn't have the exact amount of sievert
     */
    public static CheckRecipeResult wrongSievert(int required) {
        return new ResultWrongSievert(required, NeededSievertType.EXACTLY);
    }
}