static ItemStack craftToolRepair( const ItemStack &item1, const ItemStack &item2, float additional_wear, IGameDef *gamedef) { IItemDefManager *idef = gamedef->idef(); if(item1.count != 1 || item2.count != 1 || item1.name != item2.name || idef->get(item1.name).type != ITEM_TOOL || idef->get(item2.name).type != ITEM_TOOL) { // Failure return ItemStack(); } s32 item1_uses = 65536 - (u32) item1.wear; s32 item2_uses = 65536 - (u32) item2.wear; s32 new_uses = item1_uses + item2_uses; s32 new_wear = 65536 - new_uses + floor(additional_wear * 65536 + 0.5); if(new_wear >= 65536) return ItemStack(); if(new_wear < 0) new_wear = 0; ItemStack repaired = item1; repaired.wear = new_wear; return repaired; }
void Camera::wield(const ItemStack &item, u16 playeritem) { IItemDefManager *idef = m_gamedef->idef(); std::string itemname = item.getDefinition(idef).name; m_wield_mesh_next = idef->getWieldMesh(itemname, m_gamedef); if(playeritem != m_previous_playeritem && !(m_previous_itemname == "" && itemname == "")) { m_previous_playeritem = playeritem; m_previous_itemname = itemname; if(m_wield_change_timer >= 0.125) m_wield_change_timer = -0.125; else if(m_wield_change_timer > 0) { m_wield_change_timer = -m_wield_change_timer; } } else { if(m_wield_mesh_next) { m_wieldnode->setMesh(m_wield_mesh_next); m_wieldnode->setVisible(true); } else { m_wieldnode->setVisible(false); } m_wield_mesh_next = NULL; if(m_previous_itemname != itemname) { m_previous_itemname = itemname; m_wield_change_timer = 0; } else m_wield_change_timer = 0.125; } }
void WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef) { ITextureSource *tsrc = gamedef->getTextureSource(); IItemDefManager *idef = gamedef->getItemDefManager(); const ItemDefinition &def = item.getDefinition(idef); // If wield_image is defined, it overrides everything else if (def.wield_image != "") { setExtruded(def.wield_image, def.wield_scale, tsrc); return; } // Handle nodes // See also CItemDefManager::createClientCached() if (def.type == ITEM_NODE) { INodeDefManager *ndef = gamedef->getNodeDefManager(); const ContentFeatures &f = ndef->get(def.name); if (f.mesh_ptr[0]) { // e.g. mesh nodes and nodeboxes changeToMesh(f.mesh_ptr[0]); // mesh_ptr[0] is pre-scaled by BS * f->visual_scale m_meshnode->setScale( def.wield_scale * WIELD_SCALE_FACTOR / (BS * f.visual_scale)); // Customize materials for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) { assert(i < 6); video::SMaterial &material = m_meshnode->getMaterial(i); material.setTexture(0, f.tiles[i].texture); f.tiles[i].applyMaterialOptions(material); } return; } else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES) { setCube(f.tiles, def.wield_scale, tsrc); return; } else if (f.drawtype == NDT_AIRLIKE) { changeToMesh(NULL); return; } // If none of the above standard cases worked, use the wield mesh from ClientCached scene::IMesh *mesh = idef->getWieldMesh(item.name, gamedef); if (mesh) { changeToMesh(mesh); m_meshnode->setScale(def.wield_scale * WIELD_SCALE_FACTOR); return; } } // default to inventory_image if (def.inventory_image != "") { setExtruded(def.inventory_image, def.wield_scale, tsrc); return; } // no wield mesh found changeToMesh(NULL); }
void Camera::wield(const ItemStack &item) { IItemDefManager *idef = m_gamedef->idef(); scene::IMesh *wield_mesh = idef->getWieldMesh(item.getDefinition(idef).name, m_gamedef); if(wield_mesh) { m_wieldnode->setMesh(wield_mesh); m_wieldnode->setVisible(true); } else { m_wieldnode->setVisible(false); } }
// get_item_def(itemstring) int ModApiClient::l_get_item_def(lua_State *L) { IGameDef *gdef = getGameDef(L); assert(gdef); IItemDefManager *idef = gdef->idef(); assert(idef); if (!lua_isstring(L, 1)) return 0; const std::string &name(lua_tostring(L, 1)); if (!idef->isKnown(name)) return 0; const ItemDefinition &def = idef->get(name); push_item_definition_full(L, def); return 1; }
// get_item_def(itemstring) int ModApiClient::l_get_item_def(lua_State *L) { IGameDef *gdef = getGameDef(L); assert(gdef); IItemDefManager *idef = gdef->idef(); assert(idef); if (getClient(L)->checkCSMFlavourLimit(CSMFlavourLimit::CSM_FL_READ_ITEMDEFS)) return 0; if (!lua_isstring(L, 1)) return 0; const std::string &name(lua_tostring(L, 1)); if (!idef->isKnown(name)) return 0; const ItemDefinition &def = idef->get(name); push_item_definition_full(L, def); return 1; }
void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client) { ITextureSource *tsrc = client->getTextureSource(); IItemDefManager *idef = client->getItemDefManager(); IShaderSource *shdrsrc = client->getShaderSource(); const NodeDefManager *ndef = client->getNodeDefManager(); const ItemDefinition &def = item.getDefinition(idef); const ContentFeatures &f = ndef->get(def.name); content_t id = ndef->getId(def.name); scene::SMesh *mesh = nullptr; if (m_enable_shaders) { u32 shader_id = shdrsrc->getShader("wielded_shader", TILE_MATERIAL_BASIC, NDT_NORMAL); m_material_type = shdrsrc->getShaderInfo(shader_id).material; } // Color-related m_colors.clear(); m_base_color = idef->getItemstackColor(item, client); // If wield_image is defined, it overrides everything else if (!def.wield_image.empty()) { setExtruded(def.wield_image, def.wield_overlay, def.wield_scale, tsrc, 1); m_colors.emplace_back(); // overlay is white, if present m_colors.emplace_back(true, video::SColor(0xFFFFFFFF)); return; } // Handle nodes // See also CItemDefManager::createClientCached() if (def.type == ITEM_NODE) { if (f.mesh_ptr[0]) { // e.g. mesh nodes and nodeboxes mesh = cloneMesh(f.mesh_ptr[0]); postProcessNodeMesh(mesh, f, m_enable_shaders, true, &m_material_type, &m_colors); changeToMesh(mesh); mesh->drop(); // mesh is pre-scaled by BS * f->visual_scale m_meshnode->setScale( def.wield_scale * WIELD_SCALE_FACTOR / (BS * f.visual_scale)); } else { switch (f.drawtype) { case NDT_AIRLIKE: { changeToMesh(nullptr); break; } case NDT_PLANTLIKE: { setExtruded(tsrc->getTextureName(f.tiles[0].layers[0].texture_id), tsrc->getTextureName(f.tiles[0].layers[1].texture_id), def.wield_scale, tsrc, f.tiles[0].layers[0].animation_frame_count); // Add color const TileLayer &l0 = f.tiles[0].layers[0]; m_colors.emplace_back(l0.has_color, l0.color); const TileLayer &l1 = f.tiles[0].layers[1]; m_colors.emplace_back(l1.has_color, l1.color); break; } case NDT_PLANTLIKE_ROOTED: { setExtruded(tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id), "", def.wield_scale, tsrc, f.special_tiles[0].layers[0].animation_frame_count); // Add color const TileLayer &l0 = f.special_tiles[0].layers[0]; m_colors.emplace_back(l0.has_color, l0.color); break; } case NDT_NORMAL: case NDT_ALLFACES: case NDT_LIQUID: case NDT_FLOWINGLIQUID: { setCube(f, def.wield_scale); break; } default: { mesh = createSpecialNodeMesh(client, id, &m_colors); changeToMesh(mesh); mesh->drop(); m_meshnode->setScale( def.wield_scale * WIELD_SCALE_FACTOR / (BS * f.visual_scale)); } } } u32 material_count = m_meshnode->getMaterialCount(); for (u32 i = 0; i < material_count; ++i) { video::SMaterial &material = m_meshnode->getMaterial(i); material.MaterialType = m_material_type; material.setFlag(video::EMF_BACK_FACE_CULLING, true); material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter); material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter); } return; } else if (!def.inventory_image.empty()) { setExtruded(def.inventory_image, def.inventory_overlay, def.wield_scale, tsrc, 1); m_colors.emplace_back(); // overlay is white, if present m_colors.emplace_back(true, video::SColor(0xFFFFFFFF)); return; } // no wield mesh found changeToMesh(nullptr); }