forked from Mirrorlandia_minetest/minetest
Wieldhand: Specify which ItemStack to use (#8961)
Makes 'get_wield_item' to return the "main" ItemStack
This commit is contained in:
parent
47da640d77
commit
5fa614d97e
@ -2556,8 +2556,7 @@ Player Inventory lists
|
|||||||
* `craftresult`: list containing the crafted output
|
* `craftresult`: list containing the crafted output
|
||||||
* `hand`: list containing an override for the empty hand
|
* `hand`: list containing an override for the empty hand
|
||||||
* Is not created automatically, use `InvRef:set_size`
|
* Is not created automatically, use `InvRef:set_size`
|
||||||
|
* Is only used to enhance the empty hand's tool capabilities
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Colors
|
Colors
|
||||||
|
@ -638,12 +638,13 @@ int LuaEntitySAO::punch(v3f dir,
|
|||||||
FATAL_ERROR_IF(!puncher, "Punch action called without SAO");
|
FATAL_ERROR_IF(!puncher, "Punch action called without SAO");
|
||||||
|
|
||||||
s32 old_hp = getHP();
|
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(
|
PunchDamageResult result = getPunchDamage(
|
||||||
m_armor_groups,
|
m_armor_groups,
|
||||||
toolcap,
|
toolcap,
|
||||||
&punchitem,
|
&tool_item,
|
||||||
time_from_last_punch);
|
time_from_last_punch);
|
||||||
|
|
||||||
bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
|
bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
|
||||||
@ -1376,10 +1377,9 @@ u16 PlayerSAO::getWieldIndex() const
|
|||||||
return m_player->getWieldIndex();
|
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, hand);
|
||||||
return m_player->getWieldedItem(&selected_item, &hand_item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlayerSAO::setWieldedItem(const ItemStack &item)
|
bool PlayerSAO::setWieldedItem(const ItemStack &item)
|
||||||
|
@ -277,7 +277,7 @@ public:
|
|||||||
void setInventoryModified() {}
|
void setInventoryModified() {}
|
||||||
std::string getWieldList() const { return "main"; }
|
std::string getWieldList() const { return "main"; }
|
||||||
u16 getWieldIndex() const;
|
u16 getWieldIndex() const;
|
||||||
ItemStack getWieldedItem() const;
|
ItemStack getWieldedItem(ItemStack *selected, ItemStack *hand = nullptr) const;
|
||||||
bool setWieldedItem(const ItemStack &item);
|
bool setWieldedItem(const ItemStack &item);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1150,9 +1150,10 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
|
|||||||
if (pointed_object->isGone())
|
if (pointed_object->isGone())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ItemStack punchitem = playersao->getWieldedItem();
|
ItemStack selected_item, hand_item;
|
||||||
|
ItemStack tool_item = playersao->getWieldedItem(&selected_item, &hand_item);
|
||||||
ToolCapabilities toolcap =
|
ToolCapabilities toolcap =
|
||||||
punchitem.getToolCapabilities(m_itemdef);
|
tool_item.getToolCapabilities(m_itemdef);
|
||||||
v3f dir = (pointed_object->getBasePosition() -
|
v3f dir = (pointed_object->getBasePosition() -
|
||||||
(playersao->getBasePosition() + playersao->getEyeOffset())
|
(playersao->getBasePosition() + playersao->getEyeOffset())
|
||||||
).normalize();
|
).normalize();
|
||||||
@ -1291,11 +1292,12 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
|
|||||||
3: place block or right-click object
|
3: place block or right-click object
|
||||||
*/
|
*/
|
||||||
else if (action == INTERACT_PLACE) {
|
else if (action == INTERACT_PLACE) {
|
||||||
ItemStack item = playersao->getWieldedItem();
|
ItemStack selected_item;
|
||||||
|
playersao->getWieldedItem(&selected_item, nullptr);
|
||||||
|
|
||||||
// Reset build time counter
|
// Reset build time counter
|
||||||
if (pointed.type == POINTEDTHING_NODE &&
|
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;
|
getClient(pkt->getPeerId())->m_time_from_building = 0.0;
|
||||||
|
|
||||||
if (pointed.type == POINTEDTHING_OBJECT) {
|
if (pointed.type == POINTEDTHING_OBJECT) {
|
||||||
@ -1311,13 +1313,12 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
|
|||||||
|
|
||||||
// Do stuff
|
// Do stuff
|
||||||
pointed_object->rightClick(playersao);
|
pointed_object->rightClick(playersao);
|
||||||
}
|
} else if (m_script->item_OnPlace(
|
||||||
else if (m_script->item_OnPlace(
|
selected_item, playersao, pointed)) {
|
||||||
item, playersao, pointed)) {
|
|
||||||
// Placement was handled in lua
|
// Placement was handled in lua
|
||||||
|
|
||||||
// Apply returned ItemStack
|
// Apply returned ItemStack
|
||||||
if (playersao->setWieldedItem(item)) {
|
if (playersao->setWieldedItem(selected_item)) {
|
||||||
SendInventory(playersao, true);
|
SendInventory(playersao, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1327,7 +1328,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
|
|||||||
RemoteClient *client = getClient(pkt->getPeerId());
|
RemoteClient *client = getClient(pkt->getPeerId());
|
||||||
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_above, BS));
|
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_above, BS));
|
||||||
v3s16 blockpos2 = getNodeBlockPos(floatToInt(pointed_pos_under, 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);
|
client->SetBlockNotSent(blockpos);
|
||||||
if (blockpos2 != blockpos) {
|
if (blockpos2 != blockpos) {
|
||||||
client->SetBlockNotSent(blockpos2);
|
client->SetBlockNotSent(blockpos2);
|
||||||
@ -1345,15 +1346,16 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
|
|||||||
4: use
|
4: use
|
||||||
*/
|
*/
|
||||||
else if (action == INTERACT_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;
|
<< ", pointing at " << pointed.dump() << std::endl;
|
||||||
|
|
||||||
if (m_script->item_OnUse(
|
if (m_script->item_OnUse(
|
||||||
item, playersao, pointed)) {
|
selected_item, playersao, pointed)) {
|
||||||
// Apply returned ItemStack
|
// Apply returned ItemStack
|
||||||
if (playersao->setWieldedItem(item)) {
|
if (playersao->setWieldedItem(selected_item)) {
|
||||||
SendInventory(playersao, true);
|
SendInventory(playersao, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1364,14 +1366,15 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
|
|||||||
5: rightclick air
|
5: rightclick air
|
||||||
*/
|
*/
|
||||||
else if (action == INTERACT_ACTIVATE) {
|
else if (action == INTERACT_ACTIVATE) {
|
||||||
ItemStack item = playersao->getWieldedItem();
|
ItemStack selected_item;
|
||||||
|
playersao->getWieldedItem(&selected_item, nullptr);
|
||||||
|
|
||||||
actionstream << player->getName() << " activates "
|
actionstream << player->getName() << " activates "
|
||||||
<< item.name << std::endl;
|
<< selected_item.name << std::endl;
|
||||||
|
|
||||||
if (m_script->item_OnSecondaryUse(
|
if (m_script->item_OnSecondaryUse(
|
||||||
item, playersao)) {
|
selected_item, playersao)) {
|
||||||
if( playersao->setWieldedItem(item)) {
|
if (playersao->setWieldedItem(selected_item)) {
|
||||||
SendInventory(playersao, true);
|
SendInventory(playersao, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,9 @@ int ObjectRef::l_get_wielded_item(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaItemStack::create(L, co->getWieldedItem());
|
ItemStack selected_item;
|
||||||
|
co->getWieldedItem(&selected_item, nullptr);
|
||||||
|
LuaItemStack::create(L, selected_item);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,25 +68,16 @@ float ServerActiveObject::getMinimumSavedMovement()
|
|||||||
return 2.0*BS;
|
return 2.0*BS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack ServerActiveObject::getWieldedItem() const
|
ItemStack ServerActiveObject::getWieldedItem(ItemStack *selected, ItemStack *hand) const
|
||||||
{
|
{
|
||||||
const Inventory *inv = getInventory();
|
*selected = ItemStack();
|
||||||
if(inv)
|
if (hand)
|
||||||
{
|
*hand = ItemStack();
|
||||||
const InventoryList *list = inv->getList(getWieldList());
|
|
||||||
if(list && (getWieldIndex() < (s32)list->getSize()))
|
|
||||||
return list->getItem(getWieldIndex());
|
|
||||||
}
|
|
||||||
return ItemStack();
|
return ItemStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerActiveObject::setWieldedItem(const ItemStack &item)
|
bool ServerActiveObject::setWieldedItem(const ItemStack &item)
|
||||||
{
|
{
|
||||||
if(Inventory *inv = getInventory()) {
|
|
||||||
if (InventoryList *list = inv->getList(getWieldList())) {
|
|
||||||
list->changeItem(getWieldIndex(), item);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,8 @@ public:
|
|||||||
{ return ""; }
|
{ return ""; }
|
||||||
virtual u16 getWieldIndex() const
|
virtual u16 getWieldIndex() const
|
||||||
{ return 0; }
|
{ return 0; }
|
||||||
virtual ItemStack getWieldedItem() const;
|
virtual ItemStack getWieldedItem(ItemStack *selected,
|
||||||
|
ItemStack *hand = nullptr) const;
|
||||||
virtual bool setWieldedItem(const ItemStack &item);
|
virtual bool setWieldedItem(const ItemStack &item);
|
||||||
inline void attachParticleSpawner(u32 id)
|
inline void attachParticleSpawner(u32 id)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user