Rely on in-world tile immediately after meta tile assignment

This commit is contained in:
Ozzatron committed 2022-04-14 13:42:42 -04:00
1 parent 4b13bae46b
commit 72fc355b65
1 file changed
+25 -30
+25 -30
View File
@@ -190,28 +190,39 @@ namespace CalamityMod.Schematics
for (int y = 0; y < height; ++y)
{
SchematicMetaTile smt = schematic[x, y];
string modChestStr = TileLoader.GetTile(smt.TileType)?.ContainerName.GetDefault() ?? "";
bool isChest = smt.TileType == TileID.Containers || modChestStr != "";
smt.ApplyTo(x + cornerX, y + cornerY, originalTiles[x, y]);
Tile worldTile = Main.tile[x + cornerX, y + cornerY];
// FRAME DATA SEEMS CORRUPTED. Not sure what's going on.
// NOTE
// UNCOMMENTING THIS LINE MAKES THE GAME CRASH WITH NO ERROR IN LOG
// Framing.SelfFrame8Way(x + cornerX, y + cornerY, worldTile, true);
// If the determined tile type is a chest and this is its top left corner, define it appropriately.
if (isChest && smt.miscState.TileFrameX % 36 == 0 && smt.miscState.TileFrameY == 0)
// Skip this step if this schematic position preserves tiles.
bool isChest = worldTile.TileType == TileID.Containers || TileID.Sets.BasicChest[worldTile.TileType];
if (!smt.keepTile && isChest && worldTile.TileFrameX % 36 == 0 && worldTile.TileFrameY == 0)
{
Chest chest = PlaceChest(x + cornerX, y + cornerY, smt.TileType);
// Use the appropriate chest delegate function to fill the chest.
if (chestDelegate is Action<Chest, int, bool>)
// If a chest already exists "near" this position, then the corner was likely already defined.
// Do not do anything if a chest was already defined.
// FindChestByGuessing checks a 2x2 space starting in the given position, so nudge it up and left by 1.
int chestIndex = Chest.FindChestByGuessing(x + cornerX - 1, y + cornerY - 1);
if (chestIndex == -1)
{
(chestDelegate as Action<Chest, int, bool>)?.Invoke(chest, smt.TileType, specialCondition);
specialCondition = true;
chestIndex = Chest.CreateChest(x + cornerX, y + cornerY, -1);
Chest chest = Main.chest[chestIndex];
// Use the appropriate chest delegate function to fill the chest.
if (chestDelegate is Action<Chest, int, bool>)
{
(chestDelegate as Action<Chest, int, bool>)?.Invoke(chest, worldTile.TileType, specialCondition);
specialCondition = true;
}
else if (chestDelegate is Action<Chest>)
(chestDelegate as Action<Chest>)?.Invoke(chest);
}
else if (chestDelegate is Action<Chest>)
(chestDelegate as Action<Chest>)?.Invoke(chest);
}
// This is where the meta tile keep booleans are applied.
smt.ApplyTo(x + cornerX, y + cornerY, originalTiles[x, y]);
// Now that the tile data is correctly set, place appropriate tile entities.
Tile worldTile = Main.tile[x + cornerX, y + cornerY];
TryToPlaceTileEntities(x + cornerX, y + cornerY, worldTile);
// Activate the pile placement function if defined.
@@ -242,22 +253,6 @@ namespace CalamityMod.Schematics
else if (tileType == ModContent.TileType<LabHologramProjector>())
TileEntity.PlaceEntityNet(x, y, ModContent.TileEntityType<TELabHologramProjector>());
}
private static Chest PlaceChest(int x, int y, int chestType)
{
int chestIndex = Chest.FindEmptyChest(x, y, chestType);
Main.chest[chestIndex] = new Chest()
{
x = x,
y = y
};
Main.chest[chestIndex].item = new Item[Main.chest[chestIndex].item.Length];
for (int i = 0; i < Main.chest[chestIndex].item.Length; i++)
{
Main.chest[chestIndex].item[i] = new Item();
}
return Main.chest[chestIndex];
}
#endregion
}
}