本文整理汇总了C++中ItemStack类的典型用法代码示例。如果您正苦于以下问题:C++ ItemStack类的具体用法?C++ ItemStack怎么用?C++ ItemStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ItemStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool operator==(ItemStack const &left, ItemStack const &right)
{
if (&left.getType() == &right.getType())
return left.getAmount() == right.getAmount();
else
return false;
}
示例2: read_item
// add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_item(lua_State *L)
{
GET_ENV_PTR;
// pos
//v3f pos = checkFloatPos(L, 1);
// item
ItemStack item = read_item(L, 2,getServer(L));
if(item.empty() || !item.isKnown(getServer(L)->idef()))
return 0;
lua_pushcfunction(L, script_error_handler);
int errorhandler = lua_gettop(L);
// Use spawn_item to spawn a __builtin:item
lua_getglobal(L, "core");
lua_getfield(L, -1, "spawn_item");
lua_remove(L, -2); // Remove core
if(lua_isnil(L, -1))
return 0;
lua_pushvalue(L, 1);
lua_pushstring(L, item.getItemString().c_str());
PCALL_RESL(L, lua_pcall(L, 2, 1, errorhandler));
lua_remove(L, errorhandler); // Remove error handler
return 1;
}
示例3: checkLoot
/**
* Check to see if the player is picking up loot on the ground
*/
void GameStatePlay::checkLoot() {
if (!pc->stats.alive)
return;
if (menu->isDragging())
return;
ItemStack pickup;
// Autopickup
if (AUTOPICKUP_CURRENCY) {
pickup = loot->checkAutoPickup(pc->stats.pos);
if (!pickup.empty()) {
menu->inv->add(pickup, CARRIED, -1, true, true);
pickup.clear();
}
}
// Normal pickups
if (!pc->stats.attacking) {
pickup = loot->checkPickup(inpt->mouse, mapr->cam, pc->stats.pos);
}
if (!pickup.empty()) {
menu->inv->add(pickup, CARRIED, -1, true, true);
camp->setStatus(items->items[pickup.item].pickup_status);
pickup.clear();
}
}
示例4: add
bool MenuStash::add(ItemStack stack, int slot, bool play_sound) {
if (stack.empty()) {
return true;
}
if (play_sound) {
items->playSound(stack.item);
}
if (items->items[stack.item].quest_item) {
pc->logMsg(msg->get("Can not store quest items in the stash."), Avatar::MSG_NORMAL);
drop_stack.push(stack);
return false;
}
ItemStack leftover = stock.add(stack, slot);
if (!leftover.empty()) {
if (leftover.quantity != stack.quantity) {
updated = true;
}
pc->logMsg(msg->get("Stash is full."), Avatar::MSG_NORMAL);
drop_stack.push(leftover);
return false;
}
else {
updated = true;
}
return true;
}
示例5: read_item
// minetest.add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_item(lua_State *L)
{
GET_ENV_PTR;
// pos
//v3f pos = checkFloatPos(L, 1);
// item
ItemStack item = read_item(L, 2,getServer(L));
if(item.empty() || !item.isKnown(getServer(L)->idef()))
return 0;
// Use minetest.spawn_item to spawn a __builtin:item
lua_getglobal(L, "minetest");
lua_getfield(L, -1, "spawn_item");
if(lua_isnil(L, -1))
return 0;
lua_pushvalue(L, 1);
lua_pushstring(L, item.getItemString().c_str());
if(lua_pcall(L, 2, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
return 1;
/*lua_pushvalue(L, 1);
lua_pushstring(L, "__builtin:item");
lua_pushstring(L, item.getItemString().c_str());
return l_add_entity(L);*/
/*// Do it
ServerActiveObject *obj = createItemSAO(env, pos, item.getItemString());
int objectid = env->addActiveObject(obj);
// If failed to add, return nothing (reads as nil)
if(objectid == 0)
return 0;
// Return ObjectRef
objectrefGetOrCreate(L, obj);
return 1;*/
}
示例6: punch
int punch(v3f dir,
const ToolCapabilities *toolcap,
ServerActiveObject *puncher,
float time_from_last_punch)
{
// Take item into inventory
ItemStack item = createItemStack();
Inventory *inv = puncher->getInventory();
if(inv != NULL)
{
std::string wieldlist = puncher->getWieldList();
ItemStack leftover = inv->addItem(wieldlist, item);
puncher->setInventoryModified();
if(leftover.empty())
{
m_removed = true;
}
else
{
m_itemstring = leftover.getItemString();
m_itemstring_changed = true;
}
}
return 0;
}
示例7: click
/**
* Click-start dragging in the inventory
*/
ItemStack MenuInventory::click(Point position) {
ItemStack item;
drag_prev_src = areaOver(position);
if (drag_prev_src > -1) {
item = inventory[drag_prev_src].click(position);
if (TOUCHSCREEN) {
tablist.setCurrent(inventory[drag_prev_src].current_slot);
}
if (item.empty()) {
drag_prev_src = -1;
return item;
}
// if dragging equipment, prepare to change stats/sprites
if (drag_prev_src == EQUIPMENT) {
if (stats->humanoid) {
updateEquipment(inventory[EQUIPMENT].drag_prev_slot);
}
else {
itemReturn(item);
item.clear();
}
}
}
return item;
}
示例8: checkLoot
/**
* Check to see if the player is picking up loot on the ground
*/
void GameStatePlay::checkLoot() {
if (!pc->stats.alive)
return;
if (menu->isDragging())
return;
ItemStack pickup;
// Autopickup
if (AUTOPICKUP_CURRENCY) {
pickup = loot->checkAutoPickup(pc->stats.pos, menu->inv);
if (!pickup.empty()) menu->inv->add(pickup);
}
// Normal pickups
if (!pc->stats.attacking)
pickup = loot->checkPickup(inpt->mouse, mapr->cam, pc->stats.pos, menu->inv);
if (!pickup.empty()) {
menu->inv->add(pickup);
camp->setStatus(items->items[pickup.item].pickup_status);
}
if (loot->full_msg) {
if (inpt->pressing[MAIN1]) inpt->lock[MAIN1] = true;
if (inpt->pressing[ACCEPT]) inpt->lock[ACCEPT] = true;
menu->questlog->add(msg->get("Inventory is full."), LOG_TYPE_MESSAGES);
menu->hudlog->add(msg->get("Inventory is full."));
loot->full_msg = false;
}
}
示例9: verifyDatabase
bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
{
verifyDatabase();
str_to_sqlite(m_stmt_player_load, 1, player->getName());
if (sqlite3_step(m_stmt_player_load) != SQLITE_ROW) {
sqlite3_reset(m_stmt_player_load);
return false;
}
sao->setPitch(sqlite_to_float(m_stmt_player_load, 0));
sao->setYaw(sqlite_to_float(m_stmt_player_load, 1));
sao->setBasePosition(sqlite_to_v3f(m_stmt_player_load, 2));
sao->setHPRaw((s16) MYMIN(sqlite_to_int(m_stmt_player_load, 5), S16_MAX));
sao->setBreath((u16) MYMIN(sqlite_to_int(m_stmt_player_load, 6), U16_MAX), false);
sqlite3_reset(m_stmt_player_load);
// Load inventory
str_to_sqlite(m_stmt_player_load_inventory, 1, player->getName());
while (sqlite3_step(m_stmt_player_load_inventory) == SQLITE_ROW) {
InventoryList *invList = player->inventory.addList(
sqlite_to_string(m_stmt_player_load_inventory, 2),
sqlite_to_uint(m_stmt_player_load_inventory, 3));
invList->setWidth(sqlite_to_uint(m_stmt_player_load_inventory, 1));
u32 invId = sqlite_to_uint(m_stmt_player_load_inventory, 0);
str_to_sqlite(m_stmt_player_load_inventory_items, 1, player->getName());
int_to_sqlite(m_stmt_player_load_inventory_items, 2, invId);
while (sqlite3_step(m_stmt_player_load_inventory_items) == SQLITE_ROW) {
const std::string itemStr = sqlite_to_string(m_stmt_player_load_inventory_items, 1);
if (itemStr.length() > 0) {
ItemStack stack;
stack.deSerialize(itemStr);
invList->addItem(sqlite_to_uint(m_stmt_player_load_inventory_items, 0), stack);
}
}
sqlite3_reset(m_stmt_player_load_inventory_items);
}
sqlite3_reset(m_stmt_player_load_inventory);
str_to_sqlite(m_stmt_player_metadata_load, 1, sao->getPlayer()->getName());
while (sqlite3_step(m_stmt_player_metadata_load) == SQLITE_ROW) {
std::string attr = sqlite_to_string(m_stmt_player_metadata_load, 0);
std::string value = sqlite_to_string(m_stmt_player_metadata_load, 1);
sao->setExtendedAttribute(attr, value);
}
sqlite3_reset(m_stmt_player_metadata_load);
return true;
}
示例10: wield
void Camera::wield(const ItemStack &item)
{
IItemDefManager *idef = m_gamedef->idef();
m_eatable = item.getDefinition(idef).eatable;
scene::IMesh *wield_mesh = item.getDefinition(idef).wield_mesh;
if(wield_mesh)
{
m_wieldnode->setMesh(wield_mesh);
m_wieldnode->setVisible(true);
}
else
{
m_wieldnode->setVisible(false);
}
}
示例11: if
CraftOutput CraftDefinitionToolRepair::getOutput(const CraftInput &input, IGameDef *gamedef) const
{
ItemStack item1;
ItemStack item2;
for (const auto &item : input.items) {
if (!item.empty()) {
if (item1.empty())
item1 = item;
else if (item2.empty())
item2 = item;
}
}
ItemStack repaired = craftToolRepair(item1, item2, additional_wear, gamedef);
return CraftOutput(repaired.getItemString(), 0);
}
示例12: click
ItemStack MenuItemStorage::click(Point position) {
ItemStack item;
drag_prev_slot = slotOver(position);
// try to click on the highlighted (aka in focus) slot
// since mouse clicks defocus slots before this point,
// we don't have to worry about the mouse being over another slot
if (drag_prev_slot == -1) {
for (unsigned int i=0; i<slots.size(); i++) {
if (slots[i]->in_focus) {
drag_prev_slot = i;
break;
}
}
}
if (drag_prev_slot > -1) {
item = storage[drag_prev_slot];
if (TOUCHSCREEN) {
if (!slots[drag_prev_slot]->in_focus && !item.empty()) {
slots[drag_prev_slot]->in_focus = true;
current_slot = slots[drag_prev_slot];
item.clear();
drag_prev_slot = -1;
return item;
}
else {
slots[drag_prev_slot]->in_focus = false;
current_slot = NULL;
}
}
if (!item.empty()) {
if (item.quantity > 1 && !inpt->pressing[CTRL] && (inpt->pressing[SHIFT] || NO_MOUSE || inpt->touch_locked)) {
// we use an external menu to let the player pick the desired quantity
// we will subtract from this stack after they've made their decision
return item;
}
subtract( drag_prev_slot, item.quantity);
}
// item will be cleared if item.empty() == true
return item;
}
else {
item.clear();
return item;
}
}
示例13: read_item
ItemStack read_item(lua_State *L, int index)
{
if(index < 0)
index = lua_gettop(L) + 1 + index;
if(lua_isnil(L, index))
{
return ItemStack();
}
else if(lua_isuserdata(L, index))
{
// Convert from LuaItemStack
LuaItemStack *o = LuaItemStack::checkobject(L, index);
return o->getItem();
}
else if(lua_isstring(L, index))
{
// Convert from itemstring
std::string itemstring = lua_tostring(L, index);
IItemDefManager *idef = get_server(L)->idef();
try
{
ItemStack item;
item.deSerialize(itemstring, idef);
return item;
}
catch(SerializationError &e)
{
infostream<<"WARNING: unable to create item from itemstring"
<<": "<<itemstring<<std::endl;
return ItemStack();
}
}
else if(lua_istable(L, index))
{
// Convert from table
IItemDefManager *idef = get_server(L)->idef();
std::string name = getstringfield_default(L, index, "name", "");
int count = getintfield_default(L, index, "count", 1);
int wear = getintfield_default(L, index, "wear", 0);
std::string metadata = getstringfield_default(L, index, "metadata", "");
return ItemStack(name, count, wear, metadata, idef);
}
else
{
throw LuaError(L, "Expecting itemstack, itemstring, table or nil");
}
}
示例14: getstringfield_default
// get_craft_result(input)
int ModApiCraft::l_get_craft_result(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
int input_i = 1;
std::string method_s = getstringfield_default(L, input_i, "method", "normal");
enum CraftMethod method = (CraftMethod)getenumfield(L, input_i, "method",
es_CraftMethod, CRAFT_METHOD_NORMAL);
int width = 1;
lua_getfield(L, input_i, "width");
if(lua_isnumber(L, -1))
width = luaL_checkinteger(L, -1);
lua_pop(L, 1);
lua_getfield(L, input_i, "items");
std::vector<ItemStack> items = read_items(L, -1,getServer(L));
lua_pop(L, 1); // items
IGameDef *gdef = getServer(L);
ICraftDefManager *cdef = gdef->cdef();
CraftInput input(method, width, items);
CraftOutput output;
std::vector<ItemStack> output_replacements;
bool got = cdef->getCraftResult(input, output, output_replacements, true, gdef);
lua_newtable(L); // output table
if (got) {
ItemStack item;
item.deSerialize(output.item, gdef->idef());
LuaItemStack::create(L, item);
lua_setfield(L, -2, "item");
setintfield(L, -1, "time", output.time);
push_items(L, output_replacements);
lua_setfield(L, -2, "replacements");
} else {
LuaItemStack::create(L, ItemStack());
lua_setfield(L, -2, "item");
setintfield(L, -1, "time", 0);
lua_newtable(L);
lua_setfield(L, -2, "replacements");
}
lua_newtable(L); // decremented input table
lua_pushstring(L, method_s.c_str());
lua_setfield(L, -2, "method");
lua_pushinteger(L, width);
lua_setfield(L, -2, "width");
push_items(L, input.items);
lua_setfield(L, -2, "items");
return 2;
}
示例15: addEntity
shared_ptr<EntityItem> World::dropItem(const ItemStack &items, Point3D location) {
shared_ptr<EntityItem> item = make_shared<EntityItem>(items.getId(), items.size(), location);
addEntity(item);
for (const shared_ptr<Entity> &entity : m->entities) {
shared_ptr<Player> player = dynamic_pointer_cast<Player>(entity);
if (!player)
continue;
cout << "Found player in world!\n";
cout << player->getPosition() << " - " << location << " = " << player->getPosition().distanceTo3D(location) << '\n';
if (player->getPosition().distanceTo3D(location) < Player::ITEM_VIEW_DISTANCE) {
cout << "Found player in world near to item!\n";
player->getConnection().sendItemSpawned(item);
}
}
return item;
}