-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
318 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using MagicStorageExtra; | ||
using MagicStorageExtra.Components; | ||
using System; | ||
using System.Collections.Generic; | ||
using Terraria; | ||
using Terraria.DataStructures; | ||
|
||
namespace MechTransfer.ContainerAdapters | ||
{ | ||
internal class MagicStorageExtraInterfaceAdapter | ||
{ | ||
private TEStorageHeart FindHeart(int x, int 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; | ||
|
||
TEStorageHeart heart = ((TEStorageCenter)TileEntity.ByPosition[center]).GetHeart(); | ||
|
||
return heart; | ||
} | ||
|
||
private void HandleStorageItemChange(TEStorageHeart heart) | ||
{ | ||
if (Main.netMode == 2) | ||
{ | ||
NetHelper.SendRefreshNetworkItems(heart.ID); | ||
} | ||
else if (Main.netMode == 0) | ||
{ | ||
StorageGUI.RefreshItems(); | ||
} | ||
} | ||
|
||
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) | ||
{ | ||
HandleStorageItemChange(targetHeart); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
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); | ||
} | ||
} | ||
|
||
public void TakeItem(int x, int y, object slot, int amount) | ||
{ | ||
TEStorageHeart targetHeart = FindHeart(x, y); | ||
if (targetHeart == null) | ||
return; | ||
|
||
Item toWithdraw = ((Item)slot).Clone(); | ||
toWithdraw.stack = amount; | ||
|
||
targetHeart.TryWithdraw(toWithdraw, false); | ||
|
||
HandleStorageItemChange(targetHeart); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.