diff --git a/Config.cs b/Config.cs index e04b3ca..2f87c6e 100644 --- a/Config.cs +++ b/Config.cs @@ -5,6 +5,7 @@ using System.Runtime.Serialization; using Terraria; using Terraria.ID; +using Terraria.ModLoader; using Terraria.ModLoader.Config; namespace ItemMagnetPlus @@ -48,6 +49,11 @@ class Config : ModConfig [DefaultValue(false)] public bool Coins; + [Label("[i:3457] Pickup Effect Items")] + [Tooltip("Toggle if items like nebula armor boosters or modded items like the music notes from Thorium should be picked up by the magnet")] + [DefaultValue(true)] + public bool PickupEffect; + //------------- [Header("Custom Item Filter")] @@ -70,6 +76,7 @@ class Config : ModConfig //------------- [Header("General")] + [Label("Buff")] [Tooltip("Toggle if having the magnet active gives you a buff")] [DefaultValue(true)] @@ -83,7 +90,6 @@ class Config : ModConfig //------------- [Header("Magnet Behavior (Only works ingame)")] - //[Label("Range")] [Tooltip("Base magnet radius in tiles")] [Slider] [SliderColor(255, 255, 50)] @@ -92,7 +98,6 @@ class Config : ModConfig [DefaultValue(10)] public int Range; - //[Label("Velocity")] [Tooltip("Speed at which items get pulled towards you")] [Slider] [SliderColor(255, 255, 50)] @@ -100,7 +105,6 @@ class Config : ModConfig [DefaultValue(8)] public int Velocity; - //[Label("Acceleration")] [Tooltip("How fast an item reaches its peak speed")] [Slider] [SliderColor(255, 255, 50)] @@ -108,7 +112,6 @@ class Config : ModConfig [DefaultValue(8)] public int Acceleration; - //[Label("Acceleration")] [Tooltip("Scaling Mode")] [DrawTicks] [SliderColor(255, 255, 50)] @@ -118,6 +121,7 @@ class Config : ModConfig //------------- [Header("Resulting Magnet stats")] + [Label("Resulting Max Range")] [Slider] [SliderColor(50, 255, 50)] @@ -314,37 +318,41 @@ static class ConfigWrapper public static int[] CoinTypes; - private static bool CheckIfItemIsInPresetBlacklist(int type) + private static bool CheckIfItemIsInPresetBlacklist(Item item, Player player) { - if (Instance.Hearts && Array.BinarySearch(HeartTypes, type) > -1) + if (Instance.Hearts && Array.BinarySearch(HeartTypes, item.type) > -1) + { + return true; + } + if (Instance.ManaStars && Array.BinarySearch(ManaStarTypes, item.type) > -1) { return true; } - if (Instance.ManaStars && Array.BinarySearch(ManaStarTypes, type) > -1) + if (Instance.Coins && Array.BinarySearch(CoinTypes, item.type) > -1) { return true; } - if (Instance.Coins && Array.BinarySearch(CoinTypes, type) > -1) + if (Instance.PickupEffect && (ItemID.Sets.NebulaPickup[item.type] || ItemLoader.ItemSpace(item, player))) { return true; } return false; } - public static bool CanBePulled(int type) + public static bool CanBePulled(Item item, Player player) { - bool can = !CheckIfItemIsInPresetBlacklist(type); - ItemDefinition item = new ItemDefinition(type); + bool can = !CheckIfItemIsInPresetBlacklist(item, player); + ItemDefinition itemDef = new ItemDefinition(item.type); if (Instance.ListMode == Config.BlacklistName) { - if (Instance.Blacklist.Contains(item)) + if (Instance.Blacklist.Contains(itemDef)) { can = false; } } else if (Instance.ListMode == Config.WhitelistName) { - can = Instance.Whitelist.Contains(item); + can = Instance.Whitelist.Contains(itemDef); } return can; } diff --git a/ItemMagnetPlusPlayer.cs b/ItemMagnetPlusPlayer.cs index 8088457..f789159 100644 --- a/ItemMagnetPlusPlayer.cs +++ b/ItemMagnetPlusPlayer.cs @@ -306,7 +306,7 @@ public override void PreUpdate() Rectangle rect = new Rectangle((int)player.position.X - grabRadius, (int)player.position.Y - fullhdgrabRadius, player.width + grabRadius * 2, player.height + fullhdgrabRadius * 2); if (canGrabNetMode && rect.Intersects(item.getRect())) { - if (ConfigWrapper.CanBePulled(item.type)) + if (ConfigWrapper.CanBePulled(item, player)) { grabbedItems++; //so it can go through walls @@ -344,6 +344,26 @@ public override void PreUpdate() } } + //remove dust from grabbed coins while magnet is enabled + //credit to hamstar (Uncluttered Projectiles) + if (Main.myPlayer == player.whoAmI && !Config.Instance.Coins) + { + Dust dust; + for (int i = 0; i < Main.maxDustToDraw; i++) + { + dust = Main.dust[i]; + if (dust == null || !dust.active) continue; + + //item type 71 to 74: + //int type = 244 + item.type - 71; + //-> 244 to 247 + if (dust.type == 244 || dust.type == 245 || dust.type == 246 || dust.type == 247) + { + Main.dust[i] = new Dust(); + } + } + } + //if (Main.time % 90 == 0) //{ // if (Main.netMode == NetmodeID.Server) diff --git a/Items/ItemMagnet.cs b/Items/ItemMagnet.cs index 5b6daa2..d3692fa 100644 --- a/Items/ItemMagnet.cs +++ b/Items/ItemMagnet.cs @@ -66,7 +66,7 @@ public override bool AltFunctionUse(Player player) public static Dust QuickDust(Vector2 pos, Color color) { int type = 1; - Dust dust = Dust.NewDustDirect(pos, 4, 4, type, 0f, 0f, 120, color, 2f); + Dust dust = Dust.NewDustDirect(pos, 4, 4, type, 0f, 0f, 120, color, 1f); dust.position = pos; dust.velocity = Vector2.Zero; dust.fadeIn = 3f; @@ -138,7 +138,7 @@ public override bool UseItem(Player player) { mPlayer.ActivateMagnet(player); - Main.PlaySound(SoundID.MaxMana, player.position, 1); + Main.PlaySound(SoundID.MaxMana, player.Center, 1); mPlayer.magnetActive = 1; mPlayer.UpdateMagnetValues(mPlayer.magnetMinGrabRadius); radius = mPlayer.magnetGrabRadius; @@ -164,7 +164,7 @@ public override bool UseItem(Player player) if (radius > mPlayer.magnetMaxGrabRadius) { CombatText.NewText(player.getRect(), CombatText.DamagedFriendly, "magnet off"); - Main.PlaySound(SoundID.MaxMana, player.position, 1); + Main.PlaySound(SoundID.MaxMana, player.Center, 1); mPlayer.DeactivateMagnet(player); return true; } diff --git a/README.md b/README.md index f0bce86..7272157 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ItemMagnetPlus adds a single item called "Item Magnet" that does the obvious thi ### Adds: Item Magnet (and corresponding buff) that -* can be crafted with simple materials +* can be crafted with simple materials (Iron/Lead) * works while in your inventory * can be toggled on and off * has adjustable range and item succ speed @@ -48,7 +48,7 @@ Ends with: (killing Moonlord) ### About the config: * Buff decides if it gives you a corresponding buff icon to show the status of the magnet * Held decides if the magnet works only when held -* Filter function: Presets (hearts, mana stars, coins), blacklist/whitelist +* Filter function: Presets (hearts, mana stars, coins, pickup effects), blacklist/whitelist * Magnet stats are limited to sensible values (Range only goes up to about three screens in any direction) * If you increase Vel or Acc too much from those recommended above, items might get "stuck" on you until you deactivate it again * Beware of lag when increasing these values, especially range @@ -57,6 +57,8 @@ Ends with: (killing Moonlord) ### Changelog: + v1.0.1: Added filter for nebula pickup and modded items that have pickup effects (Thorium music notes for example), grabbed coins don't overproduce sparkles + v1.0.0.1 + 2: Fix velocity cap, other stat caps v1.0: updated to tml 0.11.4. Fixed multiplayer, updated to ingame config, fixed coin filter, added custom black/whitelist diff --git a/build.txt b/build.txt index caf2dea..ac10399 100644 --- a/build.txt +++ b/build.txt @@ -1,5 +1,5 @@ author = direwolf420 -version = 1.0.0.2 +version = 1.0.1 displayName = ItemMagnetPlus homepage = https://forums.terraria.org/index.php?threads/itemmagnetplus-customizable-item-magnet.74425/ hideCode = true diff --git a/description.txt b/description.txt index f42bc58..d056288 100644 --- a/description.txt +++ b/description.txt @@ -2,7 +2,7 @@ ItemMagnetPlus adds a single item called "Item Magnet" that does the obvious thi Adds: Item Magnet (and corresponding buff) that -* can be crafted with simple materials +* can be crafted with simple materials (Iron/Lead) * works while in your inventory * can be toggled on and off * has adjustable range and item succ speed @@ -38,7 +38,7 @@ Progression: (default config) About the config: * Buff decides if it gives you a corresponding buff icon to show the status of the magnet * Held decides if the magnet works only when held -* Filter function: Presets (hearts, mana stars, coins), blacklist/whitelist +* Filter function: Presets (hearts, mana stars, coins, pickup effects), blacklist/whitelist * Magnet stats are limited to sensible values (Range only goes up to about three screens in any direction) * If you increase Vel or Acc too much from those recommended above, items might get "stuck" on you until you deactivate it again * Beware of lag when increasing these values, especially range @@ -47,6 +47,8 @@ Progression: (default config) Changelog: + v1.0.1: Added filter for nebula pickup and modded items that have pickup effects (Thorium music notes for example), grabbed coins don't overproduce sparkles + v1.0.0.1 + 2: Fix velocity cap, other stat caps v1.0: tml 0.11.4 update. Fixed multiplayer, updated to ingame config, fixed coin filter, added custom black/whitelist