add nodebox_meta bookshelf

This commit is contained in:
darkrose 2014-05-29 21:42:18 +10:00
parent 376e8a82aa
commit 426d7ae793
15 changed files with 214 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

BIN
data/textures/bookshelf_front.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

BIN
data/textures/bookshelf_side.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

BIN
data/textures/bookshelf_top.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

View File

@ -23,6 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mineral.h"
#include "mapblock_mesh.h" // For MapBlock_LightColor()
#include "settings.h"
#include "environment.h"
#include "nodemetadata.h"
#ifndef SERVER
// Create a cuboid.
@ -3301,11 +3303,14 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
makeCuboid(&collector, box, tiles, 6, c, txc);
}
if (content_features(n).draw_type == CDT_NODEBOX_META) {
boxes = content_features(n).getNodeBoxes(n);
NodeMetadata *meta = data->m_env->getMap().getNodeMetadata(p+blockpos_nodes);
if (meta == NULL)
break;
boxes = meta->getNodeBoxes(n);
if (boxes.size() > 0) {
for (int i = 0; i < 6; i++) {
// Handles facedir rotation for textures
tiles[i] = getNodeTile(n,p,tile_dirs[i],data->m_temp_mods);
tiles[i] = getMetaTile(n,p,tile_dirs[i],data->m_temp_mods);
}
for (std::vector<aabb3f>::iterator i = boxes.begin(); i != boxes.end(); i++) {
aabb3f box = *i;

View File

@ -1340,16 +1340,27 @@ void content_mapnode_init()
i = CONTENT_BOOKSHELF;
f = &content_features(i);
f->description = std::string("Book Shelf");
f->setAllTextures("bookshelf.png");
f->setTexture(0, "wood.png");
f->setTexture(1, "wood.png");
f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png");
f->draw_type = CDT_CUBELIKE;
f->setAllTextures("bookshelf_front.png");
f->setTexture(0, "bookshelf_top.png");
f->setTexture(1, "bookshelf_top.png");
f->setTexture(2, "bookshelf_side.png");
f->setTexture(3, "bookshelf_side.png");
f->setAllMetaTextures("bookshelf_book.png");
f->setMetaTexture(0, "bookshelf_book_top.png");
f->rotate_tile_with_nodebox = true;
//f->setInventoryTextureCube("wood.png", "bookshelf.png", "bookshelf.png");
f->draw_type = CDT_NODEBOX_META;
f->param_type = CPT_FACEDIR_SIMPLE;
f->is_ground_content = true;
f->flammable = 1; // can be replaced by fire if the node under it is set on fire
f->fuel_time = 30/4;
f->type = CMT_WOOD;
f->hardness = 0.75;
f->solidness = 0;
content_nodebox_bookshelf(f);
f->setInventoryTextureNodeBox(i,"bookshelf_top.png", "bookshelf_front.png", "bookshelf_side.png");
if (f->initial_metadata == NULL)
f->initial_metadata = new BookShelfNodeMetadata();
{
u16 r[9] = {
CONTENT_WOOD, CONTENT_WOOD, CONTENT_WOOD,

View File

@ -1069,3 +1069,25 @@ void content_nodebox_roofcollide(ContentFeatures *f)
-0.3125*BS,-0.4375*BS,-0.3125*BS,0.3125*BS,-0.3125*BS,0.3125*BS
));
}
void content_nodebox_bookshelf(ContentFeatures *f)
{
f->setNodeBox(core::aabbox3d<f32>(
0.4375*BS,-0.5*BS,-0.5*BS,0.5*BS,0.5*BS,0.5*BS
));
f->addNodeBox(core::aabbox3d<f32>(
-0.5*BS,-0.5*BS,-0.5*BS,-0.4375*BS,0.5*BS,0.5*BS
));
f->addNodeBox(core::aabbox3d<f32>(
-0.4375*BS,-0.4375*BS,-0.0625*BS,0.4375*BS,0.4375*BS,0.0625*BS
));
f->addNodeBox(core::aabbox3d<f32>(
-0.4375*BS,0.4375*BS,-0.5*BS,0.4375*BS,0.5*BS,0.5*BS
));
f->addNodeBox(core::aabbox3d<f32>(
-0.4375*BS,-0.5*BS,-0.5*BS,0.4375*BS,-0.4375*BS,0.5*BS
));
f->addNodeBox(core::aabbox3d<f32>(
-0.4375*BS,-0.0625*BS,-0.5*BS,0.4375*BS,0.0625*BS,0.5*BS
));
}

View File

@ -37,5 +37,6 @@ void content_nodebox_sign_ud(ContentFeatures *f);
void content_nodebox_sign_wall(ContentFeatures *f);
void content_nodebox_jackolantern(ContentFeatures *f);
void content_nodebox_roofcollide(ContentFeatures *f);
void content_nodebox_bookshelf(ContentFeatures *f);
#endif

View File

@ -1888,3 +1888,90 @@ bool ClosedBookNodeMetadata::import(NodeMetadata *meta)
}
return false;
}
/*
BookShelfNodeMetadata
*/
// Prototype
BookShelfNodeMetadata proto_BookShelfNodeMetadata;
BookShelfNodeMetadata::BookShelfNodeMetadata()
{
NodeMetadata::registerType(typeId(), create);
m_inventory = new Inventory();
m_inventory->addList("0", 14);
}
BookShelfNodeMetadata::~BookShelfNodeMetadata()
{
delete m_inventory;
}
u16 BookShelfNodeMetadata::typeId() const
{
return CONTENT_CHEST;
}
NodeMetadata* BookShelfNodeMetadata::create(std::istream &is)
{
BookShelfNodeMetadata *d = new BookShelfNodeMetadata();
d->m_inventory->deSerialize(is);
return d;
}
NodeMetadata* BookShelfNodeMetadata::clone()
{
BookShelfNodeMetadata *d = new BookShelfNodeMetadata();
*d->m_inventory = *m_inventory;
return d;
}
void BookShelfNodeMetadata::serializeBody(std::ostream &os)
{
m_inventory->serialize(os);
}
bool BookShelfNodeMetadata::nodeRemovalDisabled()
{
/*
Disable removal if chest contains something
*/
InventoryList *list = m_inventory->getList("0");
if(list == NULL)
return false;
if(list->getUsedSlots() == 0)
return false;
return true;
}
std::string BookShelfNodeMetadata::getDrawSpecString()
{
return
"size[8,7]"
"list[current_name;0;0.5,0;7,2;]"
"list[current_player;main;0,3;8,4;]";
}
std::vector<aabb3f> BookShelfNodeMetadata::getNodeBoxes(MapNode &n) {
std::vector<aabb3f> boxes;
boxes.clear();
InventoryList *list = m_inventory->getList("0");
if(list == NULL)
return boxes;
if(list->getUsedSlots() == 0)
return boxes;
f32 x = 0;
f32 y = 0;
for (s16 i=0; i<14; i++) {
if (list->getItem(i) == NULL)
continue;
x = (i%7)*0.125;
y = (i/7)*-0.5;
boxes.push_back(aabb3f(
(-0.4375+x)*BS,(0.0625+y)*BS,-0.4375*BS,(-0.3125+x)*BS,(0.375+y)*BS,-0.0625*BS
));
boxes.push_back(aabb3f(
(0.3125-x)*BS,(0.0625+y)*BS,0.0625*BS,(0.4375-x)*BS,(0.375+y)*BS,0.4375*BS
));
}
return transformNodeBox(n,boxes);
}

View File

@ -427,5 +427,24 @@ private:
u16 m_page;
};
class BookShelfNodeMetadata : public NodeMetadata
{
public:
BookShelfNodeMetadata();
~BookShelfNodeMetadata();
virtual u16 typeId() const;
static NodeMetadata* create(std::istream &is);
virtual NodeMetadata* clone();
virtual void serializeBody(std::ostream &os);
virtual Inventory* getInventory() {return m_inventory;}
virtual bool nodeRemovalDisabled();
virtual std::string getDrawSpecString();
virtual std::vector<aabb3f> getNodeBoxes(MapNode &n);
private:
Inventory *m_inventory;
};
#endif

View File

@ -35,7 +35,7 @@ ContentFeatures::~ContentFeatures()
delete initial_metadata;
}
static std::vector<aabb3f> transformNodeBox(MapNode &n,
std::vector<aabb3f> transformNodeBox(MapNode &n,
const std::vector<aabb3f> &nodebox)
{
std::vector<aabb3f> boxes;
@ -107,6 +107,20 @@ void ContentFeatures::setTexture(u16 i, std::string name, u8 alpha)
setInventoryTexture(name);
}
void ContentFeatures::setMetaTexture(u16 i, std::string name, u8 alpha)
{
used_texturenames[name] = true;
if(g_texturesource) {
meta_tiles[i].texture = g_texturesource->getTexture(name);
}
if (alpha != 255) {
meta_tiles[i].alpha = alpha;
meta_tiles[i].material_type = MATERIAL_ALPHA_VERTEX;
}
}
void ContentFeatures::setInventoryTexture(std::string imgname)
{
if(g_texturesource == NULL)

View File

@ -138,6 +138,9 @@ enum ContentMaterialType {
struct MapNode;
class NodeMetadata;
std::vector<aabb3f> transformNodeBox(MapNode &n,
const std::vector<aabb3f> &nodebox);
struct ContentFeatures
{
#ifndef SERVER
@ -363,6 +366,18 @@ struct ContentFeatures
{}
void setAllTextureTypes(u8 type)
{}
void setMetaTexture(u16 i, std::string name, u8 alpha=255)
{}
void setAllMetaTextures(std::string name, u8 alpha=255)
{}
void setMetaTextureFlags(u16 i, u8 flags)
{}
void setAllMetaTextureFlags(u8 flags)
{}
void setMetaTextureType(u16 i, u8 type)
{}
void setAllMetaTextureTypes(u8 type)
{}
#else
void setTexture(u16 i, std::string name, u8 alpha=255);
@ -394,6 +409,36 @@ struct ContentFeatures
setTextureType(i, type);
}
}
void setMetaTexture(u16 i, std::string name, u8 alpha=255);
void setAllMetaTextures(std::string name, u8 alpha=255)
{
for (u16 i=0; i<6; i++) {
setMetaTexture(i, name, alpha);
}
}
void setMetaTextureFlags(u16 i, u8 flags)
{
meta_tiles[i].material_flags = flags;
}
void setAllMetaTextureFlags(u8 flags)
{
for (u16 i=0; i<6; i++) {
setMetaTextureFlags(i, flags);
}
}
void setMetaTextureType(u16 i, u8 type)
{
meta_tiles[i].material_type = type;
}
void setAllMetaTextureTypes(u8 type)
{
for (u16 i=0; i<6; i++) {
setMetaTextureType(i, type);
}
}
#endif
#ifndef SERVER

View File

@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream>
#include <map>
#include <vector>
#include "mapnode.h"
class Player;
@ -83,7 +84,7 @@ public:
// import data from another nodemetadata. Returns true if metadata changed.
virtual bool import(NodeMetadata *meta) {return false;}
// get nodeboxes for CDT_NODEBOX_META
virtual std::vector<aabb3f> getNodeBoxes() {return std::vector<aabb3f>();}
virtual std::vector<aabb3f> getNodeBoxes(MapNode &n) {return std::vector<aabb3f>();}
// used by tnt to arm it, but also for future circuitry
// level is the amount of power
// powersrc is the generator or such that created the power