@@ -2788,31 +2788,41 @@ Local<Value> PlayerClass::clearItem(const Arguments& args) {
2788
2788
CHECK_ARG_TYPE (args[1 ], ValueKind::kNumber );
2789
2789
clearCount = args[1 ].asNumber ().toInt32 ();
2790
2790
}
2791
- int result = 0 ;
2792
- for (std::reference_wrapper<ItemStack> item : player->getInventory ().getSlotCopies ()) {
2793
- if (item.get ().getTypeName () == args[0 ].asString ().toString ()) {
2794
- if (item.get ().mCount < clearCount) {
2795
- result += item.get ().mCount ;
2791
+ int result = 0 ;
2792
+ auto & inventorySlots = player->getInventory ().getSlots ();
2793
+ for (unsigned short slot = 0 ; slot < inventorySlots.size (); ++slot) {
2794
+ if (inventorySlots[slot]->getTypeName () == args[0 ].asString ().toString ()) {
2795
+ if (inventorySlots[slot]->mCount < clearCount) {
2796
+ result += inventorySlots[slot]->mCount ;
2797
+ } else {
2798
+ result += clearCount;
2796
2799
}
2797
- item. get ().remove ( clearCount);
2800
+ player-> getInventory ().removeItem (slot, clearCount);
2798
2801
}
2799
2802
}
2800
- for (std::reference_wrapper<ItemStack> item : player->getHandContainer ().getSlotCopies ()) {
2801
- if (item.get ().getTypeName () == args[0 ].asString ().toString ()) {
2802
- if (item.get ().mCount < clearCount) {
2803
- result += item.get ().mCount ;
2803
+ auto & handSlots = player->getHandContainer ().getSlots ();
2804
+ for (unsigned short slot = 0 ; slot < handSlots.size (); ++slot) {
2805
+ if (handSlots[slot]->getTypeName () == args[0 ].asString ().toString ()) {
2806
+ if (handSlots[slot]->mCount < clearCount) {
2807
+ result += handSlots[slot]->mCount ;
2808
+ } else {
2809
+ result += clearCount;
2804
2810
}
2805
- item. get ().remove ( clearCount);
2811
+ player-> getInventory ().removeItem (slot, clearCount);
2806
2812
}
2807
2813
}
2808
- for (std::reference_wrapper<ItemStack> item : player->getArmorContainer ().getSlotCopies ()) {
2809
- if (item.get ().getTypeName () == args[0 ].asString ().toString ()) {
2810
- if (item.get ().mCount < clearCount) {
2811
- result += item.get ().mCount ;
2814
+ auto & armorSlots = player->getArmorContainer ().getSlots ();
2815
+ for (unsigned short slot = 0 ; slot < armorSlots.size (); ++slot) {
2816
+ if (armorSlots[slot]->getTypeName () == args[0 ].asString ().toString ()) {
2817
+ if (armorSlots[slot]->mCount < clearCount) {
2818
+ result += armorSlots[slot]->mCount ;
2819
+ } else {
2820
+ result += clearCount;
2812
2821
}
2813
- item. get ().remove ( clearCount);
2822
+ player-> getInventory ().removeItem (slot, clearCount);
2814
2823
}
2815
2824
}
2825
+ player->refreshInventory ();
2816
2826
return Number::newNumber (result);
2817
2827
}
2818
2828
CATCH (" Fail in clearItem!" );
0 commit comments