FATAL_ERROR_IF(!puncher, "Punch action called without SAO");
s32 old_hp = getHP();
- const ItemStack &punchitem = puncher->getWieldedItem();
+ ItemStack selected_item, hand_item;
+ ItemStack tool_item = puncher->getWieldedItem(&selected_item, &hand_item);
PunchDamageResult result = getPunchDamage(
m_armor_groups,
toolcap,
- &punchitem,
+ &tool_item,
time_from_last_punch);
bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
return m_player->getWieldIndex();
}
-ItemStack PlayerSAO::getWieldedItem() const
+ItemStack PlayerSAO::getWieldedItem(ItemStack *selected, ItemStack *hand) const
{
- ItemStack selected_item, hand_item;
- return m_player->getWieldedItem(&selected_item, &hand_item);
+ return m_player->getWieldedItem(selected, hand);
}
bool PlayerSAO::setWieldedItem(const ItemStack &item)
if (pointed_object->isGone())
return;
- ItemStack punchitem = playersao->getWieldedItem();
+ ItemStack selected_item, hand_item;
+ ItemStack tool_item = playersao->getWieldedItem(&selected_item, &hand_item);
ToolCapabilities toolcap =
- punchitem.getToolCapabilities(m_itemdef);
+ tool_item.getToolCapabilities(m_itemdef);
v3f dir = (pointed_object->getBasePosition() -
(playersao->getBasePosition() + playersao->getEyeOffset())
).normalize();
3: place block or right-click object
*/
else if (action == INTERACT_PLACE) {
- ItemStack item = playersao->getWieldedItem();
+ ItemStack selected_item;
+ playersao->getWieldedItem(&selected_item, nullptr);
// Reset build time counter
if (pointed.type == POINTEDTHING_NODE &&
- item.getDefinition(m_itemdef).type == ITEM_NODE)
+ selected_item.getDefinition(m_itemdef).type == ITEM_NODE)
getClient(pkt->getPeerId())->m_time_from_building = 0.0;
if (pointed.type == POINTEDTHING_OBJECT) {
// Do stuff
pointed_object->rightClick(playersao);
- }
- else if (m_script->item_OnPlace(
- item, playersao, pointed)) {
+ } else if (m_script->item_OnPlace(
+ selected_item, playersao, pointed)) {
// Placement was handled in lua
// Apply returned ItemStack
- if (playersao->setWieldedItem(item)) {
+ if (playersao->setWieldedItem(selected_item)) {
SendInventory(playersao, true);
}
}
RemoteClient *client = getClient(pkt->getPeerId());
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_above, BS));
v3s16 blockpos2 = getNodeBlockPos(floatToInt(pointed_pos_under, BS));
- if (!item.getDefinition(m_itemdef).node_placement_prediction.empty()) {
+ if (!selected_item.getDefinition(m_itemdef).node_placement_prediction.empty()) {
client->SetBlockNotSent(blockpos);
if (blockpos2 != blockpos) {
client->SetBlockNotSent(blockpos2);
4: use
*/
else if (action == INTERACT_USE) {
- ItemStack item = playersao->getWieldedItem();
+ ItemStack selected_item;
+ playersao->getWieldedItem(&selected_item, nullptr);
- actionstream << player->getName() << " uses " << item.name
+ actionstream << player->getName() << " uses " << selected_item.name
<< ", pointing at " << pointed.dump() << std::endl;
if (m_script->item_OnUse(
- item, playersao, pointed)) {
+ selected_item, playersao, pointed)) {
// Apply returned ItemStack
- if (playersao->setWieldedItem(item)) {
+ if (playersao->setWieldedItem(selected_item)) {
SendInventory(playersao, true);
}
}
5: rightclick air
*/
else if (action == INTERACT_ACTIVATE) {
- ItemStack item = playersao->getWieldedItem();
+ ItemStack selected_item;
+ playersao->getWieldedItem(&selected_item, nullptr);
actionstream << player->getName() << " activates "
- << item.name << std::endl;
+ << selected_item.name << std::endl;
if (m_script->item_OnSecondaryUse(
- item, playersao)) {
- if( playersao->setWieldedItem(item)) {
+ selected_item, playersao)) {
+ if (playersao->setWieldedItem(selected_item)) {
SendInventory(playersao, true);
}
}