Skip to content

Commit

Permalink
Extractinator boost by Huldvan
Browse files Browse the repository at this point in the history
  • Loading branch information
gardenappl committed Jul 4, 2017
1 parent 689852b commit 7f4ae38
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 78 deletions.
157 changes: 80 additions & 77 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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();
}
}
}
99 changes: 99 additions & 0 deletions ExtractinatorTweak.cs
Original file line number Diff line number Diff line change
@@ -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<int, ExtractableItem> ExtractItemsCache = new Dictionary<int, ExtractableItem>();
// 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;
}
}
}
1 change: 1 addition & 0 deletions VanillaTweaks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="ExtractinatorTweak.cs" />
<Compile Include="ItemTweaks.cs" />
<Compile Include="LangTweaks.cs" />
<Compile Include="NPCTweaks.cs" />
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7f4ae38

Please sign in to comment.