Exemple #1
0
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;
	}
}
Exemple #2
0
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);
}
Exemple #3
0
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);
	}
}