Skip to content

Commit 96b0dcc

Browse files
authored
Make all material property setters return themselves to allow method chaining (GregTechCEu#2820)
1 parent 95aa35e commit 96b0dcc

File tree

13 files changed

+108
-57
lines changed

13 files changed

+108
-57
lines changed

src/main/java/gregtech/api/capability/IPropertyFluidFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @see gregtech.api.fluids.attribute.FluidAttributes
2626
* @see AttributedFluid
2727
*/
28-
public interface IPropertyFluidFilter extends IFilter<FluidStack> {
28+
public interface IPropertyFluidFilter<R> extends IFilter<FluidStack> {
2929

3030
@Override
3131
default boolean test(@NotNull FluidStack stack) {
@@ -79,7 +79,7 @@ default int getPriority() {
7979
* @param attribute the attribute to change containment status for
8080
* @param canContain whether the attribute can be contained
8181
*/
82-
void setCanContain(@NotNull FluidAttribute attribute, boolean canContain);
82+
R setCanContain(@NotNull FluidAttribute attribute, boolean canContain);
8383

8484
@NotNull
8585
@UnmodifiableView

src/main/java/gregtech/api/capability/impl/PropertyFluidFilter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import java.util.Collection;
1414

15-
public class PropertyFluidFilter implements IPropertyFluidFilter {
15+
public class PropertyFluidFilter implements IPropertyFluidFilter<PropertyFluidFilter> {
1616

1717
private final Object2BooleanMap<FluidAttribute> containmentPredicate = new Object2BooleanOpenHashMap<>();
1818

@@ -48,8 +48,9 @@ public boolean canContain(@NotNull FluidAttribute attribute) {
4848
}
4949

5050
@Override
51-
public void setCanContain(@NotNull FluidAttribute attribute, boolean canContain) {
51+
public PropertyFluidFilter setCanContain(@NotNull FluidAttribute attribute, boolean canContain) {
5252
containmentPredicate.put(attribute, canContain);
53+
return this;
5354
}
5455

5556
@Override

src/main/java/gregtech/api/unification/material/properties/BlastProperty.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,49 +81,55 @@ public int getBlastTemperature() {
8181
return blastTemperature;
8282
}
8383

84-
public void setBlastTemperature(int blastTemp) {
84+
public BlastProperty setBlastTemperature(int blastTemp) {
8585
if (blastTemp <= 0) throw new IllegalArgumentException("Blast Temperature must be greater than zero!");
8686
this.blastTemperature = blastTemp;
87+
return this;
8788
}
8889

8990
public GasTier getGasTier() {
9091
return gasTier;
9192
}
9293

93-
public void setGasTier(@NotNull GasTier tier) {
94+
public BlastProperty setGasTier(@NotNull GasTier tier) {
9495
this.gasTier = tier;
96+
return this;
9597
}
9698

9799
public int getDurationOverride() {
98100
return durationOverride;
99101
}
100102

101-
public void setDurationOverride(int duration) {
103+
public BlastProperty setDurationOverride(int duration) {
102104
this.durationOverride = duration;
105+
return this;
103106
}
104107

105108
public int getEUtOverride() {
106109
return eutOverride;
107110
}
108111

109-
public void setEutOverride(int eut) {
112+
public BlastProperty setEutOverride(int eut) {
110113
this.eutOverride = eut;
114+
return this;
111115
}
112116

113117
public int getVacuumDurationOverride() {
114118
return vacuumDurationOverride;
115119
}
116120

117-
public void setVacuumDurationOverride(int duration) {
121+
public BlastProperty setVacuumDurationOverride(int duration) {
118122
this.vacuumDurationOverride = duration;
123+
return this;
119124
}
120125

121126
public int getVacuumEUtOverride() {
122127
return vacuumEUtOverride;
123128
}
124129

125-
public void setVacuumEutOverride(int eut) {
130+
public BlastProperty setVacuumEutOverride(int eut) {
126131
this.vacuumEUtOverride = eut;
132+
return this;
127133
}
128134

129135
@Override

src/main/java/gregtech/api/unification/material/properties/DustProperty.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@ public DustProperty() {
2929
this(2, 0);
3030
}
3131

32-
public void setHarvestLevel(int harvestLevel) {
32+
public DustProperty setHarvestLevel(int harvestLevel) {
3333
if (harvestLevel <= 0) throw new IllegalArgumentException("Harvest Level must be greater than zero!");
3434
this.harvestLevel = harvestLevel;
35+
return this;
3536
}
3637

3738
public int getHarvestLevel() {
3839
return this.harvestLevel;
3940
}
4041

41-
public void setBurnTime(int burnTime) {
42+
public DustProperty setBurnTime(int burnTime) {
4243
if (burnTime < 0) throw new IllegalArgumentException("Burn Time cannot be negative!");
4344
this.burnTime = burnTime;
45+
return this;
4446
}
4547

4648
public int getBurnTime() {

src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public OverrideToolProperty() {
2828
}
2929

3030
// It does not make much sense to set these overrides:
31-
public void setShouldIgnoreCraftingTools(boolean ignore) {
31+
public OverrideToolProperty setShouldIgnoreCraftingTools(boolean ignore) {
3232
throw new UnsupportedOperationException();
3333
}
3434

35-
public void setUnbreakable(boolean isUnbreakable) {
35+
public OverrideToolProperty setUnbreakable(boolean isUnbreakable) {
3636
throw new UnsupportedOperationException();
3737
}
3838

src/main/java/gregtech/api/unification/material/properties/FluidPipeProperties.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.util.Collection;
1414
import java.util.Objects;
1515

16-
public class FluidPipeProperties implements IMaterialProperty, IPropertyFluidFilter {
16+
public class FluidPipeProperties implements IMaterialProperty, IPropertyFluidFilter<FluidPipeProperties> {
1717

1818
private final Object2BooleanMap<FluidAttribute> containmentPredicate = new Object2BooleanOpenHashMap<>();
1919

@@ -73,17 +73,19 @@ public int getThroughput() {
7373
return throughput;
7474
}
7575

76-
public void setThroughput(int throughput) {
76+
public FluidPipeProperties setThroughput(int throughput) {
7777
this.throughput = throughput;
78+
return this;
7879
}
7980

8081
@Override
8182
public int getMaxFluidTemperature() {
8283
return maxFluidTemperature;
8384
}
8485

85-
public void setMaxFluidTemperature(int maxFluidTemperature) {
86+
public FluidPipeProperties setMaxFluidTemperature(int maxFluidTemperature) {
8687
this.maxFluidTemperature = maxFluidTemperature;
88+
return this;
8789
}
8890

8991
@Override
@@ -101,8 +103,9 @@ public boolean canContain(@NotNull FluidAttribute attribute) {
101103
}
102104

103105
@Override
104-
public void setCanContain(@NotNull FluidAttribute attribute, boolean canContain) {
106+
public FluidPipeProperties setCanContain(@NotNull FluidAttribute attribute, boolean canContain) {
105107
this.containmentPredicate.put(attribute, canContain);
108+
return this;
106109
}
107110

108111
@Override
@@ -114,8 +117,9 @@ public boolean isGasProof() {
114117
return gasProof;
115118
}
116119

117-
public void setGasProof(boolean gasProof) {
120+
public FluidPipeProperties setGasProof(boolean gasProof) {
118121
this.gasProof = gasProof;
122+
return this;
119123
}
120124

121125
public boolean isAcidProof() {
@@ -126,16 +130,18 @@ public boolean isCryoProof() {
126130
return cryoProof;
127131
}
128132

129-
public void setCryoProof(boolean cryoProof) {
133+
public FluidPipeProperties setCryoProof(boolean cryoProof) {
130134
this.cryoProof = cryoProof;
135+
return this;
131136
}
132137

133138
public boolean isPlasmaProof() {
134139
return plasmaProof;
135140
}
136141

137-
public void setPlasmaProof(boolean plasmaProof) {
142+
public FluidPipeProperties setPlasmaProof(boolean plasmaProof) {
138143
this.plasmaProof = plasmaProof;
144+
return this;
139145
}
140146

141147
@Override

src/main/java/gregtech/api/unification/material/properties/FluidProperty.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ public void store(@NotNull FluidStorageKey key, @NotNull Fluid fluid) {
8181
/**
8282
* @param primaryKey the key to use primarily
8383
*/
84-
public void setPrimaryKey(@NotNull FluidStorageKey primaryKey) {
84+
public FluidProperty setPrimaryKey(@NotNull FluidStorageKey primaryKey) {
8585
this.primaryKey = primaryKey;
86+
return this;
8687
}
8788

8889
@Override
@@ -116,7 +117,8 @@ public FluidStack solidifiesFrom(int amount) {
116117
* @param solidifyingFluid The Fluid which solidifies into the material. If left null, it will be left as the
117118
* default value: the material's liquid.
118119
*/
119-
public void setSolidifyingFluid(@Nullable Fluid solidifyingFluid) {
120+
public FluidProperty setSolidifyingFluid(@Nullable Fluid solidifyingFluid) {
120121
this.solidifyingFluid = solidifyingFluid;
122+
return this;
121123
}
122124
}

src/main/java/gregtech/api/unification/material/properties/IngotProperty.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,37 @@ public class IngotProperty implements IMaterialProperty {
2929
@Nullable
3030
private Material magneticMaterial;
3131

32-
public void setSmeltingInto(Material smeltInto) {
32+
public IngotProperty setSmeltingInto(Material smeltInto) {
3333
this.smeltInto = smeltInto;
34+
return this;
3435
}
3536

3637
public Material getSmeltingInto() {
3738
return this.smeltInto;
3839
}
3940

40-
public void setArcSmeltingInto(Material arcSmeltingInto) {
41+
public IngotProperty setArcSmeltingInto(Material arcSmeltingInto) {
4142
this.arcSmeltInto = arcSmeltingInto;
43+
return this;
4244
}
4345

4446
public Material getArcSmeltInto() {
4547
return this.arcSmeltInto;
4648
}
4749

48-
public void setMagneticMaterial(@Nullable Material magneticMaterial) {
50+
public IngotProperty setMagneticMaterial(@Nullable Material magneticMaterial) {
4951
this.magneticMaterial = magneticMaterial;
52+
return this;
5053
}
5154

5255
@Nullable
5356
public Material getMagneticMaterial() {
5457
return magneticMaterial;
5558
}
5659

57-
public void setMacerateInto(Material macerateInto) {
60+
public IngotProperty setMacerateInto(Material macerateInto) {
5861
this.macerateInto = macerateInto;
62+
return this;
5963
}
6064

6165
public Material getMacerateInto() {

src/main/java/gregtech/api/unification/material/properties/ItemPipeProperties.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ public int getPriority() {
3838
/**
3939
* Sets the Priority of the item pipe
4040
*/
41-
public void setPriority(int priority) {
41+
public ItemPipeProperties setPriority(int priority) {
4242
this.priority = priority;
43+
return this;
4344
}
4445

4546
/**
@@ -56,8 +57,9 @@ public float getTransferRate() {
5657
*
5758
* @param transferRate The transfer rate
5859
*/
59-
public void setTransferRate(float transferRate) {
60+
public ItemPipeProperties setTransferRate(float transferRate) {
6061
this.transferRate = transferRate;
62+
return this;
6163
}
6264

6365
@Override

src/main/java/gregtech/api/unification/material/properties/OreProperty.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,18 @@ public OreProperty() {
105105
this(1, 1);
106106
}
107107

108-
public void setOreMultiplier(int multiplier) {
108+
public OreProperty setOreMultiplier(int multiplier) {
109109
this.oreMultiplier = multiplier;
110+
return this;
110111
}
111112

112113
public int getOreMultiplier() {
113114
return this.oreMultiplier;
114115
}
115116

116-
public void setByProductMultiplier(int multiplier) {
117+
public OreProperty setByProductMultiplier(int multiplier) {
117118
this.byProductMultiplier = multiplier;
119+
return this;
118120
}
119121

120122
public int getByProductMultiplier() {
@@ -125,34 +127,39 @@ public boolean isEmissive() {
125127
return emissive;
126128
}
127129

128-
public void setEmissive(boolean emissive) {
130+
public OreProperty setEmissive(boolean emissive) {
129131
this.emissive = emissive;
132+
return this;
130133
}
131134

132-
public void setDirectSmeltResult(@Nullable Material m) {
135+
public OreProperty setDirectSmeltResult(@Nullable Material m) {
133136
this.directSmeltResult = m;
137+
return this;
134138
}
135139

136140
@Nullable
137141
public Material getDirectSmeltResult() {
138142
return this.directSmeltResult;
139143
}
140144

141-
public void setWashedIn(@Nullable Material m) {
145+
public OreProperty setWashedIn(@Nullable Material m) {
142146
this.washedIn = m;
147+
return this;
143148
}
144149

145-
public void setWashedIn(@Nullable Material m, int washedAmount) {
150+
public OreProperty setWashedIn(@Nullable Material m, int washedAmount) {
146151
this.washedIn = m;
147152
this.washedAmount = washedAmount;
153+
return this;
148154
}
149155

150156
public Pair<Material, Integer> getWashedIn() {
151157
return Pair.of(this.washedIn, this.washedAmount);
152158
}
153159

154-
public void setSeparatedInto(Material... materials) {
160+
public OreProperty setSeparatedInto(Material... materials) {
155161
this.separatedInto.addAll(Arrays.asList(materials));
162+
return this;
156163
}
157164

158165
@Nullable
@@ -165,27 +172,30 @@ public List<Material> getSeparatedInto() {
165172
*
166173
* @param materials the materials to use as byproducts
167174
*/
168-
public void setOreByProducts(@NotNull Material... materials) {
175+
public OreProperty setOreByProducts(@NotNull Material... materials) {
169176
setOreByProducts(Arrays.asList(materials));
177+
return this;
170178
}
171179

172180
/**
173181
* Set the ore byproducts for this property
174182
*
175183
* @param materials the materials to use as byproducts
176184
*/
177-
public void setOreByProducts(@NotNull Collection<Material> materials) {
185+
public OreProperty setOreByProducts(@NotNull Collection<Material> materials) {
178186
this.oreByProducts.clear();
179187
this.oreByProducts.addAll(materials);
188+
return this;
180189
}
181190

182191
/**
183192
* Add ore byproducts to this property
184193
*
185194
* @param materials the materials to add as byproducts
186195
*/
187-
public void addOreByProducts(@NotNull Material... materials) {
196+
public OreProperty addOreByProducts(@NotNull Material... materials) {
188197
this.oreByProducts.addAll(Arrays.asList(materials));
198+
return this;
189199
}
190200

191201
public List<Material> getOreByProducts() {

0 commit comments

Comments
 (0)