Skip to content

Commit fa86d43

Browse files
committed
TE support
1 parent 0dd3cdc commit fa86d43

File tree

6 files changed

+78
-45
lines changed

6 files changed

+78
-45
lines changed

CopyWand.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ public override void SetDefaults()
2929
item.useAnimation = 20;
3030
item.rare = 1;
3131
}
32-
public override void AddRecipes()
33-
{
34-
ModRecipe r = new ModRecipe(mod);
35-
r.AddIngredient(ItemID.DirtBlock, 1);
36-
r.SetResult(this);
37-
r.AddRecipe();
38-
}
3932
public override bool UseItem(Player player)
4033
{
4134
if (player.altFunctionUse == 2 && !SecondPoint && TopLeft != null)
@@ -88,19 +81,46 @@ public void SaveStructure(Rectangle target, string targetPath = null)
8881
Tile tile = Framing.GetTileSafely(x, y);
8982
string tileName;
9083
string wallName;
91-
if (tile.type > Main.maxTileSets) tileName = ModContent.GetModTile(tile.type).GetType().AssemblyQualifiedName;
84+
string teName;
85+
if (tile.type > Main.maxTileSets) tileName = ModContent.GetModTile(tile.type).mod.Name + " " + ModContent.GetModTile(tile.type).Name;
9286
else tileName = tile.type.ToString();
93-
if (tile.wall > Main.maxWallTypes) wallName = ModContent.GetModWall(tile.wall).GetType().AssemblyQualifiedName;
87+
if (tile.wall > Main.maxWallTypes) wallName = ModContent.GetModWall(tile.wall).mod.Name + " " + ModContent.GetModWall(tile.wall).Name;
9488
else wallName = tile.wall.ToString();
9589

90+
TileEntity teTarget = null; //grabbing TE data
91+
TagCompound entityTag = null;
92+
93+
if (TileEntity.ByPosition.ContainsKey(new Point16(x, y))) teTarget = TileEntity.ByPosition[new Point16(x, y)];
94+
95+
if (teTarget != null)
96+
{
97+
if (teTarget.type < 2)
98+
{
99+
teName = teTarget.type.ToString();
100+
}
101+
else
102+
{
103+
ModTileEntity entityTarget = ModTileEntity.GetTileEntity(teTarget.type);
104+
if (entityTarget != null)
105+
{
106+
teName = entityTarget.mod.Name + " " + entityTarget.Name;
107+
entityTag = (teTarget as ModTileEntity).Save();
108+
}
109+
else teName = "";
110+
}
111+
}
112+
else teName = "";
113+
96114
byte[] wireArray = new byte[]
97115
{
98116
(byte)tile.wire().ToInt(),
99117
(byte)tile.wire2().ToInt(),
100118
(byte)tile.wire3().ToInt(),
101119
(byte)tile.wire4().ToInt()
102120
};
103-
data.Add(new TileSaveData(tile.active(), tileName, wallName, tile.frameX, tile.frameY, (short)tile.wallFrameX(), (short)tile.wallFrameY(), tile.slope(), tile.halfBrick(), tile.actuator(), tile.nactive(), tile.liquid, tile.liquidType(), tile.color(), tile.wallColor(), wireArray));
121+
data.Add(new TileSaveData(tile.active(), tileName, wallName, tile.frameX, tile.frameY, (short)tile.wallFrameX(), (short)tile.wallFrameY(),
122+
tile.slope(), tile.halfBrick(), tile.actuator(), !tile.nactive(), tile.liquid, tile.liquidType(), tile.color(), tile.wallColor(), wireArray,
123+
teName, entityTag));
104124
}
105125
}
106126
tag.Add("TileData", data);

NullBlock.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ public override void SetDefaults()
3535
item.rare = 1;
3636
item.createTile = ModContent.TileType<NullBlock>();
3737
}
38-
public override void AddRecipes()
39-
{
40-
ModRecipe r = new ModRecipe(mod);
41-
r.AddIngredient(ItemID.DirtBlock, 1);
42-
r.SetResult(this);
43-
r.AddRecipe();
44-
}
4538
}
4639

4740
class NullWallItem : ModItem
@@ -65,13 +58,6 @@ public override void SetDefaults()
6558
item.rare = 1;
6659
item.createWall = ModContent.WallType<NullWall>();
6760
}
68-
public override void AddRecipes()
69-
{
70-
ModRecipe r = new ModRecipe(mod);
71-
r.AddIngredient(ItemID.DirtBlock, 1);
72-
r.SetResult(this);
73-
r.AddRecipe();
74-
}
7561
}
7662

7763
class NullBoth : ModItem
@@ -96,12 +82,5 @@ public override void SetDefaults()
9682
item.createTile = ModContent.TileType<NullBlock>();
9783
item.createWall = ModContent.WallType<NullWall>();
9884
}
99-
public override void AddRecipes()
100-
{
101-
ModRecipe r = new ModRecipe(mod);
102-
r.AddIngredient(ItemID.DirtBlock, 1);
103-
r.SetResult(this);
104-
r.AddRecipe();
105-
}
10685
}
10786
}

StructureHelper.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ public static void GenerateStructure(string path, Point16 pos, Mod mod, bool ful
7070

7171
if (!int.TryParse(d.Tile, out int type))
7272
{
73-
try
73+
string[] parts = d.Tile.Split();
74+
if (parts.Length > 1 && ModLoader.GetMod(parts[0]) != null && ModLoader.GetMod(parts[0]).TileType(parts[1]) != 0)
75+
{
76+
type = ModLoader.GetMod(parts[0]).TileType(parts[1]);
77+
}
78+
79+
else try
7480
{
7581
Type tileType = Type.GetType(d.Tile);
7682
var getType = typeof(ModContent).GetMethod("TileType", BindingFlags.Static | BindingFlags.Public);
@@ -81,7 +87,13 @@ public static void GenerateStructure(string path, Point16 pos, Mod mod, bool ful
8187

8288
if (!int.TryParse(d.Wall, out int wallType))
8389
{
84-
try
90+
string[] parts = d.Wall.Split();
91+
if (parts.Length > 1 && ModLoader.GetMod(parts[0]) != null && ModLoader.GetMod(parts[0]).WallType(parts[1]) != 0)
92+
{
93+
wallType = ModLoader.GetMod(parts[0]).WallType(parts[1]);
94+
}
95+
96+
else try
8597
{
8698
Type wallTypeType = Type.GetType(d.Wall); //I am so sorry for this name
8799
var getWallType = typeof(ModContent).GetMethod("WallType", BindingFlags.Static | BindingFlags.Public);
@@ -105,7 +117,7 @@ public static void GenerateStructure(string path, Point16 pos, Mod mod, bool ful
105117
tile.slope(d.Slope);
106118
tile.halfBrick(d.HalfSlab);
107119
tile.actuator(d.HasActuator);
108-
tile.inActive(!d.Actuated);
120+
tile.inActive(d.Actuated);
109121
tile.liquid = d.Liquid;
110122
tile.liquidType(d.LiquidType);
111123
tile.color(d.Color);
@@ -115,6 +127,23 @@ public static void GenerateStructure(string path, Point16 pos, Mod mod, bool ful
115127
tile.wire3(d.Wire[2] > 0);
116128
tile.wire4(d.Wire[3] > 0);
117129
tile.active(d.Active);
130+
131+
if(d.TEType != "") //place and load a tile entity
132+
{
133+
int typ;
134+
135+
if (!int.TryParse(d.TEType, out typ))
136+
{
137+
string[] parts = d.TEType.Split();
138+
typ = ModLoader.GetMod(parts[0]).TileEntityType(parts[1]);
139+
}
140+
141+
if (d.TEType != "")
142+
{
143+
TileEntity.PlaceEntityNet(pos.X + x, pos.Y + y, typ);
144+
if (d.TEData != null && typ > 2) (TileEntity.ByPosition[new Point16(pos.X + x, pos.Y + y)] as ModTileEntity).Load(d.TEData);
145+
}
146+
}
118147
}
119148

120149
}

TestWands.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ public override void SetDefaults()
5555
item.useAnimation = 20;
5656
item.rare = 1;
5757
}
58-
public override void AddRecipes()
59-
{
60-
ModRecipe r = new ModRecipe(mod);
61-
r.AddIngredient(ItemID.DirtBlock, 1);
62-
r.SetResult(this);
63-
r.AddRecipe();
64-
}
6558
public override bool UseItem(Player player)
6659
{
6760
StructureHelper.GenerateStructure(ModLoader.ModPath.Replace("Mods", "SavedStructures") + "/TestWandCache", (Main.MouseWorld / 16).ToPoint16(), mod, true);

TileSaveData.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Terraria.ModLoader.IO;
3+
using Terraria.ModLoader;
34

45
namespace StructureHelper
56
{
@@ -21,7 +22,11 @@ public struct TileSaveData : TagSerializable
2122
public byte Color;
2223
public byte WallColor;
2324
public byte[] Wire;
24-
public TileSaveData(bool active, string tile, string wall, short frameX, short frameY, short wFrameX, short wFrameY, byte slope, bool halfSlab, bool hasActuator, bool actuated, byte liquid, byte liquidType, byte color, byte wallColor, byte[] wire)
25+
26+
public string TEType;
27+
public TagCompound TEData;
28+
29+
public TileSaveData(bool active, string tile, string wall, short frameX, short frameY, short wFrameX, short wFrameY, byte slope, bool halfSlab, bool hasActuator, bool actuated, byte liquid, byte liquidType, byte color, byte wallColor, byte[] wire, string teType, TagCompound teData)
2530
{
2631
Active = active;
2732
Tile = tile;
@@ -39,6 +44,9 @@ public TileSaveData(bool active, string tile, string wall, short frameX, short f
3944
Color = color;
4045
WallColor = wallColor;
4146
Wire = wire;
47+
48+
TEType = teType;
49+
TEData = teData;
4250
}
4351
public static Func<TagCompound, TileSaveData> DESERIALIZER = s => DeserializeData(s);
4452
public static TileSaveData DeserializeData(TagCompound tag)
@@ -59,7 +67,9 @@ public static TileSaveData DeserializeData(TagCompound tag)
5967
tag.GetByte("LiquidType"),
6068
tag.GetByte("Color"),
6169
tag.GetByte("WallColor"),
62-
tag.GetByteArray("Wire")
70+
tag.GetByteArray("Wire"),
71+
tag.GetString("TEType"),
72+
tag.Get<TagCompound>("TEData")
6373
);
6474
}
6575

@@ -82,7 +92,9 @@ public TagCompound SerializeData()
8292
["LiquidType"] = LiquidType,
8393
["Color"] = Color,
8494
["WallColor"] = WallColor,
85-
["Wire"] = Wire
95+
["Wire"] = Wire,
96+
["TEType"] = TEType,
97+
["TEData"] = TEData
8698
};
8799
}
88100
}

build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
displayName = Scalie's Structurizer
22
author = Scalie
3-
version = 0.1.2
3+
version = 0.1.4

0 commit comments

Comments
 (0)