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

◆ SacrificeItem()

ItemSacrificeResult Terraria.GameContent.Creative.CreativeUI.SacrificeItem ( out int amountWeSacrificed)
inline

Definition at line 267 of file CreativeUI.cs.

268 {
269 int amountNeededTotal = 0;
270 int amountWeHave = 0;
273 if (!Main.LocalPlayerCreativeTracker.ItemSacrifices.TryGetSacrificeNumbers(item.type, out amountWeHave, out amountNeededTotal))
274 {
275 return ItemSacrificeResult.CannotSacrifice;
276 }
277 int num = Utils.Clamp(amountNeededTotal - amountWeHave, 0, amountNeededTotal);
278 if (num == 0)
279 {
280 return ItemSacrificeResult.CannotSacrifice;
281 }
282 int num2 = Math.Min(num, item.stack);
283 if (!Main.ServerSideCharacter)
284 {
285 Main.LocalPlayerCreativeTracker.ItemSacrifices.RegisterItemSacrifice(item.type, num2);
286 }
287 else
288 {
290 NetManager.Instance.SendToServerOrLoopback(packet);
291 }
292 bool num3 = num2 == num;
293 item.stack -= num2;
294 if (item.stack <= 0)
295 {
296 item.TurnToAir();
297 }
300 if (item.stack > 0)
301 {
302 item.position.X = Main.player[Main.myPlayer].Center.X - (float)(item.width / 2);
303 item.position.Y = Main.player[Main.myPlayer].Center.Y - (float)(item.height / 2);
304 _itemSlotsForUI[0] = Main.LocalPlayer.GetItem(Main.myPlayer, item, GetItemSettings.InventoryUIToInventorySettings);
305 }
306 if (!num3)
307 {
308 return ItemSacrificeResult.SacrificedButNotDone;
309 }
310 return ItemSacrificeResult.SacrificedAndDone;
311 }
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static readonly NetManager Instance
Definition NetManager.cs:18

References Terraria.GameContent.Creative.CreativeUI._itemSlotsForUI, Terraria.Net.NetManager.Instance, Terraria.GetItemSettings.InventoryUIToInventorySettings, System.item, Terraria.Main.LocalPlayer, Terraria.Main.LocalPlayerCreativeTracker, System.Math.Min(), Terraria.Main.myPlayer, Terraria.Main.player, Terraria.GameContent.Creative.CreativeUI.RefreshAvailableInfiniteItemsList(), Terraria.GameContent.NetModules.NetCreativeUnlocksPlayerReportModule.SerializeSacrificeRequest(), and Terraria.Main.ServerSideCharacter.