Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recipe loading from json assets #1583

Open
wants to merge 22 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
be6c573
Merge pull request #1 from Blood-Asp/unstable
MauveCloud Oct 19, 2020
388f223
First pieces of new recipe system.
MauveCloud Nov 2, 2020
5886741
More pieces for new recipe system.
MauveCloud Nov 2, 2020
d2c02ff
Added most relevant fields for recipe map class.
MauveCloud Nov 3, 2020
3f103b2
Added core of recipe map functionality.
MauveCloud Nov 4, 2020
070ca56
RecipeAdder for new recipe system.
MauveCloud Nov 4, 2020
18077cc
Migrated machines to new recipe system.
MauveCloud Nov 5, 2020
9ed64ab
Migrated the rest of the machines to the new recipe system.
MauveCloud Nov 6, 2020
072f15b
Fixed temporary issue with cutting machine
MauveCloud Nov 6, 2020
14cbba4
Fixed temporary issues with microwave, printer, recycler, and large c…
MauveCloud Nov 7, 2020
692f34a
Added JSON recipe loading.
MauveCloud Nov 9, 2020
b9f3cbc
Transferred more mixer recipes to json.
MauveCloud Nov 10, 2020
d24c44f
More recipe files.
MauveCloud Nov 11, 2020
7b6fb3a
Even more recipes transferred to json.
MauveCloud Nov 12, 2020
9d4537e
Added special handling for soldering fluids, and reading of config fo…
MauveCloud Nov 13, 2020
2a62de1
Added a way for a player to disable certain json recipes.
MauveCloud Nov 14, 2020
b250218
Moved simple/complicated/old/shared chemical recipes to json files.
MauveCloud Nov 15, 2020
c000a70
Reverted machines etc. to original recipe system.
MauveCloud Nov 16, 2020
138578b
Changed json reader to return a list of GT_Recipe.
MauveCloud Nov 17, 2020
0c8d69e
Found better workaround to handle json-disabled recipes.
MauveCloud Nov 17, 2020
5febe79
Fixed some mistakes noticed during testing.
MauveCloud Nov 18, 2020
42fda40
Fixed remaining issues with json recipes noticed during testing.
MauveCloud Nov 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ gradlew.bat
# Linux
*~

/.nb-gradle/
5 changes: 5 additions & 0 deletions .nb-gradle-properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gradle-project-properties>
<!--DO NOT EDIT THIS FILE! - Used by the Gradle plugin of NetBeans.-->
<gradle-home/>
</gradle-project-properties>
72 changes: 72 additions & 0 deletions src/main/java/gregtech/api/recipes/GT_RecipeConditions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package gregtech.api.recipes;

import cpw.mods.fml.common.Loader;
import gregtech.GT_Mod;
import gregtech.api.enums.Materials;
import gregtech.api.util.GT_Log;
import gregtech.common.GT_Proxy;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import net.minecraftforge.fluids.FluidRegistry;

/**
*
* Maps the conditions that certain recipes might need to be enabled or disabled based on.
* Some of these are boolean fields in other classes.<br>
* Plus a few special cases:
* <ul><li>ModLoaded(<i>ModName</i>) - Checks if the named mod is loaded
* <li>ModsLoaded(<i>ModName</i>, <i>ModName</i>, ...) - Checks if all the mods in the comma separated list are loaded.
* <li>FluidExists(<i>FluidName</i>) - Checks if the named fluid has been registered.
* <li>MaterialParent(<i>MaterialName</i>) - Checks if the named material has a "parent mod" according to the field in the Materials enum.
* </ul>
*/
public class GT_RecipeConditions {
private final static Map<String, Field> sConditionMap = new HashMap<>(100);

private GT_RecipeConditions() {
// Utility class
}

public static boolean getConditionValue(String aConditionName) {
String tModLoadedPattern = "ModLoaded\\(([A-Za-z0-9_]+)\\)";
String tModsLoadedPattern = "ModsLoaded\\(([A-Za-z0-9_, ]+)\\)";
String tFluidExistsPattern = "FluidExists\\(([A-Za-z]+)\\)";
String tMaterialParentPattern = "MaterialParent\\(([A-Za-z0-9_]+)\\)";
if (aConditionName.matches(tModLoadedPattern)) {
return Loader.isModLoaded(aConditionName.replaceFirst(tModLoadedPattern, "$1"));
} else if (aConditionName.matches(tModsLoadedPattern)) {
String[] tModNames = aConditionName.replaceFirst(tModsLoadedPattern, "$1").split(", *");
for (String tModName : tModNames) {
if (!Loader.isModLoaded(tModName)) {
return false;
}
}
return true;
} else if (aConditionName.matches(tFluidExistsPattern)) {
return FluidRegistry.isFluidRegistered(aConditionName.replaceFirst(tFluidExistsPattern, "$1"));
} else if (aConditionName.matches(tMaterialParentPattern)) {
Materials tMaterial = Materials.get(aConditionName.replaceFirst(tMaterialParentPattern, "$1"));
if (tMaterial != Materials._NULL) {
return tMaterial.mHasParentMod;
}
}
try {
return sConditionMap.get(aConditionName).getBoolean(GT_Mod.gregtechproxy);
} catch (IllegalArgumentException | IllegalAccessException e) {
// ignore exceptions
}
return false;
}

static {
try {
sConditionMap.put("DisableIC2Cables", GT_Proxy.class.getField("mDisableIC2Cables"));
sConditionMap.put("HardMachineCasings", GT_Proxy.class.getField("mHardMachineCasings"));
sConditionMap.put("DisableOldChemicalRecipes", GT_Proxy.class.getField("mDisableOldChemicalRecipes"));
sConditionMap.put("MoreComplicatedChemicalRecipes", GT_Proxy.class.getField("mMoreComplicatedChemicalRecipes"));
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
}
}
}
Loading