diff --git a/Changes/TheKeyBehavior.cs b/Changes/TheKeyBehavior.cs new file mode 100644 index 0000000..b7b9e23 --- /dev/null +++ b/Changes/TheKeyBehavior.cs @@ -0,0 +1,47 @@ + +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Chat; +using Terraria.ID; +using Terraria.Localization; +using Terraria.ModLoader; +using YHTMod.Items; + +namespace YHTMod.Changes; + +public class TheKeyBehavior : GlobalTile { + + public override void RightClick(int i, int j, int type) { + + if (type != TileID.Containers) { + base.RightClick(i, j, type); + return; + } + + bool foundKey = false; + foreach (Item item in Main.LocalPlayer.inventory) { + if (item.type.Equals(ModContent.ItemType())) { + foundKey = true; + break; + } + } + ChatHelper.BroadcastChatMessage(NetworkText.FromLiteral(foundKey.ToString()), Color.White); + + if (!foundKey) { + return; + } + ChatHelper.BroadcastChatMessage(NetworkText.FromLiteral("Found key!"), Color.White); + + if (!Chest.IsLocked(i, j)) { + base.RightClick(i, j, type); + return; + } + + Chest.Unlock(i, j); + if (Main.netMode == NetmodeID.MultiplayerClient) + NetMessage.SendData(MessageID.Unlock, number: 1, number2: 1f, number3: i, number4: j); + + + } + +} \ No newline at end of file diff --git a/Items/TheKey.cs b/Items/TheKey.cs new file mode 100644 index 0000000..b3ccd68 --- /dev/null +++ b/Items/TheKey.cs @@ -0,0 +1,14 @@ +using Terraria.GameContent.Creative; +using Terraria.ModLoader; + +namespace YHTMod.Items; + +public class TheKey : ModItem { + + public override void SetStaticDefaults() { + DisplayName.SetDefault("The Key"); + Tooltip.SetDefault("Opens all locks."); + CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; + } + +} \ No newline at end of file diff --git a/Items/TheKey.png b/Items/TheKey.png new file mode 100644 index 0000000..357e8c8 Binary files /dev/null and b/Items/TheKey.png differ