aboutsummaryrefslogtreecommitdiff
Commit message (Expand)AuthorAge
...
* Fix build with libstdc++kwolekr2015-05-19
* Split ObjDef/ObjDefManager out to objdef.cppkwolekr2015-05-18
* Lower log level for unexpected behaviourest312015-05-19
* Enforce hiding nametagest312015-05-18
* Add more swp files to gitignoreest312015-05-18
* Make nametags white againest312015-05-18
* Fix null dereference when loading schematic from definition without a NodeDef...kwolekr2015-05-17
* Record MapBlock modification reasons as flags instead of stringskwolekr2015-05-17
* SAPI/Noise: Add PerlinNoiseMap:getMapSlice() functionkwolekr2015-05-17
* Mapgen v5/v7: Detect sandstone, enable sandstone brick dungeonsparamat2015-05-17
* Add optional buffer param for bulk data array writes in Luakwolekr2015-05-17
* Noise: Fix interpolation at negative coordinateskwolekr2015-05-17
* Fix current mod name change missed during rebaseShadowNinja2015-05-16
* Add -Wsign-compare for Clang builds and fix some signed/unsigned compiler war...kwolekr2015-05-16
* SAPI: Accept either ARGB8 table or ColorString to specify colorskwolekr2015-05-16
* Add core.get_dir_listShadowNinja2015-05-16
* Add core.request_insecure_environment()ShadowNinja2015-05-16
* Add core.mkdirShadowNinja2015-05-16
* Add mod securityShadowNinja2015-05-16
* Added hour:minute format to time commandLeMagnesium2015-05-16
* Fix build since last commitest312015-05-16
* Finalize init packets and enable protocol v25est312015-05-16
* Add push_ARGB8 to script/common/c_converterTeTpaAka2015-05-15
* Generalize core.get/set_nametag_color into core.get/set_nametag_attributesTeTpaAka2015-05-15
* Noise: Make buffer size parameters unsignedkwolekr2015-05-15
* Schematics: Fix probability values for .mts version 1kwolekr2015-05-15
* Add minetest.register_on_punchplayerBrandon2015-05-15
* Add get and set functions for the nametag colorTeTpaAka2015-05-15
* ANDROID: Do not limit situations where fast is enabledCraig Robbins2015-05-15
* Fix libgmp for Androidest312015-05-15
* Don't crash if an item gets dropped into unloaded spacetenplus12015-05-15
* Item entity merging refactorest312015-05-15
* Fix compiler warning about sign comparisonest312015-05-13
* Build and link gmp correctly on MSVCSmallJoker2015-05-12
* Add code to support raillike group namesNovatux2015-05-12
* is_player() is no player-only functionest312015-05-12
* Mapgen v5/6/7: Cleanup node resolver and aliasesparamat2015-05-12
* Make early protocol auth mechanism generic, and add SRPest312015-05-11
* Add LibGMPest312015-05-11
* Replaced libjpeg dependency on apt-get, it should be libjpeg-dev instead of l...Megaf2015-05-11
* Change lower limit of display_gamma to 1.0 (linear light)Craig Robbins2015-05-11
* Schematics: Add per-node force placement optionkwolekr2015-05-09
* Fix typo in WieldMesh::setItem()kwolekr2015-05-08
* Ensure that Map::findNodesWithMetadata() reports nodes strictly within the no...kwolekr2015-05-08
* Replace Wieldmesh::setItem assertion that could be triggered by the server wi...kwolekr2015-05-08
* Fix release build warningest312015-05-08
* Fix compilation for non-client builds, and fix signed comparison warningkwolekr2015-05-08
* Tests: Add schematic unittestskwolekr2015-05-08
* Gracefully handle PacketErrorsest312015-05-08
* Fix missing Y component assignment in check_v3fkwolekr2015-05-08
span> IItemDefManager *itemdef); ~ItemStack() {} // Serialization void serialize(std::ostream &os) const; // Deserialization. Pass itemdef unless you don't want aliases resolved. void deSerialize(std::istream &is, IItemDefManager *itemdef = NULL); void deSerialize(const std::string &s, IItemDefManager *itemdef = NULL); // Returns the string used for inventory std::string getItemString() const; /* Quantity methods */ bool empty() const { return count == 0; } void clear() { name = ""; count = 0; wear = 0; metadata = ""; } void add(u16 n) { count += n; } void remove(u16 n) { assert(count >= n); // Pre-condition count -= n; if(count == 0) clear(); // reset name, wear and metadata too } // Maximum size of a stack u16 getStackMax(IItemDefManager *itemdef) const { return itemdef->get(name).stack_max; } // Number of items that can be added to this stack u16 freeSpace(IItemDefManager *itemdef) const { u16 max = getStackMax(itemdef); if (count >= max) return 0; return max - count; } // Returns false if item is not known and cannot be used bool isKnown(IItemDefManager *itemdef) const { return itemdef->isKnown(name); } // Returns a pointer to the item definition struct, // or a fallback one (name="unknown") if the item is unknown. const ItemDefinition& getDefinition( IItemDefManager *itemdef) const { return itemdef->get(name); } // Get tool digging properties, or those of the hand if not a tool const ToolCapabilities& getToolCapabilities( IItemDefManager *itemdef) const { ToolCapabilities *cap; cap = itemdef->get(name).tool_capabilities; if(cap == NULL) cap = itemdef->get("").tool_capabilities; assert(cap != NULL); return *cap; } // Wear out (only tools) // Returns true if the item is (was) a tool bool addWear(s32 amount, IItemDefManager *itemdef) { if(getDefinition(itemdef).type == ITEM_TOOL) { if(amount > 65535 - wear) clear(); else if(amount < -wear) wear = 0; else wear += amount; return true; } else { return false; } } // If possible, adds newitem to this item. // 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(const ItemStack &newitem, IItemDefManager *itemdef); // Checks whether newitem could be added. // If restitem is non-NULL, it receives the part of newitem that // would be left over after adding. bool itemFits(const ItemStack &newitem, ItemStack *restitem, // may be NULL IItemDefManager *itemdef) const; // Takes some items. // If there are not enough, takes as many as it can. // Returns empty item if couldn't take any. ItemStack takeItem(u32 takecount); // Similar to takeItem, but keeps this ItemStack intact. ItemStack peekItem(u32 peekcount) const; /* Properties */ std::string name; u16 count; u16 wear; std::string metadata; }; class InventoryList { public: InventoryList(std::string name, u32 size, IItemDefManager *itemdef); ~InventoryList(); void clearItems(); void setSize(u32 newsize); void setWidth(u32 newWidth); void setName(const std::string &name); void serialize(std::ostream &os) const; void deSerialize(std::istream &is); InventoryList(const InventoryList &other); InventoryList & operator = (const InventoryList &other); bool operator == (const InventoryList &other) const; bool operator != (const InventoryList &other) const { return !(*this == other); } const std::string &getName() const; u32 getSize() const; u32 getWidth() const; // Count used slots u32 getUsedSlots() const; u32 getFreeSlots() const; // Get reference to item 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); // Delete item void deleteItem(u32 i); // Adds an item to a suitable place. Returns leftover item (possibly empty). ItemStack addItem(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); // Checks whether the item could be added to the given slot // If restitem is non-NULL, it receives the part of newitem that // would be left over after adding. bool itemFits(const u32 i, const ItemStack &newitem, ItemStack *restitem = NULL) const; // Checks whether there is room for a given item bool roomForItem(const ItemStack &item) const; // Checks whether the given count of the given item name // exists in this inventory list. bool containsItem(const ItemStack &item) const; // Removes the given count of the given item name from // this inventory list. Walks the list in reverse order. // 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); // 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); // Similar to takeItem, but keeps the slot intact. ItemStack peekItem(u32 i, u32 peekcount) const; // 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 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); private: std::vector<ItemStack> m_items; u32 m_size, m_width; std::string m_name; IItemDefManager *m_itemdef; }; class Inventory { public: ~Inventory(); void clear(); void clearContents(); Inventory(IItemDefManager *itemdef); Inventory(const Inventory &other); Inventory & operator = (const Inventory &other); bool operator == (const Inventory &other) const; bool operator != (const Inventory &other) const { return !(*this == other); } void serialize(std::ostream &os) const; void deSerialize(std::istream &is); InventoryList * addList(const std::string &name, u32 size); InventoryList * getList(const std::string &name); 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 { return m_dirty; } void setModified(const bool x) { m_dirty = x; } private: // -1 if not found const s32 getListIndex(const std::string &name) const; std::vector<InventoryList*> m_lists; IItemDefManager *m_itemdef; bool m_dirty; }; #endif