forked from oerkki/voxelands
add a clock
This commit is contained in:
parent
a4b1421b63
commit
b87f39a8d7
Binary file not shown.
After Width: | Height: | Size: 136 B |
Binary file not shown.
After Width: | Height: | Size: 148 B |
Binary file not shown.
After Width: | Height: | Size: 132 B |
|
@ -9290,6 +9290,41 @@ void content_mapnode_init()
|
|||
lists::add("craftguide",i);
|
||||
lists::add("creative",i);
|
||||
|
||||
i = CONTENT_CLOCK;
|
||||
f = &content_features(i);
|
||||
f->description = std::string("Clock");
|
||||
f->setAllTextures("clock.png");
|
||||
f->setTexture(5, "clock_front.png");
|
||||
f->setAllMetaTextures("clock_numbers.png");
|
||||
f->param_type = CPT_LIGHT;
|
||||
f->param2_type = CPT_FACEDIR_SIMPLE;
|
||||
f->draw_type = CDT_NODEBOX_META;
|
||||
f->light_propagates = true;
|
||||
f->sunlight_propagates = true;
|
||||
f->solidness = 0; // drawn separately, makes no faces
|
||||
f->walkable = false;
|
||||
f->air_equivalent = true;
|
||||
f->flammable = 1; // can be replaced by fire if the node under it is set on fire
|
||||
f->fuel_time = 1;
|
||||
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
|
||||
f->type = CMT_WOOD;
|
||||
f->hardness = 0.1;
|
||||
content_nodebox_clock(f);
|
||||
f->setInventoryTextureNodeBox(i,"clock.png","clock_front.png","clock.png");
|
||||
f->pressure_type = CST_CRUSHABLE;
|
||||
if (f->initial_metadata == NULL)
|
||||
f->initial_metadata = new ClockNodeMetadata();
|
||||
{
|
||||
u16 r[9] = {
|
||||
CONTENT_CRAFTITEM_PINE_PLANK, CONTENT_CRAFTITEM_PINE_PLANK, CONTENT_CRAFTITEM_PINE_PLANK,
|
||||
CONTENT_CRAFTITEM_PINE_PLANK, CONTENT_CRAFTITEM_MESEDUST, CONTENT_CRAFTITEM_PINE_PLANK,
|
||||
CONTENT_CRAFTITEM_PINE_PLANK, CONTENT_CRAFTITEM_PINE_PLANK, CONTENT_CRAFTITEM_PINE_PLANK
|
||||
};
|
||||
crafting::setRecipe(r,CONTENT_CLOCK,1);
|
||||
}
|
||||
lists::add("craftguide",i);
|
||||
lists::add("creative",i);
|
||||
|
||||
i = CONTENT_CIRCUIT_MESEWIRE;
|
||||
f = &content_features(i);
|
||||
f->description = std::string("Mese Wire");
|
||||
|
|
|
@ -110,7 +110,9 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version);
|
|||
#define CONTENT_PAINTING_CANVAS 0x824
|
||||
#define CONTENT_PAINTING_WHITE 0x825
|
||||
|
||||
// FREE 826-835
|
||||
// FREE 826-82F
|
||||
#define CONTENT_CLOCK 0x830
|
||||
// FREE 931-835
|
||||
|
||||
#define CONTENT_COUCH_CENTRE 0x836
|
||||
#define CONTENT_COUCH_ENDL 0x837
|
||||
|
|
|
@ -1344,3 +1344,34 @@ void content_nodebox_waterwheel(ContentFeatures *f)
|
|||
));
|
||||
}
|
||||
|
||||
void content_nodebox_clock(ContentFeatures *f)
|
||||
{
|
||||
f->setNodeBox(core::aabbox3d<f32>(
|
||||
-0.5*BS,-0.4375*BS,-0.0625*BS,0.5*BS,0.25*BS,0.125*BS
|
||||
));
|
||||
f->addNodeBox(core::aabbox3d<f32>(
|
||||
-0.5*BS,-0.5*BS,-0.125*BS,-0.25*BS,-0.4375*BS,0.125*BS
|
||||
));
|
||||
f->addNodeBox(core::aabbox3d<f32>(
|
||||
0.25*BS,-0.5*BS,-0.125*BS,0.5*BS,-0.4375*BS,0.125*BS
|
||||
));
|
||||
f->addNodeBox(core::aabbox3d<f32>(
|
||||
0.4375*BS,-0.4375*BS,-0.125*BS,0.5*BS,0.25*BS,-0.0625*BS
|
||||
));
|
||||
f->addNodeBox(core::aabbox3d<f32>(
|
||||
-0.5*BS,-0.4375*BS,-0.125*BS,-0.4375*BS,0.25*BS,-0.0625*BS
|
||||
));
|
||||
f->addNodeBox(core::aabbox3d<f32>(
|
||||
-0.4375*BS,-0.4375*BS,-0.125*BS,0.4375*BS,-0.375*BS,-0.0625*BS
|
||||
));
|
||||
f->addNodeBox(core::aabbox3d<f32>(
|
||||
-0.4375*BS,0.1875*BS,-0.125*BS,0.4375*BS,0.25*BS,-0.0625*BS
|
||||
));
|
||||
f->addNodeBox(core::aabbox3d<f32>(
|
||||
0.*BS,-0.0625*BS,-0.125*BS,0.0625*BS,0.*BS,-0.0625*BS
|
||||
));
|
||||
f->addNodeBox(core::aabbox3d<f32>(
|
||||
0.*BS,-0.1875*BS,-0.125*BS,0.0625*BS,-0.125*BS,-0.0625*BS
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -56,5 +56,6 @@ void content_nodebox_pistonarm_up(ContentFeatures *f);
|
|||
void content_nodebox_piston_down(ContentFeatures *f);
|
||||
void content_nodebox_pistonarm_down(ContentFeatures *f);
|
||||
void content_nodebox_waterwheel(ContentFeatures *f);
|
||||
void content_nodebox_clock(ContentFeatures *f);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1988,6 +1988,85 @@ std::vector<aabb3f> BookShelfNodeMetadata::getNodeBoxes(MapNode &n) {
|
|||
return transformNodeBox(n,boxes);
|
||||
}
|
||||
|
||||
/*
|
||||
ClockNodeMetadata
|
||||
*/
|
||||
|
||||
// Prototype
|
||||
ClockNodeMetadata proto_ClockNodeMetadata;
|
||||
|
||||
ClockNodeMetadata::ClockNodeMetadata():
|
||||
m_time(0)
|
||||
{
|
||||
NodeMetadata::registerType(typeId(), create);
|
||||
}
|
||||
u16 ClockNodeMetadata::typeId() const
|
||||
{
|
||||
return CONTENT_CLOCK;
|
||||
}
|
||||
NodeMetadata* ClockNodeMetadata::create(std::istream &is)
|
||||
{
|
||||
ClockNodeMetadata *d = new ClockNodeMetadata();
|
||||
int temp;
|
||||
is>>temp;
|
||||
d->m_time = temp;
|
||||
return d;
|
||||
}
|
||||
NodeMetadata* ClockNodeMetadata::clone()
|
||||
{
|
||||
ClockNodeMetadata *d = new ClockNodeMetadata();
|
||||
return d;
|
||||
}
|
||||
void ClockNodeMetadata::serializeBody(std::ostream &os)
|
||||
{
|
||||
os<<itos(m_time) << " ";
|
||||
}
|
||||
std::vector<aabb3f> ClockNodeMetadata::getNodeBoxes(MapNode &n) {
|
||||
std::vector<aabb3f> boxes;
|
||||
boxes.clear();
|
||||
|
||||
u16 h = m_time/100;
|
||||
u16 m = (u16)((float)(m_time%100)/1.6667);
|
||||
|
||||
u16 v[4];
|
||||
v[0] = h/10;
|
||||
v[1] = h%10;
|
||||
v[2] = m/10;
|
||||
v[3] = m%10;
|
||||
|
||||
f32 x[4] = {-0.125,0.0625,0.3125,0.5};
|
||||
|
||||
u8 b[10] = {0xFC,0x0C,0xB6,0x9E,0x4E,0xDA,0xFA,0x8C,0xFE,0xDE};
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
if ((b[v[i]]&0x80))
|
||||
boxes.push_back(aabb3f((-0.25+x[i])*BS,0.0625*BS,-0.125*BS,(-0.0625+x[i])*BS,0.125*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x04))
|
||||
boxes.push_back(aabb3f((-0.125+x[i])*BS,-0.0625*BS,-0.125*BS,(-0.0625+x[i])*BS,0.0625*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x08))
|
||||
boxes.push_back(aabb3f((-0.125+x[i])*BS,-0.25*BS,-0.125*BS,(-0.0625+x[i])*BS,-0.125*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x10))
|
||||
boxes.push_back(aabb3f((-0.25+x[i])*BS,-0.3125*BS,-0.125*BS,(-0.0625+x[i])*BS,-0.25*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x20))
|
||||
boxes.push_back(aabb3f((-0.25+x[i])*BS,-0.25*BS,-0.125*BS,(-0.1875+x[i])*BS,-0.125*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x40))
|
||||
boxes.push_back(aabb3f((-0.25+x[i])*BS,-0.0625*BS,-0.125*BS,(-0.1875+x[i])*BS,0.0625*BS,-0.0625*BS));
|
||||
if ((b[v[i]]&0x02))
|
||||
boxes.push_back(aabb3f((-0.1875+x[i])*BS,-0.125*BS,-0.125*BS,(-0.125+x[i])*BS,-0.0625*BS,-0.0625*BS));
|
||||
}
|
||||
|
||||
return transformNodeBox(n,boxes);
|
||||
}
|
||||
bool ClockNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
||||
{
|
||||
u32 t = env->getTimeOfDay();
|
||||
t /= 10;
|
||||
if (t == m_time)
|
||||
return false;
|
||||
m_time = t;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
CircuitNodeMetadata
|
||||
*/
|
||||
|
|
|
@ -446,6 +446,20 @@ private:
|
|||
Inventory *m_inventory;
|
||||
};
|
||||
|
||||
class ClockNodeMetadata : public NodeMetadata
|
||||
{
|
||||
public:
|
||||
ClockNodeMetadata();
|
||||
virtual u16 typeId() const;
|
||||
static NodeMetadata* create(std::istream &is);
|
||||
virtual NodeMetadata* clone();
|
||||
virtual void serializeBody(std::ostream &os);
|
||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||
virtual std::vector<aabb3f> getNodeBoxes(MapNode &n);
|
||||
private:
|
||||
u16 m_time;
|
||||
};
|
||||
|
||||
class CircuitNodeMetadata : public NodeMetadata
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue