-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathFluidPipeProperties.java
More file actions
178 lines (147 loc) · 5.57 KB
/
Copy pathFluidPipeProperties.java
File metadata and controls
178 lines (147 loc) · 5.57 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package gregtech.api.unification.material.properties;
import gregtech.api.capability.IPropertyFluidFilter;
import gregtech.api.fluids.FluidState;
import gregtech.api.fluids.attribute.FluidAttribute;
import gregtech.api.fluids.attribute.FluidAttributes;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnmodifiableView;
import java.util.Collection;
import java.util.Objects;
public class FluidPipeProperties implements IMaterialProperty, IPropertyFluidFilter<FluidPipeProperties> {
private final Object2BooleanMap<FluidAttribute> containmentPredicate = new Object2BooleanOpenHashMap<>();
private int throughput;
private final int tanks;
private int maxFluidTemperature;
private boolean gasProof;
private boolean cryoProof;
private boolean plasmaProof;
public FluidPipeProperties(int maxFluidTemperature, int throughput, boolean gasProof, boolean acidProof,
boolean cryoProof, boolean plasmaProof) {
this(maxFluidTemperature, throughput, gasProof, acidProof, cryoProof, plasmaProof, 1);
}
/**
* Should only be called from
* {@link gregtech.common.pipelike.fluidpipe.FluidPipeType#modifyProperties(FluidPipeProperties)}
*/
public FluidPipeProperties(int maxFluidTemperature, int throughput, boolean gasProof, boolean acidProof,
boolean cryoProof, boolean plasmaProof, int tanks) {
this.maxFluidTemperature = maxFluidTemperature;
this.throughput = throughput;
this.gasProof = gasProof;
if (acidProof) setCanContain(FluidAttributes.ACID, true);
this.cryoProof = cryoProof;
this.plasmaProof = plasmaProof;
this.tanks = tanks;
}
/**
* Default property constructor.
*/
public FluidPipeProperties() {
this(300, 1, false, false, false, false);
}
@Override
public void verifyProperty(MaterialProperties properties) {
if (!properties.hasProperty(PropertyKey.WOOD)) {
properties.ensureSet(PropertyKey.INGOT, true);
}
if (properties.hasProperty(PropertyKey.ITEM_PIPE)) {
throw new IllegalStateException(
"Material " + properties.getMaterial() +
" has both Fluid and Item Pipe Property, which is not allowed!");
}
}
public int getTanks() {
return tanks;
}
public int getThroughput() {
return throughput;
}
public FluidPipeProperties setThroughput(int throughput) {
this.throughput = throughput;
return this;
}
@Override
public int getMaxFluidTemperature() {
return maxFluidTemperature;
}
public FluidPipeProperties setMaxFluidTemperature(int maxFluidTemperature) {
this.maxFluidTemperature = maxFluidTemperature;
return this;
}
@Override
public boolean canContain(@NotNull FluidState state) {
return switch (state) {
case LIQUID -> true;
case GAS -> gasProof;
case PLASMA -> plasmaProof;
};
}
@Override
public boolean canContain(@NotNull FluidAttribute attribute) {
return containmentPredicate.getBoolean(attribute);
}
@Override
public FluidPipeProperties setCanContain(@NotNull FluidAttribute attribute, boolean canContain) {
this.containmentPredicate.put(attribute, canContain);
return this;
}
@Override
public @NotNull @UnmodifiableView Collection<@NotNull FluidAttribute> getContainedAttributes() {
return containmentPredicate.keySet();
}
public boolean isGasProof() {
return gasProof;
}
public FluidPipeProperties setGasProof(boolean gasProof) {
this.gasProof = gasProof;
return this;
}
public boolean isAcidProof() {
return canContain(FluidAttributes.ACID);
}
public boolean isCryoProof() {
return cryoProof;
}
public FluidPipeProperties setCryoProof(boolean cryoProof) {
this.cryoProof = cryoProof;
return this;
}
public boolean isPlasmaProof() {
return plasmaProof;
}
public FluidPipeProperties setPlasmaProof(boolean plasmaProof) {
this.plasmaProof = plasmaProof;
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FluidPipeProperties that)) return false;
return getThroughput() == that.getThroughput() &&
getTanks() == that.getTanks() &&
getMaxFluidTemperature() == that.getMaxFluidTemperature() &&
isGasProof() == that.isGasProof() &&
isCryoProof() == that.isCryoProof() &&
isPlasmaProof() == that.isPlasmaProof() &&
containmentPredicate.equals(that.containmentPredicate);
}
@Override
public int hashCode() {
return Objects.hash(getThroughput(), getTanks(), getMaxFluidTemperature(), gasProof, cryoProof, plasmaProof,
containmentPredicate);
}
@Override
public String toString() {
return "FluidPipeProperties{" +
"throughput=" + throughput +
", tanks=" + tanks +
", maxFluidTemperature=" + maxFluidTemperature +
", gasProof=" + gasProof +
", cryoProof=" + cryoProof +
", plasmaProof=" + plasmaProof +
", containmentPredicate=" + containmentPredicate +
'}';
}
}