Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros

◆ NewItem() [1/3]

static int Terraria.Item.NewItem ( IEntitySource source,
int X,
int Y,
int Width,
int Height,
int Type,
int Stack = 1,
bool noBroadcast = false,
int pfix = 0,
bool noGrabDelay = false,
bool reverseLookup = false )
inlinestatic

Definition at line 49707 of file Item.cs.

49708 {
49709 if (WorldGen.gen)
49710 {
49711 return 0;
49712 }
49713 if (Main.rand == null)
49714 {
49715 Main.rand = new UnifiedRandom();
49716 }
49717 if (Main.tenthAnniversaryWorld)
49718 {
49719 if (Type == 58)
49720 {
49721 Type = Main.rand.NextFromList(new short[3] { 1734, 1867, 58 });
49722 }
49723 if (Type == 184)
49724 {
49725 Type = Main.rand.NextFromList(new short[3] { 1735, 1868, 184 });
49726 }
49727 }
49728 if (Main.halloween)
49729 {
49730 if (Type == 58)
49731 {
49732 Type = 1734;
49733 }
49734 if (Type == 184)
49735 {
49736 Type = 1735;
49737 }
49738 }
49739 if (Main.xMas)
49740 {
49741 if (Type == 58)
49742 {
49743 Type = 1867;
49744 }
49745 if (Type == 184)
49746 {
49747 Type = 1868;
49748 }
49749 }
49750 if (Type > 0 && cachedItemSpawnsByType[Type] != -1)
49751 {
49753 return 400;
49754 }
49755 Main.item[400] = new Item();
49756 int num = 400;
49757 if (Main.netMode != 1)
49758 {
49760 }
49761 Main.timeItemSlotCannotBeReusedFor[num] = 0;
49762 Main.item[num] = new Item();
49763 Item item = Main.item[num];
49764 item.SetDefaults(Type);
49765 item.Prefix(pfix);
49766 item.stack = Stack;
49767 item.position.X = X + Width / 2 - item.width / 2;
49768 item.position.Y = Y + Height / 2 - item.height / 2;
49769 item.wet = Collision.WetCollision(item.position, item.width, item.height);
49770 item.velocity.X = (float)Main.rand.Next(-30, 31) * 0.1f;
49771 item.velocity.Y = (float)Main.rand.Next(-40, -15) * 0.1f;
49772 if (Type == 859 || Type == 4743)
49773 {
49774 item.velocity *= 0f;
49775 }
49776 if (Type == 520 || Type == 521 || (item.type >= 0 && ItemID.Sets.NebulaPickup[item.type]))
49777 {
49778 item.velocity.X = (float)Main.rand.Next(-30, 31) * 0.1f;
49779 item.velocity.Y = (float)Main.rand.Next(-30, 31) * 0.1f;
49780 }
49781 item.active = true;
49782 item.timeSinceItemSpawned = ItemID.Sets.OverflowProtectionTimeOffset[item.type];
49785 {
49786 item.newAndShiny = true;
49787 }
49788 if (Main.netMode == 2 && !noBroadcast)
49789 {
49790 NetMessage.SendData(21, -1, -1, null, num, noGrabDelay.ToInt());
49791 }
49792 else if (Main.netMode == 0)
49793 {
49794 item.playerIndexTheItemIsReservedFor = Main.myPlayer;
49795 }
49796 return num;
49797 }
static bool[] NeverAppearsAsNewInInventory
Definition ItemID.cs:1044
static int[] OverflowProtectionTimeOffset
Definition ItemID.cs:71
static bool[] NebulaPickup
Definition ItemID.cs:1058
static int numberOfNewItems
Definition Item.cs:320
static int PickAnItemSlotToSpawnItemOn(bool reverseLookup, int nextItem)
Definition Item.cs:49799
static int[] cachedItemSpawnsByType
Definition Item.cs:59
int noGrabDelay
Definition Item.cs:83
static bool HighlightNewItems
Definition ItemSlot.cs:26

References Terraria.Item.cachedItemSpawnsByType, Terraria.WorldGen.gen, Terraria.Main.halloween, Terraria.UI.ItemSlot.Options.HighlightNewItems, System.item, Terraria.Main.item, Terraria.Main.myPlayer, Terraria.ID.ItemID.Sets.NebulaPickup, Terraria.Main.netMode, Terraria.ID.ItemID.Sets.NeverAppearsAsNewInInventory, Terraria.Item.noGrabDelay, Terraria.Item.numberOfNewItems, Terraria.ID.ItemID.Sets.OverflowProtectionTimeOffset, Terraria.Item.PickAnItemSlotToSpawnItemOn(), Terraria.Main.rand, Terraria.NetMessage.SendData(), Terraria.Main.tenthAnniversaryWorld, Terraria.Main.timeItemSlotCannotBeReusedFor, Terraria.Collision.WetCollision(), System.X, Terraria.Main.xMas, and System.Y.