aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/api/thermal/energy/ThermalStorage.java
blob: a2c29ba76ad64d5045b82e55a497da07ee854849 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package gtPlusPlus.api.thermal.energy;

import net.minecraft.nbt.NBTTagCompound;

public class ThermalStorage implements IThermalStorage {

    protected int thermal_energy;
    protected int capacity;
    protected int maxReceive;
    protected int maxExtract;

    public ThermalStorage(int arg0) {
        this(arg0, arg0, arg0);
    }

    public ThermalStorage(int arg0, int arg1) {
        this(arg0, arg1, arg1);
    }

    public ThermalStorage(int arg0, int arg1, int arg2) {
        this.capacity = arg0;
        this.maxReceive = arg1;
        this.maxExtract = arg2;
    }

    public ThermalStorage readFromNBT(NBTTagCompound arg0) {
        this.thermal_energy = arg0.getInteger("ThermalEnergy");
        if (this.thermal_energy > this.capacity) {
            this.thermal_energy = this.capacity;
        }
        return this;
    }

    public NBTTagCompound writeToNBT(NBTTagCompound arg0) {
        if (this.thermal_energy < 0) {
            this.thermal_energy = 0;
        }
        arg0.setInteger("ThermalEnergy", this.thermal_energy);
        return arg0;
    }

    public void setCapacity(int arg0) {
        this.capacity = arg0;
        if (this.thermal_energy > arg0) {
            this.thermal_energy = arg0;
        }
    }

    public void setMaxTransfer(int arg0) {
        this.setMaxReceive(arg0);
        this.setMaxExtract(arg0);
    }

    public void setMaxReceive(int arg0) {
        this.maxReceive = arg0;
    }

    public void setMaxExtract(int arg0) {
        this.maxExtract = arg0;
    }

    public int getMaxReceive() {
        return this.maxReceive;
    }

    public int getMaxExtract() {
        return this.maxExtract;
    }

    public void setEnergyStored(int arg0) {
        this.thermal_energy = arg0;
        if (this.thermal_energy > this.capacity) {
            this.thermal_energy = this.capacity;
        } else if (this.thermal_energy < 0) {
            this.thermal_energy = 0;
        }
    }

    public void modifyEnergyStored(int arg0) {
        this.thermal_energy += arg0;
        if (this.thermal_energy > this.capacity) {
            this.thermal_energy = this.capacity;
        } else if (this.thermal_energy < 0) {
            this.thermal_energy = 0;
        }
    }

    @Override
    public int receiveThermalEnergy(int arg0, boolean arg1) {
        int arg2 = Math.min(this.capacity - this.thermal_energy, Math.min(this.maxReceive, arg0));
        if (!arg1) {
            this.thermal_energy += arg2;
        }

        return arg2;
    }

    @Override
    public int extractThermalEnergy(int arg0, boolean arg1) {
        int arg2 = Math.min(this.thermal_energy, Math.min(this.maxExtract, arg0));
        if (!arg1) {
            this.thermal_energy -= arg2;
        }

        return arg2;
    }

    @Override
    public int getThermalEnergyStored() {
        return this.thermal_energy;
    }

    @Override
    public int getMaxThermalEnergyStored() {
        return this.capacity;
    }
}