-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathFuelRecipeMap.java
More file actions
96 lines (79 loc) · 3.12 KB
/
FuelRecipeMap.java
File metadata and controls
96 lines (79 loc) · 3.12 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
package gregtech.api.recipes.machines;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.liquid.ILiquidStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import gregtech.api.GTValues;
import gregtech.api.recipes.FluidKey;
import gregtech.api.recipes.recipes.FuelRecipe;
import gregtech.api.util.LocalisationUtils;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Optional.Method;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import java.util.*;
@ZenClass("mods.gregtech.recipe.FuelRecipeMap")
@ZenRegister
public class FuelRecipeMap {
private static final List<FuelRecipeMap> RECIPE_MAPS = new ArrayList<>();
public final String unlocalizedName;
private final Map<FluidKey, FuelRecipe> recipeFluidMap = new HashMap<>();
private final List<FuelRecipe> recipeList = new ArrayList<>();
public FuelRecipeMap(String unlocalizedName) {
this.unlocalizedName = unlocalizedName;
RECIPE_MAPS.add(this);
}
@ZenGetter("recipeMaps")
public static List<FuelRecipeMap> getRecipeMaps() {
return RECIPE_MAPS;
}
@ZenMethod
public static FuelRecipeMap getByName(String unlocalizedName) {
return RECIPE_MAPS.stream()
.filter(map -> map.unlocalizedName.equals(unlocalizedName))
.findFirst().orElse(null);
}
@ZenMethod
public void addRecipe(FuelRecipe fuelRecipe) {
FluidKey fluidKey = new FluidKey(fuelRecipe.getRecipeFluid());
if (recipeFluidMap.containsKey(fluidKey)) {
FuelRecipe oldRecipe = recipeFluidMap.remove(fluidKey);
recipeList.remove(oldRecipe);
}
recipeFluidMap.put(fluidKey, fuelRecipe);
recipeList.add(fuelRecipe);
}
@ZenMethod
public boolean removeRecipe(FuelRecipe recipe) {
if (recipeList.contains(recipe)) {
this.recipeList.remove(recipe);
this.recipeFluidMap.remove(new FluidKey(recipe.getRecipeFluid()));
return true;
}
return false;
}
public FuelRecipe findRecipe(long maxVoltage, FluidStack inputFluid) {
if (inputFluid == null) return null;
FluidKey fluidKey = new FluidKey(inputFluid);
FuelRecipe fuelRecipe = recipeFluidMap.get(fluidKey);
return fuelRecipe != null && fuelRecipe.matches(maxVoltage, inputFluid) ? fuelRecipe : null;
}
@ZenMethod("findRecipe")
@Method(modid = GTValues.MODID_CT)
public FuelRecipe ctFindRecipe(long maxVoltage, ILiquidStack inputFluid) {
return findRecipe(maxVoltage, CraftTweakerMC.getLiquidStack(inputFluid));
}
@ZenGetter("recipes")
public List<FuelRecipe> getRecipeList() {
return Collections.unmodifiableList(recipeList);
}
@ZenGetter("localizedName")
@SuppressWarnings("deprecation")
public String getLocalizedName() {
return LocalisationUtils.format("recipemap." + unlocalizedName + ".name");
}
@ZenGetter("unlocalizedName")
public String getUnlocalizedName() {
return unlocalizedName;
}
}