diff --git a/src/API/com/bioxx/tfc/api/Crafting/CraftingManagerTFC.java b/src/API/com/bioxx/tfc/api/Crafting/CraftingManagerTFC.java index d8558c7db..4efcb9532 100644 --- a/src/API/com/bioxx/tfc/api/Crafting/CraftingManagerTFC.java +++ b/src/API/com/bioxx/tfc/api/Crafting/CraftingManagerTFC.java @@ -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; @@ -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 arraylist = new ArrayList(); Object aobj1[] = aobj; @@ -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) diff --git a/src/API/com/bioxx/tfc/api/TFCCrafting.java b/src/API/com/bioxx/tfc/api/TFCCrafting.java index f4692621e..0cda6b279 100644 --- a/src/API/com/bioxx/tfc/api/TFCCrafting.java +++ b/src/API/com/bioxx/tfc/api/TFCCrafting.java @@ -81,4 +81,6 @@ public class TFCCrafting public static boolean woodStairsRecipe; public static boolean woodToolsRecipe; public static boolean woolRecipe; + + public static boolean enableBowlsAlwaysBreak; } diff --git a/src/Common/com/bioxx/tfc/Core/Config/ConversionOption.java b/src/Common/com/bioxx/tfc/Core/Config/ConversionOption.java index 1554920dc..1c2892340 100644 --- a/src/Common/com/bioxx/tfc/Core/Config/ConversionOption.java +++ b/src/Common/com/bioxx/tfc/Core/Config/ConversionOption.java @@ -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 diff --git a/src/Common/com/bioxx/tfc/Core/Config/SyncingOption.java b/src/Common/com/bioxx/tfc/Core/Config/SyncingOption.java index e96395917..70fc6745b 100644 --- a/src/Common/com/bioxx/tfc/Core/Config/SyncingOption.java +++ b/src/Common/com/bioxx/tfc/Core/Config/SyncingOption.java @@ -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 @@ -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 { diff --git a/src/Common/com/bioxx/tfc/Core/Config/TFC_ConfigFiles.java b/src/Common/com/bioxx/tfc/Core/Config/TFC_ConfigFiles.java index 09d00b0d5..cf4643c77 100644 --- a/src/Common/com/bioxx/tfc/Core/Config/TFC_ConfigFiles.java +++ b/src/Common/com/bioxx/tfc/Core/Config/TFC_ConfigFiles.java @@ -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; @@ -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; @@ -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. 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}; @@ -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 { @@ -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 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(); diff --git a/src/Common/com/bioxx/tfc/Core/Config/VanillaRecipeOption.java b/src/Common/com/bioxx/tfc/Core/Config/VanillaRecipeOption.java index 359657105..d4f2588b7 100644 --- a/src/Common/com/bioxx/tfc/Core/Config/VanillaRecipeOption.java +++ b/src/Common/com/bioxx/tfc/Core/Config/VanillaRecipeOption.java @@ -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 diff --git a/src/Common/com/bioxx/tfc/Core/Recipes.java b/src/Common/com/bioxx/tfc/Core/Recipes.java index 66a9697c0..5f99df513 100644 --- a/src/Common/com/bioxx/tfc/Core/Recipes.java +++ b/src/Common/com/bioxx/tfc/Core/Recipes.java @@ -887,6 +887,7 @@ 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[] { "#####", @@ -894,6 +895,7 @@ private static void registerKnapping() "#####", " ### ", "# #", '#', new ItemStack(TFCItems.flatClay, 1, 1)}); + */ } private static void registerAlloys() diff --git a/src/Common/com/bioxx/tfc/Food/ItemSalad.java b/src/Common/com/bioxx/tfc/Food/ItemSalad.java index 73ddd4156..541acfb01 100644 --- a/src/Common/com/bioxx/tfc/Food/ItemSalad.java +++ b/src/Common/com/bioxx/tfc/Food/ItemSalad.java @@ -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 @@ -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); } diff --git a/src/Common/com/bioxx/tfc/Handlers/Network/ConfigSyncPacket.java b/src/Common/com/bioxx/tfc/Handlers/Network/ConfigSyncPacket.java index ded4408c4..5f194688f 100644 --- a/src/Common/com/bioxx/tfc/Handlers/Network/ConfigSyncPacket.java +++ b/src/Common/com/bioxx/tfc/Handlers/Network/ConfigSyncPacket.java @@ -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()); } } diff --git a/src/Resources/assets/terrafirmacraft/lang/en_US.lang b/src/Resources/assets/terrafirmacraft/lang/en_US.lang index fdcf8e014..597fe6744 100644 --- a/src/Resources/assets/terrafirmacraft/lang/en_US.lang +++ b/src/Resources/assets/terrafirmacraft/lang/en_US.lang @@ -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 = #==============