Skip to content

Commit 11e1d40

Browse files
committed
make custom coil stats private final and initialize in constructor
add javadoc to explain some methods
1 parent 320e60a commit 11e1d40

File tree

3 files changed

+136
-34
lines changed

3 files changed

+136
-34
lines changed
Lines changed: 98 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package gregtech.api.block.coil;
22

3+
import gregtech.api.GTValues;
4+
import gregtech.api.recipes.properties.impl.TemperatureProperty;
35
import gregtech.api.unification.material.Material;
6+
import gregtech.api.unification.material.Materials;
47
import gregtech.api.util.GTUtility;
58
import gregtech.api.util.function.QuadConsumer;
69

@@ -13,76 +16,152 @@
1316

1417
public class CoilStatBuilder {
1518

16-
private final CustomCoilStats stats;
17-
private ResourceLocation textureLocation;
1819
private final String modid;
1920

21+
private String name;
22+
23+
// electric blast furnace properties
24+
private int coilTemperature = -1;
25+
26+
// multi smelter properties
27+
private int level = -1;
28+
private int energyDiscount = 0;
29+
30+
// voltage tier
31+
private int tier = GTValues.ULV;
32+
33+
private Material material = Materials.Iron;
34+
private ResourceLocation textureLocation;
35+
private boolean isGeneric;
36+
private QuadConsumer<ItemStack, World, List<String>, Boolean> additionalTooltips;
37+
2038
CoilStatBuilder(String modid) {
2139
this.modid = modid;
22-
this.stats = new CustomCoilStats();
2340
}
2441

42+
/**
43+
* @param material Material that this coil should be based off of. Used for
44+
* {@link TemperatureProperty#registerCoilType(int, Material, String)}.
45+
* @return this
46+
*/
2547
public CoilStatBuilder material(Material material) {
26-
stats.material = material;
27-
stats.name = material.getResourceLocation().getPath();
48+
return material(material, material.getName());
49+
}
50+
51+
/**
52+
* @param material Material that this coil should be based off of. Used for
53+
* {@link TemperatureProperty#registerCoilType(int, Material, String)}.
54+
* @param name Name of the variant to look for in the model json (typically the name of the material).
55+
* @return this
56+
*/
57+
public CoilStatBuilder material(Material material, String name) {
58+
this.material = material;
59+
this.name = name;
2860
return this;
2961
}
3062

3163
public CoilStatBuilder coilTemp(int coilTemperature) {
32-
stats.coilTemperature = coilTemperature;
64+
this.coilTemperature = coilTemperature;
3365
return this;
3466
}
3567

68+
/**
69+
* @param tier The voltage tier of this coil variant, used for the energy discount in the cracking unit and pyrolyse
70+
* oven
71+
* @return this
72+
*/
3673
public CoilStatBuilder tier(int tier) {
37-
stats.tier = Math.max(0, tier);
74+
this.tier = Math.max(0, tier);
3875
return this;
3976
}
4077

78+
/**
79+
* @param level This is used for the amount of parallel recipes in the multi smelter. Multiplied by 32.
80+
* @param energyDiscount This is used for the energy discount in the multi smelter
81+
* @return this
82+
*/
4183
public CoilStatBuilder multiSmelter(int level, int energyDiscount) {
42-
stats.level = level;
43-
stats.energyDiscount = energyDiscount;
84+
this.level = level;
85+
this.energyDiscount = energyDiscount;
4486
return this;
4587
}
4688

89+
/**
90+
* @param location Location of the block model json
91+
* @return this
92+
*/
4793
public CoilStatBuilder texture(String location) {
4894
this.textureLocation = new ResourceLocation(this.modid, location);
4995
return this;
5096
}
5197

98+
/**
99+
* @param location Location of the block model json
100+
* @param generic If true, the coil will use a grayscale texture to tint based off of the materials color.
101+
* Otherwise, it will look for a texture specifically for this variant.
102+
* @return this
103+
*/
52104
public CoilStatBuilder texture(String location, boolean generic) {
53105
return texture(location).generic(generic);
54106
}
55107

108+
/**
109+
* @param generic If true, the coil will use a grayscale texture to tint based off of the materials color.
110+
* Otherwise, it will look for a texture specifically for this variant.
111+
* @return this
112+
*/
56113
public CoilStatBuilder generic(boolean generic) {
57-
this.stats.isGeneric = generic;
114+
this.isGeneric = generic;
58115
return this;
59116
}
60117

118+
/**
119+
* Marks this variant as generic, it will look for a grayscale texture and tint based on material color.
120+
*
121+
* @return this
122+
*/
61123
public CoilStatBuilder generic() {
62124
return generic(true);
63125
}
64126

127+
/**
128+
* @param additionalTooltips Used for adding additional tooltips for this variant
129+
* @return this
130+
*/
65131
public CoilStatBuilder tooltip(QuadConsumer<ItemStack, World, List<String>, Boolean> additionalTooltips) {
66-
this.stats.additionalTooltips = additionalTooltips;
132+
this.additionalTooltips = additionalTooltips;
67133
return this;
68134
}
69135

70136
CustomCoilStats build() {
71137
if (this.textureLocation == null) {
72138
this.textureLocation = GTUtility.gregtechId("wire_coil");
73139
}
140+
74141
String variant;
75-
if (this.stats.isGeneric) {
142+
ModelResourceLocation inactive;
143+
ModelResourceLocation active;
144+
if (this.isGeneric) {
76145
variant = "%s";
77-
this.stats.inactive = new ModelResourceLocation(this.textureLocation, String.format(variant, "normal"));
78-
this.stats.active = new ModelResourceLocation(this.textureLocation, String.format(variant, "active"));
146+
inactive = new ModelResourceLocation(this.textureLocation, String.format(variant, "normal"));
147+
active = new ModelResourceLocation(this.textureLocation, String.format(variant, "active"));
79148
} else {
80149
variant = "active=%s,variant=%s";
81-
this.stats.inactive = new ModelResourceLocation(this.textureLocation,
82-
String.format(variant, false, stats.name));
83-
this.stats.active = new ModelResourceLocation(this.textureLocation,
84-
String.format(variant, true, stats.name));
150+
inactive = new ModelResourceLocation(this.textureLocation,
151+
String.format(variant, false, this.name));
152+
active = new ModelResourceLocation(this.textureLocation,
153+
String.format(variant, true, this.name));
85154
}
86-
return this.stats;
155+
return new CustomCoilStats(
156+
this.name,
157+
this.coilTemperature,
158+
this.level,
159+
this.energyDiscount,
160+
this.tier,
161+
this.material,
162+
active,
163+
inactive,
164+
this.isGeneric,
165+
this.additionalTooltips);
87166
}
88167
}

src/main/java/gregtech/api/block/coil/CustomCoilBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public CustomCoilBlock(List<CustomCoilStats> stats) {
6565
@NotNull
6666
@Override
6767
public BlockRenderLayer getRenderLayer(CustomCoilStats value) {
68-
return value.isGeneric ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID;
68+
return value.isGeneric() ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID;
6969
}
7070

7171
@Override

src/main/java/gregtech/api/block/coil/CustomCoilStats.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package gregtech.api.block.coil;
22

3-
import gregtech.api.GTValues;
43
import gregtech.api.block.IHeatingCoilBlockStats;
54
import gregtech.api.unification.material.Material;
6-
import gregtech.api.unification.material.Materials;
75
import gregtech.api.util.function.QuadConsumer;
86
import gregtech.client.model.ActiveVariantBlockBakedModel;
97

@@ -24,24 +22,45 @@
2422
public final class CustomCoilStats implements IHeatingCoilBlockStats, Comparable<CustomCoilStats>,
2523
IStringSerializable {
2624

27-
String name;
25+
private final String name;
2826

2927
// electric blast furnace properties
30-
int coilTemperature = -1;
28+
private final int coilTemperature;
3129

3230
// multi smelter properties
33-
int level = -1;
34-
int energyDiscount = 0;
31+
private final int level;
32+
private final int energyDiscount;
3533

3634
// voltage tier
37-
int tier = GTValues.ULV;
38-
39-
Material material = Materials.Iron;
40-
ModelResourceLocation active, inactive;
41-
boolean isGeneric;
42-
QuadConsumer<ItemStack, World, List<String>, Boolean> additionalTooltips;
43-
44-
CustomCoilStats() {}
35+
private final int tier;
36+
37+
private final Material material;
38+
private final ModelResourceLocation active;
39+
private final ModelResourceLocation inactive;
40+
private final boolean isGeneric;
41+
private final QuadConsumer<ItemStack, World, List<String>, Boolean> additionalTooltips;
42+
43+
CustomCoilStats(String name,
44+
int coilTemperature,
45+
int level,
46+
int energyDiscount,
47+
int tier,
48+
Material material,
49+
ModelResourceLocation active,
50+
ModelResourceLocation inactive,
51+
boolean isGeneric,
52+
QuadConsumer<ItemStack, World, List<String>, Boolean> additionalTooltips) {
53+
this.name = name;
54+
this.coilTemperature = coilTemperature;
55+
this.level = level;
56+
this.energyDiscount = energyDiscount;
57+
this.tier = tier;
58+
this.material = material;
59+
this.active = active;
60+
this.inactive = inactive;
61+
this.isGeneric = isGeneric;
62+
this.additionalTooltips = additionalTooltips;
63+
}
4564

4665
@Override
4766
public @NotNull String getName() {
@@ -91,4 +110,8 @@ public void addInformation(@NotNull ItemStack itemStack, @Nullable World worldIn
91110
this.additionalTooltips.accept(itemStack, worldIn, lines, tooltipFlag.isAdvanced());
92111
}
93112
}
113+
114+
public boolean isGeneric() {
115+
return isGeneric;
116+
}
94117
}

0 commit comments

Comments
 (0)