public override void Click(UIMouseEvent evt) { base.Click(evt); if (CanInteract?.Invoke(Item, Main.mouseItem) ?? true) { Item.newAndShiny = false; Player player = Main.LocalPlayer; if (ItemSlot.ShiftInUse) { Main.NewText("move to inventory"); return; } Item temp = Item; Utils.Swap(ref temp, ref Main.mouseItem); Item = temp; if (Item.stack > 0) { AchievementsHelper.NotifyItemPickup(player, Item); } if (Item.type == 0 || Item.stack < 1) { Item = new Item(); } if (Main.mouseItem.IsTheSameAs(Item)) { Utils.Swap(ref Item.favorited, ref Main.mouseItem.favorited); if (Item.stack != Item.maxStack && Main.mouseItem.stack != Main.mouseItem.maxStack) { if (Main.mouseItem.stack + Item.stack <= Main.mouseItem.maxStack) { Item.stack += Main.mouseItem.stack; Main.mouseItem.stack = 0; } else { int delta = Main.mouseItem.maxStack - Item.stack; Item.stack += delta; Main.mouseItem.stack -= delta; } } } if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > 0 || Item.type > 0) { Terraria.Recipe.FindRecipes(); Main.PlaySound(7); } OnInteract?.Invoke(); } SendUpdate(); }
public override bool OnPickup(Item item, Player player) { switch (item.type) { case ItemID.CopperCoin: case ItemID.SilverCoin: case ItemID.GoldCoin: case ItemID.PlatinumCoin: return(true); } var myplayer = TmlHelpers.SafelyGetModPlayer <ExtensibleInventoryPlayer>(player); int oldStack = item.stack; if (myplayer.Library.CurrentBook.Share(player, item) > 0) { if (item.stack == 0) { item.stack = oldStack; item.active = true; if (player.whoAmI == Main.myPlayer) { Recipe.FindRecipes(); } ItemText.NewText(item, oldStack, false, false); Main.PlaySound(7, (int)player.position.X, (int)player.position.Y, 1, 1f, 0f); AchievementsHelper.NotifyItemPickup(player, item); item.stack = 0; item.active = false; } } if (item.stack != oldStack) { Item worldItem = Main.item[item.whoAmI]; if (worldItem != null && !worldItem.IsAir && !worldItem.IsNotTheSameAs(item)) { if (Main.netMode != 0) { NetMessage.SendData(MessageID.SyncItem, -1, -1, null, item.whoAmI, 0f, 0f, 0f, 0, 0, 0); } } } return(true); //return item.stack > 0; }
internal static void Create(Recipe r) { if (r.P_GroupDef as RecipeDef == null) { r.CreateBasic(); } else { r.CreateUnion(); } AchievementsHelper.NotifyItemCraft(r); AchievementsHelper.NotifyItemPickup(Main.player[Main.myPlayer], r.createItem); Recipe.FindRecipes(); }
/* * public override void ScrollWheel(UIScrollWheelEvent evt) * { * if (!Main.keyState.IsKeyDown(Keys.LeftAlt)) return; * * if (evt.ScrollWheelValue > 0) * { * if (Main.mouseItem.type == Item.type && Main.mouseItem.stack < Main.mouseItem.maxStack) * { * Main.mouseItem.stack++; * if (--Item.stack <= 0) Item.TurnToAir(); * } * else if (Main.mouseItem.IsAir) * { * Main.mouseItem = Item.Clone(); * Main.mouseItem.stack = 1; * if (--Item.stack <= 0) Item.TurnToAir(); * } * } * else if (evt.ScrollWheelValue < 0) * { * if (Item.type == Main.mouseItem.type && Item.stack < Item.maxStack) * { * Item.stack++; * if (--Main.mouseItem.stack <= 0) Main.mouseItem.TurnToAir(); * } * else if (Item.IsAir) * { * Item = Main.mouseItem.Clone(); * Item.stack = 1; * if (--Main.mouseItem.stack <= 0) Main.mouseItem.TurnToAir(); * } * } * } */ public override void Click(UIMouseEvent evt) { Item.newAndShiny = false; Player player = Main.LocalPlayer; if (ItemSlot.ShiftInUse) { Item = Utility.PutItemInInventory(Item); OnInteract?.Invoke(); base.Click(evt); return; } if (Main.mouseItem.IsAir) { Main.mouseItem = Network.ExtractItem(Item); } else { Network.InsertItem(ref Main.mouseItem); Main.PlaySound(SoundID.Grab); } if (Item.stack > 0) { AchievementsHelper.NotifyItemPickup(player, Item); } if (Main.mouseItem.type > 0 || Item.type > 0) { Recipe.FindRecipes(); Main.PlaySound(SoundID.Grab); } OnInteract?.Invoke(); base.Click(evt); }
private bool TryPlaceItem(ref Item item, ref Item target, bool isCoin, bool incrementStack) { bool dispose = false; if (target.type == 0 && !incrementStack) { target = item; ItemText.NewText(item, item.stack); AchievementsHelper.NotifyItemPickup(Player, item); dispose = true; } else if (incrementStack && target.type > 0 && target.stack < target.maxStack && item.IsTheSameAs(target)) { if (item.stack + target.stack <= target.maxStack) { target.stack += item.stack; ItemText.NewText(item, item.stack); AchievementsHelper.NotifyItemPickup(Player, item); dispose = true; } else { AchievementsHelper.NotifyItemPickup(Player, item, target.maxStack - target.stack); item.stack -= target.maxStack - target.stack; ItemText.NewText(item, target.maxStack - target.stack); target.stack = target.maxStack; } } Main.PlaySound(isCoin ? SoundID.CoinPickup : SoundID.Grab, (int)Player.position.X, (int)Player.position.Y, 1, 1f, 0f); if (Player.whoAmI == Main.myPlayer) { API.FindRecipes(); } return(dispose); }
//TODO make IL //I method swapped because I could not get IL working private void On_LeftClick(On.Terraria.UI.ItemSlot.orig_LeftClick_ItemArray_int_int orig, Item[] inv, int context, int slot) { //Main.NewText(Main.cursorOverride); if (!(bool)overrideLeftClick.Invoke(null, new object[] { inv, context, slot })) { inv[slot].newAndShiny = false; Player player = Main.player[Main.myPlayer]; bool flag = false; if ((uint)context <= 4u) { flag = (player.chest == -1); } if (ControlInUse & flag) { sellOrTrash.Invoke(null, new object[] { inv, context, slot }); } else if (player.itemAnimation == 0 && player.itemTime == 0) { switch (ItemSlot.PickItemMovementAction(inv, context, slot, Main.mouseItem)) { case 0: if (context == 6 && Main.mouseItem.type != ItemID.None) { inv[slot].SetDefaults(0, false); } Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem); if (inv[slot].stack > 0) { if (context != 0) { if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u) { AchievementsHelper.HandleOnEquip(player, inv[slot], context); } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } if (inv[slot].type == ItemID.None || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.IsTheSameAs(inv[slot])) { Utils.Swap <bool>(ref inv[slot].favorited, ref Main.mouseItem.favorited); if (inv[slot].stack != inv[slot].maxStack && Main.mouseItem.stack != Main.mouseItem.maxStack) { if (Main.mouseItem.stack + inv[slot].stack <= Main.mouseItem.maxStack) { inv[slot].stack += Main.mouseItem.stack; Main.mouseItem.stack = 0; } else { int num3 = Main.mouseItem.maxStack - inv[slot].stack; inv[slot].stack += num3; Main.mouseItem.stack -= num3; } } } if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > ItemID.None || inv[slot].type > ItemID.None) { Recipe.FindRecipes(); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); } if (context == 3 && Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.SyncChestItem, -1, -1, null, player.chest, slot, 0f, 0f, 0, 0, 0); } break; case 1: if (Main.mouseItem.stack == 1 && Main.mouseItem.type > ItemID.None && inv[slot].type > ItemID.None && inv[slot].IsNotTheSameAs(Main.mouseItem)) { Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); if (inv[slot].stack > 0) { if (context != 0) { if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u) { AchievementsHelper.HandleOnEquip(player, inv[slot], context); } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } } else if (Main.mouseItem.type == ItemID.None && inv[slot].type > ItemID.None) { Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem); if (inv[slot].type == ItemID.None || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type <= ItemID.None && inv[slot].type <= ItemID.None) { break; } Recipe.FindRecipes(); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); } else if (Main.mouseItem.type > ItemID.None && inv[slot].type == ItemID.None) { if (Main.mouseItem.stack == 1) { Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem); if (inv[slot].type == ItemID.None || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > ItemID.None || inv[slot].type > ItemID.None) { Recipe.FindRecipes(); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); } } else { Main.mouseItem.stack--; inv[slot].SetDefaults(Main.mouseItem.type, false); Recipe.FindRecipes(); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); } if (inv[slot].stack > 0) { if (context != 0) { if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u) { AchievementsHelper.HandleOnEquip(player, inv[slot], context); } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } } break; case 2: if (Main.mouseItem.stack == 1 && Main.mouseItem.dye > 0 && inv[slot].type > ItemID.None && inv[slot].type != Main.mouseItem.type) { Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); if (inv[slot].stack > 0) { if (context != 0) { if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u) { AchievementsHelper.HandleOnEquip(player, inv[slot], context); } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } } else if (Main.mouseItem.type == ItemID.None && inv[slot].type > ItemID.None) { Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem); if (inv[slot].type == ItemID.None || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type <= ItemID.None && inv[slot].type <= ItemID.None) { break; } Recipe.FindRecipes(); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); } else if (Main.mouseItem.dye > 0 && inv[slot].type == ItemID.None) { if (Main.mouseItem.stack == 1) { Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem); if (inv[slot].type == ItemID.None || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > ItemID.None || inv[slot].type > ItemID.None) { Recipe.FindRecipes(); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); } } else { Main.mouseItem.stack--; inv[slot].SetDefaults(Main.mouseItem.type, false); Recipe.FindRecipes(); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); } if (inv[slot].stack > 0) { if (context != 0) { if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u) { AchievementsHelper.HandleOnEquip(player, inv[slot], context); } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } } break; case 3: if (PlayerHooks.CanBuyItem(player, Main.npc[player.talkNPC], inv, inv[slot])) { Main.mouseItem = inv[slot].Clone(); Main.mouseItem.stack = 1; if (inv[slot].buyOnce) { Main.mouseItem.value *= 5; } else { Main.mouseItem.Prefix(-1); } Main.mouseItem.position = player.Center - new Vector2(Main.mouseItem.width, Main.mouseItem.headSlot) / 2f; ItemText.NewText(Main.mouseItem, Main.mouseItem.stack, false, false); if (inv[slot].buyOnce && --inv[slot].stack <= 0) { inv[slot].SetDefaults(0, false); } if (inv[slot].value > 0) { Main.PlaySound(SoundID.Coins, -1, -1, 1, 1f, 0f); } else { Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); } PlayerHooks.PostBuyItem(player, Main.npc[player.talkNPC], inv, Main.mouseItem); } break; case 4: if (PlayerHooks.CanSellItem(player, Main.npc[player.talkNPC], inv, Main.mouseItem)) { Chest chest = Main.instance.shop[Main.npcShop]; if (player.SellItem(Main.mouseItem.value, Main.mouseItem.stack)) { int num = chest.AddShop(Main.mouseItem); Main.mouseItem.SetDefaults(0, false); Main.PlaySound(SoundID.Coins, -1, -1, 1, 1f, 0f); PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[num]); } else if (Main.mouseItem.value == 0) { int num2 = chest.AddShop(Main.mouseItem); Main.mouseItem.SetDefaults(0, false); Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f); PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[num2]); } Recipe.FindRecipes(); } break; } if ((uint)context > 2u && context != 5) { inv[slot].favorited = false; } } } }
public static void ApiCreate(this Terraria.Recipe recipe) { for (int requirementIndex = 0; requirementIndex < Terraria.Recipe.maxRequirements; requirementIndex++) { Item requiredItem = recipe.requiredItem[requirementIndex]; if (requiredItem.type == ItemID.None) { break; } int requiredAmount = requiredItem.stack; if (recipe is ModRecipe modRecipe) { requiredAmount = modRecipe.ConsumeItem(requiredItem.type, requiredItem.stack); } if (recipe.alchemy && Main.player[Main.myPlayer].alchemyTable) { if (requiredAmount > 1) { int num2 = 0; for (int j = 0; j < requiredAmount; j++) { if (Main.rand.Next(3) == 0) { num2++; } } requiredAmount -= num2; } else if (Main.rand.Next(3) == 0) { requiredAmount = 0; } } if (requiredAmount <= 0) { continue; } Item[] array = Main.player[Main.myPlayer].inventory; InvLogic(recipe, array, requiredItem, requiredAmount); PlayerCharacter character = Main.LocalPlayer.GetModPlayer <PlayerCharacter>(); for (int j = 0; j < character.Inventories.Length; j += 1) { if (character.ActiveInvPage != j) { array = character.Inventories[j]; InvLogic(recipe, array, requiredItem, requiredAmount); } } if (Main.player[Main.myPlayer].chest == -1) { continue; } if (Main.player[Main.myPlayer].chest > -1) { array = Main.chest[Main.player[Main.myPlayer].chest].item; } else { switch (Main.player[Main.myPlayer].chest) { case -2: array = Main.player[Main.myPlayer].bank.item; break; case -3: array = Main.player[Main.myPlayer].bank2.item; break; case -4: array = Main.player[Main.myPlayer].bank3.item; break; } } for (int l = 0; l < 40; l++) { Item item3 = array[l]; if (requiredAmount <= 0) { break; } if (!item3.IsTheSameAs(requiredItem) && !recipe.useWood(item3.type, requiredItem.type) && !recipe.useSand(item3.type, requiredItem.type) && !recipe.useIronBar(item3.type, requiredItem.type) && !recipe.usePressurePlate(item3.type, requiredItem.type) && !recipe.useFragment(item3.type, requiredItem.type) && !recipe.AcceptedByItemGroups(item3.type, requiredItem.type)) { continue; } if (item3.stack > requiredAmount) { item3.stack -= requiredAmount; if (Main.netMode == NetmodeID.MultiplayerClient && Main.player[Main.myPlayer].chest >= 0) { NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, l); } requiredAmount = 0; } else { requiredAmount -= item3.stack; array[l] = new Item(); if (Main.netMode == NetmodeID.MultiplayerClient && Main.player[Main.myPlayer].chest >= 0) { NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, l); } } } } AchievementsHelper.NotifyItemCraft(recipe); AchievementsHelper.NotifyItemPickup(Main.player[Main.myPlayer], recipe.createItem); FindRecipes(); }
private void ItemSlot_LeftClick(On.Terraria.UI.ItemSlot.orig_LeftClick_ItemArray_int_int orig, Item[] inv, int context, int slot) { //Invoke ItemSlot.OverrideLeftClick and save it as a varible to check for later var OverrideLeftClick = MethodInfo_ItemSlot_OverrideLeftClick.Invoke(null, new object[3] { inv, context, slot }); //Check if ItemSlot.OverrideLeftClick returns true, if so return if ((bool)OverrideLeftClick) { return; } inv[slot].newAndShiny = false; Player player = Main.player[Main.myPlayer]; bool flag = false; switch (context) { case 0: case 1: case 2: case 3: case 4: flag = player.chest == -1; break; } if (ItemSlot.ShiftInUse && flag) { //Invoke the ItemSlot.SellOrTrash method MethodInfo_ItemSlot_SellOrTrash.Invoke(null, new object[3] { inv, context, slot }); return; } if (player.itemAnimation == 0 && player.itemTime == 0) { int num = ItemSlot.PickItemMovementAction(inv, context, slot, Main.mouseItem); if (num == 0) { if (context == 6 && Main.mouseItem.type != 0) { inv[slot].SetDefaults(0, false); } //Check if the inventory isnt the lock. If not, procide with the pickup if (Main.LocalPlayer.inventory[slot].type != ModContent.ItemType <ItemLock>()) { Utils.Swap(ref inv[slot], ref Main.mouseItem); } if (inv[slot].stack > 0) { if (context != 0) { switch (context) { case 8: case 9: case 10: case 11: case 12: case 16: case 17: AchievementsHelper.HandleOnEquip(player, inv[slot], context); break; } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } if (inv[slot].type == 0 || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.IsTheSameAs(inv[slot])) { Utils.Swap(ref inv[slot].favorited, ref Main.mouseItem.favorited); if (inv[slot].stack != inv[slot].maxStack && Main.mouseItem.stack != Main.mouseItem.maxStack) { if (Main.mouseItem.stack + inv[slot].stack <= Main.mouseItem.maxStack) { inv[slot].stack += Main.mouseItem.stack; Main.mouseItem.stack = 0; } else { int stack = Main.mouseItem.maxStack - inv[slot].stack; inv[slot].stack += stack; Main.mouseItem.stack -= stack; } } } if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > 0 || inv[slot].type > 0) { Recipe.FindRecipes(); if (Main.LocalPlayer.inventory[slot].type != ModContent.ItemType <ItemLock>()) { Main.PlaySound(7, -1, -1, 1, 1f, 0f); } } if (context == 3 && Main.netMode == 1) { NetMessage.SendData(32, -1, -1, null, player.chest, slot, 0f, 0f, 0, 0, 0); } } else if (num == 1) { if (Main.mouseItem.stack == 1 && Main.mouseItem.type > 0 && inv[slot].type > 0 && inv[slot].IsNotTheSameAs(Main.mouseItem)) { Utils.Swap(ref inv[slot], ref Main.mouseItem); Main.PlaySound(7, -1, -1, 1, 1f, 0f); if (inv[slot].stack > 0) { if (context != 0) { switch (context) { case 8: case 9: case 10: case 11: case 12: case 16: case 17: AchievementsHelper.HandleOnEquip(player, inv[slot], context); break; } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } } else if (Main.mouseItem.type == 0 && inv[slot].type > 0) { Utils.Swap(ref inv[slot], ref Main.mouseItem); if (inv[slot].type == 0 || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > 0 || inv[slot].type > 0) { Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } } else if (Main.mouseItem.type > 0 && inv[slot].type == 0) { if (Main.mouseItem.stack == 1) { Utils.Swap(ref inv[slot], ref Main.mouseItem); if (inv[slot].type == 0 || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > 0 || inv[slot].type > 0) { Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } } else { Main.mouseItem.stack--; inv[slot].SetDefaults(Main.mouseItem.type, false); Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } if (inv[slot].stack > 0) { if (context != 0) { switch (context) { case 8: case 9: case 10: case 11: case 12: case 16: case 17: AchievementsHelper.HandleOnEquip(player, inv[slot], context); break; } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } } } else if (num == 2) { if (Main.mouseItem.stack == 1 && Main.mouseItem.dye > 0 && inv[slot].type > 0 && inv[slot].type != Main.mouseItem.type) { Utils.Swap(ref inv[slot], ref Main.mouseItem); Main.PlaySound(7, -1, -1, 1, 1f, 0f); if (inv[slot].stack > 0) { if (context != 0) { switch (context) { case 8: case 9: case 10: case 11: case 12: case 16: case 17: AchievementsHelper.HandleOnEquip(player, inv[slot], context); break; } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } } else if (Main.mouseItem.type == 0 && inv[slot].type > 0) { Utils.Swap(ref inv[slot], ref Main.mouseItem); if (inv[slot].type == 0 || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > 0 || inv[slot].type > 0) { Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } } else if (Main.mouseItem.dye > 0 && inv[slot].type == 0) { if (Main.mouseItem.stack == 1) { Utils.Swap(ref inv[slot], ref Main.mouseItem); if (inv[slot].type == 0 || inv[slot].stack < 1) { inv[slot] = new Item(); } if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > 0 || inv[slot].type > 0) { Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } } else { Main.mouseItem.stack--; inv[slot].SetDefaults(Main.mouseItem.type, false); Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } if (inv[slot].stack > 0) { if (context != 0) { switch (context) { case 8: case 9: case 10: case 11: case 12: case 16: case 17: AchievementsHelper.HandleOnEquip(player, inv[slot], context); break; } } else { AchievementsHelper.NotifyItemPickup(player, inv[slot]); } } } } else if (num == 3 && PlayerHooks.CanBuyItem(player, Main.npc[player.talkNPC], inv, inv[slot])) { Main.mouseItem = inv[slot].Clone(); Main.mouseItem.stack = 1; if (inv[slot].buyOnce) { Main.mouseItem.value *= 5; } else { Main.mouseItem.Prefix(-1); } Main.mouseItem.position = player.Center - new Vector2(Main.mouseItem.width, Main.mouseItem.headSlot) / 2f; ItemText.NewText(Main.mouseItem, Main.mouseItem.stack, false, false); if (inv[slot].buyOnce && --inv[slot].stack <= 0) { inv[slot].SetDefaults(0, false); } if (inv[slot].value > 0) { Main.PlaySound(18, -1, -1, 1, 1f, 0f); } else { Main.PlaySound(7, -1, -1, 1, 1f, 0f); } PlayerHooks.PostBuyItem(player, Main.npc[player.talkNPC], inv, Main.mouseItem); } else if (num == 4 && PlayerHooks.CanSellItem(player, Main.npc[player.talkNPC], inv, Main.mouseItem)) { Chest chest = Main.instance.shop[Main.npcShop]; if (player.SellItem(Main.mouseItem.value, Main.mouseItem.stack)) { int soldItemIndex = chest.AddShop(Main.mouseItem); Main.mouseItem.SetDefaults(0, false); Main.PlaySound(18, -1, -1, 1, 1f, 0f); PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[soldItemIndex]); } else if (Main.mouseItem.value == 0) { int soldItemIndex = chest.AddShop(Main.mouseItem); Main.mouseItem.SetDefaults(0, false); Main.PlaySound(7, -1, -1, 1, 1f, 0f); PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[soldItemIndex]); } Recipe.FindRecipes(); } switch (context) { case 0: case 1: case 2: case 5: return; case 3: case 4: default: inv[slot].favorited = false; return; } } }
//Makes it so that grabbed items will not enter the first hotbar slot //also changes all text to short, and doesn't count fallen star and snowball as ammo (side effects) public override bool OnPickup(Item item, Player player) { bool flag = item.type >= 71 && item.type <= 74; int num1 = 50; int num2 = 0; //if ammo then use normal if (((item.ammo > 0 || item.bait > 0) && !item.notAmmo || item.type == 530) && (item.type != 75 && item.type != 949)) { return(true); } //use coin numbers if (flag) { return(true); } //if heart or star vairant, use normal if (item.type == 58 || item.type == 1867 || item.type == 1734 || item.type == 184 || item.type == 1868 || item.type == 1735 || (item.type > 3453 && item.type <= 3455)) { return(true); } //if adding to a stack, use normal for (int index = num2; index < 50; ++index) { int i = index; if (i < 0) { i = 54 + index; } if (player.inventory[i].type > 0 && player.inventory[i].stack < player.inventory[i].maxStack && item.IsTheSameAs(player.inventory[i])) { if (item.stack + player.inventory[i].stack <= player.inventory[i].maxStack) { return(true); } } } //start at 1, eliminating use of the first slot for usable items if (!flag && item.useStyle > 0) { for (int i = 1; i < 10; ++i) { if (player.inventory[i].type == 0) { player.inventory[i] = item; ItemText.NewText(item, item.stack, false, false); player.DoCoins(i); if (flag) { Main.PlaySound(38, (int)player.position.X, (int)player.position.Y, 1, 1f, 0.0f); } else { Main.PlaySound(7, (int)player.position.X, (int)player.position.Y, 1, 1f, 0.0f); } if (player.whoAmI == Main.myPlayer) { Recipe.FindRecipes(); } AchievementsHelper.NotifyItemPickup(player, item); return(false); } } } //end at 1, eliminating use of first slot for unusable items if (!item.favorited) { for (int i = num1 - 1; i >= 1; --i) { if (player.inventory[i].type == 0) { player.inventory[i] = item; ItemText.NewText(item, item.stack, false, false); player.DoCoins(i); if (flag) { Main.PlaySound(38, (int)player.position.X, (int)player.position.Y, 1, 1f, 0.0f); } else { Main.PlaySound(7, (int)player.position.X, (int)player.position.Y, 1, 1f, 0.0f); } if (player.whoAmI == Main.myPlayer) { Recipe.FindRecipes(); } AchievementsHelper.NotifyItemPickup(player, item); return(false); } } } return(true); }