TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ LeftClick() [1/2]

static void Terraria.UI.ItemSlot.LeftClick ( Item[] inv,
int context = 0,
int slot = 0 )
inlinestatic

Definition at line 681 of file ItemSlot.cs.

682 {
683 Player player = Main.player[Main.myPlayer];
684 bool flag = Main.mouseLeftRelease && Main.mouseLeft;
685 if (flag)
686 {
687 if (OverrideLeftClick(inv, context, slot))
688 {
689 return;
690 }
691 inv[slot].newAndShiny = false;
692 if (LeftClick_SellOrTrash(inv, context, slot) || player.itemAnimation != 0 || player.itemTime != 0)
693 {
694 return;
695 }
696 }
697 int num = PickItemMovementAction(inv, context, slot, Main.mouseItem);
698 if (num != 3 && !flag)
699 {
700 return;
701 }
702 switch (num)
703 {
704 case 0:
705 {
706 if (context == 6 && Main.mouseItem.type != 0)
707 {
708 inv[slot].SetDefaults();
709 }
710 if ((IsAccessoryContext(context) && !ItemLoader.CanEquipAccessory(inv[slot], slot, context < 0)) || (context == 11 && !inv[slot].FitsAccessoryVanitySlot) || (context < 0 && !LoaderManager.Get<AccessorySlotLoader>().CanAcceptItem(slot, inv[slot], context)))
711 {
712 break;
713 }
714 if (Main.mouseItem.maxStack <= 1 || inv[slot].type != Main.mouseItem.type || inv[slot].stack == inv[slot].maxStack || Main.mouseItem.stack == Main.mouseItem.maxStack)
715 {
716 Utils.Swap(ref inv[slot], ref Main.mouseItem);
717 }
718 if (inv[slot].stack > 0)
719 {
720 AnnounceTransfer(new ItemTransferInfo(inv[slot], 21, context, inv[slot].stack));
721 }
722 else
723 {
724 AnnounceTransfer(new ItemTransferInfo(Main.mouseItem, context, 21, Main.mouseItem.stack));
725 }
726 if (inv[slot].stack > 0)
727 {
728 switch (Math.Abs(context))
729 {
730 case 0:
732 break;
733 case 8:
734 case 9:
735 case 10:
736 case 11:
737 case 12:
738 case 16:
739 case 17:
740 case 25:
741 case 27:
742 case 33:
743 AchievementsHelper.HandleOnEquip(player, inv[slot], context);
744 break;
745 }
746 }
747 if (inv[slot].type == 0 || inv[slot].stack < 1)
748 {
749 inv[slot] = new Item();
750 }
751 if (Main.mouseItem.IsTheSameAs(inv[slot]) && inv[slot].stack != inv[slot].maxStack && Main.mouseItem.stack != Main.mouseItem.maxStack && ItemLoader.TryStackItems(inv[slot], Main.mouseItem, out var numTransfered))
752 {
753 AnnounceTransfer(new ItemTransferInfo(inv[slot], 21, context, numTransfered));
754 }
755 if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
756 {
757 Main.mouseItem = new Item();
758 }
759 if (Main.mouseItem.type > 0 || inv[slot].type > 0)
760 {
761 Recipe.FindRecipes();
763 }
764 if (context == 3 && Main.netMode == 1)
765 {
766 NetMessage.SendData(32, -1, -1, null, player.chest, slot);
767 }
768 break;
769 }
770 case 1:
771 if (Main.mouseItem.stack == 1 && Main.mouseItem.type > 0 && inv[slot].type > 0 && inv[slot].IsNotTheSameAs(Main.mouseItem) && (context != 11 || Main.mouseItem.FitsAccessoryVanitySlot))
772 {
773 if ((IsAccessoryContext(context) && !ItemLoader.CanEquipAccessory(Main.mouseItem, slot, context < 0)) || (Math.Abs(context) == 11 && !Main.mouseItem.FitsAccessoryVanitySlot) || (context < 0 && !LoaderManager.Get<AccessorySlotLoader>().CanAcceptItem(slot, Main.mouseItem, context)))
774 {
775 break;
776 }
777 Utils.Swap(ref inv[slot], ref Main.mouseItem);
779 if (inv[slot].stack > 0)
780 {
781 switch (Math.Abs(context))
782 {
783 case 0:
785 break;
786 case 8:
787 case 9:
788 case 10:
789 case 11:
790 case 12:
791 case 16:
792 case 17:
793 case 25:
794 case 27:
795 case 33:
796 AchievementsHelper.HandleOnEquip(player, inv[slot], context);
797 break;
798 }
799 }
800 }
801 else if (Main.mouseItem.type == 0 && inv[slot].type > 0)
802 {
803 Utils.Swap(ref inv[slot], ref Main.mouseItem);
804 if (inv[slot].type == 0 || inv[slot].stack < 1)
805 {
806 inv[slot] = new Item();
807 }
808 if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
809 {
810 Main.mouseItem = new Item();
811 }
812 if (Main.mouseItem.type > 0 || inv[slot].type > 0)
813 {
814 Recipe.FindRecipes();
816 }
817 }
818 else if (Main.mouseItem.type > 0 && inv[slot].type == 0 && (context != 11 || Main.mouseItem.FitsAccessoryVanitySlot))
819 {
820 if ((IsAccessoryContext(context) && !ItemLoader.CanEquipAccessory(Main.mouseItem, slot, context < 0)) || (Math.Abs(context) == 11 && !Main.mouseItem.FitsAccessoryVanitySlot) || (context < 0 && !LoaderManager.Get<AccessorySlotLoader>().CanAcceptItem(slot, Main.mouseItem, context)))
821 {
822 break;
823 }
824 inv[slot] = ItemLoader.TransferWithLimit(Main.mouseItem, 1);
825 Recipe.FindRecipes();
827 if (inv[slot].stack > 0)
828 {
829 switch (Math.Abs(context))
830 {
831 case 0:
833 break;
834 case 8:
835 case 9:
836 case 10:
837 case 11:
838 case 12:
839 case 16:
840 case 17:
841 case 25:
842 case 27:
843 case 33:
844 AchievementsHelper.HandleOnEquip(player, inv[slot], context);
845 break;
846 }
847 }
848 }
849 if ((context == 23 || context == 24) && Main.netMode == 1)
850 {
851 NetMessage.SendData(121, -1, -1, null, Main.myPlayer, player.tileEntityAnchor.interactEntityID, slot);
852 }
853 if (context == 26 && Main.netMode == 1)
854 {
855 NetMessage.SendData(124, -1, -1, null, Main.myPlayer, player.tileEntityAnchor.interactEntityID, slot);
856 }
857 break;
858 case 2:
859 if (Main.mouseItem.stack == 1 && Main.mouseItem.dye > 0 && inv[slot].type > 0 && inv[slot].type != Main.mouseItem.type)
860 {
861 Utils.Swap(ref inv[slot], ref Main.mouseItem);
863 if (inv[slot].stack > 0)
864 {
865 switch (Math.Abs(context))
866 {
867 case 0:
869 break;
870 case 8:
871 case 9:
872 case 10:
873 case 11:
874 case 12:
875 case 16:
876 case 17:
877 case 25:
878 case 27:
879 case 33:
880 AchievementsHelper.HandleOnEquip(player, inv[slot], context);
881 break;
882 }
883 }
884 }
885 else if (Main.mouseItem.type == 0 && inv[slot].type > 0)
886 {
887 Utils.Swap(ref inv[slot], ref Main.mouseItem);
888 if (inv[slot].type == 0 || inv[slot].stack < 1)
889 {
890 inv[slot] = new Item();
891 }
892 if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
893 {
894 Main.mouseItem = new Item();
895 }
896 if (Main.mouseItem.type > 0 || inv[slot].type > 0)
897 {
898 Recipe.FindRecipes();
900 }
901 }
902 else if (Main.mouseItem.dye > 0 && inv[slot].type == 0)
903 {
904 inv[slot] = ItemLoader.TransferWithLimit(Main.mouseItem, 1);
905 Recipe.FindRecipes();
907 if (inv[slot].stack > 0)
908 {
909 switch (Math.Abs(context))
910 {
911 case 0:
913 break;
914 case 8:
915 case 9:
916 case 10:
917 case 11:
918 case 12:
919 case 16:
920 case 17:
921 case 25:
922 case 27:
923 case 33:
924 AchievementsHelper.HandleOnEquip(player, inv[slot], context);
925 break;
926 }
927 }
928 }
929 if (context == 25 && Main.netMode == 1)
930 {
931 NetMessage.SendData(121, -1, -1, null, Main.myPlayer, player.tileEntityAnchor.interactEntityID, slot, 1f);
932 }
933 if (context == 27 && Main.netMode == 1)
934 {
935 NetMessage.SendData(124, -1, -1, null, Main.myPlayer, player.tileEntityAnchor.interactEntityID, slot, 1f);
936 }
937 break;
938 case 3:
940 break;
941 case 4:
942 if (PlayerLoader.CanSellItem(player, player.TalkNPC, inv, Main.mouseItem))
943 {
944 Chest chest = Main.instance.shop[Main.npcShop];
945 if (player.SellItem(Main.mouseItem))
946 {
947 int soldItemIndex = chest.AddItemToShop(Main.mouseItem);
948 Main.mouseItem.SetDefaults();
950 AnnounceTransfer(new ItemTransferInfo(inv[slot], 21, 15));
951 PlayerLoader.PostSellItem(player, player.TalkNPC, chest.item, chest.item[soldItemIndex]);
952 }
953 else if (Main.mouseItem.value == 0)
954 {
955 int soldItemIndex2 = chest.AddItemToShop(Main.mouseItem);
956 Main.mouseItem.SetDefaults();
958 AnnounceTransfer(new ItemTransferInfo(inv[slot], 21, 15));
959 PlayerLoader.PostSellItem(player, player.TalkNPC, chest.item, chest.item[soldItemIndex2]);
960 }
961 Recipe.FindRecipes();
962 Main.stackSplit = 9999;
963 }
964 break;
965 case 5:
966 if (Main.mouseItem.IsAir)
967 {
969 Main.mouseItem = inv[slot].Clone();
970 Main.mouseItem.stack = Main.mouseItem.maxStack;
971 Main.mouseItem.OnCreated(new JourneyDuplicationItemCreationContext());
972 AnnounceTransfer(new ItemTransferInfo(inv[slot], 29, 21));
973 }
974 break;
975 }
976 if ((uint)context > 2u && context != 5 && context != 32)
977 {
978 inv[slot].favorited = false;
979 }
980 }
static SlotId PlaySound(in SoundStyle? style, Vector2? position=null, SoundUpdateCallback? updateCallback=null)
Attempts to play a sound style with the provided sound style (if it's not null), and returns a valid ...
static void NotifyItemPickup(Player player, Item item)
static void HandleOnEquip(Player player, Item item, int context)
bool CanAcceptItem(int index, Item checkItem, int context)
This serves as a central place to store equipment slots and their corresponding textures....
static bool TryStackItems(Item destination, Item source, out int numTransferred, bool infiniteSource=false)
Stacks source onto destination if CanStack permits the transfer.
static Item TransferWithLimit(Item source, int limit)
Extract up to limit items from source . If some items remain, M:Terraria.ModLoader....
static bool CanEquipAccessory(Item item, int slot, bool modded)
This serves as the central class from which item-related functions are carried out....
Definition ItemLoader.cs:26
static void PostSellItem(Player player, NPC npc, Item[] shopInventory, Item item)
static bool CanSellItem(Player player, NPC npc, Item[] shopInventory, Item item)
This is where all ModPlayer hooks are gathered and called.
static bool OverrideLeftClick(Item[] inv, int context=0, int slot=0)
Definition ItemSlot.cs:582
static void HandleShopSlot(Item[] inv, int slot, bool rightClickIsValid, bool leftClickIsValid)
Definition ItemSlot.cs:1746
static int PickItemMovementAction(Item[] inv, int context, int slot, Item checkItem)
Definition ItemSlot.cs:1162
static void AnnounceTransfer(ItemTransferInfo info)
Definition ItemSlot.cs:270
static bool IsAccessoryContext(int context)
Definition ItemSlot.cs:675
static bool LeftClick_SellOrTrash(Item[] inv, int context, int slot)
Definition ItemSlot.cs:991

References Terraria.Chest.AddItemToShop(), Terraria.UI.ItemSlot.AnnounceTransfer(), Terraria.ModLoader.AccessorySlotLoader.CanAcceptItem(), Terraria.ModLoader.ItemLoader.CanEquipAccessory(), Terraria.ModLoader.PlayerLoader.CanSellItem(), Terraria.Player.chest, Terraria.Recipe.FindRecipes(), Terraria.GameContent.Achievements.AchievementsHelper.HandleOnEquip(), Terraria.UI.ItemSlot.HandleShopSlot(), Terraria.Main.instance, Terraria.DataStructures.PlayerInteractionAnchor.interactEntityID, Terraria.UI.ItemSlot.IsAccessoryContext(), Terraria.Chest.item, Terraria.Player.itemAnimation, Terraria.Player.itemTime, Terraria.UI.ItemSlot.LeftClick_SellOrTrash(), Terraria.Main.mouseItem, Terraria.Main.mouseLeft, Terraria.Main.myPlayer, Terraria.Main.netMode, Terraria.GameContent.Achievements.AchievementsHelper.NotifyItemPickup(), Terraria.Main.npcShop, Terraria.UI.ItemSlot.OverrideLeftClick(), Terraria.UI.ItemSlot.PickItemMovementAction(), Terraria.Main.player, Terraria.Audio.SoundEngine.PlaySound(), Terraria.ModLoader.PlayerLoader.PostSellItem(), Terraria.Player.SellItem(), Terraria.NetMessage.SendData(), Terraria.Player.TalkNPC, Terraria.Player.tileEntityAnchor, Terraria.ModLoader.ItemLoader.TransferWithLimit(), and Terraria.ModLoader.ItemLoader.TryStackItems().

+ Here is the call graph for this function: