mirror of https://github.com/minetest/minetest.git
Adding inventory callbacks API
Geting rid of another old branch fixing bugs
This commit is contained in:
parent
74eb7f50c9
commit
7bff58d5d4
|
@ -553,6 +553,15 @@ core.registered_craft_predicts, core.register_craft_predict = make_registration(
|
|||
core.registered_on_protection_violation, core.register_on_protection_violation = make_registration()
|
||||
core.registered_on_item_eats, core.register_on_item_eat = make_registration()
|
||||
core.registered_on_punchplayers, core.register_on_punchplayer = make_registration()
|
||||
core.registered_on_player_inventory_remove_item, core.register_on_player_inventory_remove_item = make_registration()
|
||||
core.registered_on_player_inventory_change_item, core.register_on_player_inventory_change_item = make_registration()
|
||||
core.registered_on_player_inventory_add_item, core.register_on_player_inventory_add_item = make_registration()
|
||||
core.registered_on_nodemeta_inventory_remove_item, core.register_on_nodemeta_inventory_remove_item = make_registration()
|
||||
core.registered_on_nodemeta_inventory_change_item, core.register_on_nodemeta_inventory_change_item = make_registration()
|
||||
core.registered_on_nodemeta_inventory_add_item, core.register_on_nodemeta_inventory_add_item = make_registration()
|
||||
core.registered_on_detached_inventory_remove_item, core.register_on_detached_inventory_remove_item = make_registration()
|
||||
core.registered_on_detached_inventory_change_item, core.register_on_detached_inventory_change_item = make_registration()
|
||||
core.registered_on_detached_inventory_add_item, core.register_on_detached_inventory_add_item = make_registration()
|
||||
|
||||
--
|
||||
-- Compatibility for on_mapgen_init()
|
||||
|
|
|
@ -2040,6 +2040,30 @@ Call these functions only at load time!
|
|||
* `minetest.register_on_item_eat(func(hp_change, replace_with_item, itemstack, user, pointed_thing))`
|
||||
* Called when an item is eaten, by `minetest.item_eat`
|
||||
* Return `true` or `itemstack` to cancel the default item eat response (i.e.: hp increase)
|
||||
* `minetest.register_on_nodemeta_inventory_add_item(func(pos, list_name, slot, stack))`
|
||||
* Called when any node metadata inventory receive item.
|
||||
* 'pos' - {'x','y','z'} - absolute position of affected node with metadata.
|
||||
* `minetest.register_on_nodemeta_inventory_change_item(func(pos, list_name, slot, old_item, new_item))`
|
||||
* Called when any node metadata inventory change it content in slot number 'slot' from 'old_item' ItemStack to 'new_item' ItemStack.
|
||||
* 'pos' - {'x','y','z'} - absolute position of affected node with metadata.
|
||||
* `minetest.register_on_nodemeta_inventory_remove_item(func(pos, list_name, stack))`
|
||||
* Called when any node metadata inventory loose item.
|
||||
* 'pos' - {'x','y','z'} - absolute position of affected node with metadata.
|
||||
* `minetest.register_on_detached_inventory_add_item(func(name, list_name, slot, stack))`
|
||||
* Called when any detached inventory receive item.
|
||||
* 'name' - String, name of detached inventory.
|
||||
* `minetest.register_on_detached_inventory_change_item(func(name, list_name, slot, old_item, new_item))`
|
||||
* Called when any detached inventory change it content in slot number 'slot' from 'old_item' ItemStack to 'new_item' ItemStack.
|
||||
* 'name' - String, name of detached inventory.
|
||||
* `minetest.register_on_detached_inventory_remove_item(func(name, list_name, stack))`
|
||||
* Called when any detached inventory loose item.
|
||||
* 'name' - String, name of detached inventory.
|
||||
* `minetest.register_on_player_inventory_add_item(func(player, list_name, slot, stack))`
|
||||
* Called when any player receive item.
|
||||
* `minetest.register_on_player_inventory_change_item(func(player, list_name, slot, old_item, new_item))`
|
||||
* Called when any players' inventory change it content in slot number 'slot' from 'old_item' ItemStack to 'new_item' ItemStack.
|
||||
* `minetest.register_on_player_inventory_remove_item(func(player, list_name, stack))`
|
||||
* Called when any player loose item.
|
||||
|
||||
### Other registration functions
|
||||
* `minetest.register_chatcommand(cmd, chatcommand definition)`
|
||||
|
|
|
@ -145,7 +145,7 @@ static bool content_nodemeta_deserialize_legacy_meta(
|
|||
|
||||
void content_nodemeta_deserialize_legacy(std::istream &is,
|
||||
NodeMetadataList *meta, NodeTimerList *timers,
|
||||
IItemDefManager *item_def_mgr)
|
||||
IItemDefManager *item_def_mgr, v3s16 relative_mapblock_pos)
|
||||
{
|
||||
meta->clear();
|
||||
timers->clear();
|
||||
|
@ -181,7 +181,7 @@ void content_nodemeta_deserialize_legacy(std::istream &is,
|
|||
continue;
|
||||
}
|
||||
|
||||
NodeMetadata *data = new NodeMetadata(item_def_mgr);
|
||||
NodeMetadata *data = new NodeMetadata(item_def_mgr, relative_mapblock_pos + p);
|
||||
bool need_timer = content_nodemeta_deserialize_legacy_meta(is, data);
|
||||
meta->set(p, data);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define CONTENT_NODEMETA_HEADER
|
||||
|
||||
#include <iostream>
|
||||
#include "irr_v3d.h" // For v3s16
|
||||
|
||||
class NodeMetadataList;
|
||||
class NodeTimerList;
|
||||
|
@ -32,7 +33,7 @@ class IItemDefManager;
|
|||
|
||||
void content_nodemeta_deserialize_legacy(std::istream &is,
|
||||
NodeMetadataList *meta, NodeTimerList *timers,
|
||||
IItemDefManager *item_def_mgr);
|
||||
IItemDefManager *item_def_mgr, v3s16 relative_mapblock_pos);
|
||||
|
||||
void content_nodemeta_serialize_legacy(std::ostream &os, NodeMetadataList *meta);
|
||||
|
||||
|
|
|
@ -396,8 +396,8 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
|
|||
(*ii).second.X, (*ii).second.Y)); // m_bone_position.size
|
||||
}
|
||||
os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
|
||||
for (UNORDERED_SET<int>::const_iterator ii = m_attachment_child_ids.begin();
|
||||
(ii != m_attachment_child_ids.end()); ++ii) {
|
||||
for (UNORDERED_SET<int>::const_iterator ii = m_attachment_child_ids.begin();
|
||||
ii != m_attachment_child_ids.end(); ++ii) {
|
||||
if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) {
|
||||
os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(), obj->getClientInitializationData(protocol_version)));
|
||||
}
|
||||
|
@ -888,7 +888,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
|
|||
m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
|
||||
m_physics_override_sneak_glitch)); // 5
|
||||
os << serializeLongString(gob_cmd_update_nametag_attributes(m_prop.nametag_color)); // 6 (GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only.
|
||||
for (UNORDERED_SET<int>::const_iterator ii = m_attachment_child_ids.begin();
|
||||
for (UNORDERED_SET<int>::const_iterator ii = m_attachment_child_ids.begin();
|
||||
ii != m_attachment_child_ids.end(); ++ii) {
|
||||
if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) {
|
||||
os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(), obj->getClientInitializationData(protocol_version)));
|
||||
|
|
|
@ -2193,7 +2193,8 @@ bool Game::createClient(const std::string &playername,
|
|||
sky = new Sky(smgr->getRootSceneNode(), smgr, -1, texture_src);
|
||||
skybox = NULL; // This is used/set later on in the main run loop
|
||||
|
||||
local_inventory = new Inventory(itemdef_manager);
|
||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||
local_inventory = new Inventory(itemdef_manager, player);
|
||||
|
||||
if (!(sky && local_inventory)) {
|
||||
*error_message = "Memory allocation error (sky or local inventory)";
|
||||
|
@ -2224,7 +2225,6 @@ bool Game::createClient(const std::string &playername,
|
|||
str += L"]";
|
||||
device->setWindowCaption(str.c_str());
|
||||
|
||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||
player->hurt_tilt_timer = 0;
|
||||
player->hurt_tilt_strength = 0;
|
||||
|
||||
|
|
|
@ -434,12 +434,13 @@ ItemStack ItemStack::peekItem(u32 peekcount) const
|
|||
Inventory
|
||||
*/
|
||||
|
||||
InventoryList::InventoryList(std::string name, u32 size, IItemDefManager *itemdef)
|
||||
InventoryList::InventoryList(std::string name, u32 size, IItemDefManager *itemdef, InventoryChangeReceiver *rec)
|
||||
{
|
||||
m_name = name;
|
||||
m_size = size;
|
||||
m_width = 0;
|
||||
m_itemdef = itemdef;
|
||||
m_rec=rec;
|
||||
clearItems();
|
||||
//m_dirty = false;
|
||||
}
|
||||
|
@ -564,6 +565,7 @@ InventoryList & InventoryList::operator = (const InventoryList &other)
|
|||
m_width = other.m_width;
|
||||
m_name = other.m_name;
|
||||
m_itemdef = other.m_itemdef;
|
||||
m_rec = other.m_rec;
|
||||
//setDirty(true);
|
||||
|
||||
return *this;
|
||||
|
@ -632,24 +634,26 @@ ItemStack& InventoryList::getItem(u32 i)
|
|||
return m_items[i];
|
||||
}
|
||||
|
||||
ItemStack InventoryList::changeItem(u32 i, const ItemStack &newitem)
|
||||
ItemStack InventoryList::changeItem(GameScripting *script_interface, u32 i, const ItemStack &newitem)
|
||||
{
|
||||
if(i >= m_items.size())
|
||||
return newitem;
|
||||
|
||||
ItemStack olditem = m_items[i];
|
||||
m_items[i] = newitem;
|
||||
m_rec->on_change_item(script_interface, this, i, olditem, newitem);
|
||||
//setDirty(true);
|
||||
return olditem;
|
||||
}
|
||||
|
||||
void InventoryList::deleteItem(u32 i)
|
||||
void InventoryList::deleteItem(GameScripting *script_interface, u32 i)
|
||||
{
|
||||
assert(i < m_items.size()); // Pre-condition
|
||||
m_rec->on_remove_item(script_interface, this, m_items[i]);
|
||||
m_items[i].clear();
|
||||
}
|
||||
|
||||
ItemStack InventoryList::addItem(const ItemStack &newitem_)
|
||||
ItemStack InventoryList::addItem(GameScripting *script_interface, const ItemStack &newitem_)
|
||||
{
|
||||
ItemStack newitem = newitem_;
|
||||
|
||||
|
@ -665,7 +669,7 @@ ItemStack InventoryList::addItem(const ItemStack &newitem_)
|
|||
if(m_items[i].empty())
|
||||
continue;
|
||||
// Try adding
|
||||
newitem = addItem(i, newitem);
|
||||
newitem = addItem(script_interface, i, newitem);
|
||||
if(newitem.empty())
|
||||
return newitem; // All was eaten
|
||||
}
|
||||
|
@ -679,7 +683,7 @@ ItemStack InventoryList::addItem(const ItemStack &newitem_)
|
|||
if(!m_items[i].empty())
|
||||
continue;
|
||||
// Try adding
|
||||
newitem = addItem(i, newitem);
|
||||
newitem = addItem(script_interface, i, newitem);
|
||||
if(newitem.empty())
|
||||
return newitem; // All was eaten
|
||||
}
|
||||
|
@ -688,12 +692,16 @@ ItemStack InventoryList::addItem(const ItemStack &newitem_)
|
|||
return newitem;
|
||||
}
|
||||
|
||||
ItemStack InventoryList::addItem(u32 i, const ItemStack &newitem)
|
||||
ItemStack InventoryList::addItem(GameScripting *script_interface, u32 i, const ItemStack &newitem)
|
||||
{
|
||||
if(i >= m_items.size())
|
||||
return newitem;
|
||||
|
||||
ItemStack leftover = m_items[i].addItem(newitem, m_itemdef);
|
||||
if (leftover.count != newitem.count) {
|
||||
ItemStack added_item(newitem.name,newitem.count - leftover.count, newitem.wear, newitem.metadata, m_itemdef);
|
||||
m_rec->on_add_item(script_interface, this, i, added_item);
|
||||
}
|
||||
//if(leftover != newitem)
|
||||
// setDirty(true);
|
||||
return leftover;
|
||||
|
@ -747,7 +755,7 @@ bool InventoryList::containsItem(const ItemStack &item) const
|
|||
return false;
|
||||
}
|
||||
|
||||
ItemStack InventoryList::removeItem(const ItemStack &item)
|
||||
ItemStack InventoryList::removeItem(GameScripting *script_interface, const ItemStack &item)
|
||||
{
|
||||
ItemStack removed;
|
||||
for(std::vector<ItemStack>::reverse_iterator
|
||||
|
@ -762,10 +770,11 @@ ItemStack InventoryList::removeItem(const ItemStack &item)
|
|||
break;
|
||||
}
|
||||
}
|
||||
m_rec->on_remove_item(script_interface, this, removed);
|
||||
return removed;
|
||||
}
|
||||
|
||||
ItemStack InventoryList::takeItem(u32 i, u32 takecount)
|
||||
ItemStack InventoryList::takeItem(GameScripting *script_interface, u32 i, u32 takecount)
|
||||
{
|
||||
if(i >= m_items.size())
|
||||
return ItemStack();
|
||||
|
@ -773,6 +782,7 @@ ItemStack InventoryList::takeItem(u32 i, u32 takecount)
|
|||
ItemStack taken = m_items[i].takeItem(takecount);
|
||||
//if(!taken.empty())
|
||||
// setDirty(true);
|
||||
m_rec->on_remove_item(script_interface, this, taken);
|
||||
return taken;
|
||||
}
|
||||
|
||||
|
@ -784,14 +794,14 @@ ItemStack InventoryList::peekItem(u32 i, u32 peekcount) const
|
|||
return m_items[i].peekItem(peekcount);
|
||||
}
|
||||
|
||||
void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count)
|
||||
void InventoryList::moveItemSomewhere(GameScripting *script_interface, u32 i, InventoryList *dest, u32 count)
|
||||
{
|
||||
// Take item from source list
|
||||
ItemStack item1;
|
||||
if (count == 0)
|
||||
item1 = changeItem(i, ItemStack());
|
||||
item1 = changeItem(script_interface, i, ItemStack());
|
||||
else
|
||||
item1 = takeItem(i, count);
|
||||
item1 = takeItem(script_interface, i, count);
|
||||
|
||||
if (item1.empty())
|
||||
return;
|
||||
|
@ -801,7 +811,7 @@ void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count)
|
|||
// First try all the non-empty slots
|
||||
for (u32 dest_i = 0; dest_i < dest_size; dest_i++) {
|
||||
if (!m_items[dest_i].empty()) {
|
||||
item1 = dest->addItem(dest_i, item1);
|
||||
item1 = dest->addItem(script_interface, dest_i, item1);
|
||||
if (item1.empty()) return;
|
||||
}
|
||||
}
|
||||
|
@ -809,17 +819,17 @@ void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count)
|
|||
// Then try all the empty ones
|
||||
for (u32 dest_i = 0; dest_i < dest_size; dest_i++) {
|
||||
if (m_items[dest_i].empty()) {
|
||||
item1 = dest->addItem(dest_i, item1);
|
||||
item1 = dest->addItem(script_interface, dest_i, item1);
|
||||
if (item1.empty()) return;
|
||||
}
|
||||
}
|
||||
|
||||
// If we reach this, the item was not fully added
|
||||
// Add the remaining part back to the source item
|
||||
addItem(i, item1);
|
||||
addItem(script_interface, i, item1);
|
||||
}
|
||||
|
||||
u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i,
|
||||
u32 InventoryList::moveItem(GameScripting *script_interface, u32 i, InventoryList *dest, u32 dest_i,
|
||||
u32 count, bool swap_if_needed, bool *did_swap)
|
||||
{
|
||||
if(this == dest && i == dest_i)
|
||||
|
@ -828,16 +838,16 @@ u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i,
|
|||
// Take item from source list
|
||||
ItemStack item1;
|
||||
if(count == 0)
|
||||
item1 = changeItem(i, ItemStack());
|
||||
item1 = changeItem(script_interface, i, ItemStack());
|
||||
else
|
||||
item1 = takeItem(i, count);
|
||||
item1 = takeItem(script_interface, i, count);
|
||||
|
||||
if(item1.empty())
|
||||
return 0;
|
||||
|
||||
// Try to add the item to destination list
|
||||
u32 oldcount = item1.count;
|
||||
item1 = dest->addItem(dest_i, item1);
|
||||
item1 = dest->addItem(script_interface, dest_i, item1);
|
||||
|
||||
// If something is returned, the item was not fully added
|
||||
if(!item1.empty())
|
||||
|
@ -847,7 +857,7 @@ u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i,
|
|||
|
||||
// If something else is returned, part of the item was left unadded.
|
||||
// Add the other part back to the source item
|
||||
addItem(i, item1);
|
||||
addItem(script_interface, i, item1);
|
||||
|
||||
// If olditem is returned, nothing was added.
|
||||
// Swap the items
|
||||
|
@ -857,16 +867,63 @@ u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i,
|
|||
*did_swap = true;
|
||||
}
|
||||
// Take item from source list
|
||||
item1 = changeItem(i, ItemStack());
|
||||
item1 = changeItem(script_interface, i, ItemStack());
|
||||
// Adding was not possible, swap the items.
|
||||
ItemStack item2 = dest->changeItem(dest_i, item1);
|
||||
ItemStack item2 = dest->changeItem(script_interface, dest_i, item1);
|
||||
// Put item from destination list to the source list
|
||||
changeItem(i, item2);
|
||||
changeItem(script_interface, i, item2);
|
||||
}
|
||||
}
|
||||
return (oldcount - item1.count);
|
||||
}
|
||||
|
||||
/*
|
||||
DetachedInventoryChangeReceiver
|
||||
*/
|
||||
|
||||
DetachedInventoryChangeReceiver::DetachedInventoryChangeReceiver(const std::string &name)
|
||||
{
|
||||
m_name=name;
|
||||
}
|
||||
|
||||
DetachedInventoryChangeReceiver::~DetachedInventoryChangeReceiver()
|
||||
{
|
||||
delete &m_name;
|
||||
}
|
||||
|
||||
void DetachedInventoryChangeReceiver::on_remove_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
const ItemStack &deleted_item)
|
||||
{
|
||||
if(script_interface){
|
||||
script_interface->on_detached_inventory_remove_item(m_name, inventory_list->getName(), deleted_item);
|
||||
}
|
||||
}
|
||||
|
||||
void DetachedInventoryChangeReceiver::on_change_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item)
|
||||
{
|
||||
if(script_interface){
|
||||
script_interface->on_detached_inventory_change_item(m_name, inventory_list->getName(), query_slot, old_item, new_item);
|
||||
}
|
||||
}
|
||||
|
||||
void DetachedInventoryChangeReceiver::on_add_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item)
|
||||
{
|
||||
if(script_interface){
|
||||
script_interface->on_detached_inventory_add_item(m_name, inventory_list->getName(), query_slot, added_item);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Inventory
|
||||
*/
|
||||
|
@ -894,15 +951,16 @@ void Inventory::clearContents()
|
|||
InventoryList *list = m_lists[i];
|
||||
for(u32 j=0; j<list->getSize(); j++)
|
||||
{
|
||||
list->deleteItem(j);
|
||||
list->deleteItem(NULL, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Inventory::Inventory(IItemDefManager *itemdef)
|
||||
Inventory::Inventory(IItemDefManager *itemdef, InventoryChangeReceiver *rec)
|
||||
{
|
||||
m_dirty = false;
|
||||
m_itemdef = itemdef;
|
||||
m_rec = rec;
|
||||
}
|
||||
|
||||
Inventory::Inventory(const Inventory &other)
|
||||
|
@ -919,6 +977,7 @@ Inventory & Inventory::operator = (const Inventory &other)
|
|||
m_dirty = true;
|
||||
clear();
|
||||
m_itemdef = other.m_itemdef;
|
||||
m_rec = other.m_rec;
|
||||
for(u32 i=0; i<other.m_lists.size(); i++)
|
||||
{
|
||||
m_lists.push_back(new InventoryList(*other.m_lists[i]));
|
||||
|
@ -983,7 +1042,7 @@ void Inventory::deSerialize(std::istream &is)
|
|||
std::getline(iss, listname, ' ');
|
||||
iss>>listsize;
|
||||
|
||||
InventoryList *list = new InventoryList(listname, listsize, m_itemdef);
|
||||
InventoryList *list = new InventoryList(listname, listsize, m_itemdef, m_rec);
|
||||
list->deSerialize(is);
|
||||
|
||||
m_lists.push_back(list);
|
||||
|
@ -1004,7 +1063,7 @@ InventoryList * Inventory::addList(const std::string &name, u32 size)
|
|||
if(m_lists[i]->getSize() != size)
|
||||
{
|
||||
delete m_lists[i];
|
||||
m_lists[i] = new InventoryList(name, size, m_itemdef);
|
||||
m_lists[i] = new InventoryList(name, size, m_itemdef, m_rec);
|
||||
}
|
||||
return m_lists[i];
|
||||
}
|
||||
|
@ -1013,7 +1072,7 @@ InventoryList * Inventory::addList(const std::string &name, u32 size)
|
|||
//don't create list with invalid name
|
||||
if (name.find(" ") != std::string::npos) return NULL;
|
||||
|
||||
InventoryList *list = new InventoryList(name, size, m_itemdef);
|
||||
InventoryList *list = new InventoryList(name, size, m_itemdef, m_rec);
|
||||
m_lists.push_back(list);
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -27,8 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "script/scripting_game.h"
|
||||
|
||||
struct ToolCapabilities;
|
||||
class InventoryChangeReceiver;
|
||||
|
||||
struct ItemStack
|
||||
{
|
||||
|
@ -172,7 +174,7 @@ struct ItemStack
|
|||
class InventoryList
|
||||
{
|
||||
public:
|
||||
InventoryList(std::string name, u32 size, IItemDefManager *itemdef);
|
||||
InventoryList(std::string name, u32 size, IItemDefManager *itemdef, InventoryChangeReceiver *rec);
|
||||
~InventoryList();
|
||||
void clearItems();
|
||||
void setSize(u32 newsize);
|
||||
|
@ -200,18 +202,18 @@ public:
|
|||
const ItemStack& getItem(u32 i) const;
|
||||
ItemStack& getItem(u32 i);
|
||||
// Returns old item. Parameter can be an empty item.
|
||||
ItemStack changeItem(u32 i, const ItemStack &newitem);
|
||||
ItemStack changeItem(GameScripting *script_interface, u32 i, const ItemStack &newitem);
|
||||
// Delete item
|
||||
void deleteItem(u32 i);
|
||||
void deleteItem(GameScripting *script_interface, u32 i);
|
||||
|
||||
// Adds an item to a suitable place. Returns leftover item (possibly empty).
|
||||
ItemStack addItem(const ItemStack &newitem);
|
||||
ItemStack addItem(GameScripting *script_interface, const ItemStack &newitem);
|
||||
|
||||
// If possible, adds item to given slot.
|
||||
// If cannot be added at all, returns the item back.
|
||||
// If can be added partly, decremented item is returned back.
|
||||
// If can be added fully, empty item is returned.
|
||||
ItemStack addItem(u32 i, const ItemStack &newitem);
|
||||
ItemStack addItem(GameScripting *script_interface, u32 i, const ItemStack &newitem);
|
||||
|
||||
// Checks whether the item could be added to the given slot
|
||||
// If restitem is non-NULL, it receives the part of newitem that
|
||||
|
@ -231,12 +233,12 @@ public:
|
|||
// If not as many items exist as requested, removes as
|
||||
// many as possible.
|
||||
// Returns the items that were actually removed.
|
||||
ItemStack removeItem(const ItemStack &item);
|
||||
ItemStack removeItem(GameScripting *script_interface, const ItemStack &item);
|
||||
|
||||
// Takes some items from a slot.
|
||||
// If there are not enough, takes as many as it can.
|
||||
// Returns empty item if couldn't take any.
|
||||
ItemStack takeItem(u32 i, u32 takecount);
|
||||
ItemStack takeItem(GameScripting *script_interface, u32 i, u32 takecount);
|
||||
|
||||
// Similar to takeItem, but keeps the slot intact.
|
||||
ItemStack peekItem(u32 i, u32 peekcount) const;
|
||||
|
@ -244,18 +246,63 @@ public:
|
|||
// Move an item to a different list (or a different stack in the same list)
|
||||
// count is the maximum number of items to move (0 for everything)
|
||||
// returns number of moved items
|
||||
u32 moveItem(u32 i, InventoryList *dest, u32 dest_i,
|
||||
u32 moveItem(GameScripting *script_interface, u32 i, InventoryList *dest, u32 dest_i,
|
||||
u32 count = 0, bool swap_if_needed = true, bool *did_swap = NULL);
|
||||
|
||||
// like moveItem, but without a fixed destination index
|
||||
// also with optional rollback recording
|
||||
void moveItemSomewhere(u32 i, InventoryList *dest, u32 count);
|
||||
void moveItemSomewhere(GameScripting *script_interface, u32 i, InventoryList *dest, u32 count);
|
||||
|
||||
private:
|
||||
std::vector<ItemStack> m_items;
|
||||
u32 m_size, m_width;
|
||||
std::string m_name;
|
||||
IItemDefManager *m_itemdef;
|
||||
InventoryChangeReceiver *m_rec;
|
||||
};
|
||||
|
||||
class InventoryChangeReceiver
|
||||
{
|
||||
public:
|
||||
virtual void on_remove_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
const ItemStack &deleted_item) = 0;
|
||||
virtual void on_change_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item) = 0;
|
||||
virtual void on_add_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item) = 0;
|
||||
virtual ~InventoryChangeReceiver() {};
|
||||
};
|
||||
|
||||
class DetachedInventoryChangeReceiver: public InventoryChangeReceiver
|
||||
{
|
||||
std::string m_name;
|
||||
public:
|
||||
DetachedInventoryChangeReceiver(const std::string &name);
|
||||
~DetachedInventoryChangeReceiver();
|
||||
void on_remove_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
const ItemStack &deleted_item);
|
||||
void on_change_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item);
|
||||
void on_add_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item);
|
||||
};
|
||||
|
||||
class Inventory
|
||||
|
@ -266,7 +313,7 @@ public:
|
|||
void clear();
|
||||
void clearContents();
|
||||
|
||||
Inventory(IItemDefManager *itemdef);
|
||||
Inventory(IItemDefManager *itemdef, InventoryChangeReceiver *m_rec);
|
||||
Inventory(const Inventory &other);
|
||||
Inventory & operator = (const Inventory &other);
|
||||
bool operator == (const Inventory &other) const;
|
||||
|
@ -283,15 +330,6 @@ public:
|
|||
const InventoryList * getList(const std::string &name) const;
|
||||
std::vector<const InventoryList*> getLists();
|
||||
bool deleteList(const std::string &name);
|
||||
// A shorthand for adding items. Returns leftover item (possibly empty).
|
||||
ItemStack addItem(const std::string &listname, const ItemStack &newitem)
|
||||
{
|
||||
m_dirty = true;
|
||||
InventoryList *list = getList(listname);
|
||||
if(list == NULL)
|
||||
return newitem;
|
||||
return list->addItem(newitem);
|
||||
}
|
||||
|
||||
bool checkModified() const
|
||||
{
|
||||
|
@ -308,6 +346,7 @@ private:
|
|||
const s32 getListIndex(const std::string &name) const;
|
||||
|
||||
std::vector<InventoryList*> m_lists;
|
||||
InventoryChangeReceiver *m_rec;
|
||||
IItemDefManager *m_itemdef;
|
||||
bool m_dirty;
|
||||
};
|
||||
|
|
|
@ -376,7 +376,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
|||
same as source), nothing happens
|
||||
*/
|
||||
bool did_swap = false;
|
||||
move_count = list_from->moveItem(from_i,
|
||||
move_count = list_from->moveItem(PLAYER_TO_SA(player), from_i,
|
||||
list_to, to_i, count, !caused_by_move_somewhere, &did_swap);
|
||||
|
||||
// If source is infinite, reset it's stack
|
||||
|
@ -392,24 +392,24 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
|||
if (from_stack_was.name != to_stack_was.name) {
|
||||
for (u32 i = 0; i < list_to->getSize(); i++) {
|
||||
if (list_to->getItem(i).empty()) {
|
||||
list_to->changeItem(i, to_stack_was);
|
||||
list_to->changeItem(PLAYER_TO_SA(player), i, to_stack_was);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (move_count > 0 || did_swap) {
|
||||
list_from->deleteItem(from_i);
|
||||
list_from->addItem(from_i, from_stack_was);
|
||||
list_from->deleteItem(PLAYER_TO_SA(player), from_i);
|
||||
list_from->addItem(PLAYER_TO_SA(player), from_i, from_stack_was);
|
||||
}
|
||||
}
|
||||
// If destination is infinite, reset it's stack and take count from source
|
||||
if(dst_can_put_count == -1){
|
||||
list_to->deleteItem(to_i);
|
||||
list_to->addItem(to_i, to_stack_was);
|
||||
list_from->deleteItem(from_i);
|
||||
list_from->addItem(from_i, from_stack_was);
|
||||
list_from->takeItem(from_i, count);
|
||||
list_to->deleteItem(PLAYER_TO_SA(player), to_i);
|
||||
list_to->addItem(PLAYER_TO_SA(player), to_i, to_stack_was);
|
||||
list_from->deleteItem(PLAYER_TO_SA(player), from_i);
|
||||
list_from->addItem(PLAYER_TO_SA(player), from_i, from_stack_was);
|
||||
list_from->takeItem(PLAYER_TO_SA(player), from_i, count);
|
||||
}
|
||||
|
||||
infostream << "IMoveAction::apply(): moved"
|
||||
|
@ -550,9 +550,9 @@ void IMoveAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
|
|||
return;
|
||||
|
||||
if (!move_somewhere)
|
||||
list_from->moveItem(from_i, list_to, to_i, count);
|
||||
list_from->moveItem(NULL, from_i, list_to, to_i, count);
|
||||
else
|
||||
list_from->moveItemSomewhere(from_i, list_to, count);
|
||||
list_from->moveItemSomewhere(NULL, from_i, list_to, count);
|
||||
|
||||
mgr->setInventoryModified(from_inv);
|
||||
if(inv_from != inv_to)
|
||||
|
@ -663,7 +663,7 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
|||
// If source isn't infinite
|
||||
if(src_can_take_count != -1){
|
||||
// Take item from source list
|
||||
ItemStack item2 = list_from->takeItem(from_i, actually_dropped_count);
|
||||
ItemStack item2 = list_from->takeItem(PLAYER_TO_SA(player), from_i, actually_dropped_count);
|
||||
|
||||
if(item2.count != actually_dropped_count)
|
||||
errorstream<<"Could not take dropped count of items"<<std::endl;
|
||||
|
@ -741,9 +741,9 @@ void IDropAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
|
|||
return;
|
||||
|
||||
if(count == 0)
|
||||
list_from->changeItem(from_i, ItemStack());
|
||||
list_from->changeItem(NULL, from_i, ItemStack());
|
||||
else
|
||||
list_from->takeItem(from_i, count);
|
||||
list_from->takeItem(NULL, from_i, count);
|
||||
|
||||
mgr->setInventoryModified(from_inv);
|
||||
}
|
||||
|
@ -801,7 +801,7 @@ void ICraftAction::apply(InventoryManager *mgr,
|
|||
ItemStack craftresultitem;
|
||||
int count_remaining = count;
|
||||
std::vector<ItemStack> output_replacements;
|
||||
getCraftingResult(inv_craft, crafted, output_replacements, false, gamedef);
|
||||
getCraftingResult(PLAYER_TO_SA(player), inv_craft, crafted, output_replacements, false, gamedef);
|
||||
PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
|
||||
bool found = !crafted.empty();
|
||||
|
||||
|
@ -810,9 +810,9 @@ void ICraftAction::apply(InventoryManager *mgr,
|
|||
|
||||
std::vector<ItemStack> temp;
|
||||
// Decrement input and add crafting output
|
||||
getCraftingResult(inv_craft, crafted, temp, true, gamedef);
|
||||
getCraftingResult(PLAYER_TO_SA(player), inv_craft, crafted, temp, true, gamedef);
|
||||
PLAYER_TO_SA(player)->item_OnCraft(crafted, player, &saved_craft_list, craft_inv);
|
||||
list_craftresult->addItem(0, crafted);
|
||||
list_craftresult->addItem(PLAYER_TO_SA(player), 0, crafted);
|
||||
mgr->setInventoryModified(craft_inv);
|
||||
|
||||
// Add the new replacements to the list
|
||||
|
@ -842,7 +842,7 @@ void ICraftAction::apply(InventoryManager *mgr,
|
|||
count_remaining--;
|
||||
|
||||
// Get next crafting result
|
||||
found = getCraftingResult(inv_craft, crafted, temp, false, gamedef);
|
||||
found = getCraftingResult(PLAYER_TO_SA(player), inv_craft, crafted, temp, false, gamedef);
|
||||
PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
|
||||
found = !crafted.empty();
|
||||
}
|
||||
|
@ -852,7 +852,7 @@ void ICraftAction::apply(InventoryManager *mgr,
|
|||
for (std::vector<ItemStack>::iterator it = output_replacements.begin();
|
||||
it != output_replacements.end(); ++it) {
|
||||
if (list_main)
|
||||
*it = list_main->addItem(*it);
|
||||
*it = list_main->addItem(PLAYER_TO_SA(player), *it);
|
||||
if (it->empty())
|
||||
continue;
|
||||
u16 count = it->count;
|
||||
|
@ -882,7 +882,7 @@ void ICraftAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
|
|||
|
||||
|
||||
// Crafting helper
|
||||
bool getCraftingResult(Inventory *inv, ItemStack& result,
|
||||
bool getCraftingResult(GameScripting *script_interface, Inventory *inv, ItemStack& result,
|
||||
std::vector<ItemStack> &output_replacements,
|
||||
bool decrementInput, IGameDef *gamedef)
|
||||
{
|
||||
|
@ -914,7 +914,7 @@ bool getCraftingResult(Inventory *inv, ItemStack& result,
|
|||
// CraftInput has been changed, apply changes in clist
|
||||
for(u16 i=0; i<clist->getSize(); i++)
|
||||
{
|
||||
clist->changeItem(i, ci.items[i]);
|
||||
clist->changeItem(script_interface, i, ci.items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -254,9 +254,13 @@ struct ICraftAction : public InventoryAction
|
|||
};
|
||||
|
||||
// Crafting helper
|
||||
bool getCraftingResult(Inventory *inv, ItemStack& result,
|
||||
std::vector<ItemStack> &output_replacements,
|
||||
bool decrementInput, IGameDef *gamedef);
|
||||
bool getCraftingResult(
|
||||
GameScripting *script_interface,
|
||||
Inventory *inv,
|
||||
ItemStack& result,
|
||||
std::vector<ItemStack> &output_replacements,
|
||||
bool decrementInput,
|
||||
IGameDef *gamedef);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -83,6 +83,21 @@ LocalPlayer::~LocalPlayer()
|
|||
{
|
||||
}
|
||||
|
||||
void LocalPlayer::on_remove_item(GameScripting *script_interface, const InventoryList *inventory_list, const ItemStack &deleted_item)
|
||||
{
|
||||
// Do nothing, because no client-side lua
|
||||
}
|
||||
|
||||
void LocalPlayer::on_change_item(GameScripting *script_interface, const InventoryList *inventory_list, u32 query_slot, const ItemStack &old_item, const ItemStack &new_item)
|
||||
{
|
||||
// Do nothing, because no client-side lua
|
||||
}
|
||||
|
||||
void LocalPlayer::on_add_item(GameScripting *script_interface, const InventoryList *inventory_list, u32 query_slot, const ItemStack &added_item)
|
||||
{
|
||||
// Do nothing, because no client-side lua
|
||||
}
|
||||
|
||||
void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
|
||||
std::vector<CollisionInfo> *collision_info)
|
||||
{
|
||||
|
|
|
@ -38,6 +38,22 @@ public:
|
|||
LocalPlayer(Client *gamedef, const char *name);
|
||||
virtual ~LocalPlayer();
|
||||
|
||||
void on_remove_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
const ItemStack &deleted_item);
|
||||
void on_change_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item);
|
||||
void on_add_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item);
|
||||
|
||||
ClientActiveObject *parent;
|
||||
|
||||
bool got_teleported;
|
||||
|
|
|
@ -701,11 +701,11 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk)
|
|||
decompressZlib(is, oss);
|
||||
std::istringstream iss(oss.str(), std::ios_base::binary);
|
||||
if (version >= 23)
|
||||
m_node_metadata.deSerialize(iss, m_gamedef->idef());
|
||||
m_node_metadata.deSerialize(iss, m_gamedef->idef(), getPosRelative());
|
||||
else
|
||||
content_nodemeta_deserialize_legacy(iss,
|
||||
&m_node_metadata, &m_node_timers,
|
||||
m_gamedef->idef());
|
||||
m_gamedef->idef(), getPosRelative());
|
||||
} catch(SerializationError &e) {
|
||||
warningstream<<"MapBlock::deSerialize(): Ignoring an error"
|
||||
<<" while deserializing node metadata at ("
|
||||
|
@ -880,7 +880,7 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk)
|
|||
std::istringstream iss(data, std::ios_base::binary);
|
||||
content_nodemeta_deserialize_legacy(iss,
|
||||
&m_node_metadata, &m_node_timers,
|
||||
m_gamedef->idef());
|
||||
m_gamedef->idef(), getPosRelative());
|
||||
} else {
|
||||
//std::string data = deSerializeLongString(is);
|
||||
std::ostringstream oss(std::ios_base::binary);
|
||||
|
@ -888,7 +888,7 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk)
|
|||
std::istringstream iss(oss.str(), std::ios_base::binary);
|
||||
content_nodemeta_deserialize_legacy(iss,
|
||||
&m_node_metadata, &m_node_timers,
|
||||
m_gamedef->idef());
|
||||
m_gamedef->idef(), getPosRelative());
|
||||
}
|
||||
} catch(SerializationError &e) {
|
||||
warningstream<<"MapBlock::deSerialize(): Ignoring an error"
|
||||
|
|
|
@ -861,7 +861,9 @@ void Client::handleCommand_DetachedInventory(NetworkPacket* pkt)
|
|||
if (m_detached_inventories.count(name) > 0)
|
||||
inv = m_detached_inventories[name];
|
||||
else {
|
||||
inv = new Inventory(m_itemdef);
|
||||
DetachedInventoryChangeReceiver *detached_inventory_change_receiver =
|
||||
new DetachedInventoryChangeReceiver(name);
|
||||
inv = new Inventory(m_itemdef, detached_inventory_change_receiver);
|
||||
m_detached_inventories[name] = inv;
|
||||
}
|
||||
inv->deSerialize(is);
|
||||
|
|
|
@ -1619,7 +1619,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
|
|||
// Placement was handled in lua
|
||||
|
||||
// Apply returned ItemStack
|
||||
if (playersao->setWieldedItem(item)) {
|
||||
if (playersao->setWieldedItem(m_script, item)) {
|
||||
SendInventory(playersao);
|
||||
}
|
||||
}
|
||||
|
@ -1655,7 +1655,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
|
|||
if (m_script->item_OnUse(
|
||||
item, playersao, pointed)) {
|
||||
// Apply returned ItemStack
|
||||
if (playersao->setWieldedItem(item)) {
|
||||
if (playersao->setWieldedItem(m_script, item)) {
|
||||
SendInventory(playersao);
|
||||
}
|
||||
}
|
||||
|
@ -1673,7 +1673,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
|
|||
|
||||
if (m_script->item_OnSecondaryUse(
|
||||
item, playersao)) {
|
||||
if( playersao->setWieldedItem(item)) {
|
||||
if( playersao->setWieldedItem(m_script, item)) {
|
||||
SendInventory(playersao);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,14 +25,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/serialize.h"
|
||||
#include "constants.h" // MAP_BLOCKSIZE
|
||||
#include <sstream>
|
||||
#include "script/scripting_game.h"
|
||||
|
||||
/*
|
||||
NodeMetadata
|
||||
*/
|
||||
|
||||
NodeMetadata::NodeMetadata(IItemDefManager *item_def_mgr):
|
||||
NodeMetadata::NodeMetadata(IItemDefManager *item_def_mgr, v3s16 node_pos):
|
||||
m_stringvars(),
|
||||
m_inventory(new Inventory(item_def_mgr))
|
||||
m_inventory(new Inventory(item_def_mgr, this)),
|
||||
m_node_pos(node_pos)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,6 +43,42 @@ NodeMetadata::~NodeMetadata()
|
|||
delete m_inventory;
|
||||
}
|
||||
|
||||
void NodeMetadata::on_remove_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
const ItemStack &deleted_item)
|
||||
{
|
||||
if (script_interface) {
|
||||
script_interface->on_nodemeta_inventory_remove_item(
|
||||
m_node_pos, inventory_list->getName(), deleted_item);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeMetadata::on_change_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item)
|
||||
{
|
||||
if (script_interface) {
|
||||
script_interface->on_nodemeta_inventory_change_item(
|
||||
m_node_pos, inventory_list->getName(), query_slot, old_item, new_item);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeMetadata::on_add_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item)
|
||||
{
|
||||
if (script_interface) {
|
||||
script_interface->on_nodemeta_inventory_add_item(
|
||||
m_node_pos, inventory_list->getName(), query_slot, added_item);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeMetadata::serialize(std::ostream &os) const
|
||||
{
|
||||
int num_vars = m_stringvars.size();
|
||||
|
@ -114,7 +152,7 @@ void NodeMetadataList::serialize(std::ostream &os) const
|
|||
}
|
||||
}
|
||||
|
||||
void NodeMetadataList::deSerialize(std::istream &is, IItemDefManager *item_def_mgr)
|
||||
void NodeMetadataList::deSerialize(std::istream &is, IItemDefManager *item_def_mgr, v3s16 relative_map_block_pos)
|
||||
{
|
||||
clear();
|
||||
|
||||
|
@ -152,7 +190,7 @@ void NodeMetadataList::deSerialize(std::istream &is, IItemDefManager *item_def_m
|
|||
continue;
|
||||
}
|
||||
|
||||
NodeMetadata *data = new NodeMetadata(item_def_mgr);
|
||||
NodeMetadata *data = new NodeMetadata(item_def_mgr, relative_map_block_pos+p);
|
||||
data->deSerialize(is);
|
||||
m_data[p] = data;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "util/string.h"
|
||||
#include "inventory.h" // For InventoryChangeReceiver class
|
||||
|
||||
/*
|
||||
NodeMetadata stores arbitary amounts of data for special blocks.
|
||||
|
@ -37,12 +38,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
class Inventory;
|
||||
class IItemDefManager;
|
||||
|
||||
class NodeMetadata
|
||||
class NodeMetadata: public InventoryChangeReceiver
|
||||
{
|
||||
public:
|
||||
NodeMetadata(IItemDefManager *item_def_mgr);
|
||||
NodeMetadata(IItemDefManager *item_def_mgr, v3s16 node_pos);
|
||||
~NodeMetadata();
|
||||
|
||||
void on_remove_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
const ItemStack &deleted_item);
|
||||
void on_change_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item);
|
||||
void on_add_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item);
|
||||
|
||||
void serialize(std::ostream &os) const;
|
||||
void deSerialize(std::istream &is);
|
||||
|
||||
|
@ -68,6 +85,7 @@ public:
|
|||
private:
|
||||
StringMap m_stringvars;
|
||||
Inventory *m_inventory;
|
||||
v3s16 m_node_pos;
|
||||
};
|
||||
|
||||
|
||||
|
@ -81,7 +99,7 @@ public:
|
|||
~NodeMetadataList();
|
||||
|
||||
void serialize(std::ostream &os) const;
|
||||
void deSerialize(std::istream &is, IItemDefManager *item_def_mgr);
|
||||
void deSerialize(std::istream &is, IItemDefManager *item_def_mgr, v3s16 relative_map_block_pos);
|
||||
|
||||
// Add all keys in this list to the vector keys
|
||||
std::vector<v3s16> getAllKeys();
|
||||
|
|
|
@ -28,10 +28,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "log.h"
|
||||
#include "porting.h" // strlcpy
|
||||
|
||||
|
||||
Player::Player(const char *name, IItemDefManager *idef):
|
||||
camera_barely_in_ceiling(false),
|
||||
inventory(idef),
|
||||
inventory(idef, this),
|
||||
hp(PLAYER_MAX_HP),
|
||||
peer_id(PEER_ID_INEXISTENT),
|
||||
keyPressed(0),
|
||||
|
|
19
src/player.h
19
src/player.h
|
@ -102,17 +102,34 @@ class Map;
|
|||
struct CollisionInfo;
|
||||
struct HudElement;
|
||||
class Environment;
|
||||
class GameScripting;
|
||||
|
||||
// IMPORTANT:
|
||||
// Do *not* perform an assignment or copy operation on a Player or
|
||||
// RemotePlayer object! This will copy the lock held for HUD synchronization
|
||||
class Player
|
||||
class Player: public InventoryChangeReceiver
|
||||
{
|
||||
public:
|
||||
|
||||
Player(const char *name, IItemDefManager *idef);
|
||||
virtual ~Player() = 0;
|
||||
|
||||
virtual void on_remove_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
const ItemStack &deleted_item) = 0;
|
||||
virtual void on_change_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item) = 0;
|
||||
virtual void on_add_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item) = 0;
|
||||
|
||||
virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
|
||||
{}
|
||||
virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
|
||||
|
|
|
@ -66,6 +66,27 @@ RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef):
|
|||
movement_gravity = g_settings->getFloat("movement_gravity") * BS;
|
||||
}
|
||||
|
||||
void RemotePlayer::on_remove_item(GameScripting *script_interface, const InventoryList *inventory_list, const ItemStack &deleted_item)
|
||||
{
|
||||
if(script_interface && m_sao){
|
||||
script_interface->on_player_inventory_remove_item(m_sao, inventory_list->getName(), deleted_item);
|
||||
}
|
||||
}
|
||||
|
||||
void RemotePlayer::on_change_item(GameScripting *script_interface, const InventoryList *inventory_list, u32 query_slot, const ItemStack &old_item,const ItemStack &new_item)
|
||||
{
|
||||
if(script_interface && m_sao){
|
||||
script_interface->on_player_inventory_change_item(m_sao, inventory_list->getName(), query_slot, old_item, new_item);
|
||||
}
|
||||
}
|
||||
|
||||
void RemotePlayer::on_add_item(GameScripting *script_interface, const InventoryList *inventory_list, u32 query_slot, const ItemStack &added_item)
|
||||
{
|
||||
if(script_interface && m_sao){
|
||||
script_interface->on_player_inventory_add_item(m_sao, inventory_list->getName(), query_slot, added_item);
|
||||
}
|
||||
}
|
||||
|
||||
void RemotePlayer::save(std::string savedir, IGameDef *gamedef)
|
||||
{
|
||||
/*
|
||||
|
@ -155,7 +176,7 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername)
|
|||
if(craftresult_is_preview)
|
||||
{
|
||||
// Clear craftresult
|
||||
inventory.getList("craftresult")->changeItem(0, ItemStack());
|
||||
inventory.getList("craftresult")->changeItem(NULL, 0, ItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,22 @@ public:
|
|||
RemotePlayer(const char *name, IItemDefManager *idef);
|
||||
virtual ~RemotePlayer() {}
|
||||
|
||||
void on_remove_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
const ItemStack &deleted_item);
|
||||
void on_change_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item);
|
||||
void on_add_item(
|
||||
GameScripting *script_interface,
|
||||
const InventoryList *inventory_list,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item);
|
||||
|
||||
void save(std::string savedir, IGameDef *gamedef);
|
||||
void deSerialize(std::istream &is, const std::string &playername);
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gam
|
|||
} else {
|
||||
NodeMetadata *meta = map->getNodeMetadata(p);
|
||||
if (!meta) {
|
||||
meta = new NodeMetadata(gamedef->idef());
|
||||
meta = new NodeMetadata(gamedef->idef(), p);
|
||||
if (!map->setNodeMetadata(p, meta)) {
|
||||
delete meta;
|
||||
infostream << "RollbackAction::applyRevert(): "
|
||||
|
@ -217,9 +217,9 @@ bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gam
|
|||
// Silently ignore different current item
|
||||
if (list->getItem(inventory_index).name != real_name)
|
||||
return false;
|
||||
list->takeItem(inventory_index, inventory_stack.count);
|
||||
list->takeItem(NULL, inventory_index, inventory_stack.count);
|
||||
} else {
|
||||
list->addItem(inventory_index, inventory_stack);
|
||||
list->addItem(NULL, inventory_index, inventory_stack);
|
||||
}
|
||||
// Inventory was modified; send to clients
|
||||
imgr->setInventoryModified(loc);
|
||||
|
|
|
@ -899,11 +899,11 @@ void read_inventory_list(lua_State *L, int tableindex,
|
|||
i = items.begin(); i != items.end(); i++){
|
||||
if(forcesize != -1 && index == forcesize)
|
||||
break;
|
||||
invlist->changeItem(index, *i);
|
||||
invlist->changeItem(NULL, index, *i);
|
||||
index++;
|
||||
}
|
||||
while(forcesize != -1 && index < forcesize){
|
||||
invlist->deleteItem(index);
|
||||
invlist->deleteItem(NULL, index);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,6 +202,62 @@ void ScriptApiDetached::detached_inventory_OnTake(
|
|||
lua_pop(L, 1); // Pop error handler
|
||||
}
|
||||
|
||||
void ScriptApiDetached::on_detached_inventory_remove_item(
|
||||
const std::string &name,
|
||||
const std::string &inventory_list_name,
|
||||
const ItemStack &deleted_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_detached_inventory_remove_item");
|
||||
// Call callbacks
|
||||
lua_pushstring(L, name.c_str());// name 1
|
||||
lua_pushstring(L, inventory_list_name.c_str());// listname 2
|
||||
LuaItemStack::create(L, deleted_item); // stack 3
|
||||
runCallbacks(3, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
void ScriptApiDetached::on_detached_inventory_change_item(
|
||||
const std::string &name,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_inventory_change_item
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_detached_inventory_change_item");
|
||||
// Call callbacks
|
||||
lua_pushstring(L, name.c_str());// name 1
|
||||
lua_pushstring(L, inventory_list_name.c_str());// listname 2
|
||||
lua_pushnumber(L, query_slot);// slot 3
|
||||
LuaItemStack::create(L, old_item); // stack 4
|
||||
LuaItemStack::create(L, new_item); // stack 5
|
||||
runCallbacks(5, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
void ScriptApiDetached::on_detached_inventory_add_item(
|
||||
const std::string &name,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_inventory_add_item
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_detached_inventory_add_item");
|
||||
// Call callbacks
|
||||
lua_pushstring(L, name.c_str());// name 1
|
||||
lua_pushstring(L, inventory_list_name.c_str());// listname 2
|
||||
lua_pushnumber(L, query_slot);
|
||||
LuaItemStack::create(L, added_item); // stack 4
|
||||
runCallbacks(4, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
// Retrieves core.detached_inventories[name][callbackname]
|
||||
// If that is nil or on error, return false and stack is unchanged
|
||||
// If that is a function, returns true and pushes the
|
||||
|
|
|
@ -61,6 +61,25 @@ public:
|
|||
const std::string &name,
|
||||
const std::string &listname, int index, ItemStack &stack,
|
||||
ServerActiveObject *player);
|
||||
|
||||
void on_detached_inventory_remove_item(
|
||||
const std::string &name,
|
||||
const std::string &inventory_list_name,
|
||||
const ItemStack &deleted_item);
|
||||
|
||||
void on_detached_inventory_change_item(
|
||||
const std::string &name,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item);
|
||||
|
||||
void on_detached_inventory_add_item(
|
||||
const std::string &name,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item);
|
||||
|
||||
private:
|
||||
bool getDetachedInventoryCallback(
|
||||
const std::string &name, const char *callbackname);
|
||||
|
|
|
@ -233,6 +233,62 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake(v3s16 p,
|
|||
lua_pop(L, 1); // Pop error handler
|
||||
}
|
||||
|
||||
void ScriptApiNodemeta::on_nodemeta_inventory_remove_item(
|
||||
v3s16 p,
|
||||
const std::string &inventory_list_name,
|
||||
const ItemStack &deleted_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_nodemeta_inventory_remove_item");
|
||||
// Call callbacks
|
||||
push_v3s16(L, p); // pos
|
||||
lua_pushstring(L, inventory_list_name.c_str()); // listname
|
||||
LuaItemStack::create(L, deleted_item); // stack
|
||||
runCallbacks(3, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
void ScriptApiNodemeta::on_nodemeta_inventory_change_item(
|
||||
v3s16 p,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_inventory_change_item
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_nodemeta_inventory_change_item");
|
||||
// Call callbacks
|
||||
push_v3s16(L, p); // pos
|
||||
lua_pushstring(L, inventory_list_name.c_str()); // listname
|
||||
lua_pushnumber(L, query_slot); // slot
|
||||
LuaItemStack::create(L, old_item); // stack
|
||||
LuaItemStack::create(L, new_item); // stack
|
||||
runCallbacks(5, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
void ScriptApiNodemeta::on_nodemeta_inventory_add_item(
|
||||
v3s16 p,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_inventory_add_item
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_nodemeta_inventory_add_item");
|
||||
// Call callbacks
|
||||
push_v3s16(L, p); // pos
|
||||
lua_pushstring(L, inventory_list_name.c_str()); // listname
|
||||
lua_pushnumber(L, query_slot); // index
|
||||
LuaItemStack::create(L, added_item); // stack
|
||||
runCallbacks(4, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
ScriptApiNodemeta::ScriptApiNodemeta()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -60,6 +60,25 @@ public:
|
|||
void nodemeta_inventory_OnTake(v3s16 p,
|
||||
const std::string &listname, int index, ItemStack &stack,
|
||||
ServerActiveObject *player);
|
||||
|
||||
void on_nodemeta_inventory_remove_item(
|
||||
v3s16 p,
|
||||
const std::string &inventory_list_name,
|
||||
const ItemStack &deleted_item);
|
||||
|
||||
void on_nodemeta_inventory_change_item(
|
||||
v3s16 p,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item);
|
||||
|
||||
void on_nodemeta_inventory_add_item(
|
||||
v3s16 p,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
|
|
@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "common/c_converter.h"
|
||||
#include "common/c_content.h"
|
||||
#include "util/string.h"
|
||||
#include "script/lua_api/l_item.h" // For LuaItemStack.
|
||||
|
||||
void ScriptApiPlayer::on_newplayer(ServerActiveObject *player)
|
||||
{
|
||||
|
@ -192,6 +193,62 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
|
|||
runCallbacks(3, RUN_CALLBACKS_MODE_OR_SC);
|
||||
}
|
||||
|
||||
void ScriptApiPlayer::on_player_inventory_remove_item(
|
||||
ServerActiveObject *player_sao,
|
||||
const std::string &inventory_list_name,
|
||||
const ItemStack &deleted_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_player_inventory_remove_item");
|
||||
// Call callbacks
|
||||
objectrefGetOrCreate(L, player_sao); // player
|
||||
lua_pushstring(L, inventory_list_name.c_str()); // listname
|
||||
LuaItemStack::create(L, deleted_item); // stack
|
||||
runCallbacks(3, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
void ScriptApiPlayer::on_player_inventory_change_item(
|
||||
ServerActiveObject *player_sao,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_inventory_change_item
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_player_inventory_change_item");
|
||||
// Call callbacks
|
||||
objectrefGetOrCreate(L, player_sao); // player
|
||||
lua_pushstring(L, inventory_list_name.c_str()); // listname
|
||||
lua_pushnumber(L, query_slot); // slot
|
||||
LuaItemStack::create(L, old_item); // stack
|
||||
LuaItemStack::create(L, new_item); // stack
|
||||
runCallbacks(5, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
void ScriptApiPlayer::on_player_inventory_add_item(
|
||||
ServerActiveObject *player_sao,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_inventory_add_item
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_player_inventory_add_item");
|
||||
// Call callbacks
|
||||
objectrefGetOrCreate(L, player_sao); // player
|
||||
lua_pushstring(L, inventory_list_name.c_str()); // listname
|
||||
lua_pushnumber(L, query_slot); // index
|
||||
LuaItemStack::create(L, added_item); // stack
|
||||
runCallbacks(4, RUN_CALLBACKS_MODE_LAST);
|
||||
}
|
||||
|
||||
ScriptApiPlayer::~ScriptApiPlayer()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/string.h"
|
||||
|
||||
struct ToolCapabilities;
|
||||
struct ItemStack;
|
||||
|
||||
class ScriptApiPlayer
|
||||
: virtual public ScriptApiBase
|
||||
|
@ -46,6 +47,21 @@ public:
|
|||
s16 on_player_hpchange(ServerActiveObject *player, s16 hp_change);
|
||||
void on_playerReceiveFields(ServerActiveObject *player,
|
||||
const std::string &formname, const StringMap &fields);
|
||||
void on_player_inventory_remove_item(
|
||||
ServerActiveObject *player_sao,
|
||||
const std::string &inventory_list_name,
|
||||
const ItemStack &deleted_item);
|
||||
void on_player_inventory_change_item(
|
||||
ServerActiveObject *player_sao,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &old_item,
|
||||
const ItemStack &new_item);
|
||||
void on_player_inventory_add_item(
|
||||
ServerActiveObject *player_sao,
|
||||
const std::string &inventory_list_name,
|
||||
u32 query_slot,
|
||||
const ItemStack &added_item);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ int InvRef::l_set_stack(lua_State *L)
|
|||
ItemStack newitem = read_item(L, 4, getServer(L));
|
||||
InventoryList *list = getlist(L, ref, listname);
|
||||
if(list != NULL && i >= 0 && i < (int) list->getSize()){
|
||||
list->changeItem(i, newitem);
|
||||
list->changeItem(getServer(L)->getScriptIface(), i, newitem);
|
||||
reportInventoryChange(L, ref);
|
||||
lua_pushboolean(L, true);
|
||||
} else {
|
||||
|
@ -298,7 +298,7 @@ int InvRef::l_add_item(lua_State *L)
|
|||
ItemStack item = read_item(L, 3, getServer(L));
|
||||
InventoryList *list = getlist(L, ref, listname);
|
||||
if(list){
|
||||
ItemStack leftover = list->addItem(item);
|
||||
ItemStack leftover = list->addItem(getServer(L)->getScriptIface(), item);
|
||||
if(leftover.count != item.count)
|
||||
reportInventoryChange(L, ref);
|
||||
LuaItemStack::create(L, leftover);
|
||||
|
@ -352,7 +352,7 @@ int InvRef::l_remove_item(lua_State *L)
|
|||
ItemStack item = read_item(L, 3, getServer(L));
|
||||
InventoryList *list = getlist(L, ref, listname);
|
||||
if(list){
|
||||
ItemStack removed = list->removeItem(item);
|
||||
ItemStack removed = list->removeItem(getServer(L)->getScriptIface(), item);
|
||||
if(!removed.empty())
|
||||
reportInventoryChange(L, ref);
|
||||
LuaItemStack::create(L, removed);
|
||||
|
|
|
@ -44,7 +44,7 @@ NodeMetadata* NodeMetaRef::getmeta(NodeMetaRef *ref, bool auto_create)
|
|||
{
|
||||
NodeMetadata *meta = ref->m_env->getMap().getNodeMetadata(ref->m_p);
|
||||
if(meta == NULL && auto_create) {
|
||||
meta = new NodeMetadata(ref->m_env->getGameDef()->idef());
|
||||
meta = new NodeMetadata(ref->m_env->getGameDef()->idef(), ref->m_p);
|
||||
if(!ref->m_env->getMap().setNodeMetadata(ref->m_p, meta)) {
|
||||
delete meta;
|
||||
return NULL;
|
||||
|
|
|
@ -364,7 +364,7 @@ int ObjectRef::l_set_wielded_item(lua_State *L)
|
|||
if (co == NULL) return 0;
|
||||
// Do it
|
||||
ItemStack item = read_item(L, 2, getServer(L));
|
||||
bool success = co->setWieldedItem(item);
|
||||
bool success = co->setWieldedItem(getServer(L)->getScriptIface(), item);
|
||||
if (success && co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
|
||||
getServer(L)->SendInventory(((PlayerSAO*)co));
|
||||
}
|
||||
|
|
|
@ -2698,7 +2698,7 @@ void Server::UpdateCrafting(RemotePlayer *player)
|
|||
InventoryLocation loc;
|
||||
loc.setPlayer(player->getName());
|
||||
std::vector<ItemStack> output_replacements;
|
||||
getCraftingResult(&player->inventory, preview, output_replacements, false, this);
|
||||
getCraftingResult(getEnv().getScriptIface(), &player->inventory, preview, output_replacements, false, this);
|
||||
m_env->getScriptIface()->item_CraftPredict(preview, player->getPlayerSAO(),
|
||||
(&player->inventory)->getList("craft"), loc);
|
||||
|
||||
|
@ -2706,7 +2706,7 @@ void Server::UpdateCrafting(RemotePlayer *player)
|
|||
InventoryList *plist = player->inventory.getList("craftpreview");
|
||||
sanity_check(plist);
|
||||
sanity_check(plist->getSize() >= 1);
|
||||
plist->changeItem(0, preview);
|
||||
plist->changeItem(NULL, 0, preview);
|
||||
}
|
||||
|
||||
void Server::handleChatInterfaceEvent(ChatEvent *evt)
|
||||
|
@ -3215,7 +3215,8 @@ Inventory* Server::createDetachedInventory(const std::string &name)
|
|||
} else {
|
||||
infostream<<"Server creating detached inventory \""<<name<<"\""<<std::endl;
|
||||
}
|
||||
Inventory *inv = new Inventory(m_itemdef);
|
||||
DetachedInventoryChangeReceiver *detached_inventory_change_reciever = new DetachedInventoryChangeReceiver(name);
|
||||
Inventory *inv = new Inventory(m_itemdef, detached_inventory_change_reciever);
|
||||
sanity_check(inv);
|
||||
m_detached_inventories[name] = inv;
|
||||
//TODO find a better way to do this
|
||||
|
|
|
@ -88,11 +88,11 @@ ItemStack ServerActiveObject::getWieldedItem() const
|
|||
return ItemStack();
|
||||
}
|
||||
|
||||
bool ServerActiveObject::setWieldedItem(const ItemStack &item)
|
||||
bool ServerActiveObject::setWieldedItem(GameScripting *script_interface, const ItemStack &item)
|
||||
{
|
||||
if(Inventory *inv = getInventory()) {
|
||||
if (InventoryList *list = inv->getList(getWieldList())) {
|
||||
list->changeItem(getWieldIndex(), item);
|
||||
list->changeItem(script_interface, getWieldIndex(), item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ public:
|
|||
virtual int getWieldIndex() const
|
||||
{ return 0; }
|
||||
virtual ItemStack getWieldedItem() const;
|
||||
virtual bool setWieldedItem(const ItemStack &item);
|
||||
virtual bool setWieldedItem(GameScripting *script_interface, const ItemStack &item);
|
||||
inline void attachParticleSpawner(u32 id)
|
||||
{
|
||||
m_attached_particle_spawners.insert(id);
|
||||
|
@ -197,7 +197,6 @@ public:
|
|||
m_attached_particle_spawners.erase(id);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Number of players which know about this object. Object won't be
|
||||
deleted until this is 0 to keep the id preserved for the right
|
||||
|
|
|
@ -48,7 +48,8 @@ void TestInventory::runTests(IGameDef *gamedef)
|
|||
|
||||
void TestInventory::testSerializeDeserialize(IItemDefManager *idef)
|
||||
{
|
||||
Inventory inv(idef);
|
||||
DetachedInventoryChangeReceiver * detached_inventory_change_receiver = new DetachedInventoryChangeReceiver("test");
|
||||
Inventory inv(idef, detached_inventory_change_receiver);
|
||||
std::istringstream is(serialized_inventory, std::ios::binary);
|
||||
|
||||
inv.deSerialize(is);
|
||||
|
|
Loading…
Reference in New Issue