This repository was archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtecharria.cs
More file actions
214 lines (187 loc) · 7.95 KB
/
techarria.cs
File metadata and controls
214 lines (187 loc) · 7.95 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using Terraria.ModLoader;
using Terraria;
using Microsoft.Xna.Framework;
using Terraria.DataStructures;
using System;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using ReLogic.Content;
using System.Collections.Generic;
using Techarria.Content.Tiles.Misc;
using System.Windows.Forms;
using System.IO;
namespace Techarria
{
public class Techarria : Mod
{
public static float GenerationMultiplier = 1;
public static float CapacityMultiplier = 1;
public static float UsageMultiplier = 1;
public static bool BlockDusts = false;
public static Dictionary<int, NPC> moddedBannerToNPC = new();
public static bool Intersects(Rectangle rect, LineSegment line)
{
Rectangle aabb = new Rectangle();
aabb.X = (int)Math.Min(line.Start.X, (int)line.End.X);
aabb.Y = (int)Math.Min(line.Start.Y, (int)line.End.Y);
aabb.Width = (int)Math.Max(line.Start.X, (int)line.End.X) - aabb.X;
aabb.Height = (int)Math.Max(line.Start.Y, (int)line.End.Y) - aabb.Y;
if (!aabb.Intersects(rect))
{
return false;
}
float m = (line.Start.Y - line.End.Y) / (line.Start.X - line.End.X);
Vector2 slideTR = new Vector2(rect.Left, rect.Top - rect.Width * m);
Vector2 slideBR = new Vector2(rect.Left, slideTR.Y + rect.Width);
float topBound = Math.Max(rect.Top, rect.Bottom);
topBound = Math.Max(topBound, slideTR.Y);
topBound = Math.Max(topBound, slideBR.Y);
float bottomBound = Math.Min(rect.Top, rect.Bottom);
bottomBound = Math.Min(bottomBound, slideTR.Y);
bottomBound = Math.Min(bottomBound, slideBR.Y);
float b = m * (rect.Left - line.Start.X) + line.Start.Y;
return b <= topBound && b >= bottomBound;
}
public static void print(object obj)
{
System.Console.WriteLine(obj);
}
/// <summary>Whether or not this type is an item transfer tile</summary>
public static bool[] tileIsTransferDuct = new bool[TileLoader.TileCount];
/// <summary>Whether or not transfer ducts should connect to this type of tile</summary>
public static bool[] tileConnectToPipe = new bool[TileLoader.TileCount];
/// <summary>
/// Updates the texture of the transfer duct at the specified coords
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void TransferDuctFrame(int x, int y)
{
if (tileIsTransferDuct[Main.tile[x, y].TileType])
{
ModTile tileInstance = TileLoader.GetTile(Main.tile[x, y].TileType);
bool idc = false;
tileInstance.TileFrame(x, y, ref idc, ref idc);
}
}
public override void Load()
{
Terraria.On_WorldGen.paintTile += WorldGen_paintTile;
Terraria.On_Dust.NewDust += DustDetour;
Terraria.On_Main.DrawWires += DrawPowerTransfer;
Terraria.On_Player.Update += On_Player_Update;
}
int biorepulsionFieldType;
int invertedBiorepulsionFieldType;
private void On_Player_Update(On_Player.orig_Update orig, Player self, int i) {
Main.tileSolid[biorepulsionFieldType] = true;
Main.tileSolid[invertedBiorepulsionFieldType] = false;
orig(self, i);
Main.tileSolid[biorepulsionFieldType] = false;
Main.tileSolid[invertedBiorepulsionFieldType] = true;
}
public override void PostSetupContent() {
Console.WriteLine("Techaria: Linking Banners...");
foreach (Mod mod in ModLoader.Mods) {
foreach (ModNPC npc in mod.GetContent<ModNPC>()) {
if (npc.BannerItem != 0) {
moddedBannerToNPC.TryAdd(npc.BannerItem, npc.NPC);
Console.WriteLine($"Linked banner with item type \"{npc.BannerItem}\" to \"{npc.DisplayName.Value}\"");
}
}
}
biorepulsionFieldType = ModContent.TileType<BiorepulsionField>();
invertedBiorepulsionFieldType = ModContent.TileType<InvertedBiorepulsionField>();
}
/*
public override void PostAddRecipes()
{
string missingRecipes = "";
foreach (ModItem modItem in GetContent<ModItem>())
{
int type = modItem.Type;
foreach (Recipe recipe in Main.recipe)
{
Console.WriteLine($"Recipe produces item type {recipe.createItem.type}, needs type");
if (recipe.createItem.type == type)
{
Console.WriteLine($"\n\n\n\nRecipe Found\n\n\n\n");
goto RecipeFound;
}
}
missingRecipes += $"{modItem.Name}\n";
RecipeFound:
continue;
}
File.WriteAllText("C:/Users/bluem/OneDrive/Documents/My Games/Terraria/tModLoader/ModSources/Techarria/delete before public release/random bullshit my code spat out.txt", missingRecipes);
}
*/
private void DrawPowerTransfer(Terraria.On_Main.orig_DrawWires orig, Main self)
{
orig(self);
foreach (Wire wire in Power.DisplayInfos.Keys)
{
Color color;
switch (wire.C)
{
case 0:
color = new Color(218 / 255f, 2 / 255f, 5 / 255f);
break;
case 1:
color = new Color(2 / 255f, 124 / 255f, 218 / 255f);
break;
case 2:
color = new Color(2 / 255f, 218 / 255f, 91 / 255f);
break;
default:
color = new Color(218 / 255f, 194 / 255f, 2 / 255f);
break;
}
int j = wire.X;
int i = wire.Y;
PowerDisplayInfo displayInfo = Power.DisplayInfos[wire];
Main.spriteBatch.Draw(
ModContent.Request<Texture2D>("Techarria/Content/PowerTransferDisplay").Value,
new Rectangle(j * 16 - (int)Main.screenPosition.X, i * 16 - (int)Main.screenPosition.Y, 16, 16),
new Rectangle(0, 0, 16, 16),
color * (1 - displayInfo.age / 30f)
);
Main.spriteBatch.Draw(
ModContent.Request<Texture2D>("Techarria/Content/PowerTransferDisplay_TheSecond").Value,
new Rectangle(j * 16 - (int)Main.screenPosition.X, i * 16 - (int)Main.screenPosition.Y, 16, 16),
new Rectangle(0, 0, 16, 16),
Color.White * (1 - displayInfo.age / 30f)
);
if (++displayInfo.age >= 30)
Power.DisplayInfos.Remove(wire);
}
}
private int DustDetour(Terraria.On_Dust.orig_NewDust orig, Vector2 Position, int Width, int Height, int Type, float SpeedX, float SpeedY, int Alpha, Color newColor, float Scale)
{
if (BlockDusts)
{
return Main.maxDust;
}
return orig(Position, Width, Height, Type, SpeedX, SpeedY, Alpha, newColor, Scale);
}
public override void Unload()
{
Terraria.On_WorldGen.paintTile -= WorldGen_paintTile;
Terraria.On_Dust.NewDust -= DustDetour;
Terraria.On_Main.DrawWires -= DrawPowerTransfer;
Terraria.On_Player.Update -= On_Player_Update;
}
private bool WorldGen_paintTile(Terraria.On_WorldGen.orig_paintTile orig, int x, int y, byte color, bool broadCast)
{
bool result = orig.Invoke(x, y, color, broadCast);
TransferDuctFrame(x, y);
TransferDuctFrame(x+1, y);
TransferDuctFrame(x, y+1);
TransferDuctFrame(x-1, y);
TransferDuctFrame(x, y-1);
return result;
}
}
}