Skip to content

Commit 919f249

Browse files
committed
fix: fix clearItem #186
1 parent 03902a9 commit 919f249

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/legacy/api/PlayerAPI.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "mc/enums/d_b_helpers/Category.h"
3434
#include "mc/nbt/ListTag.h"
3535
#include "mc/network/ConnectionRequest.h"
36-
#include "mc/network/NetworkIdentifier.h"
3736
#include "mc/network/ServerNetworkHandler.h"
3837
#include "mc/network/packet/BossEventPacket.h"
3938
#include "mc/network/packet/LevelChunkPacket.h"
@@ -56,7 +55,6 @@
5655
#include "mc/world/Minecraft.h"
5756
#include "mc/world/SimpleContainer.h"
5857
#include "mc/world/actor/ActorDamageByActorSource.h"
59-
#include "mc/world/actor/player/EnderChestContainer.h"
6058
#include "mc/world/actor/player/PlayerScoreSetFunction.h"
6159
#include "mc/world/effect/MobEffectInstance.h"
6260
#include "mc/world/events/BossEventUpdateType.h"
@@ -73,11 +71,9 @@
7371
#include <algorithm>
7472
#include <climits>
7573
#include <list>
76-
#include <mc/entity/EntityContext.h>
7774
#include <mc/entity/utilities/ActorEquipment.h>
7875
#include <mc/entity/utilities/ActorMobilityUtils.h>
7976
#include <mc/nbt/CompoundTag.h>
80-
#include <mc/world/SimpleContainer.h>
8177
#include <mc/world/actor/Actor.h>
8278
#include <mc/world/actor/SynchedActorData.h>
8379
#include <mc/world/actor/SynchedActorDataEntityWrapper.h>
@@ -88,14 +84,12 @@
8884
#include <mc/world/attribute/SharedAttributes.h>
8985
#include <mc/world/level/BlockSource.h>
9086
#include <mc/world/level/Command.h>
91-
#include <mc/world/level/IConstBlockSource.h>
9287
#include <mc/world/level/biome/Biome.h>
9388
#include <mc/world/level/material/Material.h>
9489
#include <mc/world/scores/Objective.h>
9590
#include <memory>
9691
#include <optional>
9792
#include <string>
98-
#include <unordered_map>
9993
#include <vector>
10094

10195
//////////////////// Class Definition ////////////////////
@@ -2890,33 +2884,48 @@ Local<Value> PlayerClass::clearItem(const Arguments& args) {
28902884
int result = 0;
28912885
auto& inventorySlots = player->getInventory().getSlots();
28922886
for (unsigned short slot = 0; slot < inventorySlots.size(); ++slot) {
2887+
if (clearCount <= 0) {
2888+
break;
2889+
}
28932890
if (inventorySlots[slot]->getTypeName() == args[0].asString().toString()) {
28942891
if (inventorySlots[slot]->mCount < clearCount) {
28952892
result += inventorySlots[slot]->mCount;
2893+
clearCount -= inventorySlots[slot]->mCount;
28962894
} else {
28972895
result += clearCount;
2896+
clearCount = 0;
28982897
}
28992898
player->getInventory().removeItem(slot, clearCount);
29002899
}
29012900
}
29022901
auto& handSlots = ActorEquipment::getHandContainer(player->getEntityContext()).getSlots();
29032902
for (unsigned short slot = 0; slot < handSlots.size(); ++slot) {
2903+
if (clearCount <= 0) {
2904+
break;
2905+
}
29042906
if (handSlots[slot]->getTypeName() == args[0].asString().toString()) {
29052907
if (handSlots[slot]->mCount < clearCount) {
29062908
result += handSlots[slot]->mCount;
2909+
clearCount -= handSlots[slot]->mCount;
29072910
} else {
29082911
result += clearCount;
2912+
clearCount = 0;
29092913
}
29102914
ActorEquipment::getHandContainer(player->getEntityContext()).removeItem(slot, clearCount);
29112915
}
29122916
}
29132917
auto& armorSlots = ActorEquipment::getArmorContainer(player->getEntityContext()).getSlots();
29142918
for (unsigned short slot = 0; slot < armorSlots.size(); ++slot) {
2919+
if (clearCount <= 0) {
2920+
break;
2921+
}
29152922
if (armorSlots[slot]->getTypeName() == args[0].asString().toString()) {
29162923
if (armorSlots[slot]->mCount < clearCount) {
29172924
result += armorSlots[slot]->mCount;
2925+
clearCount -= armorSlots[slot]->mCount;
29182926
} else {
29192927
result += clearCount;
2928+
clearCount = 0;
29202929
}
29212930
ActorEquipment::getArmorContainer(player->getEntityContext()).removeItem(slot, clearCount);
29222931
}

0 commit comments

Comments
 (0)