Wieldhand: Allow overriding the hand
This commit is contained in:
parent
e4ee6548af
commit
785a9a6c1a
|
@ -1759,6 +1759,13 @@ Inventory locations
|
||||||
* `"nodemeta:<X>,<Y>,<Z>"`: Any node metadata
|
* `"nodemeta:<X>,<Y>,<Z>"`: Any node metadata
|
||||||
* `"detached:<name>"`: A detached inventory
|
* `"detached:<name>"`: A detached inventory
|
||||||
|
|
||||||
|
Player Inventory lists
|
||||||
|
----------------------
|
||||||
|
* `main`: list containing the default inventory
|
||||||
|
* `craft`: list containing the craft input
|
||||||
|
* `craftpreview`: list containing the craft output
|
||||||
|
* `hand`: list containing an override for the empty hand
|
||||||
|
|
||||||
`ColorString`
|
`ColorString`
|
||||||
-------------
|
-------------
|
||||||
`#RGB` defines a color in hexadecimal format.
|
`#RGB` defines a color in hexadecimal format.
|
||||||
|
|
|
@ -1341,6 +1341,42 @@ std::string PlayerSAO::getWieldList() const
|
||||||
return "main";
|
return "main";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemStack PlayerSAO::getWieldedItem() const
|
||||||
|
{
|
||||||
|
const Inventory *inv = getInventory();
|
||||||
|
ItemStack ret;
|
||||||
|
const InventoryList *mlist = inv->getList(getWieldList());
|
||||||
|
if (mlist && getWieldIndex() < (s32)mlist->getSize())
|
||||||
|
ret = mlist->getItem(getWieldIndex());
|
||||||
|
if (ret.name.empty()) {
|
||||||
|
const InventoryList *hlist = inv->getList("hand");
|
||||||
|
if (hlist)
|
||||||
|
ret = hlist->getItem(0);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlayerSAO::setWieldedItem(const ItemStack &item)
|
||||||
|
{
|
||||||
|
Inventory *inv = getInventory();
|
||||||
|
if (inv) {
|
||||||
|
InventoryList *mlist = inv->getList(getWieldList());
|
||||||
|
if (mlist) {
|
||||||
|
ItemStack olditem = mlist->getItem(getWieldIndex());
|
||||||
|
if (olditem.name.empty()) {
|
||||||
|
InventoryList *hlist = inv->getList("hand");
|
||||||
|
if (hlist) {
|
||||||
|
hlist->changeItem(0, item);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mlist->changeItem(getWieldIndex(), item);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int PlayerSAO::getWieldIndex() const
|
int PlayerSAO::getWieldIndex() const
|
||||||
{
|
{
|
||||||
return m_wield_index;
|
return m_wield_index;
|
||||||
|
|
|
@ -251,6 +251,8 @@ public:
|
||||||
const Inventory* getInventory() const;
|
const Inventory* getInventory() const;
|
||||||
InventoryLocation getInventoryLocation() const;
|
InventoryLocation getInventoryLocation() const;
|
||||||
std::string getWieldList() const;
|
std::string getWieldList() const;
|
||||||
|
ItemStack getWieldedItem() const;
|
||||||
|
bool setWieldedItem(const ItemStack &item);
|
||||||
int getWieldIndex() const;
|
int getWieldIndex() const;
|
||||||
void setWieldIndex(int i);
|
void setWieldIndex(int i);
|
||||||
|
|
||||||
|
|
17
src/game.cpp
17
src/game.cpp
|
@ -3684,6 +3684,12 @@ void Game::updateCamera(VolatileRunFlags *flags, u32 busy_time,
|
||||||
if (mlist && client->getPlayerItem() < mlist->getSize())
|
if (mlist && client->getPlayerItem() < mlist->getSize())
|
||||||
playeritem = mlist->getItem(client->getPlayerItem());
|
playeritem = mlist->getItem(client->getPlayerItem());
|
||||||
}
|
}
|
||||||
|
if (playeritem.getDefinition(itemdef_manager).name.empty()) { // override the hand
|
||||||
|
InventoryList *hlist = local_inventory->getList("hand");
|
||||||
|
if (hlist)
|
||||||
|
playeritem = hlist->getItem(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ToolCapabilities playeritem_toolcap =
|
ToolCapabilities playeritem_toolcap =
|
||||||
playeritem.getToolCapabilities(itemdef_manager);
|
playeritem.getToolCapabilities(itemdef_manager);
|
||||||
|
@ -3768,6 +3774,11 @@ void Game::processPlayerInteraction(GameRunData *runData,
|
||||||
playeritem = mlist->getItem(client->getPlayerItem());
|
playeritem = mlist->getItem(client->getPlayerItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (playeritem.getDefinition(itemdef_manager).name.empty()) { // override the hand
|
||||||
|
InventoryList *hlist = local_inventory->getList("hand");
|
||||||
|
if (hlist)
|
||||||
|
playeritem = hlist->getItem(0);
|
||||||
|
}
|
||||||
const ItemDefinition &playeritem_def =
|
const ItemDefinition &playeritem_def =
|
||||||
playeritem.getDefinition(itemdef_manager);
|
playeritem.getDefinition(itemdef_manager);
|
||||||
|
|
||||||
|
@ -4321,8 +4332,14 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
|
||||||
|
|
||||||
if (mlist && (client->getPlayerItem() < mlist->getSize())) {
|
if (mlist && (client->getPlayerItem() < mlist->getSize())) {
|
||||||
ItemStack item = mlist->getItem(client->getPlayerItem());
|
ItemStack item = mlist->getItem(client->getPlayerItem());
|
||||||
|
if (item.getDefinition(itemdef_manager).name.empty()) { // override the hand
|
||||||
|
InventoryList *hlist = local_inventory->getList("hand");
|
||||||
|
if (hlist)
|
||||||
|
item = hlist->getItem(0);
|
||||||
|
}
|
||||||
camera->wield(item);
|
camera->wield(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
runData->update_wielded_item_trigger = false;
|
runData->update_wielded_item_trigger = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1529,10 +1529,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
|
||||||
m_script->on_cheat(playersao, "finished_unknown_dig");
|
m_script->on_cheat(playersao, "finished_unknown_dig");
|
||||||
}
|
}
|
||||||
// Get player's wielded item
|
// Get player's wielded item
|
||||||
ItemStack playeritem;
|
ItemStack playeritem = playersao->getWieldedItem();
|
||||||
InventoryList *mlist = playersao->getInventory()->getList("main");
|
|
||||||
if (mlist != NULL)
|
|
||||||
playeritem = mlist->getItem(playersao->getWieldIndex());
|
|
||||||
ToolCapabilities playeritem_toolcap =
|
ToolCapabilities playeritem_toolcap =
|
||||||
playeritem.getToolCapabilities(m_itemdef);
|
playeritem.getToolCapabilities(m_itemdef);
|
||||||
// Get diggability and expected digging time
|
// Get diggability and expected digging time
|
||||||
|
|
|
@ -40,6 +40,7 @@ Player::Player(const char *name, IItemDefManager *idef):
|
||||||
|
|
||||||
inventory.clear();
|
inventory.clear();
|
||||||
inventory.addList("main", PLAYER_INVENTORY_SIZE);
|
inventory.addList("main", PLAYER_INVENTORY_SIZE);
|
||||||
|
inventory.addList("hand", 1);
|
||||||
InventoryList *craft = inventory.addList("craft", 9);
|
InventoryList *craft = inventory.addList("craft", 9);
|
||||||
craft->setWidth(3);
|
craft->setWidth(3);
|
||||||
inventory.addList("craftpreview", 1);
|
inventory.addList("craftpreview", 1);
|
||||||
|
|
Loading…
Reference in New Issue