Skip to content

Commit c710290

Browse files
authored
Merge pull request #4 from AE2-Enthusiast/main
Properly Implement Special Case Colors
2 parents f72fd3b + e5eaf67 commit c710290

File tree

5 files changed

+85
-31
lines changed

5 files changed

+85
-31
lines changed
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
11
ServerEvents.recipes(event =>{
22
event.recipes.gtceu.prismatic_crucible("test2")
3-
.inputStates(PrismaticColor.RED)
3+
.inputColor(PrismaticColor.RED)
44
.itemInputs("minecraft:red_dye")
55
.itemOutputs("minecraft:green_dye")
66
.EUt(128)
77
.duration(100)
88
.outputStates(PrismaticColor.GREEN)
99

1010
event.recipes.gtceu.prismatic_crucible("test3")
11-
.inputStates(PrismaticColor.GREEN)
11+
.inputColor(PrismaticColor.GREEN)
1212
.itemInputs("minecraft:green_dye")
1313
.itemOutputs("minecraft:red_dye")
1414
.EUt(128)
1515
.duration(100)
1616
.outputStates(PrismaticColor.RED)
1717

1818
event.recipes.gtceu.prismatic_crucible("test4")
19-
.inputStates(PrismaticColor.GREEN)
19+
.inputColor(PrismaticColor.GREEN)
2020
.itemInputs("minecraft:stone")
2121
.itemOutputs("minecraft:cobblestone")
2222
.EUt(128)
2323
.duration(100)
2424
.outputStates(PrismaticColor.RED)
2525

2626
event.recipes.gtceu.prismatic_crucible("test5")
27-
.inputStatesSpecial(SpecialCase.BASIC)
27+
.inputColor(PrismaticColor.BASIC)
2828
.itemInputs("minecraft:white_dye")
2929
.itemOutputs("minecraft:black_dye")
3030
.EUt(128)
3131
.duration(100)
32+
.outputStates(PrismaticColor.MAGENTA)
3233

3334
event.recipes.gtceu.prismatic_crucible("test6")
34-
.inputStates(PrismaticColor.RED)
35+
.inputColor(PrismaticColor.RED)
3536
.itemInputs("minecraft:stone")
3637
.itemOutputs("minecraft:diamond", 4)
3738
.EUt(128)
3839
.duration(100)
3940
.outputStates(PrismaticColor.GREEN)
40-
})
41+
42+
event.recipes.gtceu.prismatic_crucible("test7")
43+
.inputColor(PrismaticColor.ANY)
44+
.itemInputs("minecraft:dirt")
45+
.itemOutputs("minecraft:diamond", 4)
46+
.EUt(128)
47+
.duration(100)
48+
.outputStates(PrismaticColor.GREEN)
49+
})

src/main/java/net/neganote/monilabs/capability/recipe/ChromaRecipeCapability.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.neganote.monilabs.capability.recipe;
22

33
import java.util.ArrayList;
4+
import java.util.Collection;
45
import java.util.List;
56

67
import com.google.gson.JsonElement;
@@ -10,6 +11,7 @@
1011
import com.gregtechceu.gtceu.api.recipe.lookup.AbstractMapIngredient;
1112
import com.mojang.serialization.Codec;
1213

14+
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
1315
import net.neganote.monilabs.common.machine.multiblock.PrismaticCrucibleMachine.Color;
1416

1517
public class ChromaRecipeCapability extends RecipeCapability<Color> {
@@ -27,15 +29,30 @@ public boolean isRecipeSearchFilter() {
2729
@Override
2830
public List<AbstractMapIngredient> convertToMapIngredient(Object ingredient) {
2931
if (ingredient instanceof Color ingredientColor) {
30-
//TODO add the generic/special case "colors" ie primary colors
31-
List<AbstractMapIngredient> list = new ArrayList<>();
32-
list.add(new MapColorIngredient(ingredientColor));
33-
return list;
32+
List<AbstractMapIngredient> ingredients = new ObjectArrayList<>();
33+
ingredients.add(new MapColorIngredient(ingredientColor));
34+
int key = ingredientColor.key;
35+
if (key % 4 == 0) {
36+
ingredients.add(new MapColorIngredient(Color.PRIMARY));
37+
ingredients.add(new MapColorIngredient(Color.BASIC));
38+
} else if ((key + 2) % 4 == 0) {
39+
ingredients.add(new MapColorIngredient(Color.SECONDARY));
40+
ingredients.add(new MapColorIngredient(Color.BASIC));
41+
} else {
42+
ingredients.add(new MapColorIngredient(Color.TERTIARY));
43+
}
44+
ingredients.add(new MapColorIngredient(Color.ANY));
45+
return ingredients;
3446
} else {
3547
return super.convertToMapIngredient(ingredient);
3648
}
3749
}
3850

51+
@Override
52+
public Color copyInner(Color content) {
53+
return content;
54+
}
55+
3956
private static class SerializerColor implements IContentSerializer<Color> {
4057
public static SerializerColor INSTANCE = new SerializerColor();
4158

src/main/java/net/neganote/monilabs/common/machine/multiblock/PrismaticCrucibleMachine.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,26 @@ public enum Color {
107107
BLUE(8, "monilabs.prismatic.color_name.blue", 0f, 0f, 1.0f),
108108
INDIGO(9, "monilabs.prismatic.color_name.indigo", 0.5f, 0f, 1.0f),
109109
MAGENTA(10, "monilabs.prismatic.color_name.magenta", 1.0f, 0f, 1.0f),
110-
PINK(11, "monilabs.prismatic.color_name.pink", 1.0f, 0f, 0.5f);
110+
PINK(11, "monilabs.prismatic.color_name.pink", 1.0f, 0f, 0.5f),
111+
PRIMARY(12, "", 0f, 0f, 0f),
112+
SECONDARY(13, "", 0f, 0f, 0f),
113+
BASIC(14, "", 0f, 0f, 0f),
114+
TERTIARY(15, "", 0f, 0f, 0f),
115+
ANY(16, "", 0f, 0f, 0f);
111116

112117
public static final Color[] COLORS = Color.values();
113118

119+
public static final Color[] ACTUAL_COLORS = new Color[]{RED, ORANGE, YELLOW, LIME, GREEN, TEAL, CYAN, AZURE, BLUE, INDIGO, MAGENTA, PINK};
120+
114121
public final String nameKey;
115122
public final int key;
116123
public final float r;
117124
public final float g;
118125
public final float b;
119126

120-
public static final int COLOR_COUNT = Color.values().length;
127+
public static final int COLOR_COUNT = COLORS.length;
128+
129+
public static final int ACTUAL_COLOR_COUNT = ACTUAL_COLORS.length;
121130

122131
Color(int key, String nameKey, float r, float g, float b) {
123132
this.key = key;
@@ -127,11 +136,27 @@ public enum Color {
127136
this.b = b;
128137
}
129138

139+
public boolean isPrimary() {
140+
return this == RED || this == GREEN || this == BLUE;
141+
}
142+
143+
public boolean isSecondary() {
144+
return this == YELLOW || this == CYAN || this == MAGENTA;
145+
}
146+
147+
public boolean isBasic() {
148+
return isPrimary() || isSecondary();
149+
}
150+
151+
public boolean isTertiary() {
152+
return !isBasic();
153+
}
154+
130155
public static Color getColorFromKey(int pKey) {
131156
return COLORS[pKey];
132157
}
133158
public static int getRandomColor() {
134-
return (int) Math.floor(Math.random() * Color.COLOR_COUNT);
159+
return (int) Math.floor(Math.random() * Color.ACTUAL_COLOR_COUNT);
135160
}
136161

137162
public static int getRandomColorFromKeys(int[] keys) {

src/main/java/net/neganote/monilabs/common/machine/trait/NotifiableChromaContainer.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ public List<Color> handleRecipeInner(IO io, GTRecipe recipe, List<Color> left, @
5757
if (left.contains(heldColor) && colors.contains(heldColor)) {
5858
return null;
5959
} else {
60+
for (Color color : colors) {
61+
int key = this.heldColor.key;
62+
if (key % 4 == 0) {
63+
if (color == Color.PRIMARY)
64+
return null;
65+
if (color == Color.BASIC)
66+
return null;
67+
} else if ((key + 2) % 4 == 0) {
68+
if (color == Color.SECONDARY)
69+
return null;
70+
if (color == Color.BASIC)
71+
return null;
72+
} else {
73+
if (color == Color.TERTIARY)
74+
return null;
75+
}
76+
if (color == Color.ANY)
77+
return null;
78+
}
6079
return left;
6180
}
6281
}

src/main/java/net/neganote/monilabs/integration/kjs/recipe/MoniRecipeSchema.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,12 @@ enum SpecialCase {
2626
@SuppressWarnings({ "unused", "UnusedReturnValue" })
2727
@Accessors(chain = true, fluent = true)
2828
class MoniRecipeJS extends GTRecipeSchema.GTRecipeJS {
29-
30-
public GTRecipeSchema.GTRecipeJS inputStates(Color... states) {
31-
for (Color color : states) {
32-
this.input(MoniRecipeCapabilities.CHROMA, color);
33-
}
29+
public GTRecipeSchema.GTRecipeJS inputColor(Color color) {
30+
this.input(MoniRecipeCapabilities.CHROMA, color);
3431

3532
return this;
3633
}
3734

38-
// Used to have a shorthand for special cases in recipe definitions
39-
public GTRecipeSchema.GTRecipeJS inputStatesSpecial(SpecialCase specialCase) {
40-
return switch (specialCase) {
41-
case PRIMARY -> this.inputStates(Color.RED, Color.GREEN, Color.BLUE); // Red, Green, Blue
42-
case SECONDARY -> this.inputStates(Color.YELLOW, Color.CYAN, Color.MAGENTA); // Yellow, Cyan, Magenta
43-
case BASIC -> this.inputStates(Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE, Color.MAGENTA); // Primary + Secondary Colors
44-
case TERTIARY -> this.inputStates(Color.ORANGE, Color.LIME, Color.TEAL, Color.AZURE, Color.INDIGO, Color.PINK); // Non-Basic Colors
45-
46-
// Saving computation by skipping unnecessary steps
47-
case ANY -> this.addData("input_states", Color.COLOR_COUNT);
48-
};
49-
}
50-
5135

5236
public GTRecipeSchema.GTRecipeJS outputStates(boolean relative, Color... states) {
5337

0 commit comments

Comments
 (0)