Skip to content

Commit

Permalink
Part2: Made recipes/boolean options sync-able
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Aug 19, 2015
1 parent c25c019 commit 6796203
Show file tree
Hide file tree
Showing 16 changed files with 613 additions and 589 deletions.
95 changes: 75 additions & 20 deletions .gitignore
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
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ allprojects {

minecraft {
version = config.minecraft_version + "-" + config.forge_version
if(file('../run').exists()){
runDir = "../run"
if(file('../run').exists()) {
runDir = "../run"
} else {
runDir = "run"
runDir = "run"
if (!file(runDir).exists()) file(runDir).mkdir()
}
}

Expand Down
1 change: 1 addition & 0 deletions src/API/com/bioxx/tfc/api/TFCCrafting.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* These fields are updated using reflection when the server - cient sync happends.
*/
@SuppressWarnings("unused")
public class TFCCrafting
{
public static boolean appleConversion;
Expand Down
8 changes: 4 additions & 4 deletions src/API/com/bioxx/tfc/api/TFCItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ public class TFCItems

public static void registerItems()
{
TerraFirmaCraft.log.info(new StringBuilder().append("Registering Items").toString());
TerraFirmaCraft.log.info("Registering Items");

GameRegistry.registerItem(GoldPan, GoldPan.getUnlocalizedName());
GameRegistry.registerItem(SluiceItem, SluiceItem.getUnlocalizedName());
Expand Down Expand Up @@ -1438,7 +1438,7 @@ public static void registerItems()
GameRegistry.registerItem(Fertilizer, Fertilizer.getUnlocalizedName());


TerraFirmaCraft.log.info(new StringBuilder().append("Registering Food").toString());
TerraFirmaCraft.log.info("Registering Food");
GameRegistry.registerItem(FruitTreeSapling, FruitTreeSapling.getUnlocalizedName());
GameRegistry.registerItem(RedApple, RedApple.getUnlocalizedName());
GameRegistry.registerItem(Banana, Banana.getUnlocalizedName());
Expand Down Expand Up @@ -1548,7 +1548,7 @@ public static void registerItems()
GameRegistry.registerItem(GooseberryLeaf, GooseberryLeaf.getUnlocalizedName());
GameRegistry.registerItem(CloudberryLeaf, CloudberryLeaf.getUnlocalizedName());

TerraFirmaCraft.log.info(new StringBuilder().append("Registering Armor").toString());
TerraFirmaCraft.log.info("Registering Armor");
GameRegistry.registerItem(BismuthSheet, BismuthSheet.getUnlocalizedName());
GameRegistry.registerItem(BismuthBronzeSheet, BismuthBronzeSheet.getUnlocalizedName());
GameRegistry.registerItem(BlackBronzeSheet, BlackBronzeSheet.getUnlocalizedName());
Expand Down Expand Up @@ -1679,7 +1679,7 @@ public static void registerItems()

GameRegistry.registerItem(Shears, Shears.getUnlocalizedName());

TerraFirmaCraft.log.info(new StringBuilder().append("All Items Registered").toString());
TerraFirmaCraft.log.info("All Items Registered");
}


Expand Down
2 changes: 2 additions & 0 deletions src/API/com/bioxx/tfc/api/TFCOptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bioxx.tfc.api;

import com.bioxx.tfc.Core.Config.TFC_ConfigFiles;

/**
* Values in here are default, for bounds look in:
* @see com.bioxx.tfc.Core.TFC_ConfigFiles
Expand Down
36 changes: 36 additions & 0 deletions src/Common/com/bioxx/tfc/Core/Config/ConversionOption.java
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() + "]";
}
}
69 changes: 69 additions & 0 deletions src/Common/com/bioxx/tfc/Core/Config/SyncingOption.java
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();
}
Loading

0 comments on commit 6796203

Please sign in to comment.