Skip to content

Commit

Permalink
Merge pull request #800 from dries007/master_
Browse files Browse the repository at this point in the history
Added enableBowlsAlwaysBreak option + fixed logic of ConfigSyncPacket
  • Loading branch information
Kittychanley committed Sep 10, 2015
2 parents c2453ef + 590597f commit 14a2354
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 14 deletions.
13 changes: 8 additions & 5 deletions src/API/com/bioxx/tfc/api/Crafting/CraftingManagerTFC.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private CraftingManagerTFC()
//System.out.println(new StringBuilder().append(recipes.size()).append(" recipes").toString());
}

public void addRecipe(ItemStack itemstack, Object aobj[])
public ShapedRecipesTFC addRecipe(ItemStack itemstack, Object aobj[])
{
String s = "";
int i = 0;
Expand Down Expand Up @@ -91,10 +91,12 @@ else if (aobj[i + 1] instanceof ItemStack)
}
}

recipes.add(new ShapedRecipesTFC(j, k, aitemstack, itemstack));
ShapedRecipesTFC shapedRecipesTFC = new ShapedRecipesTFC(j, k, aitemstack, itemstack);
recipes.add(shapedRecipesTFC);
return shapedRecipesTFC;
}

public void addShapelessRecipe(ItemStack itemstack, Object aobj[])
public ShapelessRecipesTFC addShapelessRecipe(ItemStack itemstack, Object aobj[])
{
ArrayList<ItemStack> arraylist = new ArrayList<ItemStack>();
Object aobj1[] = aobj;
Expand All @@ -121,8 +123,9 @@ public void addShapelessRecipe(ItemStack itemstack, Object aobj[])
throw new RuntimeException("Invalid shapeless recipy!");
}
}

recipes.add(new ShapelessRecipesTFC(itemstack, arraylist));
ShapelessRecipesTFC recipesTFC = new ShapelessRecipesTFC(itemstack, arraylist);
recipes.add(recipesTFC);
return recipesTFC;
}

public ItemStack findMatchingRecipe(InventoryCrafting inventorycrafting, World world)
Expand Down
2 changes: 2 additions & 0 deletions src/API/com/bioxx/tfc/api/TFCCrafting.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ public class TFCCrafting
public static boolean woodStairsRecipe;
public static boolean woodToolsRecipe;
public static boolean woolRecipe;

public static boolean enableBowlsAlwaysBreak;
}
4 changes: 2 additions & 2 deletions src/Common/com/bioxx/tfc/Core/Config/ConversionOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

/**
* 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.
* Since normally the recipes affected by this class are new recipes, they don't have to be removed in the constructor.
* If this is not the case, you must remove them after initializing the object, but before the loadFromConfig is called. Otherwise you may end up with double entries in the recipe list.
* @author Dries007
*/
public class ConversionOption extends SyncingOption
Expand Down
7 changes: 5 additions & 2 deletions src/Common/com/bioxx/tfc/Core/Config/SyncingOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import static com.bioxx.tfc.Core.Config.TFC_ConfigFiles.SYNCING_OPTION_MAP;

/**
* When the value (config or from server, depending on context) is true the recipes are (re)added to the recipe list. Otherwise they are removed.
* This behaviour may be changed by overriding the .apply(boolean) method
* Also keeps the static values from the class passed in the constructor in sync with the actual status of things.
* @author Dries007
*/
public abstract class SyncingOption
Expand All @@ -24,8 +27,8 @@ public abstract class SyncingOption
public final Configuration cfg;
public final String cat;

private boolean ourConfigValue;
private boolean currentValue;
protected boolean ourConfigValue;
protected boolean currentValue;

public SyncingOption(String name, Class<?> clazz, Configuration cfg, String cat) throws NoSuchFieldException, IllegalAccessException
{
Expand Down
46 changes: 46 additions & 0 deletions src/Common/com/bioxx/tfc/Core/Config/TFC_ConfigFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapelessRecipes;

import net.minecraftforge.common.config.ConfigCategory;
Expand All @@ -18,9 +20,13 @@
import com.bioxx.tfc.TerraFirmaCraft;
import com.bioxx.tfc.Core.Util.CaseInsensitiveHashMap;
import com.bioxx.tfc.WorldGen.Generators.OreSpawnData;
import com.bioxx.tfc.api.Crafting.CraftingManagerTFC;
import com.bioxx.tfc.api.Crafting.ShapedRecipesTFC;
import com.bioxx.tfc.api.TFCBlocks;
import com.bioxx.tfc.api.TFCCrafting;
import com.bioxx.tfc.api.TFCItems;
import com.bioxx.tfc.api.Constant.Global;
import com.bioxx.tfc.api.TFCOptions;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -58,6 +64,7 @@ public class TFC_ConfigFiles
// Crafting
public static final String CONVERSION = "Conversion";
public static final String ENABLE_VANILLA_RECIPES = "Enable Vanilla Recipes";
public static final String CRAFTING_OPTIONS = "Crafting Options";

// Used internally to move from top to colors.<name>
private static final String[] COLOR_CATEGORIES = {COLOR_NUTRIENT_A, COLOR_NUTRIENT_B, COLOR_NUTRIENT_C, CROP_FERTILIZER_COLOR, ANVIL_RULE_COLOR0, ANVIL_RULE_COLOR1, ANVIL_RULE_COLOR2};
Expand Down Expand Up @@ -146,6 +153,7 @@ public static void firstLoadCrafting()

craftingConfig.setCategoryLanguageKey(CONVERSION, "config.gui.TFCCrafting.conversion");
craftingConfig.setCategoryLanguageKey(ENABLE_VANILLA_RECIPES, "config.gui.TFCCrafting.vanilla");
craftingConfig.setCategoryLanguageKey(CRAFTING_OPTIONS, "config.gui.TFCCrafting.options");

try
{
Expand Down Expand Up @@ -263,6 +271,44 @@ public static void firstLoadCrafting()
new VanillaRecipeOption("woodToolsRecipe", new ItemStack(Items.wooden_pickaxe), new ItemStack(Items.wooden_axe), new ItemStack(Items.wooden_shovel), new ItemStack(Items.wooden_hoe), new ItemStack(Items.wooden_sword));
new VanillaRecipeOption("woolRecipe", new ItemStack(Blocks.wool));

/**
* Custom SyncingOption for enableBowlsAlwaysBreak
* getRecipes() is unused, but returns an ImmutableList of the bowl crafting recipe for conviniance & consistency.
*/
new SyncingOption("enableBowlsAlwaysBreak", TFCCrafting.class, craftingConfig, CRAFTING_OPTIONS)
{
private IRecipe recipesTFC = CraftingManagerTFC.getInstance().addRecipe(new ItemStack(TFCItems.potteryBowl, 2), new Object[] {
"#####",
"#####",
"#####",
" ### ",
"# #", '#', new ItemStack(TFCItems.flatClay, 1, 1)});

@Override
public void apply(boolean enabled) throws IllegalAccessException
{
if (currentValue != enabled) // if we need to change states
{
recipesTFC.getRecipeOutput().stackSize = enabled ? 4 : 2;
if (TFCOptions.enableDebugMode) TerraFirmaCraft.LOG.info("Crafting option {} changed from {} to {}. Stacksize {}", name, currentValue, enabled, recipesTFC.getRecipeOutput().stackSize);
field.setBoolean(null, enabled); // Keep the field up to date as well
currentValue = enabled;
}
}

@Override
public ImmutableList<IRecipe> getRecipes()
{
return ImmutableList.of(recipesTFC);
}

@Override
public String toString()
{
return name + "[default:" + defaultValue + " current:" + isAplied() + " config:" + inConfig() + " #ofRecipes: 1]";
}
};

for (SyncingOption option : SYNCING_OPTION_MAP.values())
{
option.loadFromConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

/**
* Used to represent the "enable vanilla recipe" 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.
* This removes the recipes affected in the constructor, to be re-added later if required.
* @author Dries007
*/
public class VanillaRecipeOption extends SyncingOption
Expand Down
2 changes: 2 additions & 0 deletions src/Common/com/bioxx/tfc/Core/Recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,15 @@ private static void registerKnapping()
" ### ",
" ### ",
" ", '#', new ItemStack(TFCItems.flatClay, 1, 1)});
/* Moved to TFC_ConfigFiles.firstLoadCrafting(), as it is dependant on a configureation option.
CraftingManagerTFC.getInstance().addRecipe(new ItemStack(TFCItems.potteryBowl, 2), new Object[]
{
"#####",
"#####",
"#####",
" ### ",
"# #", '#', new ItemStack(TFCItems.flatClay, 1, 1)});
*/
}

private static void registerAlloys()
Expand Down
5 changes: 3 additions & 2 deletions src/Common/com/bioxx/tfc/Food/ItemSalad.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.bioxx.tfc.Core.TFC_Sounds;
import com.bioxx.tfc.Core.TFC_Time;
import com.bioxx.tfc.api.TFCCrafting;
import com.bioxx.tfc.api.TFCItems;

public class ItemSalad extends ItemMeal
Expand Down Expand Up @@ -58,8 +59,8 @@ public ItemStack onEaten(ItemStack is, World world, EntityPlayer player)
// If the last of the salad has been eaten
if (is.stackSize == 0)
{
// 50% chance the bowl is broken, and the sound is played
if (world.rand.nextInt(2) == 0)
// Blows always break OR 50% chance the bowl is broken, and the sound is played
if (TFCCrafting.enableBowlsAlwaysBreak || world.rand.nextInt(2) == 0)
{
world.playSoundAtEntity(player, TFC_Sounds.CERAMICBREAK, 0.7f, player.worldObj.rand.nextFloat() * 0.2F + 0.8F);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
for (SyncingOption option : SYNCING_OPTION_MAP.values())
{
ByteBufUtils.writeUTF8String(buffer, option.name);
buffer.writeBoolean(option.isAplied());
buffer.writeBoolean(option.inConfig());
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Resources/assets/terrafirmacraft/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ config.gui.TFCCrafting.conversion.tooltip=WARNING: Conversions for food are irre

config.gui.TFCCrafting.vanilla=Vanilla Crafting Recipes

config.gui.TFCCrafting.options=Crafting Options

#==============
#= Entities =
#==============
Expand Down

0 comments on commit 14a2354

Please sign in to comment.