Skip to content

Commit 96973e2

Browse files
committed
fixed enchanting crash on non enchantable items
1 parent 43b96be commit 96973e2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/MiNET/MiNET.Console/minet.zip

37.3 KB
Binary file not shown.

src/MiNET/MiNET/ItemStackInventoryManager.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using MiNET.Crafting;
3131
using MiNET.Items;
3232
using MiNET.Utils;
33+
using Newtonsoft.Json.Linq;
3334

3435
namespace MiNET
3536
{
@@ -340,10 +341,27 @@ protected virtual void ProcessPlaceAction(PlaceAction action, List<StackResponse
340341
SetContainerItem(destination.ContainerId, destination.Slot, destItem);
341342
}
342343

343-
if (destination.ContainerId == 21 || destination.ContainerId == 22)
344+
if (destination.ContainerId == 22)
344345
{
345-
if (!(GetContainerItem(21, 14) is ItemAir) && !(GetContainerItem(22, 15) is ItemAir)) Enchantment.SendEnchantments(_player, GetContainerItem(21, 14));
346-
else Enchantment.SendEmptyEnchantments(_player);
346+
if (Enum.IsDefined(typeof(ItemType), GetContainerItem(21, 14).ItemType) && !(GetContainerItem(22, 15) is ItemAir))
347+
{
348+
Enchantment.SendEnchantments(_player, GetContainerItem(21, 14));
349+
}
350+
else
351+
{
352+
Enchantment.SendEmptyEnchantments(_player);
353+
}
354+
}
355+
else if (destination.ContainerId == 23)
356+
{
357+
if (Enum.IsDefined(typeof(ItemType), GetContainerItem(21, 14).ItemType) && !(GetContainerItem(21, 14) is ItemAir) && !(GetContainerItem(22, 15) is ItemAir))
358+
{
359+
Enchantment.SendEnchantments(_player, GetContainerItem(21, 14));
360+
}
361+
else
362+
{
363+
Enchantment.SendEmptyEnchantments(_player);
364+
}
347365
}
348366

349367
stackResponses.Add(new StackResponseContainerInfo
@@ -405,10 +423,9 @@ protected virtual void ProcessTakeAction(TakeAction action, List<StackResponseCo
405423

406424
SetContainerItem(destination.ContainerId, destination.Slot, destItem);
407425

408-
if (source.ContainerId == 21 || source.ContainerId == 22)
426+
if (source.ContainerId == 22 || source.ContainerId == 23)
409427
{
410-
if (!(GetContainerItem(21, 14) is ItemAir) && !(GetContainerItem(22, 15) is ItemAir)) Enchantment.SendEnchantments(_player, GetContainerItem(21, 14));
411-
else Enchantment.SendEmptyEnchantments(_player);
428+
Enchantment.SendEmptyEnchantments(_player);
412429
}
413430

414431
stackResponses.Add(new StackResponseContainerInfo

0 commit comments

Comments
 (0)