Skip to content

Commit

Permalink
added pickup effect filter, remove dusts on coins when grabbed
Browse files Browse the repository at this point in the history
  • Loading branch information
direwolf420 committed Oct 4, 2019
1 parent b0c6f66 commit 36d05f2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 22 deletions.
34 changes: 21 additions & 13 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.Serialization;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Config;

namespace ItemMagnetPlus
Expand Down Expand Up @@ -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")]

Expand All @@ -70,6 +76,7 @@ class Config : ModConfig

//-------------
[Header("General")]

[Label("Buff")]
[Tooltip("Toggle if having the magnet active gives you a buff")]
[DefaultValue(true)]
Expand All @@ -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)]
Expand All @@ -92,23 +98,20 @@ class Config : ModConfig
[DefaultValue(10)]
public int Range;

//[Label("Velocity")]
[Tooltip("Speed at which items get pulled towards you")]
[Slider]
[SliderColor(255, 255, 50)]
[Range(VelocityMin, VelocityMax)]
[DefaultValue(8)]
public int Velocity;

//[Label("Acceleration")]
[Tooltip("How fast an item reaches its peak speed")]
[Slider]
[SliderColor(255, 255, 50)]
[Range(AccelerationMin, AccelerationMax)]
[DefaultValue(8)]
public int Acceleration;

//[Label("Acceleration")]
[Tooltip("Scaling Mode")]
[DrawTicks]
[SliderColor(255, 255, 50)]
Expand All @@ -118,6 +121,7 @@ class Config : ModConfig

//-------------
[Header("Resulting Magnet stats")]

[Label("Resulting Max Range")]
[Slider]
[SliderColor(50, 255, 50)]
Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 21 additions & 1 deletion ItemMagnetPlusPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Items/ItemMagnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 36d05f2

Please sign in to comment.