Merge pull request #854 from CalamityTeam/wallsvisiblethroughwater
This commit is contained in:
6 files changed
+134
-6
No files matched your search
@@ -13,6 +13,7 @@ using Terraria.GameContent.Liquid;
|
||||
using Terraria.GameContent.UI.Elements;
|
||||
using Terraria.GameContent.UI.States;
|
||||
using Terraria.Graphics.Light;
|
||||
using Terraria.Map;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.ILEditing
|
||||
@@ -160,6 +161,9 @@ namespace CalamityMod.ILEditing
|
||||
|
||||
// Fix vanilla not accounting for multiple bobbers when fishing with truffle worm
|
||||
IL_Player.ItemCheck_CheckFishingBobbers += FixTruffleWormFishing;
|
||||
|
||||
// Allow specified walls to be visible through water on the map
|
||||
IL_MapHelper.CreateMapTile += UseVisibleThroughWaterMapTile;
|
||||
|
||||
//Additional detours that are in their own item files given they are only relevant to these specific items:
|
||||
//Rover drive detours on Player.DrawInfernoRings to draw its shield
|
||||
|
||||
@@ -7,12 +7,14 @@ using CalamityMod.Items.Materials;
|
||||
using CalamityMod.Items.TreasureBags.MiscGrabBags;
|
||||
using CalamityMod.NPCs.AcidRain;
|
||||
using CalamityMod.NPCs.NormalNPCs;
|
||||
using CalamityMod.Walls;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Mono.Cecil.Cil;
|
||||
using MonoMod.Cil;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ID;
|
||||
using Terraria.Map;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.ILEditing
|
||||
@@ -898,5 +900,62 @@ namespace CalamityMod.ILEditing
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Render Special Map Colors
|
||||
private static void UseVisibleThroughWaterMapTile(ILContext il)
|
||||
{
|
||||
var c = new ILCursor(il);
|
||||
|
||||
if (!c.TryGotoNext(x => x.MatchCall<Tilemap>("get_Item")))
|
||||
{
|
||||
LogFailure("Use VisibleThroughWater Map Tile", "Could not locate call to Terraria.Map.TileMap::get_Item.");
|
||||
return;
|
||||
}
|
||||
|
||||
int tileIndex = -1;
|
||||
if (!c.TryGotoNext(x => x.MatchStloc(out tileIndex)) || tileIndex == -1)
|
||||
{
|
||||
LogFailure("Use VisibleThroughWater Map Tile", "Could not determine the local variable index tile is pushed to.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!c.TryGotoNext(x => x.MatchCall<Tile>("liquidType")))
|
||||
{
|
||||
LogFailure("Use VisibleThroughWater Map Tile", "Could not locate call to Terraria.Tile::liquidType.");
|
||||
return;
|
||||
}
|
||||
|
||||
int liquidTypeIndex = -1;
|
||||
if (!c.TryGotoNext(x => x.MatchStloc(out liquidTypeIndex)) || liquidTypeIndex == -1)
|
||||
{
|
||||
LogFailure("Use VisibleThroughWater Map Tile", "Could not determine the local variable index liquidType is pushed to.");
|
||||
return;
|
||||
}
|
||||
|
||||
int relativeMapTypeIndex = -1;
|
||||
if (!c.TryGotoNext(MoveType.After, x => x.MatchStloc(out relativeMapTypeIndex)) || relativeMapTypeIndex == -1)
|
||||
{
|
||||
LogFailure("Use VisibleThroughWater Map Tile", "Could not determine the local variable index of the relative map type.");
|
||||
return;
|
||||
}
|
||||
|
||||
c.Emit(OpCodes.Ldloc_0);
|
||||
c.Emit(OpCodes.Ldloc, relativeMapTypeIndex);
|
||||
c.Emit(OpCodes.Ldloc, liquidTypeIndex);
|
||||
c.EmitDelegate(
|
||||
(Tile tile, int relativeMapType, int liquidType) =>
|
||||
{
|
||||
if (liquidType != LiquidID.Water)
|
||||
return relativeMapType;
|
||||
|
||||
if (WallLoader.GetWall(tile.WallType) is IVisibleThroughWater visibleThroughWater)
|
||||
return visibleThroughWater.WaterMapEntry;
|
||||
|
||||
return relativeMapType;
|
||||
}
|
||||
);
|
||||
c.Emit(OpCodes.Stloc, relativeMapTypeIndex);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria.Localization;
|
||||
using Terraria.Map;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Walls
|
||||
{
|
||||
/// <summary>
|
||||
/// Walls that implement this interface may be revealed on the map through
|
||||
/// water. This allows them to show on the map despite always being
|
||||
/// submerged.
|
||||
/// </summary>
|
||||
public interface IVisibleThroughWater : ILoadable
|
||||
{
|
||||
int WaterMapEntry { get; set; }
|
||||
}
|
||||
|
||||
internal static class VisibleThroughWater
|
||||
{
|
||||
private sealed class VisibleThroughWaterSystem : ModSystem
|
||||
{
|
||||
public override void AddRecipes()
|
||||
{
|
||||
InitializeWaterMapEntryLookups();
|
||||
}
|
||||
}
|
||||
|
||||
public const float WaterTransparency = 0.5f;
|
||||
public static readonly Color WaterColor = new Color(9, 61, 191);
|
||||
|
||||
public static void AddMapEntryWithWaterVisibility(this IVisibleThroughWater visibleThroughWater, Color baseColor, LocalizedText text = null)
|
||||
{
|
||||
AssertIsWall(visibleThroughWater, out var wall);
|
||||
wall.AddMapEntry(baseColor, text);
|
||||
wall.AddMapEntry(Color.Lerp(baseColor, WaterColor, WaterTransparency), text);
|
||||
}
|
||||
|
||||
public static void InitializeWaterMapEntryLookups()
|
||||
{
|
||||
foreach (var visibleThroughWater in CalamityMod.Instance.GetContent<IVisibleThroughWater>())
|
||||
{
|
||||
AssertIsWall(visibleThroughWater, out var wall);
|
||||
visibleThroughWater.WaterMapEntry = MapHelper.wallLookup[wall.Type] + 1;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerStepThrough]
|
||||
[StackTraceHidden]
|
||||
private static void AssertIsWall(IVisibleThroughWater visibleThroughWater, out ModWall wall)
|
||||
{
|
||||
if (visibleThroughWater is not ModWall theWall)
|
||||
throw new InvalidCastException($"{nameof(IVisibleThroughWater)} is implemented on type {visibleThroughWater.GetType().FullName}; said type should inherit from {nameof(ModWall)}");
|
||||
|
||||
wall = theWall;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,14 @@
|
||||
using Terraria.ModLoader;
|
||||
namespace CalamityMod.Walls
|
||||
{
|
||||
public class NavystoneWall : ModWall
|
||||
public class NavystoneWall : ModWall, IVisibleThroughWater
|
||||
{
|
||||
int IVisibleThroughWater.WaterMapEntry { get; set; }
|
||||
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DustType = 96;
|
||||
AddMapEntry(new Color(16, 45, 48));
|
||||
this.AddMapEntryWithWaterVisibility(new Color(16, 45, 48));
|
||||
}
|
||||
|
||||
public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3;
|
||||
|
||||
@@ -4,13 +4,15 @@ using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Walls
|
||||
{
|
||||
public class NavystoneWallSafe : ModWall
|
||||
public class NavystoneWallSafe : ModWall, IVisibleThroughWater
|
||||
{
|
||||
int IVisibleThroughWater.WaterMapEntry { get; set; }
|
||||
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
Main.wallHouse[Type] = true;
|
||||
DustType = 96;
|
||||
AddMapEntry(new Color(0, 50, 50));
|
||||
this.AddMapEntryWithWaterVisibility(new Color(0, 50, 50));
|
||||
}
|
||||
|
||||
public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3;
|
||||
|
||||
@@ -5,13 +5,15 @@ using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Walls
|
||||
{
|
||||
public class SmoothNavystoneWall : ModWall
|
||||
public class SmoothNavystoneWall : ModWall, IVisibleThroughWater
|
||||
{
|
||||
int IVisibleThroughWater.WaterMapEntry { get; set; }
|
||||
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
Main.wallHouse[Type] = true;
|
||||
|
||||
AddMapEntry(new Color(27, 35, 36));
|
||||
this.AddMapEntryWithWaterVisibility(new Color(27, 35, 36));
|
||||
}
|
||||
|
||||
public override bool CreateDust(int i, int j, ref int type)
|
||||
|
||||
Reference in new issue
Block a user