From 7f4ae388f4f094eeebc107b066f9c9579f38accd Mon Sep 17 00:00:00 2001 From: goldenapple3 Date: Tue, 4 Jul 2017 23:01:43 +0300 Subject: [PATCH] Extractinator boost by Huldvan --- Config.cs | 157 +++++++++++++++++++++--------------------- ExtractinatorTweak.cs | 99 ++++++++++++++++++++++++++ VanillaTweaks.csproj | 1 + build.txt | 2 +- 4 files changed, 181 insertions(+), 78 deletions(-) create mode 100644 ExtractinatorTweak.cs diff --git a/Config.cs b/Config.cs index bad0f19..1940112 100644 --- a/Config.cs +++ b/Config.cs @@ -6,33 +6,34 @@ namespace VanillaTweaks { - public static class Config - { - public static bool GladiatorArmorTweak = true; - public static bool ObsidianArmorTweak = true; - public static bool MeteorArmorTweak = true; - public static bool RainArmorTweak = true; - public static bool HammerTweaks = true; - public static bool NightsEdgeAutoswing = true; - public static bool TrueSwordsAutoswing = true; - public static bool SwatHelmetTweak = true; - public static bool SkullTweak = true; - public static bool FishBowlTweak = true; - public static bool SandstoneRename = true; - public static bool CobaltShieldRename = true; - public static bool BoneBlockFix = true; - public static bool GoldCritterDropTweak = true; - - static string ConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks.json"); - - static string OldConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks"); - static string OldConfigPath = Path.Combine(OldConfigFolderPath, "config.json"); - static string OldConfigVersionPath = Path.Combine(OldConfigFolderPath, "config.version"); - - static readonly Preferences Configuration = new Preferences(ConfigPath); - - public static void Load() - { + public static class Config + { + public static bool GladiatorArmorTweak = true; + public static bool ObsidianArmorTweak = true; + public static bool MeteorArmorTweak = true; + public static bool RainArmorTweak = true; + public static bool HammerTweaks = true; + public static bool NightsEdgeAutoswing = true; + public static bool TrueSwordsAutoswing = true; + public static bool SwatHelmetTweak = true; + public static bool SkullTweak = true; + public static bool FishBowlTweak = true; + public static bool SandstoneRename = true; + public static bool CobaltShieldRename = true; + public static bool BoneBlockFix = true; + public static bool GoldCritterDropTweak = true; + public static float ExtractSpeedMultipltier = 5f; + + static string ConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks.json"); + + static string OldConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks"); + static string OldConfigPath = Path.Combine(OldConfigFolderPath, "config.json"); + static string OldConfigVersionPath = Path.Combine(OldConfigFolderPath, "config.version"); + + static readonly Preferences Configuration = new Preferences(ConfigPath); + + public static void Load() + { if(Directory.Exists(OldConfigFolderPath)) { if(File.Exists(OldConfigPath)) @@ -53,54 +54,56 @@ public static void Load() VanillaTweaks.Log("Old config folder still cotains some files/directories. They will not get deleted."); } } - if(!ReadConfig()) - { - VanillaTweaks.Log("Failed to read config file! Recreating config..."); - SaveConfig(); - } - } - - static bool ReadConfig() - { - if(Configuration.Load()) - { - Configuration.Get("GladiatorArmorTweak", ref GladiatorArmorTweak); - Configuration.Get("ObsidianArmorTweak", ref ObsidianArmorTweak); - Configuration.Get("MeteorArmorTweak", ref MeteorArmorTweak); - Configuration.Get("HammerTweaks", ref HammerTweaks); - Configuration.Get("NightsEdgeAutoswing", ref NightsEdgeAutoswing); - Configuration.Get("TrueSwordsAutoswing", ref TrueSwordsAutoswing); - Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak); - Configuration.Get("SkullTweak", ref SkullTweak); - Configuration.Get("FishBowlTweak", ref FishBowlTweak); - Configuration.Get("SandstoneRename", ref SandstoneRename); - Configuration.Get("CobaltShieldRename", ref CobaltShieldRename); - Configuration.Get("BoneBlockFix", ref BoneBlockFix); - Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak); - Configuration.Get("GoldCritterDropTweak", ref GoldCritterDropTweak); - return true; - } - return false; - } - - static void SaveConfig() - { - Configuration.Clear(); - Configuration.Put("GladiatorArmorTweak", GladiatorArmorTweak); - Configuration.Put("ObsidianArmorTweak", ObsidianArmorTweak); - Configuration.Put("MeteorArmorTweak", MeteorArmorTweak); - Configuration.Put("HammerTweaks", HammerTweaks); - Configuration.Put("NightsEdgeAutoswing", NightsEdgeAutoswing); - Configuration.Put("TrueSwordsAutoswing", TrueSwordsAutoswing); - Configuration.Put("SwatHelmetTweak", SwatHelmetTweak); - Configuration.Put("SkullTweak", SkullTweak); - Configuration.Put("FishBowlTweak", FishBowlTweak); - Configuration.Put("SandstoneRename", SandstoneRename); - Configuration.Put("CobaltShieldRename", CobaltShieldRename); - Configuration.Put("BoneBlockFix", BoneBlockFix); - Configuration.Put("SwatHelmetTweak", SwatHelmetTweak); - Configuration.Put("GoldCritterDropTweak", GoldCritterDropTweak); - Configuration.Save(); - } - } + if(!ReadConfig()) + { + VanillaTweaks.Log("Failed to read config file! Recreating config..."); + } + SaveConfig(); + } + + static bool ReadConfig() + { + if(Configuration.Load()) + { + Configuration.Get("GladiatorArmorTweak", ref GladiatorArmorTweak); + Configuration.Get("ObsidianArmorTweak", ref ObsidianArmorTweak); + Configuration.Get("MeteorArmorTweak", ref MeteorArmorTweak); + Configuration.Get("HammerTweaks", ref HammerTweaks); + Configuration.Get("NightsEdgeAutoswing", ref NightsEdgeAutoswing); + Configuration.Get("TrueSwordsAutoswing", ref TrueSwordsAutoswing); + Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak); + Configuration.Get("SkullTweak", ref SkullTweak); + Configuration.Get("FishBowlTweak", ref FishBowlTweak); + Configuration.Get("SandstoneRename", ref SandstoneRename); + Configuration.Get("CobaltShieldRename", ref CobaltShieldRename); + Configuration.Get("BoneBlockFix", ref BoneBlockFix); + Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak); + Configuration.Get("GoldCritterDropTweak", ref GoldCritterDropTweak); + Configuration.Get("ExtractSpeedMulitplier", ref ExtractSpeedMultipltier); + return true; + } + return false; + } + + static void SaveConfig() + { + Configuration.Clear(); + Configuration.Put("GladiatorArmorTweak", GladiatorArmorTweak); + Configuration.Put("ObsidianArmorTweak", ObsidianArmorTweak); + Configuration.Put("MeteorArmorTweak", MeteorArmorTweak); + Configuration.Put("HammerTweaks", HammerTweaks); + Configuration.Put("NightsEdgeAutoswing", NightsEdgeAutoswing); + Configuration.Put("TrueSwordsAutoswing", TrueSwordsAutoswing); + Configuration.Put("SwatHelmetTweak", SwatHelmetTweak); + Configuration.Put("SkullTweak", SkullTweak); + Configuration.Put("FishBowlTweak", FishBowlTweak); + Configuration.Put("SandstoneRename", SandstoneRename); + Configuration.Put("CobaltShieldRename", CobaltShieldRename); + Configuration.Put("BoneBlockFix", BoneBlockFix); + Configuration.Put("SwatHelmetTweak", SwatHelmetTweak); + Configuration.Put("GoldCritterDropTweak", GoldCritterDropTweak); + Configuration.Put("ExtractSpeedMulitplier", ExtractSpeedMultipltier); + Configuration.Save(); + } + } } diff --git a/ExtractinatorTweak.cs b/ExtractinatorTweak.cs new file mode 100644 index 0000000..fd104b3 --- /dev/null +++ b/ExtractinatorTweak.cs @@ -0,0 +1,99 @@ +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using System.Collections.Generic; +using System.Linq; + +namespace VanillaTweaks +{ + //original code by Hulvdan, modified by goldenapple + class ExtractinatorTweak : GlobalItem + { + struct ExtractableItem + { + public ExtractableItem(int ut, int ua, string n) + { + UseTime = ut; + UseAnimation = ua; + Name = n; + } + public int UseTime; + public int UseAnimation; + public string Name; + } + + static int[] VanillaExtractables = { ItemID.SiltBlock, ItemID.SlushBlock, ItemID.DesertFossil }; + static Dictionary ExtractItemsCache = new Dictionary(); +// static string Boost = " [Boosted]"; + +// private static ExtractableItem GetItemValue(int i) +// { +// ExtractableItem v; +// if (ExtractableItemsCache.TryGetValue(i, out v)) +// return v; +// return new ExtractableItem(2, 4, "BFMTWEAKERROR"); +// } + + static void SpeedUpExtract(Item item) + { + if(Config.ExtractSpeedMultipltier == 1f) + return; + + if (IsExtractable(item)) + { + if (!ExtractItemsCache.ContainsKey(item.type)) + ExtractItemsCache.Add(item.type, new ExtractableItem(item.useTime, item.useAnimation, item.Name)); + + var extractItem = ExtractItemsCache[item.type]; + if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == TileID.Extractinator) + { + //useTime must be 2 or higher or else items dissapear + item.useTime = Math.Max(2, (int)(extractItem.UseTime / Config.ExtractSpeedMultipltier)); + //useAnimation less than 4 looks really weird as there aren't enough frames + item.useAnimation = Math.Max(6, (int)(extractItem.UseAnimation / Config.ExtractSpeedMultipltier)); +// item.SetNameOverride(extractItem.Name + Boost); + } + else + { +// item.SetNameOverride(extractItem.Name); + item.useTime = extractItem.UseTime; + item.useAnimation = extractItem.UseAnimation; + } + } + } + + /* + public override bool UseItem(Item item, Player player) + { + if (bfmtweaks.tweak_extractinator) + ExtractinatorTweaker.onItemUse(item); + + return false; + }*/ + +// public override void UpdateInventory(Item item, Player player) +// { +// //if (bfmtweaks.tweak_extractinator) +// if(Config.ExtractSpeedMultipltier != 1f) +// ExtractinatorTweak.OnItemUse(item); +// } + + public override bool CanUseItem(Item item, Player player) + { + SpeedUpExtract(item); + return base.CanUseItem(item, player); + } + + static bool IsExtractable(Item item) + { + if(VanillaExtractables.Contains(item.type)) + return true; + + int resultType = 0; + int resultStack = 0; + ItemLoader.ExtractinatorUse(ref resultType, ref resultStack, item.type); + return resultType != 0 || resultStack != 0; + } + } +} \ No newline at end of file diff --git a/VanillaTweaks.csproj b/VanillaTweaks.csproj index 717cebb..6beb5aa 100644 --- a/VanillaTweaks.csproj +++ b/VanillaTweaks.csproj @@ -56,6 +56,7 @@ + diff --git a/build.txt b/build.txt index 1ae396b..0733ee5 100644 --- a/build.txt +++ b/build.txt @@ -1,6 +1,6 @@ displayName = Vanilla Tweaks author = goldenapple -version = 2.2.1 +version = 2.3 homepage = http://forums.terraria.org/index.php?threads/vanilla-tweaks-a-mod-with-no-content.37443/ hideCode = false includeSource = true