tModLoader Reduced crafting material costs

Threesan

Terrarian
Gameplay current version: v0.0.5 (2017-08-06)
Technically current version: v0.0.6 (2017-09-05)

This thread serves as the homepage of the "Reduced crafting material costs" mod, which can be obtained via the tModLoader in-game mod browser. This is and is intended to remain a small & simple modification.

The ore-grind in vanilla Terraria was preventing me from starting another playthrough. Thus, this mod. There are likely some infinite-resource loops and/or other shenanigans left to be found & fixed, but it works as originally designed.


== Description ==

Reduces crafting material cost to 35% (rounded up). Affects everything in the base game, with a few exceptions to avoid silliness. This does include both ore-to-bars and bars-to-equipment.

Does NOT affect other mods' recipes (though base-game bar types etc will be cheaper to smelt).

Example: Full iron armor + pickaxe + sword
Base game: 95 bars, from 285 iron ore (3 per bar)
This mod: 35 bars, from 70 iron ore (2 per bar)

v0.0.6 (2017-09-05):
No game changes. Defensive code, speculative fix for failure-to-enable-mod.

v0.0.5 (2017-08-06):
Wooden Arrow, Musket Ball, Empty Bullet, Throwing Knife, and Grenade are restored to 1-to-1 upgrading (e.g., 5 Grenades makes 5 Sticky Grenades).

v0.0.4 (2017-08-02#2):
Excluded coins (inf.doh). (thanks snova0112)

v0.0.3 (2017-08-02):
Excluded *Wall and *Platform mats (inf.mats).
Excluded Mana Crystal (already cheap).

v0.0.2 (2017-07-30):
Added forum homepage (here).
Excluded 4 rope-coil types, since they turn into 10 rope when thrown.
Excluded goggles and sunglasses (require 2 lenses).

v0.0.1 (2017-07-29):
Initial release. Affects all vanilla recipes.
 
Last edited:
I don't really know why, but every time i enable the mod i get this error on the Adding Recipes.


Object reference not set to an instance of an object
At ResourcesQoL.ResourcesQoL.AddRecipes() in c:Users\Mike\Documents\my games\Terraria\Modloader\Mod Sources\ResourcesQoL\ResourcesQoL.cs:line 57
At Terraria.ModLoader.RecipeHooks.AddRecipes()
 
Puzzling. I'm guessing you're already using the current mod version, 0.0.5 (about 30 days old).

I haven't been able to reproduce the problem, but given the line number I've made a speculative fix and uploaded a new version. I'd give it 60% odds of loading successfully, but 30% odds of not modifying any of your recipes. My current guess is one of your other mods is modifying the vanilla recipes in a way that doesn't make sense to me (setting an entry to null; perhaps the mod is trying to "take ownership" of the recipe).

Do you have a list of mods you have installed? I'm wondering if one of them is doing something "weird" to stuff the code is interacting with.

I'd be interested to know if it loads or not, and if it actually reduces vanilla crafting costs.

I've tried installing several mods dealing with extra items and recipes but had no issue. I also confirmed mod recipes aren't affected. I deleted my cached copy and redownloaded. New character, moderately late-game character. Normal mode, expert mode. Loading, unloading, reloading.


I'm not terribly familiar with C#, but I'm not sure where things could going wrong for you. Of the objects referenced on the offending line, one is a locally defined dictionary, and the other is being foreach-fetched from a list of the vanilla recipes. So it seems like the object references ought to be valid, unless someone is doing something horrible like nulling a vanilla recipe.
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ResourcesQoL
{
    class ResourcesQoL : Mod
    {
        public ResourcesQoL()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }

        public override void AddRecipes()
        {
            // Exceptions to the global scaling factor applied below.
            Dictionary<string, float> output_item_multiplier_overrides = new Dictionary<string, float>()
            {
                { "Platinum Coin",  1.0F }, // reason: infinite money! (u/snova0112)
                { "Gold Coin",      1.0F }, //     "
                { "Silver Coin",    1.0F }, //     "
                { "Copper Coin",    1.0F }, //     "
                { "Mana Crystal",   1.0F }, // already cheap
                { "Goggles",        1.0F }, // 2 lenses
                { "Sunglasses",     1.0F }, //     "
                { "Rope Coil",      1.0F }, // infinite rope from refund on throw
                { "Silk Rope Coil", 1.0F }, //   "
                { "Vine Rope Coil", 1.0F }, //   "
                { "Web Rope Coil",  1.0F }, //   "
            }; // todo - arrows->upgrades. bullets->upgrades.

            Dictionary<string, float> input_item_multiplier_overrides = new Dictionary<string, float>()
            {
                { "Wooden Arrow",   1.0F }, // reason: 1-to-1 in/out ammo ratio
                { "Musket Ball",    1.0F }, //   "
                { "Empty Bullet",   1.0F }, //   "
                { "Throwing Knife", 1.0F }, //   "
                { "Grenade",        1.0F }, //   "
            };

            // Reduce crafting requirements for all non-mod recipes by the scaling factor (result rounded up),
            // respecting the above exceptions.
            const float DefaultRecipeScalingFactor = 0.35F;
            List<Recipe> recs = Main.recipe.ToList();
            foreach (Recipe rcp in Main.recipe)
            {
  // Speculative fix for a mysterious crash 'J the Gamer' was having on line:
  // """if (output_item_multiplier_overrides.ContainsKey(rcp.createItem.Name))""".
  // However, if some mod has moved all the recipes and left nulls, there
  // might be no recipes left to reduce costs of.
  if (null == rcp || null == rcp.createItem || null == rcp.createItem.Name || null == rcp.requiredItem)
  {
    continue;
  }

                float target_multiplier = DefaultRecipeScalingFactor;
                if (output_item_multiplier_overrides.ContainsKey(rcp.createItem.Name)) // ======== LINE 57 =========
                {
                    target_multiplier = output_item_multiplier_overrides[rcp.createItem.Name];
                }

                foreach (Item input_mat in rcp.requiredItem)
                {
  // also new
  if (null == input_mat || null == input_mat.Name)
  {
    continue;
  }

                    float input_multiplier = target_multiplier;
                    if (input_item_multiplier_overrides.ContainsKey(input_mat.Name))
                    {
                        input_multiplier = input_item_multiplier_overrides[input_mat.Name];
                    }

                    // don't reduce the cost of any walls or platforms (would generate resources)
                    if (input_mat.Name.EndsWith("Wall") || input_mat.Name.EndsWith("Platform"))
                    {
                        continue;
                    }

                    input_mat.stack = (int) Math.Ceiling(input_mat.stack * input_multiplier);
                }
            }
        }
    }
}
 
Heres the enabled.json file. I'd normally copy and paste but my computer is acting up and the wifi won't work.
 

Attachments

  • enabled.json
    1.7 KB · Views: 288
Why don't you put mod options like if you want that it affect all recipes coins, platform, mods, etc...
i like this mod :) Thanks for made this
 
Back
Top Bottom