blob: 05e5ae689cb61d0a77e9df29fc6fe6742feabd0e (
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
package mekanism.api.gas;
import net.minecraft.nbt.NBTTagCompound;
/**
* GasStack - a specified amount of a defined Gas with certain properties.
* @author aidancbrady
*
*/
public class GasStack
{
private Gas type;
public int amount;
/**
* Creates a new GasStack with a defined gas ID and quantity.
* @param id - gas ID to associate this GasStack to, will perform a GasRegistry lookup in the constructor
* @param quantity - amount of gas to be referenced in this GasStack
*/
public GasStack(int id, int quantity)
{
type = GasRegistry.getGas(id);
amount = quantity;
}
/**
* Creates a new GasStack with a defined Gas type and quantity.
* @param gas - gas type of the stack
* @param quantity - amount of gas to be referenced in this GasStack
*/
public GasStack(Gas gas, int quantity)
{
type = gas;
amount = quantity;
}
private GasStack() {}
/**
* Gets the Gas type of this GasStack.
* @return this GasStack's Gas type
*/
public Gas getGas()
{
return type;
}
public GasStack withAmount(int newAmount)
{
amount = newAmount;
return this;
}
/**
* Writes this GasStack to a defined tag compound.
* @param nbtTags - tag compound to write to
* @return tag compound with this GasStack's data
*/
public NBTTagCompound write(NBTTagCompound nbtTags)
{
type.write(nbtTags);
nbtTags.setInteger("amount", amount);
return nbtTags;
}
/**
* Reads this GasStack's data from a defined tag compound.
* @param nbtTags - tag compound to read from
*/
public void read(NBTTagCompound nbtTags)
{
type = Gas.readFromNBT(nbtTags);
amount = nbtTags.getInteger("amount");
}
/**
* Returns the GasStack stored in the defined tag compound, or null if it doesn't exist.
* @param nbtTags - tag compound to read from
* @return GasStack stored in the tag compound
*/
public static GasStack readFromNBT(NBTTagCompound nbtTags)
{
if(nbtTags == null || nbtTags.hasNoTags())
{
return null;
}
GasStack stack = new GasStack();
stack.read(nbtTags);
if(stack.getGas() == null || stack.amount <= 0)
{
return null;
}
return stack;
}
/**
* Returns a copied form of this GasStack.
* @return copied GasStack
*/
public GasStack copy()
{
return new GasStack(type, amount);
}
/**
* Whether or not this GasStack's gas type is equal to the other defined GasStack.
* @param stack - GasStack to check
* @return if the GasStacks contain the same gas type
*/
public boolean isGasEqual(GasStack stack)
{
return stack != null && getGas() == stack.getGas();
}
@Override
public String toString()
{
return "[" + type + ", " + amount + "]";
}
@Override
public int hashCode()
{
return type == null ? 0 : type.getID();
}
}
|