diff --git a/Minecraft.World/ArmorStand.cpp b/Minecraft.World/ArmorStand.cpp index c6ccd322..81925869 100644 --- a/Minecraft.World/ArmorStand.cpp +++ b/Minecraft.World/ArmorStand.cpp @@ -106,6 +106,7 @@ bool ArmorStand::interact(shared_ptr player) float lookYDiff = -tan(pitchRad) * distHoriz; float hitY = (player->y + 1.62f + lookYDiff) - this->y; + int targetSlot = SLOT_WEAPON; if (hitY >= 0.1f && hitY < 0.55f) { targetSlot = SLOT_BOOTS; @@ -118,35 +119,39 @@ bool ArmorStand::interact(shared_ptr player) } shared_ptr playerItem = player->getCarriedItem(); + + + int slotToInteract = (playerItem != nullptr) ? getEquipmentSlotForItem(playerItem) : targetSlot; + if (isSlotDisabled(slotToInteract)) return false; + + shared_ptr standItem = getItemInSlot(slotToInteract); + + if (playerItem != nullptr) { - int correctSlot = getEquipmentSlotForItem(playerItem); - if (isSlotDisabled(correctSlot)) return false; + shared_ptr toPlace = ItemInstance::clone(playerItem); + toPlace->count = 1; + setEquippedSlot(slotToInteract, toPlace); - shared_ptr standItem = getItemInSlot(correctSlot); - - - shared_ptr toPlace = ItemInstance::clone(playerItem); - toPlace->count = 1; - setEquippedSlot(correctSlot, toPlace); - - - if (standItem != nullptr) { - - if (playerItem->count > 1) { - playerItem->remove(1); - if (!player->inventory->add(standItem)) spawnAtLocation(standItem, 0.0f); + if (standItem != nullptr) { + if (playerItem->count > 1) { + playerItem->remove(1); + if (!player->inventory->add(standItem)) spawnAtLocation(standItem, 0.0f); + } else { + player->inventory->setItem(player->inventory->selected, standItem); + } } else { - - player->inventory->setItem(player->inventory->selected, standItem); + playerItem->remove(1); } - } else { - - playerItem->remove(1); + } + + else if (standItem != nullptr) { + player->inventory->setItem(player->inventory->selected, standItem); + setEquippedSlot(slotToInteract, nullptr); } + return true; } -} bool ArmorStand::hurt(DamageSource *source, float damage) { if (isInvulnerable() || level->isClientSide || removed || isMarker()) return false;