Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The feature to register ungettable items (like Blacklist?) #13

Open
wants to merge 6 commits into
base: 1.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions ItemChecklist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public class ItemChecklist : Mod
internal static UserInterface ItemChecklistInterface;
internal ItemChecklistUI ItemChecklistUI;
internal event Action<int> OnNewItem;
internal List<int> UnfindableItems;

public override void Load()
{
// Latest uses ItemID.Sets.IsAMaterial, added 0.10.1.5
instance = this;
ToggleChecklistHotKey = KeybindLoader.RegisterKeybind(this, "Toggle Item Checklist", "I");
UnfindableItems = new List<int>();
MagicStorageIntegration.Load();

if (!Main.dedServ)
Expand All @@ -44,6 +46,7 @@ public override void Unload()
instance = null;
ToggleChecklistHotKey = null;
ItemChecklistInterface = null;
UnfindableItems = null;
MagicStorageIntegration.Unload();

UIElements.UICheckbox.checkboxTexture = null;
Expand Down Expand Up @@ -85,6 +88,42 @@ public override object Call(params object[] args)
OnNewItem += callback;
return "RegisterSuccess";
}
else if (message == "RegisterUnfindableItems")
{
int[] unfindableItems = args[1] as int[];
for (var i = 0; i < unfindableItems; i++)
{
if (unfindableItems[i] < 0 || unfindableItems[i] > ItemLoader.ItemCount)
{
throw new IndexOutOfRangeException("Attempted to register item type out of range");
}
if (!UnfindableItems.Contains(unfindableItems[i])
{
UnfindableItems.Add(unfindableItems[i]);
}
}
return "RegisterSuccess";
}
else if (message == "ModifyFindableFlag")
{
if (Main.gameMenu)
{
return "NotInGame";
}
int type = args[1] as int;
bool findable = args[2] as bool;
Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>().findableItems[type] = findable;
return "ModifySuccess";
}
else if (message == "IsFindable")
{
if (Main.gameMenu)
{
return null;
}
int type = args[1] as int;
return Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>().findableItems[type];
}
else
{
Logger.Error("ItemChecklist Call Error: Unknown Message: " + message);
Expand Down
2 changes: 1 addition & 1 deletion ItemChecklistPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public override void Initialize()
findableItems = new bool[ItemLoader.ItemCount];
for (int i = 0; i < ItemLoader.ItemCount; i++)
{
if (i > 0 && !ItemID.Sets.Deprecated[i] && ItemLoader.GetItem(i) is not Terraria.ModLoader.Default.UnloadedItem && ItemChecklistUI.vanillaIDsInSortOrder != null && ItemChecklistUI.vanillaIDsInSortOrder[i] != -1) // TODO, is this guaranteed?
if (i > 0 && !ItemID.Sets.Deprecated[i] && ItemLoader.GetItem(i) is not Terraria.ModLoader.Default.UnloadedItem && ItemChecklistUI.vanillaIDsInSortOrder != null && ItemChecklistUI.vanillaIDsInSortOrder[i] != -1 && !ItemChecklist.instance.UnfindableItems.Contains(i)) // TODO, is this guaranteed?
{
totalItemsToFind++;
findableItems[i] = true;
Expand Down