Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <ItemGrid.h>
Classes | |
class | cListener |
This class is used as a callback for when a slot changes. More... | |
Public Types | |
typedef std::vector< cListener * > | cListeners |
Public Member Functions | |
char | AddItem (cItem &a_ItemStack, bool a_AllowNewStacks=true, int a_PrioritySlot=-1) |
Adds as many items out of a_ItemStack as can fit. More... | |
char | AddItems (cItems &a_ItemStackList, bool a_AllowNewStacks=true, int a_PrioritySlot=-1) |
Same as AddItem, but works on an entire list of item stacks. More... | |
void | AddListener (cListener &a_Listener) |
Adds a callback that gets called whenever a slot changes. More... | |
char | ChangeSlotCount (int a_SlotNum, char a_AddToCount) |
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot. More... | |
char | ChangeSlotCount (int a_X, int a_Y, char a_AddToCount) |
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot. More... | |
cItemGrid (int a_Width, int a_Height) | |
void | Clear (void) |
Sets all items as empty. More... | |
void | CopyFrom (const cItemGrid &a_Src) |
Copies all items from a_Src to this grid. More... | |
void | CopyToItems (cItems &a_Items) const |
Copies the contents into a cItems object; preserves the original a_Items contents. More... | |
bool | DamageItem (int a_SlotNum, short a_Amount) |
Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact) More... | |
bool | DamageItem (int a_X, int a_Y, short a_Amount) |
Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact) More... | |
void | EmptySlot (int a_SlotNum) |
void | EmptySlot (int a_X, int a_Y) |
cItem * | FindItem (const cItem &a_RecipeItem) |
Finds an item based on ItemType and ItemDamage (<- defines the itemType, too) More... | |
void | GenerateRandomLootWithBooks (const cLootProbab *a_LootProbabs, size_t a_CountLootProbabs, int a_NumSlots, int a_Seed) |
Generates random loot from the specified loot probability table, with a chance of enchanted books added. More... | |
int | GetFirstEmptySlot (void) const |
Returns the index of the first empty slot; -1 if all full. More... | |
int | GetFirstUsedSlot (void) const |
Returns the index of the first non-empty slot; -1 if all empty. More... | |
int | GetHeight (void) const |
int | GetLastEmptySlot (void) const |
Returns the index of the last empty slot; -1 if all full. More... | |
int | GetLastUsedSlot (void) const |
Returns the index of the last used slot; -1 if all empty. More... | |
int | GetNextEmptySlot (int a_StartFrom) const |
Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked) More... | |
int | GetNextUsedSlot (int a_StartFrom) const |
Returns the index of the first used slot following a_StartFrom (a_StartFrom is not checked) More... | |
int | GetNumSlots (void) const |
const cItem & | GetSlot (int a_SlotNum) const |
const cItem & | GetSlot (int a_X, int a_Y) const |
void | GetSlotCoords (int a_SlotNum, int &a_X, int &a_Y) const |
Converts slot number into XY coords; sets coords to -1 on invalid slot number. More... | |
int | GetSlotNum (int a_X, int a_Y) const |
Converts XY coords into slot number; returns -1 on invalid coords. More... | |
int | GetWidth (void) const |
bool | HasItems (const cItem &a_ItemStack) |
Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack. More... | |
int | HowManyCanFit (const cItem &a_ItemStack, bool a_AllowNewStacks=true) |
Returns number of items out of a_ItemStack that can fit in the storage. More... | |
int | HowManyItems (const cItem &a_Item) |
Returns the number of items of type a_Item that are stored. More... | |
bool | IsSlotEmpty (int a_SlotNum) const |
Returns true if the specified slot is empty or the slot doesn't exist. More... | |
bool | IsSlotEmpty (int a_X, int a_Y) const |
Returns true if the specified slot is empty or the slot doesn't exist. More... | |
bool | IsValidSlotCoords (int a_X, int a_Y) const |
Returns true if slot coordinates lie within the grid. More... | |
bool | IsValidSlotNum (int a_SlotNum) const |
Returns true if slot number is within the grid. More... | |
char | RemoveItem (const cItem &a_ItemStack) |
Removes the specified item from the grid, as many as possible, up to a_ItemStack.m_ItemCount. More... | |
void | RemoveListener (cListener &a_Listener) |
Removes a slot-change-callback. More... | |
cItem | RemoveOneItem (int a_SlotNum) |
Removes one item from the stack in the specified slot, and returns it. More... | |
cItem | RemoveOneItem (int a_X, int a_Y) |
Removes one item from the stack in the specified slot, and returns it. More... | |
void | SetSlot (int a_SlotNum, const cItem &a_Item) |
void | SetSlot (int a_SlotNum, short a_ItemType, char a_ItemCount, short a_ItemDamage) |
void | SetSlot (int a_X, int a_Y, const cItem &a_Item) |
void | SetSlot (int a_X, int a_Y, short a_ItemType, char a_ItemCount, short a_ItemDamage) |
Protected Member Functions | |
char | AddItemToSlot (const cItem &a_ItemStack, int a_Slot, int a_Num, int a_MaxStack) |
Adds up to a_Num items out of a_ItemStack, as many as can fit, in specified slot Returns the number of items that did fit. More... | |
void | TriggerListeners (int a_SlotNum) |
Calls all m_Listeners for the specified slot number. More... | |
Protected Attributes | |
cCriticalSection | m_CSListeners |
CS that guards the m_Listeners against multi-thread access. More... | |
int | m_Height |
bool | m_IsInTriggerListeners |
Set to true while TriggerListeners is running, to detect attempts to manipulate listener list while triggerring. More... | |
cListeners | m_Listeners |
Listeners which should be notified on slot changes; the pointers are not owned by this object. More... | |
cLazyArray< cItem > | m_Slots |
int | m_Width |
Definition at line 19 of file ItemGrid.h.
typedef std::vector<cListener *> cItemGrid::cListeners |
Definition at line 33 of file ItemGrid.h.
cItemGrid::cItemGrid | ( | int | a_Width, |
int | a_Height | ||
) |
Definition at line 15 of file ItemGrid.cpp.
char cItemGrid::AddItem | ( | cItem & | a_ItemStack, |
bool | a_AllowNewStacks = true , |
||
int | a_PrioritySlot = -1 |
||
) |
Adds as many items out of a_ItemStack as can fit.
If a_AllowNewStacks is set to false, only existing stacks can be topped up; If a_AllowNewStacks is set to true, empty slots can be used for the rest. If a_PrioritySlot is set to a positive value, then the corresponding slot will be used first (if empty or compatible with added items). If a_PrioritySlot is set to -1, regular order applies. Returns the number of items that fit.
Definition at line 313 of file ItemGrid.cpp.
char cItemGrid::AddItems | ( | cItems & | a_ItemStackList, |
bool | a_AllowNewStacks = true , |
||
int | a_PrioritySlot = -1 |
||
) |
Same as AddItem, but works on an entire list of item stacks.
The a_ItemStackList is modified to reflect the leftover items. If a_AllowNewStacks is set to false, only existing stacks can be topped up; If a_AllowNewStacks is set to true, empty slots can be used for the rest. If a_PrioritySlot is set to a positive value, then the corresponding slot will be used first (if empty or compatible with added items). If a_PrioritySlot is set to -1, regular order applies. Returns the total number of items that fit.
Definition at line 381 of file ItemGrid.cpp.
|
protected |
Adds up to a_Num items out of a_ItemStack, as many as can fit, in specified slot Returns the number of items that did fit.
Definition at line 283 of file ItemGrid.cpp.
void cItemGrid::AddListener | ( | cListener & | a_Listener | ) |
Adds a callback that gets called whenever a slot changes.
Must not be called from within the listener callback!
Definition at line 809 of file ItemGrid.cpp.
char cItemGrid::ChangeSlotCount | ( | int | a_SlotNum, |
char | a_AddToCount | ||
) |
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot.
If the slot is empty, ignores the call. Returns the new count.
Definition at line 468 of file ItemGrid.cpp.
char cItemGrid::ChangeSlotCount | ( | int | a_X, |
int | a_Y, | ||
char | a_AddToCount | ||
) |
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot.
If the slot is empty, ignores the call. Returns the new count.
Definition at line 507 of file ItemGrid.cpp.
void cItemGrid::Clear | ( | void | ) |
Sets all items as empty.
Definition at line 228 of file ItemGrid.cpp.
void cItemGrid::CopyFrom | ( | const cItemGrid & | a_Src | ) |
Copies all items from a_Src to this grid.
Doesn't copy the listeners.
Definition at line 83 of file ItemGrid.cpp.
void cItemGrid::CopyToItems | ( | cItems & | a_Items | ) | const |
Copies the contents into a cItems object; preserves the original a_Items contents.
Definition at line 703 of file ItemGrid.cpp.
bool cItemGrid::DamageItem | ( | int | a_SlotNum, |
short | a_Amount | ||
) |
Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact)
Definition at line 723 of file ItemGrid.cpp.
bool cItemGrid::DamageItem | ( | int | a_X, |
int | a_Y, | ||
short | a_Amount | ||
) |
Adds the specified damage to the specified item; returns true if the item broke (but the item is left intact)
Definition at line 743 of file ItemGrid.cpp.
void cItemGrid::EmptySlot | ( | int | a_SlotNum | ) |
Definition at line 178 of file ItemGrid.cpp.
void cItemGrid::EmptySlot | ( | int | a_X, |
int | a_Y | ||
) |
Definition at line 169 of file ItemGrid.cpp.
Finds an item based on ItemType and ItemDamage (<- defines the itemType, too)
Definition at line 443 of file ItemGrid.cpp.
void cItemGrid::GenerateRandomLootWithBooks | ( | const cLootProbab * | a_LootProbabs, |
size_t | a_CountLootProbabs, | ||
int | a_NumSlots, | ||
int | a_Seed | ||
) |
Generates random loot from the specified loot probability table, with a chance of enchanted books added.
A total of a_NumSlots are taken by the loot. Cannot export to Lua due to raw array a_LootProbabs. TODO: Make this exportable / export through ManualBindings.cpp with a Lua table as LootProbabs
Definition at line 752 of file ItemGrid.cpp.
int cItemGrid::GetFirstEmptySlot | ( | void | ) | const |
Returns the index of the first empty slot; -1 if all full.
Definition at line 595 of file ItemGrid.cpp.
int cItemGrid::GetFirstUsedSlot | ( | void | ) | const |
Returns the index of the first non-empty slot; -1 if all empty.
Definition at line 604 of file ItemGrid.cpp.
|
inline |
Definition at line 39 of file ItemGrid.h.
int cItemGrid::GetLastEmptySlot | ( | void | ) | const |
Returns the index of the last empty slot; -1 if all full.
Definition at line 613 of file ItemGrid.cpp.
int cItemGrid::GetLastUsedSlot | ( | void | ) | const |
Returns the index of the last used slot; -1 if all empty.
Definition at line 629 of file ItemGrid.cpp.
int cItemGrid::GetNextEmptySlot | ( | int | a_StartFrom | ) | const |
Returns the index of the first empty slot following a_StartFrom (a_StartFrom is not checked)
Definition at line 650 of file ItemGrid.cpp.
int cItemGrid::GetNextUsedSlot | ( | int | a_StartFrom | ) | const |
Returns the index of the first used slot following a_StartFrom (a_StartFrom is not checked)
Definition at line 674 of file ItemGrid.cpp.
|
inline |
Definition at line 40 of file ItemGrid.h.
const cItem & cItemGrid::GetSlot | ( | int | a_SlotNum | ) | const |
Definition at line 105 of file ItemGrid.cpp.
const cItem & cItemGrid::GetSlot | ( | int | a_X, |
int | a_Y | ||
) | const |
Definition at line 96 of file ItemGrid.cpp.
void cItemGrid::GetSlotCoords | ( | int | a_SlotNum, |
int & | a_X, | ||
int & | a_Y | ||
) | const |
Converts slot number into XY coords; sets coords to -1 on invalid slot number.
Exported in ManualBindings.cpp
Definition at line 64 of file ItemGrid.cpp.
int cItemGrid::GetSlotNum | ( | int | a_X, |
int | a_Y | ||
) | const |
Converts XY coords into slot number; returns -1 on invalid coords.
Definition at line 48 of file ItemGrid.cpp.
|
inline |
Definition at line 38 of file ItemGrid.h.
bool cItemGrid::HasItems | ( | const cItem & | a_ItemStack | ) |
Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack.
Definition at line 585 of file ItemGrid.cpp.
int cItemGrid::HowManyCanFit | ( | const cItem & | a_ItemStack, |
bool | a_AllowNewStacks = true |
||
) |
Returns number of items out of a_ItemStack that can fit in the storage.
Definition at line 246 of file ItemGrid.cpp.
int cItemGrid::HowManyItems | ( | const cItem & | a_Item | ) |
Returns the number of items of type a_Item that are stored.
Definition at line 563 of file ItemGrid.cpp.
bool cItemGrid::IsSlotEmpty | ( | int | a_SlotNum | ) | const |
Returns true if the specified slot is empty or the slot doesn't exist.
Definition at line 203 of file ItemGrid.cpp.
bool cItemGrid::IsSlotEmpty | ( | int | a_X, |
int | a_Y | ||
) | const |
Returns true if the specified slot is empty or the slot doesn't exist.
Definition at line 219 of file ItemGrid.cpp.
bool cItemGrid::IsValidSlotCoords | ( | int | a_X, |
int | a_Y | ||
) | const |
Returns true if slot coordinates lie within the grid.
Definition at line 36 of file ItemGrid.cpp.
bool cItemGrid::IsValidSlotNum | ( | int | a_SlotNum | ) | const |
Returns true if slot number is within the grid.
Definition at line 27 of file ItemGrid.cpp.
char cItemGrid::RemoveItem | ( | const cItem & | a_ItemStack | ) |
Removes the specified item from the grid, as many as possible, up to a_ItemStack.m_ItemCount.
Returns the number of items that were removed.
Definition at line 405 of file ItemGrid.cpp.
void cItemGrid::RemoveListener | ( | cListener & | a_Listener | ) |
Removes a slot-change-callback.
Must not be called from within the listener callback!
Definition at line 820 of file ItemGrid.cpp.
cItem cItemGrid::RemoveOneItem | ( | int | a_SlotNum | ) |
Removes one item from the stack in the specified slot, and returns it.
If the slot was empty, returns an empty item
Definition at line 516 of file ItemGrid.cpp.
cItem cItemGrid::RemoveOneItem | ( | int | a_X, |
int | a_Y | ||
) |
Removes one item from the stack in the specified slot, and returns it.
If the slot was empty, returns an empty item
Definition at line 554 of file ItemGrid.cpp.
void cItemGrid::SetSlot | ( | int | a_SlotNum, |
const cItem & | a_Item | ||
) |
Definition at line 139 of file ItemGrid.cpp.
void cItemGrid::SetSlot | ( | int | a_SlotNum, |
short | a_ItemType, | ||
char | a_ItemCount, | ||
short | a_ItemDamage | ||
) |
Definition at line 160 of file ItemGrid.cpp.
void cItemGrid::SetSlot | ( | int | a_X, |
int | a_Y, | ||
const cItem & | a_Item | ||
) |
Definition at line 121 of file ItemGrid.cpp.
void cItemGrid::SetSlot | ( | int | a_X, |
int | a_Y, | ||
short | a_ItemType, | ||
char | a_ItemCount, | ||
short | a_ItemDamage | ||
) |
Definition at line 130 of file ItemGrid.cpp.
|
protected |
Calls all m_Listeners for the specified slot number.
Definition at line 838 of file ItemGrid.cpp.
|
protected |
CS that guards the m_Listeners against multi-thread access.
Definition at line 192 of file ItemGrid.h.
|
protected |
Definition at line 188 of file ItemGrid.h.
|
protected |
Set to true while TriggerListeners is running, to detect attempts to manipulate listener list while triggerring.
Definition at line 193 of file ItemGrid.h.
|
protected |
Listeners which should be notified on slot changes; the pointers are not owned by this object.
Definition at line 191 of file ItemGrid.h.
|
protected |
Definition at line 189 of file ItemGrid.h.
|
protected |
Definition at line 187 of file ItemGrid.h.