Skip to content

Commit 7f4ae38

Browse files
committed
Extractinator boost by Huldvan
1 parent 689852b commit 7f4ae38

File tree

4 files changed

+181
-78
lines changed

4 files changed

+181
-78
lines changed

Config.cs

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,34 @@
66

77
namespace VanillaTweaks
88
{
9-
public static class Config
10-
{
11-
public static bool GladiatorArmorTweak = true;
12-
public static bool ObsidianArmorTweak = true;
13-
public static bool MeteorArmorTweak = true;
14-
public static bool RainArmorTweak = true;
15-
public static bool HammerTweaks = true;
16-
public static bool NightsEdgeAutoswing = true;
17-
public static bool TrueSwordsAutoswing = true;
18-
public static bool SwatHelmetTweak = true;
19-
public static bool SkullTweak = true;
20-
public static bool FishBowlTweak = true;
21-
public static bool SandstoneRename = true;
22-
public static bool CobaltShieldRename = true;
23-
public static bool BoneBlockFix = true;
24-
public static bool GoldCritterDropTweak = true;
25-
26-
static string ConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks.json");
27-
28-
static string OldConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks");
29-
static string OldConfigPath = Path.Combine(OldConfigFolderPath, "config.json");
30-
static string OldConfigVersionPath = Path.Combine(OldConfigFolderPath, "config.version");
31-
32-
static readonly Preferences Configuration = new Preferences(ConfigPath);
33-
34-
public static void Load()
35-
{
9+
public static class Config
10+
{
11+
public static bool GladiatorArmorTweak = true;
12+
public static bool ObsidianArmorTweak = true;
13+
public static bool MeteorArmorTweak = true;
14+
public static bool RainArmorTweak = true;
15+
public static bool HammerTweaks = true;
16+
public static bool NightsEdgeAutoswing = true;
17+
public static bool TrueSwordsAutoswing = true;
18+
public static bool SwatHelmetTweak = true;
19+
public static bool SkullTweak = true;
20+
public static bool FishBowlTweak = true;
21+
public static bool SandstoneRename = true;
22+
public static bool CobaltShieldRename = true;
23+
public static bool BoneBlockFix = true;
24+
public static bool GoldCritterDropTweak = true;
25+
public static float ExtractSpeedMultipltier = 5f;
26+
27+
static string ConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks.json");
28+
29+
static string OldConfigFolderPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks");
30+
static string OldConfigPath = Path.Combine(OldConfigFolderPath, "config.json");
31+
static string OldConfigVersionPath = Path.Combine(OldConfigFolderPath, "config.version");
32+
33+
static readonly Preferences Configuration = new Preferences(ConfigPath);
34+
35+
public static void Load()
36+
{
3637
if(Directory.Exists(OldConfigFolderPath))
3738
{
3839
if(File.Exists(OldConfigPath))
@@ -53,54 +54,56 @@ public static void Load()
5354
VanillaTweaks.Log("Old config folder still cotains some files/directories. They will not get deleted.");
5455
}
5556
}
56-
if(!ReadConfig())
57-
{
58-
VanillaTweaks.Log("Failed to read config file! Recreating config...");
59-
SaveConfig();
60-
}
61-
}
62-
63-
static bool ReadConfig()
64-
{
65-
if(Configuration.Load())
66-
{
67-
Configuration.Get("GladiatorArmorTweak", ref GladiatorArmorTweak);
68-
Configuration.Get("ObsidianArmorTweak", ref ObsidianArmorTweak);
69-
Configuration.Get("MeteorArmorTweak", ref MeteorArmorTweak);
70-
Configuration.Get("HammerTweaks", ref HammerTweaks);
71-
Configuration.Get("NightsEdgeAutoswing", ref NightsEdgeAutoswing);
72-
Configuration.Get("TrueSwordsAutoswing", ref TrueSwordsAutoswing);
73-
Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak);
74-
Configuration.Get("SkullTweak", ref SkullTweak);
75-
Configuration.Get("FishBowlTweak", ref FishBowlTweak);
76-
Configuration.Get("SandstoneRename", ref SandstoneRename);
77-
Configuration.Get("CobaltShieldRename", ref CobaltShieldRename);
78-
Configuration.Get("BoneBlockFix", ref BoneBlockFix);
79-
Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak);
80-
Configuration.Get("GoldCritterDropTweak", ref GoldCritterDropTweak);
81-
return true;
82-
}
83-
return false;
84-
}
85-
86-
static void SaveConfig()
87-
{
88-
Configuration.Clear();
89-
Configuration.Put("GladiatorArmorTweak", GladiatorArmorTweak);
90-
Configuration.Put("ObsidianArmorTweak", ObsidianArmorTweak);
91-
Configuration.Put("MeteorArmorTweak", MeteorArmorTweak);
92-
Configuration.Put("HammerTweaks", HammerTweaks);
93-
Configuration.Put("NightsEdgeAutoswing", NightsEdgeAutoswing);
94-
Configuration.Put("TrueSwordsAutoswing", TrueSwordsAutoswing);
95-
Configuration.Put("SwatHelmetTweak", SwatHelmetTweak);
96-
Configuration.Put("SkullTweak", SkullTweak);
97-
Configuration.Put("FishBowlTweak", FishBowlTweak);
98-
Configuration.Put("SandstoneRename", SandstoneRename);
99-
Configuration.Put("CobaltShieldRename", CobaltShieldRename);
100-
Configuration.Put("BoneBlockFix", BoneBlockFix);
101-
Configuration.Put("SwatHelmetTweak", SwatHelmetTweak);
102-
Configuration.Put("GoldCritterDropTweak", GoldCritterDropTweak);
103-
Configuration.Save();
104-
}
105-
}
57+
if(!ReadConfig())
58+
{
59+
VanillaTweaks.Log("Failed to read config file! Recreating config...");
60+
}
61+
SaveConfig();
62+
}
63+
64+
static bool ReadConfig()
65+
{
66+
if(Configuration.Load())
67+
{
68+
Configuration.Get("GladiatorArmorTweak", ref GladiatorArmorTweak);
69+
Configuration.Get("ObsidianArmorTweak", ref ObsidianArmorTweak);
70+
Configuration.Get("MeteorArmorTweak", ref MeteorArmorTweak);
71+
Configuration.Get("HammerTweaks", ref HammerTweaks);
72+
Configuration.Get("NightsEdgeAutoswing", ref NightsEdgeAutoswing);
73+
Configuration.Get("TrueSwordsAutoswing", ref TrueSwordsAutoswing);
74+
Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak);
75+
Configuration.Get("SkullTweak", ref SkullTweak);
76+
Configuration.Get("FishBowlTweak", ref FishBowlTweak);
77+
Configuration.Get("SandstoneRename", ref SandstoneRename);
78+
Configuration.Get("CobaltShieldRename", ref CobaltShieldRename);
79+
Configuration.Get("BoneBlockFix", ref BoneBlockFix);
80+
Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak);
81+
Configuration.Get("GoldCritterDropTweak", ref GoldCritterDropTweak);
82+
Configuration.Get("ExtractSpeedMulitplier", ref ExtractSpeedMultipltier);
83+
return true;
84+
}
85+
return false;
86+
}
87+
88+
static void SaveConfig()
89+
{
90+
Configuration.Clear();
91+
Configuration.Put("GladiatorArmorTweak", GladiatorArmorTweak);
92+
Configuration.Put("ObsidianArmorTweak", ObsidianArmorTweak);
93+
Configuration.Put("MeteorArmorTweak", MeteorArmorTweak);
94+
Configuration.Put("HammerTweaks", HammerTweaks);
95+
Configuration.Put("NightsEdgeAutoswing", NightsEdgeAutoswing);
96+
Configuration.Put("TrueSwordsAutoswing", TrueSwordsAutoswing);
97+
Configuration.Put("SwatHelmetTweak", SwatHelmetTweak);
98+
Configuration.Put("SkullTweak", SkullTweak);
99+
Configuration.Put("FishBowlTweak", FishBowlTweak);
100+
Configuration.Put("SandstoneRename", SandstoneRename);
101+
Configuration.Put("CobaltShieldRename", CobaltShieldRename);
102+
Configuration.Put("BoneBlockFix", BoneBlockFix);
103+
Configuration.Put("SwatHelmetTweak", SwatHelmetTweak);
104+
Configuration.Put("GoldCritterDropTweak", GoldCritterDropTweak);
105+
Configuration.Put("ExtractSpeedMulitplier", ExtractSpeedMultipltier);
106+
Configuration.Save();
107+
}
108+
}
106109
}

ExtractinatorTweak.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System;
2+
using Terraria;
3+
using Terraria.ID;
4+
using Terraria.ModLoader;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
namespace VanillaTweaks
9+
{
10+
//original code by Hulvdan, modified by goldenapple
11+
class ExtractinatorTweak : GlobalItem
12+
{
13+
struct ExtractableItem
14+
{
15+
public ExtractableItem(int ut, int ua, string n)
16+
{
17+
UseTime = ut;
18+
UseAnimation = ua;
19+
Name = n;
20+
}
21+
public int UseTime;
22+
public int UseAnimation;
23+
public string Name;
24+
}
25+
26+
static int[] VanillaExtractables = { ItemID.SiltBlock, ItemID.SlushBlock, ItemID.DesertFossil };
27+
static Dictionary<int, ExtractableItem> ExtractItemsCache = new Dictionary<int, ExtractableItem>();
28+
// static string Boost = " [Boosted]";
29+
30+
// private static ExtractableItem GetItemValue(int i)
31+
// {
32+
// ExtractableItem v;
33+
// if (ExtractableItemsCache.TryGetValue(i, out v))
34+
// return v;
35+
// return new ExtractableItem(2, 4, "BFMTWEAKERROR");
36+
// }
37+
38+
static void SpeedUpExtract(Item item)
39+
{
40+
if(Config.ExtractSpeedMultipltier == 1f)
41+
return;
42+
43+
if (IsExtractable(item))
44+
{
45+
if (!ExtractItemsCache.ContainsKey(item.type))
46+
ExtractItemsCache.Add(item.type, new ExtractableItem(item.useTime, item.useAnimation, item.Name));
47+
48+
var extractItem = ExtractItemsCache[item.type];
49+
if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == TileID.Extractinator)
50+
{
51+
//useTime must be 2 or higher or else items dissapear
52+
item.useTime = Math.Max(2, (int)(extractItem.UseTime / Config.ExtractSpeedMultipltier));
53+
//useAnimation less than 4 looks really weird as there aren't enough frames
54+
item.useAnimation = Math.Max(6, (int)(extractItem.UseAnimation / Config.ExtractSpeedMultipltier));
55+
// item.SetNameOverride(extractItem.Name + Boost);
56+
}
57+
else
58+
{
59+
// item.SetNameOverride(extractItem.Name);
60+
item.useTime = extractItem.UseTime;
61+
item.useAnimation = extractItem.UseAnimation;
62+
}
63+
}
64+
}
65+
66+
/*
67+
public override bool UseItem(Item item, Player player)
68+
{
69+
if (bfmtweaks.tweak_extractinator)
70+
ExtractinatorTweaker.onItemUse(item);
71+
72+
return false;
73+
}*/
74+
75+
// public override void UpdateInventory(Item item, Player player)
76+
// {
77+
// //if (bfmtweaks.tweak_extractinator)
78+
// if(Config.ExtractSpeedMultipltier != 1f)
79+
// ExtractinatorTweak.OnItemUse(item);
80+
// }
81+
82+
public override bool CanUseItem(Item item, Player player)
83+
{
84+
SpeedUpExtract(item);
85+
return base.CanUseItem(item, player);
86+
}
87+
88+
static bool IsExtractable(Item item)
89+
{
90+
if(VanillaExtractables.Contains(item.type))
91+
return true;
92+
93+
int resultType = 0;
94+
int resultStack = 0;
95+
ItemLoader.ExtractinatorUse(ref resultType, ref resultStack, item.type);
96+
return resultType != 0 || resultStack != 0;
97+
}
98+
}
99+
}

VanillaTweaks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
</ItemGroup>
5757
<ItemGroup>
5858
<Compile Include="Config.cs" />
59+
<Compile Include="ExtractinatorTweak.cs" />
5960
<Compile Include="ItemTweaks.cs" />
6061
<Compile Include="LangTweaks.cs" />
6162
<Compile Include="NPCTweaks.cs" />

build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
displayName = Vanilla Tweaks
22
author = goldenapple
3-
version = 2.2.1
3+
version = 2.3
44
homepage = http://forums.terraria.org/index.php?threads/vanilla-tweaks-a-mod-with-no-content.37443/
55
hideCode = false
66
includeSource = true

0 commit comments

Comments
 (0)