Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
DRKV333 committed Dec 20, 2021
2 parents 59e72f1 + 5975cd5 commit 9129140
Show file tree
Hide file tree
Showing 41 changed files with 318 additions and 242 deletions.
84 changes: 84 additions & 0 deletions ContainerAdapters/MagicStorageExtraInterfaceAdapter.cs
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);
}
}
}
4 changes: 2 additions & 2 deletions ContainerAdapters/PlayerInterfaceAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private int FindInside(int x, int y)

public IEnumerable<Tuple<Item, object>> EnumerateItems(int x, int y)
{
Point16 origin = mod.GetTile<PlayerInterfaceTile>().GetOrigin(x, y);
Point16 origin = ModContent.GetInstance<PlayerInterfaceTile>().GetOrigin(x, y);
int p = FindInside(origin.X, origin.Y);

if (p == -1)
Expand Down Expand Up @@ -108,7 +108,7 @@ public void TakeItem(int x, int y, object slot, int amount)
//I should be handling achievements here, like in ItemSlot.SwapEquip, but meh... :/
public bool InjectItem(int x, int y, Item item)
{
Point16 origin = mod.GetTile<PlayerInterfaceTile>().GetOrigin(x, y);
Point16 origin = ModContent.GetInstance<PlayerInterfaceTile>().GetOrigin(x, y);
int p = FindInside(origin.X, origin.Y);

if (p == -1)
Expand Down
12 changes: 7 additions & 5 deletions Content/content.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
{ "p" : "OmniTurretTile.png", "t" : "Tiles" },
{ "p" : "PlayerInterfaceTile.png", "t" : "Tiles" },
{ "p" : "MagicStorageInterfaceTile.png", "t" : "Tiles" },
{ "p" : "MagicStorageInterfaceTile.png", "t" : "Tiles/MagicStorageExtraInterfaceTile.png" },
{ "p" : "TransferAssemblerTile.png", "t" : "Tiles" },
{ "p" : "LivingHellstoneTile.png", "t" : "Tiles" }
]
Expand Down Expand Up @@ -72,11 +73,12 @@
"action" : ">bettergridder(i,i.getpixel((16,0)))",
"files" :
[
{ "p" : ">crelayitem:TransferRelayTile.png", "t" : "Items/TransferRelayItem.png" },
{ "p" : ">stiles:MagicStorageInterfaceTile.png", "t" : "Items/MagicStorageInterfaceItem.png" },
{ "p" : ">cturretitem1:OmniTurretTile.png", "t" : "Items/OmniTurretItem.png" },
{ "p" : ">cturretitem2:OmniTurretTile.png", "t" : "Items/SuperOmniTurretItem.png" },
{ "p" : ">cturretitem3:OmniTurretTile.png", "t" : "Items/MatterProjectorItem.png" }
{ "p" : ">crelayitem:TransferRelayTile.png", "t" : "Items/TransferRelayItem.png" },
{ "p" : ">stiles:MagicStorageInterfaceTile.png", "t" : "Items/MagicStorageInterfaceItem.png" },
{ "p" : ">stiles:MagicStorageExtraInterfaceTile.png", "t" : "Items/MagicStorageExtraInterfaceItem.png" },
{ "p" : ">cturretitem1:OmniTurretTile.png", "t" : "Items/OmniTurretItem.png" },
{ "p" : ">cturretitem2:OmniTurretTile.png", "t" : "Items/SuperOmniTurretItem.png" },
{ "p" : ">cturretitem3:OmniTurretTile.png", "t" : "Items/MatterProjectorItem.png" }

]
},
Expand Down
2 changes: 1 addition & 1 deletion Items/ItemFilterItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override void AddRecipes()
//Needed to stop ModLoader from assigning a default display name
public override void AutoStaticDefaults()
{
Main.itemTexture[item.type] = ModLoader.GetTexture(Texture);
Main.itemTexture[item.type] = ModContent.GetTexture(Texture);
}
}
}
Binary file added Items/MagicStorageExtraInterfaceItem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Items/SimplePrototypeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override bool Autoload(ref string name)
//Needed to stop ModLoader from assigning a default display name
public override void AutoStaticDefaults()
{
Main.itemTexture[item.type] = ModLoader.GetTexture(Texture);
Main.itemTexture[item.type] = ModContent.GetTexture(Texture);
}

public static SimplePrototypeItem MakePlaceable(Mod mod, string name, int placeType, int width = 16, int height = 16, int placeStyle = 0, int value = 50000)
Expand Down
2 changes: 1 addition & 1 deletion LivingHellstoneGlobalItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override void Update(Item item, ref float gravity, ref float maxFallSpeed
foreach (var p in Collision.GetEntityEdgeTiles(item))
{
if (p.X > 0 && p.X < Main.maxTilesX && p.Y > 0 && p.Y < Main.maxTilesY &&
Main.tile[p.X, p.Y].active() && Main.tile[p.X, p.Y].type == mod.TileType<LivingHellstoneTile>())
Main.tile[p.X, p.Y].active() && Main.tile[p.X, p.Y].type == ModContent.TileType<LivingHellstoneTile>())
{
if (++burnTime > 0)
{
Expand Down
3 changes: 3 additions & 0 deletions Localization/en-US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ ItemTooltip.TransferOutletItem = Drops item
ItemName.MagicStorageInterfaceItem = Magic Storage Interface
ItemTooltip.MagicStorageInterfaceItem = Allows you to inject and extract items from storage systems

ItemName.MagicStorageExtraInterfaceItem = Magic Storage Extra Interface
ItemTooltip.MagicStorageExtraInterfaceItem = Allows you to inject and extract items from your storage systems

ItemName.PlayerInterfaceItem = Player Interface
ItemTooltip.PlayerInterfaceItem = Allows you to inject and extract items from a players inventory

Expand Down
13 changes: 13 additions & 0 deletions Localization/ru-RU.lang
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
UI.Hover.NotSet = Не задано
UI.Hover.Generic = Фильтр:

ItemName.PneumaticActuatorItem = Пневматический привод
ItemTooltip.PneumaticActuatorItem = Используется в крафте устройств для перемещения предметов

Expand Down Expand Up @@ -25,8 +28,10 @@ ItemTooltip.TransferInletItem = Собирает упавшие вещи

ItemName.TransferFilterItem = Транспортный фильтр (белый список)
ItemTooltip.TransferFilterItem = Поставьте в транспортировочную линию для фильтрации предметов\nПКМ предметом в руке для настройки фильтра
UI.Hover.TransferFilterItem = Предметы разрешены:
ItemName.InverseTransferFilterItem = Транспортный фильтр (чёрный список)
ItemTooltip.InverseTransferFilterItem = Поставьте в транспортировочную линию для фильтрации предметов\nПКМ предметом в руке для настройки фильтра
UI.Hover.InverseTransferFilterItem = Предметы блокируются:

ItemName.TransferGateItem = Транспортный люк
ItemTooltip.TransferGateItem = Поставьте в транспортировочную линию для перекрытия перемещения претметов
Expand Down Expand Up @@ -79,8 +84,16 @@ ItemName.MoneyFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Мо
ItemName.BagFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Мешки с сокровищами)
ItemName.ToolFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Инструмент)
ItemName.WeaponFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Оружие)
ItemName.MeleeFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Ближний бой)
ItemName.MagicFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Магическое оружие)
ItemName.RangedFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Дистанционное оружие)
ItemName.SummonFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Оружие призывателя)
ItemName.ThrownFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Оружие метателя)
ItemName.ConsumableFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Расходуется)
ItemName.MaterialFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Материал)
ItemName.PotionFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Зелье)
ItemName.TileFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Блок)
ItemName.WallFilterItem = {$Mods.MechTransfer.Common.ItemName.FilterItem} (Стена)

ItemName.LivingHellstoneItem = Живой адский камень
ItemTooltip.LivingHellstoneItem = Уничтожает любой предмет при контакте, независимо от редкости
59 changes: 40 additions & 19 deletions MechTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MechTransfer : Mod
private List<Action> simpleTileAddRecipequeue;

private Mod modMagicStorage = null;
private Mod modMagicStorageExtra = null;

public MechTransfer()
{
Expand All @@ -47,46 +48,46 @@ public override object Call(params object[] args)
{
if (args.Length != 5)
{
ErrorLogger.Log(callErorPrefix + "Invalid number of arguments at " + registerAdapter);
this.Logger.Error(callErorPrefix + "Invalid number of arguments at " + registerAdapter);
return null;
}

ContainerAdapterDefinition definition = new ContainerAdapterDefinition();

if (!(args[1] is InjectItemDelegate))
{
ErrorLogger.Log(callErorPrefix + "Invalid argument 2 InjectItem at " + registerAdapter);
this.Logger.Error(callErorPrefix + "Invalid argument 2 InjectItem at " + registerAdapter);
return null;
}

definition.InjectItem = args[1] as InjectItemDelegate;

if (!(args[2] is EnumerateItemsDelegate))
{
ErrorLogger.Log(callErorPrefix + "Invalid argument 3 EnumerateItems at " + registerAdapter);
this.Logger.Error(callErorPrefix + "Invalid argument 3 EnumerateItems at " + registerAdapter);
return null;
}

definition.EnumerateItems = args[2] as EnumerateItemsDelegate;

if (!(args[3] is TakeItemDelegate))
{
ErrorLogger.Log(callErorPrefix + "Invalid argument 4 TakeItem at " + registerAdapter);
this.Logger.Error(callErorPrefix + "Invalid argument 4 TakeItem at " + registerAdapter);
return null;
}

definition.TakeItem = args[3] as TakeItemDelegate;

if (!(args[4] is int[]))
{
ErrorLogger.Log(callErorPrefix + "Invalid argument 5 TileType at " + registerAdapter);
this.Logger.Error(callErorPrefix + "Invalid argument 5 TileType at " + registerAdapter);
return null;
}

foreach (var type in (int[])args[4])
{
if (!GetModWorld<TransferAgent>().ContainerAdapters.ContainsKey(type))
GetModWorld<TransferAgent>().ContainerAdapters.Add(type, definition);
if (!ModContent.GetInstance<TransferAgent>().ContainerAdapters.ContainsKey(type))
ModContent.GetInstance<TransferAgent>().ContainerAdapters.Add(type, definition);
}
return definition;
}
Expand Down Expand Up @@ -125,25 +126,25 @@ public override object Call(params object[] args)

if (!(args[2] is int[]))
{
ErrorLogger.Log(callErorPrefix + "Invalid argument 5 TileType at " + registerAdapterReflection);
this.Logger.Error(callErorPrefix + "Invalid argument 5 TileType at " + registerAdapterReflection);
return null;
}

foreach (var t in (int[])args[2])
{
if (!GetModWorld<TransferAgent>().ContainerAdapters.ContainsKey(t))
GetModWorld<TransferAgent>().ContainerAdapters.Add(t, definition);
if (!ModContent.GetInstance<TransferAgent>().ContainerAdapters.ContainsKey(t))
ModContent.GetInstance<TransferAgent>().ContainerAdapters.Add(t, definition);
}
return definition;
}
catch (Exception e)
{
ErrorLogger.Log(callErorPrefix + "An exception has occurred while loading adapter at " + registerAdapterReflection);
ErrorLogger.Log(e.Message);
this.Logger.Error(callErorPrefix + "An exception has occurred while loading adapter at " + registerAdapterReflection);
this.Logger.Error(e.Message);
return null;
}
}
ErrorLogger.Log(callErorPrefix + "Invalid command");
this.Logger.Error(callErorPrefix + "Invalid command");
return null;
}

Expand All @@ -155,6 +156,7 @@ public override void HandlePacket(BinaryReader reader, int whoAmI)
public override void Load()
{
modMagicStorage = ModLoader.GetMod("MagicStorage");
modMagicStorageExtra = ModLoader.GetMod("MagicStorageExtra");

Assembly asm = Assembly.GetExecutingAssembly();
simpleTileAddRecipequeue = new List<Action>();
Expand Down Expand Up @@ -285,21 +287,28 @@ private void LoadAdapters()

//Omni turret
OmniTurretAdapter omniTurretAdapter = new OmniTurretAdapter(this);
Call(registerAdapterReflection, omniTurretAdapter, new int[] { TileType<OmniTurretTile>() });
Call(registerAdapterReflection, omniTurretAdapter, new int[] { ModContent.TileType<OmniTurretTile>() });

//Extractinator
ExtractinatorAdapter extractinatorAdapter = new ExtractinatorAdapter();
Call(registerAdapterReflection, extractinatorAdapter, new int[] { TileID.Extractinator });

//Player interface
PlayerInterfaceAdapter playerInterfaceAdapter = new PlayerInterfaceAdapter(this);
Call(registerAdapterReflection, playerInterfaceAdapter, new int[] { TileType<PlayerInterfaceTile>() });
Call(registerAdapterReflection, playerInterfaceAdapter, new int[] { ModContent.TileType<PlayerInterfaceTile>() });

if (modMagicStorage != null)
{
//Magic storage interface
MagicStorageInterfaceAdapter magicStorageInterfaceAdapter = new MagicStorageInterfaceAdapter();
Call(registerAdapterReflection, magicStorageInterfaceAdapter, new int[] { TileType<MagicStorageInterfaceTile>() });
Call(registerAdapterReflection, magicStorageInterfaceAdapter, new int[] { ModContent.TileType<MagicStorageInterfaceTile>() });
}

if (modMagicStorageExtra != null)
{
//Magic storage extra interface
MagicStorageExtraInterfaceAdapter magicStorageExtraInterfaceAdapter = new MagicStorageExtraInterfaceAdapter();
Call(registerAdapterReflection, magicStorageExtraInterfaceAdapter, new int[] { ModContent.TileType<MagicStorageExtraInterfaceTile>() });
}
}

Expand Down Expand Up @@ -332,12 +341,24 @@ public override void AddRecipes()
ModRecipe r = new ModRecipe(this);
r.AddIngredient(modMagicStorage.ItemType("StorageComponent"));
r.AddRecipeGroup("MagicStorage:AnyDiamond", 1);
r.AddIngredient(ItemType<PneumaticActuatorItem>(), 1);
r.AddIngredient(ModContent.ItemType<PneumaticActuatorItem>(), 1);
r.AddTile(TileID.WorkBenches);
r.SetResult(ItemType("MagicStorageInterfaceItem"));
r.AddRecipe();
}

if (modMagicStorageExtra != null)
{
//Magic storage extra interface
ModRecipe r = new ModRecipe(this);
r.AddIngredient(modMagicStorageExtra.ItemType("StorageComponent"));
r.AddRecipeGroup("MagicStorageExtra:AnyDiamond", 1);
r.AddIngredient(ModContent.ItemType<PneumaticActuatorItem>(), 1);
r.AddTile(TileID.WorkBenches);
r.SetResult(ItemType("MagicStorageExtraInterfaceItem"));
r.AddRecipe();
}

LoadChestAdapters();
}

Expand All @@ -356,13 +377,13 @@ public static class ModExtensions
{
public static ModItem GetPlaceItem<T>(this Mod mod) where T : SimplePlaceableTile
{
SimplePlaceableTile tile = mod.GetTile<T>();
SimplePlaceableTile tile = ModContent.GetInstance<T>();
return tile.PlaceItem;
}

public static ModItem GetPlaceItem<T>(this Mod mod, int kind) where T : SimpleTileObject
{
SimpleTileObject tile = mod.GetTile<T>();
SimpleTileObject tile = ModContent.GetInstance<T>();
return tile.GetPlaceItem(kind);
}

Expand Down
Loading

0 comments on commit 9129140

Please sign in to comment.