Skip to content

Commit fdab28c

Browse files
Update systems to new Recipe Properties (#1672)
1 parent 6ba4e77 commit fdab28c

File tree

7 files changed

+108
-17
lines changed

7 files changed

+108
-17
lines changed

src/main/java/gregtech/api/recipes/builders/FusionRecipeBuilder.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gregtech.api.recipes.Recipe;
55
import gregtech.api.recipes.RecipeBuilder;
66
import gregtech.api.recipes.RecipeMap;
7+
import gregtech.api.recipes.recipeproperties.FusionEUToStartProperty;
78
import gregtech.api.util.EnumValidationResult;
89
import gregtech.api.util.GTLog;
910
import gregtech.api.util.ValidationResult;
@@ -18,7 +19,7 @@ public FusionRecipeBuilder() {
1819

1920
public FusionRecipeBuilder(Recipe recipe, RecipeMap<FusionRecipeBuilder> recipeMap) {
2021
super(recipe, recipeMap);
21-
this.EUToStart = recipe.getIntegerProperty("EUToStart");
22+
this.EUToStart = recipe.getRecipePropertyStorage().getRecipePropertyValue(FusionEUToStartProperty.getInstance(), 0);
2223
}
2324

2425
public FusionRecipeBuilder(RecipeBuilder<FusionRecipeBuilder> recipeBuilder) {
@@ -49,17 +50,20 @@ public FusionRecipeBuilder EUToStart(int EUToStart) {
4950
}
5051

5152
public ValidationResult<Recipe> build() {
52-
return ValidationResult.newResult(finalizeAndValidate(),
53-
new Recipe(inputs, outputs, chancedOutputs, fluidInputs, fluidOutputs,
54-
ImmutableMap.of("eu_to_start", EUToStart),
55-
duration, EUt, hidden));
53+
Recipe recipe = new Recipe(inputs, outputs, chancedOutputs, fluidInputs, fluidOutputs,
54+
duration, EUt, hidden);
55+
if (!recipe.getRecipePropertyStorage().store(ImmutableMap.of(FusionEUToStartProperty.getInstance(), EUToStart))) {
56+
return ValidationResult.newResult(EnumValidationResult.INVALID, recipe);
57+
}
58+
59+
return ValidationResult.newResult(finalizeAndValidate(), recipe);
5660
}
5761

5862
@Override
5963
public String toString() {
6064
return new ToStringBuilder(this)
6165
.appendSuper(super.toString())
62-
.append("EUToStart", EUToStart)
66+
.append(FusionEUToStartProperty.getInstance().getKey(), EUToStart)
6367
.toString();
6468
}
6569
}

src/main/java/gregtech/api/recipes/builders/ImplosionRecipeBuilder.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package gregtech.api.recipes.builders;
22

3+
import com.google.common.collect.ImmutableMap;
4+
import gregtech.api.recipes.CountableIngredient;
35
import gregtech.api.recipes.Recipe;
46
import gregtech.api.recipes.RecipeBuilder;
57
import gregtech.api.recipes.RecipeMap;
8+
import gregtech.api.recipes.recipeproperties.ImplosionExplosiveProperty;
69
import gregtech.api.util.EnumValidationResult;
710
import gregtech.api.util.GTLog;
811
import gregtech.api.util.GTUtility;
@@ -22,6 +25,7 @@ public ImplosionRecipeBuilder() {
2225

2326
public ImplosionRecipeBuilder(Recipe recipe, RecipeMap<ImplosionRecipeBuilder> recipeMap) {
2427
super(recipe, recipeMap);
28+
this.explosivesType = recipe.getRecipePropertyStorage().getRecipePropertyValue(ImplosionExplosiveProperty.getInstance(), ItemStack.EMPTY);
2529
}
2630

2731
public ImplosionRecipeBuilder(RecipeBuilder<ImplosionRecipeBuilder> recipeBuilder) {
@@ -68,27 +72,33 @@ public ImplosionRecipeBuilder explosivesType(ItemStack explosivesType) {
6872
return this;
6973
}
7074

71-
@Override
72-
public void buildAndRegister() {
75+
public ValidationResult<Recipe> build() {
76+
77+
//Adjust the explosive type and the explosive amount. This is done here because it was null otherwise, for some reason
7378
int amount = Math.max(1, explosivesAmount / 2);
7479
if (explosivesType == null) {
75-
explosivesType = new ItemStack(Blocks.TNT, amount);
80+
this.explosivesType = new ItemStack(Blocks.TNT, amount);
7681
} else {
77-
explosivesType = new ItemStack(explosivesType.getItem(), amount, explosivesType.getMetadata());
82+
this.explosivesType = new ItemStack(explosivesType.getItem(), amount, explosivesType.getMetadata());
7883
}
79-
recipeMap.addRecipe(this.copy().inputs(explosivesType).build());
80-
}
84+
inputs.add(CountableIngredient.from(explosivesType));
8185

82-
public ValidationResult<Recipe> build() {
83-
return ValidationResult.newResult(finalizeAndValidate(),
84-
new Recipe(inputs, outputs, chancedOutputs, fluidInputs, fluidOutputs, duration, EUt, hidden));
86+
87+
Recipe recipe = new Recipe(inputs, outputs, chancedOutputs, fluidInputs, fluidOutputs,
88+
duration, EUt, hidden);
89+
90+
if (!recipe.getRecipePropertyStorage().store(ImmutableMap.of(ImplosionExplosiveProperty.getInstance(), explosivesType))) {
91+
return ValidationResult.newResult(EnumValidationResult.INVALID, recipe);
92+
}
93+
94+
return ValidationResult.newResult(finalizeAndValidate(), recipe);
8595
}
8696

8797
@Override
8898
public String toString() {
8999
return new ToStringBuilder(this)
90100
.appendSuper(super.toString())
91-
.append("explosivesAmount", explosivesAmount)
101+
.append(ImplosionExplosiveProperty.getInstance().getKey(), explosivesType)
92102
.toString();
93103
}
94104
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package gregtech.api.recipes.recipeproperties;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.resources.I18n;
5+
6+
public class FusionEUToStartProperty extends RecipeProperty<Integer>{
7+
8+
9+
private static final String KEY = "eu_to_start";
10+
11+
private static FusionEUToStartProperty INSTANCE;
12+
13+
private FusionEUToStartProperty() {
14+
super(KEY, Integer.class);
15+
}
16+
17+
public static FusionEUToStartProperty getInstance() {
18+
if (INSTANCE == null) {
19+
INSTANCE = new FusionEUToStartProperty();
20+
}
21+
22+
return INSTANCE;
23+
}
24+
25+
@Override
26+
public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) {
27+
minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.eu_to_start",
28+
value), x, y, color);
29+
}
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package gregtech.api.recipes.recipeproperties;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.resources.I18n;
5+
import net.minecraft.item.ItemStack;
6+
7+
public class ImplosionExplosiveProperty extends RecipeProperty<ItemStack>{
8+
9+
private static final String KEY = "explosives";
10+
11+
private static ImplosionExplosiveProperty INSTANCE;
12+
13+
14+
private ImplosionExplosiveProperty() {
15+
super(KEY, ItemStack.class);
16+
}
17+
18+
public static ImplosionExplosiveProperty getInstance() {
19+
if (INSTANCE == null) {
20+
INSTANCE = new ImplosionExplosiveProperty();
21+
}
22+
23+
return INSTANCE;
24+
}
25+
26+
@Override
27+
public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) {
28+
minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.explosive",
29+
((ItemStack) value).getDisplayName()), x, y, color);
30+
}
31+
32+
@Override
33+
public boolean isHidden() {
34+
return true;
35+
}
36+
}

src/main/java/gregtech/api/recipes/recipeproperties/RecipeProperty.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public T castValue(Object value) {
2727
return this.type.cast(value);
2828
}
2929

30+
/**
31+
* Controls if the property should display any information in JEI
32+
* @return true to hide information from JEI
33+
*/
34+
public boolean isHidden() {
35+
return false;
36+
}
37+
3038
@Override
3139
public boolean equals(Object o) {
3240
if (this == o) return true;

src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int
138138
minecraft.fontRenderer.drawString(I18n.format(recipe.getEUt() >= 0 ? "gregtech.recipe.eu" : "gregtech.recipe.eu_inverted", Math.abs(recipe.getEUt()), JEIHelpers.getMinTierForVoltage(recipe.getEUt())), 0, yPosition += LINE_HEIGHT, 0x111111);
139139
minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.duration", recipe.getDuration() / 20f), 0, yPosition += LINE_HEIGHT, 0x111111);
140140
for (Map.Entry<RecipeProperty<?>, Object> propertyEntry : recipe.getRecipePropertyStorage().getRecipeProperties()) {
141-
propertyEntry.getKey().drawInfo(minecraft, 0, yPosition += LINE_HEIGHT, 0x111111, propertyEntry.getValue());
141+
if(!propertyEntry.getKey().isHidden()) {
142+
propertyEntry.getKey().drawInfo(minecraft, 0, yPosition += LINE_HEIGHT, 0x111111, propertyEntry.getValue());
143+
}
142144
}
143145
}
144146

src/main/resources/assets/gregtech/lang/en_us.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,7 @@ gregtech.recipe.amperage=Amperage: %,d
29022902
gregtech.recipe.not_consumed=Not consumed in process
29032903
gregtech.recipe.chance=Chance: %s%% +%s%%/tier
29042904
gregtech.recipe.blast_furnace_temperature=Temperature: %,dK (%s)
2905+
gregtech.recipe.explosive=Explosive: %s
29052906
gregtech.recipe.eu_to_start=Energy To Start: %,dEU
29062907

29072908
gregtech.fluid.click_to_fill=§7Click with a empty fluid container to fill it from tank.

0 commit comments

Comments
 (0)