forked from gardenappl/VanillaTweaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractinatorTweak.cs
77 lines (68 loc) · 2.2 KB
/
ExtractinatorTweak.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System.Collections.Generic;
using System.Linq;
using static Terraria.ModLoader.ModContent;
namespace VanillaTweaks
{
//original code by Hulvdan, modified by goldenapple
class ExtractinatorTweak : GlobalItem
{
struct ExtractableItem
{
public ExtractableItem(Item item)
{
UseTime = item.useTime;
UseAnimation = item.useAnimation;
Name = item.Name;
}
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 void SpeedUpExtract(Item item)
{
if(GetInstance<ServerConfig>().ExtractSpeedMultiplier == 1f)
return;
if(Main.tile[Player.tileTargetX, Player.tileTargetY].TileType == TileID.Extractinator)
{
if(!ExtractItemsCache.ContainsKey(item.type) && IsExtractable(item))
ExtractItemsCache.Add(item.type, new ExtractableItem(item));
}
if(ExtractItemsCache.ContainsKey(item.type))
{
var extractItem = ExtractItemsCache[item.type];
if (Main.tile[Player.tileTargetX, Player.tileTargetY].TileType == TileID.Extractinator)
{
//useTime must be 2 or higher or else items dissapear
item.useTime = Math.Max(2, (int)(extractItem.UseTime / GetInstance<ServerConfig>().ExtractSpeedMultiplier));
//useAnimation less than 4 looks really weird as there aren't enough frames
item.useAnimation = Math.Max(6, (int)(extractItem.UseAnimation / GetInstance<ServerConfig>().ExtractSpeedMultiplier));
}
else
{
item.useTime = extractItem.UseTime;
item.useAnimation = extractItem.UseAnimation;
}
}
}
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;
}
}
}