Skip to content

Commit

Permalink
add activate on enter config
Browse files Browse the repository at this point in the history
  • Loading branch information
direwolf420 committed May 31, 2020
1 parent 7c7c5f8 commit 906cd99
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 45 deletions.
5 changes: 5 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class Config : ModConfig
[DefaultValue(false)]
public bool Held;

[Label("Activate on enter")]
[Tooltip("Toggle if magnet should be automatically activated when entering the world")]
[DefaultValue(true)]
public bool OnEnter;

//-------------
[Header("Magnet Behavior (Only works ingame)")]

Expand Down
3 changes: 3 additions & 0 deletions ItemMagnetPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<Target Name="BuildMod" AfterTargets="Build">
<Exec Command="&quot;$(tMLBuildServerPath)&quot; -build $(ProjectDir) -eac $(TargetPath) -define $(DefineConstants) -unsafe $(AllowUnsafeBlocks)" />
</Target>
<ItemGroup>
<None Remove="**\*.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="tModLoader.CodeAssist" Version="0.1.*" />
</ItemGroup>
Expand Down
31 changes: 28 additions & 3 deletions ItemMagnetPlusPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override void SyncPlayer(int toWho, int fromWho, bool newPlayer)
}
}

public void ActivateMagnet(Player player)
public void ActivateMagnet()
{
if (!Config.Instance.Buff)
{
Expand Down Expand Up @@ -161,7 +161,7 @@ public override void OnRespawn(Player player)
if (hadMagnetActive)
{
hadMagnetActive = false;
ActivateMagnet(player);
ActivateMagnet();
}
}

Expand Down Expand Up @@ -280,8 +280,33 @@ public void UpdateMagnetValues(int currentRadius)
}
}

private bool entered = false;

private bool activated = false;

private void DoEnter()
{
if (!entered)
{
entered = true;
}
else
{
if (!activated)
{
activated = true;
if (Config.Instance.OnEnter && player.HasItem(ModContent.ItemType<ItemMagnet>()))
{
ActivateMagnet();
}
}
}
}

public override void PreUpdate()
{
DoEnter();

//doing this only client side causes a small "lag" when the item first gets dragged toward the player
currentlyActive = Config.Instance.Buff ? player.HasBuff(ModContent.BuffType<ItemMagnetBuff>()) : magnetActive == 1;
bool whileHeld = Config.Instance.Held ? player.HeldItem.type == ModContent.ItemType<ItemMagnet>() : true;
Expand All @@ -295,7 +320,7 @@ public override void PreUpdate()

int grabbedItems = 0;

for (int j = 0; j < 400; j++)
for (int j = 0; j < Main.maxItems; j++)
{
Item item = Main.item[j];
if (item.active && item.noGrabDelay == 0 && !ItemLoader.GrabStyle(item, player) && ItemLoader.CanPickup(item, player) /*&& Main.player[item.owner].ItemSpace(item)*/)
Expand Down
2 changes: 1 addition & 1 deletion Items/ItemMagnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public override bool UseItem(Player player)

if (mPlayer.magnetActive == 0)
{
mPlayer.ActivateMagnet(player);
mPlayer.ActivateMagnet();

Main.PlaySound(SoundID.MaxMana, player.Center, 1);
mPlayer.magnetActive = 1;
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Ends with: (killing Moonlord)

### Changelog:

v1.0.2: Added "Activate on enter" config that allows a magnet in your inventory to automatically activate itself when entering a world

v1.0.1.3: tml 0.11.7 update. Cleaner range indicator, now also shows when mouseovering the buff icon

v1.0.1.2: tml 0.11.6 update. Fixed unintended config saving in multiplayer, fixed preset filter being inverted
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.1.3
version = 1.0.2
displayName = ItemMagnetPlus
homepage = https://forums.terraria.org/index.php?threads/itemmagnetplus-customizable-item-magnet.74425/
hideCode = true
Expand Down
43 changes: 3 additions & 40 deletions description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Progression: (default config)
* Contrary to other tModLoader configs, the preset filters have inverted logic on them (filled black dot means "on")
* 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
* Activate on enter decides if magnet should be automatically activated when entering the world
* 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
Expand All @@ -48,44 +49,6 @@ Progression: (default config)

Changelog:

v1.0.1.3: tml 0.11.7 update. Cleaner range indicator, now also shows when mouseovering the buff icon
v1.0.2: Added "Activate on enter" config that allows a magnet in your inventory to automatically activate itself when entering a world

v1.0.1.2: tml 0.11.6 update. Fixed unintended config saving in multiplayer, fixed preset filter being inverted

v1.0.1.1: Fixed incompatibility with Jpans Bags of Holding, the "Pickup Effect Items" setting will be ignored with this mod enabled

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

v0.1.11: Added config flag to have the magnet work either from inside the inventory or only when held

v0.1.10: Scale spark rate on pulled items, fixed some desync bugs in MP, fixed grab bags being pulled in by all players

v0.1.9: Fixed desync bug with more than two players in MP

v0.1.8: Made config entirely server side now, the mod is stable in MP

v0.1.7: Made config entirely client side now

v0.1.6.2: Reverted hotfix

v0.1.6.1: Hotfix bug where items get deleted very rarely when opening crate-like things (now you won't attract items with a full inventory)

v0.1.6: Added persistency: Magnet now keeps its state when you respawn! (Also switched scale mode 0 and 2 around, check your config)

v0.1.5: Added new scale config mode: Keep all the buffs from killing bosses but don't shuffle through each range again upon activation

v0.1.4.1 + 2 + 3 + 4: Filter hotfix, fix stuck range when using magnet inside inventory, another filter hotfix

v0.1.4: Added blacklist "filter" to be able to filter hearts, mana stars and coins (for now)

v0.1.3: Added config flag "buff" to be able to decide if a buff should be applied while the magnet is active

v0.1.2: Added Buff- and Tooltip to show range, updated icons (Thanks to Harblesnargits!)

v0.1.1: Fixed incompatibility with Even More Modifiers, changed acceleration values (updating will set it back to default)

v0.1: Initial release
v1.0.1.3: tml 0.11.7 update. Cleaner range indicator, now also shows when mouseovering the buff icon

0 comments on commit 906cd99

Please sign in to comment.