Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
DRKV333 committed Jan 26, 2018
2 parents 3c0178e + 890d697 commit 324139b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
19 changes: 14 additions & 5 deletions ContainerAdapters/MagicStorageInterfaceAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ internal class MagicStorageInterfaceAdapter
{
private TEStorageHeart FindHeart(int x, int y)
{
Point16 center = TEStorageComponent.FindStorageCenter(new Point16(x, y));
Tile tile = Main.tile[x, y];

int originX = x - tile.frameX / 18;
int originY = y - tile.frameY / 18;

Point16 center = TEStorageComponent.FindStorageCenter(new Point16(originX, originY));
if (center.X == -1 && center.Y == -1)
return null;

Expand All @@ -32,16 +37,15 @@ private void HandleStorageItemChange(TEStorageHeart heart)
}
}

public void KickMe()
{
Main.LocalPlayer.GetModPlayer<StoragePlayer>().CloseStorage();
}

public bool InjectItem(int x, int y, Item item)
{
int oldstack = item.stack;

TEStorageHeart targetHeart = FindHeart(x, y);
if (targetHeart == null)
return false;

targetHeart.DepositItem(item);

if (oldstack != item.stack)
Expand All @@ -55,6 +59,9 @@ public bool InjectItem(int x, int y, Item item)
public IEnumerable<Tuple<Item, object>> EnumerateItems(int x, int y)
{
TEStorageHeart targetHeart = FindHeart(x, y);
if (targetHeart == null)
yield break;

foreach (var item in targetHeart.GetStoredItems())
{
yield return new Tuple<Item, object>(item, item.type);
Expand All @@ -64,6 +71,8 @@ public IEnumerable<Tuple<Item, object>> EnumerateItems(int x, int y)
public void TakeItem(int x, int y, object slot, int amount)
{
TEStorageHeart targetHeart = FindHeart(x, y);
if (targetHeart == null)
return;

Item toWithdraw = new Item();
toWithdraw.SetDefaults((int)slot);
Expand Down
1 change: 1 addition & 0 deletions Tiles/TransferOutletTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public bool Receive(TransferUtils agent, Point16 location, Item item)
int dropTarget = Item.NewItem(location.X * 16, location.Y * 16, 16, 16, item.type, item.stack, false, item.prefix);
Main.item[dropTarget].velocity = Vector2.Zero;
item.stack = 0;
mod.GetModWorld<MechTransferWorld>().TripWireDelayed(location.X, location.Y, 1, 1);
return true;
}
}
Expand Down
27 changes: 21 additions & 6 deletions TransferUtils.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using MechTransfer.ContainerAdapters;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace MechTransfer
{
Expand All @@ -23,15 +26,27 @@ public int StartTransfer(int startX, int startY, Item item)

int olstack = item.stack;
Item clone = item.Clone();
SearchForTarget(startX, startY, clone);

running--;

if (running == 0)
try
{
TargetTriggered.Clear();
SearchForTarget(startX, startY, clone);
}

catch(Exception e)
{
Main.NewText("An exception has occurred at MechTransfer.TransferUtils.SearchForTarget (Please look at the log in Documents/My Games/Terraria/ModLoader/Logs)", Color.Red);
ErrorLogger.Log("\nMechTransfer has logged an exception:");
ErrorLogger.Log(e.ToString());
ErrorLogger.Log("Please report it on the MechTransfer forum page.\n");
}
finally
{
running--;
if (running == 0)
{
TargetTriggered.Clear();
}
}

return olstack - clone.stack;
}

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 = DRKV
version = 1.5
version = 1.5.1
displayName = MechTransfer
includePDB = false
weakReferences = [email protected]
Expand Down
6 changes: 5 additions & 1 deletion description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ v1.5
- New tool-tip
- Added Magic Storage Interface
- Added blacklist filter
- Added Stack extractor
- Added Stack extractor

v1.5.1
- Fixed outlet wire output
- Added error handling

0 comments on commit 324139b

Please sign in to comment.