forked from Deadrik/TFCraft
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part2: Made recipes/boolean options sync-able
- Loading branch information
Showing
16 changed files
with
613 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,79 @@ | ||
.DS_Store | ||
*.pyc | ||
*~ | ||
*swp | ||
TFC Build/ | ||
bin/ | ||
.gradle/ | ||
# Created by https://www.gitignore.io | ||
# Following settings: Gradle, intellij, eclipse | ||
### Gradle ### | ||
.gradle | ||
build/ | ||
|
||
# Ignore Gradle GUI config | ||
gradle-app.setting | ||
|
||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) | ||
!gradle-wrapper.jar | ||
|
||
|
||
### Intellij ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
|
||
*.iml | ||
|
||
## Directory-based project format: | ||
.idea/ | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
|
||
|
||
### Eclipse ### | ||
*.pydevproject | ||
.metadata | ||
.gradle | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.settings/ | ||
logs/ | ||
crash-reports/ | ||
config/ | ||
saves/ | ||
screenshots/ | ||
.loadpath | ||
|
||
# Eclipse Core | ||
.project | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# CDT-specific | ||
.cproject | ||
|
||
# JDT-specific (Eclipse Java Development Tools) | ||
.classpath | ||
options.txt | ||
out | ||
*.iws | ||
*.ipr | ||
*.iml | ||
mods | ||
asm | ||
*Thumbs.db | ||
|
||
# PDT-specific | ||
.buildpath | ||
|
||
# sbteclipse plugin | ||
.target | ||
|
||
# TeXlipse plugin | ||
.texlipse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Common/com/bioxx/tfc/Core/Config/ConversionOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.bioxx.tfc.Core.Config; | ||
|
||
import net.minecraft.item.crafting.IRecipe; | ||
|
||
import com.bioxx.tfc.api.TFCCrafting; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
/** | ||
* Used to represent the "conversion" option | ||
* When the value (config or from server, depending on context) is true the recipes are (re)added to the recipe list. | ||
* Also keeps the static values from the TFCCrafting class in sync with the actual status of things. | ||
* @author Dries007 | ||
*/ | ||
public class ConversionOption extends SyncingOption | ||
{ | ||
public final ImmutableList<IRecipe> recipes; | ||
|
||
public ConversionOption(String name, IRecipe... shapelessRecipes) throws NoSuchFieldException, IllegalAccessException | ||
{ | ||
super(name, TFCCrafting.class, TFC_ConfigFiles.getCraftingConfig(), TFC_ConfigFiles.CONVERSION); | ||
if (shapelessRecipes.length == 0) throw new IllegalArgumentException("No recipes for conversion " + name); | ||
this.recipes = ImmutableList.copyOf(shapelessRecipes); | ||
} | ||
|
||
@Override | ||
public ImmutableList<IRecipe> getRecipes() | ||
{ | ||
return recipes; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return name + "[default:" + defaultValue + " current:" + isAplied() + " config:" + inConfig() + " #ofRecipes:" + recipes.size() + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.bioxx.tfc.Core.Config; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import net.minecraft.item.crafting.CraftingManager; | ||
import net.minecraft.item.crafting.IRecipe; | ||
import net.minecraftforge.common.config.Configuration; | ||
|
||
import com.bioxx.tfc.TerraFirmaCraft; | ||
import com.bioxx.tfc.api.TFCOptions; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import static com.bioxx.tfc.Core.Config.TFC_ConfigFiles.SYNCING_OPTION_MAP; | ||
|
||
/** | ||
* @author Dries007 | ||
*/ | ||
public abstract class SyncingOption | ||
{ | ||
public final String name; | ||
public final Field field; | ||
public final boolean defaultValue; | ||
public final Configuration cfg; | ||
public final String cat; | ||
|
||
private boolean ourConfigValue; | ||
private boolean currentValue; | ||
|
||
public SyncingOption(String name, Class<?> clazz, Configuration cfg, String cat) throws NoSuchFieldException, IllegalAccessException | ||
{ | ||
if (SYNCING_OPTION_MAP.containsKey(name)) throw new IllegalArgumentException("Duplicate key: " + name); | ||
SYNCING_OPTION_MAP.put(name, this); | ||
this.name = name; | ||
this.field = clazz.getDeclaredField(name); | ||
this.cfg = cfg; | ||
this.cat = cat; | ||
this.defaultValue = field.getBoolean(null); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public void apply(boolean enabled) throws IllegalAccessException | ||
{ | ||
if (currentValue != enabled) // if we need to change states | ||
{ | ||
boolean result = enabled ? CraftingManager.getInstance().getRecipeList().addAll(getRecipes()) : CraftingManager.getInstance().getRecipeList().removeAll(getRecipes()); | ||
if (TFCOptions.enableDebugMode) TerraFirmaCraft.log.info("Conversion option {} changed from {} to {}. Result: {}", name, currentValue, enabled, result); | ||
field.setBoolean(null, enabled); // Keep the field up to date as well | ||
currentValue = enabled; | ||
} | ||
} | ||
|
||
public boolean inConfig() | ||
{ | ||
return ourConfigValue; | ||
} | ||
|
||
public boolean isAplied() | ||
{ | ||
return currentValue; | ||
} | ||
|
||
public void loadFromConfig() throws IllegalAccessException | ||
{ | ||
ourConfigValue = cfg.getBoolean(name, cat, defaultValue, ""); | ||
apply(ourConfigValue); | ||
} | ||
|
||
public abstract ImmutableList<IRecipe> getRecipes(); | ||
} |
Oops, something went wrong.