|
33 | 33 | #include "mc/enums/d_b_helpers/Category.h" |
34 | 34 | #include "mc/nbt/ListTag.h" |
35 | 35 | #include "mc/network/ConnectionRequest.h" |
36 | | -#include "mc/network/NetworkIdentifier.h" |
37 | 36 | #include "mc/network/ServerNetworkHandler.h" |
38 | 37 | #include "mc/network/packet/BossEventPacket.h" |
39 | 38 | #include "mc/network/packet/LevelChunkPacket.h" |
|
56 | 55 | #include "mc/world/Minecraft.h" |
57 | 56 | #include "mc/world/SimpleContainer.h" |
58 | 57 | #include "mc/world/actor/ActorDamageByActorSource.h" |
59 | | -#include "mc/world/actor/player/EnderChestContainer.h" |
60 | 58 | #include "mc/world/actor/player/PlayerScoreSetFunction.h" |
61 | 59 | #include "mc/world/effect/MobEffectInstance.h" |
62 | 60 | #include "mc/world/events/BossEventUpdateType.h" |
|
73 | 71 | #include <algorithm> |
74 | 72 | #include <climits> |
75 | 73 | #include <list> |
76 | | -#include <mc/entity/EntityContext.h> |
77 | 74 | #include <mc/entity/utilities/ActorEquipment.h> |
78 | 75 | #include <mc/entity/utilities/ActorMobilityUtils.h> |
79 | 76 | #include <mc/nbt/CompoundTag.h> |
80 | | -#include <mc/world/SimpleContainer.h> |
81 | 77 | #include <mc/world/actor/Actor.h> |
82 | 78 | #include <mc/world/actor/SynchedActorData.h> |
83 | 79 | #include <mc/world/actor/SynchedActorDataEntityWrapper.h> |
|
88 | 84 | #include <mc/world/attribute/SharedAttributes.h> |
89 | 85 | #include <mc/world/level/BlockSource.h> |
90 | 86 | #include <mc/world/level/Command.h> |
91 | | -#include <mc/world/level/IConstBlockSource.h> |
92 | 87 | #include <mc/world/level/biome/Biome.h> |
93 | 88 | #include <mc/world/level/material/Material.h> |
94 | 89 | #include <mc/world/scores/Objective.h> |
95 | 90 | #include <memory> |
96 | 91 | #include <optional> |
97 | 92 | #include <string> |
98 | | -#include <unordered_map> |
99 | 93 | #include <vector> |
100 | 94 |
|
101 | 95 | //////////////////// Class Definition //////////////////// |
@@ -2890,33 +2884,48 @@ Local<Value> PlayerClass::clearItem(const Arguments& args) { |
2890 | 2884 | int result = 0; |
2891 | 2885 | auto& inventorySlots = player->getInventory().getSlots(); |
2892 | 2886 | for (unsigned short slot = 0; slot < inventorySlots.size(); ++slot) { |
| 2887 | + if (clearCount <= 0) { |
| 2888 | + break; |
| 2889 | + } |
2893 | 2890 | if (inventorySlots[slot]->getTypeName() == args[0].asString().toString()) { |
2894 | 2891 | if (inventorySlots[slot]->mCount < clearCount) { |
2895 | 2892 | result += inventorySlots[slot]->mCount; |
| 2893 | + clearCount -= inventorySlots[slot]->mCount; |
2896 | 2894 | } else { |
2897 | 2895 | result += clearCount; |
| 2896 | + clearCount = 0; |
2898 | 2897 | } |
2899 | 2898 | player->getInventory().removeItem(slot, clearCount); |
2900 | 2899 | } |
2901 | 2900 | } |
2902 | 2901 | auto& handSlots = ActorEquipment::getHandContainer(player->getEntityContext()).getSlots(); |
2903 | 2902 | for (unsigned short slot = 0; slot < handSlots.size(); ++slot) { |
| 2903 | + if (clearCount <= 0) { |
| 2904 | + break; |
| 2905 | + } |
2904 | 2906 | if (handSlots[slot]->getTypeName() == args[0].asString().toString()) { |
2905 | 2907 | if (handSlots[slot]->mCount < clearCount) { |
2906 | 2908 | result += handSlots[slot]->mCount; |
| 2909 | + clearCount -= handSlots[slot]->mCount; |
2907 | 2910 | } else { |
2908 | 2911 | result += clearCount; |
| 2912 | + clearCount = 0; |
2909 | 2913 | } |
2910 | 2914 | ActorEquipment::getHandContainer(player->getEntityContext()).removeItem(slot, clearCount); |
2911 | 2915 | } |
2912 | 2916 | } |
2913 | 2917 | auto& armorSlots = ActorEquipment::getArmorContainer(player->getEntityContext()).getSlots(); |
2914 | 2918 | for (unsigned short slot = 0; slot < armorSlots.size(); ++slot) { |
| 2919 | + if (clearCount <= 0) { |
| 2920 | + break; |
| 2921 | + } |
2915 | 2922 | if (armorSlots[slot]->getTypeName() == args[0].asString().toString()) { |
2916 | 2923 | if (armorSlots[slot]->mCount < clearCount) { |
2917 | 2924 | result += armorSlots[slot]->mCount; |
| 2925 | + clearCount -= armorSlots[slot]->mCount; |
2918 | 2926 | } else { |
2919 | 2927 | result += clearCount; |
| 2928 | + clearCount = 0; |
2920 | 2929 | } |
2921 | 2930 | ActorEquipment::getArmorContainer(player->getEntityContext()).removeItem(slot, clearCount); |
2922 | 2931 | } |
|
0 commit comments