From ce6518ab432b3a5fc37b859dd87496d5b360c42b Mon Sep 17 00:00:00 2001 From: darkrose Date: Sun, 17 Aug 2014 20:32:26 +1000 Subject: [PATCH] add waterwheel generators --- data/textures/circuit_waterwheel.png | Bin 0 -> 757 bytes data/textures/circuit_waterwheel_side.png | Bin 0 -> 597 bytes src/content_mapnode.cpp | 34 ++++++++ src/content_nodebox.cpp | 25 ++++++ src/content_nodebox.h | 1 + src/content_nodemeta.cpp | 93 ++++++++++++++++++++++ src/content_nodemeta.h | 11 +++ 7 files changed, 164 insertions(+) create mode 100644 data/textures/circuit_waterwheel.png create mode 100644 data/textures/circuit_waterwheel_side.png diff --git a/data/textures/circuit_waterwheel.png b/data/textures/circuit_waterwheel.png new file mode 100644 index 0000000000000000000000000000000000000000..90d8b396a216f951bd60dd4b799e840a313673aa GIT binary patch literal 757 zcmVPx#32;bRa{vGf6951U69E94oEQKA00(qQO+^RZ2oVT77WzP^6#xJNhexzvc*FnM_5iEB7}rp5D~EuBsRcuNC^-mjw~b+ge@Ui@>nzX z-hNb7R}~2x;4I0d2osd7S(V|&C`{RjgCQaK!SZYTigj5q zM{78%dH(zf%^9rj=+;pq@^-Ns~I&@S3fO*wIqgf(a8LTDB#z=M4}{%?&>|-n_bl1{tV( zXRtzB6XrNG+z2?B9lXzAEa*?aL_{#oTSSB}zJ9?egSmc6SDlvLL2tO8vDTtg#F>D0 zmZk!~y;3MG7!l!U2Q5AY59;tB8#ZHe(_WM4D2Ys7k%(;4ZB5F&1xKuuUTqD7NZ!6>EZt?}~r zKRC7(W1*(b7&Ywx8-%Mkaz0j$y^+wU@e%mX|2ycN!AIPqXZU=kl*;^JE*|L>(ZXdtxZfL(uPwSe<|#5=&5YOA#KGa#L@5Pxtsd(NloRE&lS-tPfH4N+f@fVe?)HU!e@h$!^E}hFP@1q_7WOKf nHsJ%4iC2y-Z74f&IqP)Px#32;bRa{vGf6951U69E94oEQKA00(qQO+^RZ2oVT4EnsFH@&Et<=Sf6CR4C77 zj=O4=K@^4eb!N_qqA6@8&t##JCILYZw6gIvl2*{hr1PC5Z3^||oc}VjFBSnov#M2m zi*Moi+f!uDa3=K}eGFy2Jiq?*{mtkWmh&{J7Hu-RO@{+n1QM9Jhk3-Kqod37YXEQy zrNT^7md_AqLh$v7jhashw!*1%k-dg3tAFs{= zVm{2GdVKtJU6*D4%}f~yiOeV>QcE?rge+XmeeDYosmOkR2Z@iL91XXz3_t)t@g8+k z3KWEN&x^Bf|6O|b`Q>KQh73$ZL@HHP6#-bp)8IkcwhA+Y5D^OzB3c*#%*$Mh-a|Jh zw>KxZ_q}Qz!&p&O5r{|#5dqP9Wa2}^vMftqhnt0ovSa`e0fZDXANSDnAJ6^{)}=Eu z7;@!x9YRDIp;VwIvph5q5dcIwq!6QE=B93Uce`bt5%K+(*8otP{`$Ey_fkr&D9V%^ z5PdaS)^$H0n24F(Ga?dW+IuZ6*O{3yDFe)Hzuz&d^xj)*7S=~sF3g;P!P#nUj|v7s z!rIq}D7B6;$hx`vSVt|DnKM9JQBh`2!^A`aRV7v*CL&Z?oenc15=f#;<-T-cOn`)( jrfFGLcZV=ivEhFJO#>axORbp`00000NkvXXu0mjfZ58&N literal 0 HcmV?d00001 diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index d48ab1f..42ad52f 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -9394,6 +9394,39 @@ void content_mapnode_init() lists::add("craftguide",i); lists::add("creative",i); + i = CONTENT_CIRCUIT_WATERWHEEL; + f = &content_features(i); + f->description = std::string("Water Wheel"); + f->setAllTextures("circuit_waterwheel.png"); + f->setTexture(2,"circuit_waterwheel_side.png"); + f->setTexture(3,"circuit_waterwheel_side.png^[transformFX"); + f->param_type = CPT_LIGHT; + f->param2_type = CPT_FACEDIR_SIMPLE; + f->draw_type = CDT_NODEBOX; + f->energy_type = CET_SWITCH; + f->energy_drop = 0; + f->light_propagates = true; + f->sunlight_propagates = true; + f->rotate_tile_with_nodebox = true; + f->solidness = 0; // drawn separately, makes no faces + f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; + f->type = CMT_WOOD; + f->hardness = 0.10; + content_nodebox_waterwheel(f); + f->setInventoryTextureNodeBox(i,"circuit_waterwheel.png","circuit_waterwheel.png","circuit_waterwheel_side.png"); + if (f->initial_metadata == NULL) + f->initial_metadata = new WaterWheelNodeMetadata(); + { + u16 r[9] = { + CONTENT_STONE, CONTENT_WOOD_SLAB, CONTENT_STONE, + CONTENT_CRAFTITEM_MESEDUST, CONTENT_CRAFTITEM_STEEL_INGOT, CONTENT_CRAFTITEM_QUARTZ_DUST, + CONTENT_STONE, CONTENT_WOOD_SLAB, CONTENT_STONE + }; + crafting::setRecipe(r,CONTENT_CIRCUIT_WATERWHEEL,1); + } + lists::add("craftguide",i); + lists::add("creative",i); + i = CONTENT_CIRCUIT_SWITCH; f = &content_features(i); f->description = std::string("Switch"); @@ -9401,6 +9434,7 @@ void content_mapnode_init() f->setTexture(5,"circuit_switch_front.png"); f->param_type = CPT_FACEDIR_WALLMOUNT; f->draw_type = CDT_NODEBOX; + f->rotate_tile_with_nodebox = true; f->is_ground_content = true; f->energy_type = CET_SWITCH; f->energy_drop = 0; diff --git a/src/content_nodebox.cpp b/src/content_nodebox.cpp index 1a7bcb0..b9f7537 100644 --- a/src/content_nodebox.cpp +++ b/src/content_nodebox.cpp @@ -1319,3 +1319,28 @@ void content_nodebox_pistonarm_down(ContentFeatures *f) )); } +void content_nodebox_waterwheel(ContentFeatures *f) +{ + f->setNodeBox(core::aabbox3d( + 0.375*BS,-0.5*BS,-0.5*BS,0.5*BS,0.5*BS,0.5*BS + )); + f->addNodeBox(core::aabbox3d( + -0.5*BS,-0.5*BS,-0.5*BS,-0.375*BS,0.5*BS,0.5*BS + )); + f->addNodeBox(core::aabbox3d( + -0.375*BS,-0.0625*BS,-0.0625*BS,0.375*BS,0.0625*BS,0.0625*BS + )); + f->addNodeBox(core::aabbox3d( + -0.375*BS,0.0625*BS,0.*BS,0.375*BS,0.5*BS,0.0625*BS + )); + f->addNodeBox(core::aabbox3d( + -0.375*BS,-0.0625*BS,0.0625*BS,0.375*BS,0.*BS,0.5*BS + )); + f->addNodeBox(core::aabbox3d( + -0.375*BS,-0.5*BS,-0.0625*BS,0.375*BS,-0.0625*BS,0.*BS + )); + f->addNodeBox(core::aabbox3d( + -0.375*BS,0.*BS,-0.5*BS,0.375*BS,0.0625*BS,-0.0625*BS + )); +} + diff --git a/src/content_nodebox.h b/src/content_nodebox.h index 3fa4e83..00c8f58 100644 --- a/src/content_nodebox.h +++ b/src/content_nodebox.h @@ -55,5 +55,6 @@ void content_nodebox_piston_up(ContentFeatures *f); 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); #endif diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 2da2393..835e7d9 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -2282,6 +2282,99 @@ bool SolarPanelNodeMetadata::energise(u8 level, v3s16 powersrc, v3s16 signalsrc, return true; } +/* + WaterWheelNodeMetadata +*/ + +// Prototype +WaterWheelNodeMetadata proto_WaterWheelNodeMetadata; + +WaterWheelNodeMetadata::WaterWheelNodeMetadata() +{ + m_energy = 0; + m_ptime = 0; + m_sources.clear(); + NodeMetadata::registerType(typeId(), create); +} +u16 WaterWheelNodeMetadata::typeId() const +{ + return CONTENT_CIRCUIT_WATERWHEEL; +} +NodeMetadata* WaterWheelNodeMetadata::create(std::istream &is) +{ + WaterWheelNodeMetadata *d = new WaterWheelNodeMetadata(); + int temp; + is>>temp; + d->m_energy = temp; + is>>temp; + d->m_ptime = (float)temp/10; + int i; + is>>i; + v3s16 p; + for (; i > 0; i--) { + is>>temp; + p.X = temp; + is>>temp; + p.Y = temp; + is>>temp; + p.Z = temp; + is>>temp; + d->m_sources[p] = temp; + } + return d; +} +NodeMetadata* WaterWheelNodeMetadata::clone() +{ + WaterWheelNodeMetadata *d = new WaterWheelNodeMetadata(); + return d; +} +bool WaterWheelNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env) +{ + MapNode n = env->getMap().getNodeNoEx(pos); + v3s16 dir = n.getRotation(); + if (dir == v3s16(1,1,1)) { + dir = v3s16(0,0,-1); + }else if (dir == v3s16(-1,1,1)) { + dir = v3s16(-1,0,0); + }else if (dir == v3s16(-1,1,-1)) { + dir = v3s16(0,0,1); + }else if (dir == v3s16(1,1,-1)) { + dir = v3s16(1,0,0); + } + MapNode inlet = env->getMap().getNodeNoEx(pos-dir); + MapNode outlet = env->getMap().getNodeNoEx(pos+dir); + if (inlet.getContent() != CONTENT_WATERSOURCE) { + if (outlet.getContent() == CONTENT_WATERSOURCE) + env->getMap().removeNodeWithEvent(pos+dir); + if (m_energy) { + m_energy = 0; + return true; + } + return false; + } + if (outlet.getContent() != CONTENT_WATERSOURCE) { + if (outlet.getContent() != CONTENT_AIR) { + if (m_energy) { + m_energy = 0; + return true; + } + return false; + } + outlet.setContent(CONTENT_WATERSOURCE); + env->getMap().addNodeWithEvent(pos+dir,outlet); + } + + m_energy = ENERGY_MAX; + env->propogateEnergy(ENERGY_MAX,pos,pos,pos); + return true; +} +bool WaterWheelNodeMetadata::energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos) +{ + if (!m_energy) + return false; + return true; +} + /* SourceNodeMetadata */ diff --git a/src/content_nodemeta.h b/src/content_nodemeta.h index 19ce8a2..18f1ee6 100644 --- a/src/content_nodemeta.h +++ b/src/content_nodemeta.h @@ -510,6 +510,17 @@ public: virtual bool energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos); }; +class WaterWheelNodeMetadata : public CircuitNodeMetadata +{ +public: + WaterWheelNodeMetadata(); + virtual u16 typeId() const; + static NodeMetadata* create(std::istream &is); + virtual NodeMetadata* clone(); + virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env); + virtual bool energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos); +}; + class NotGateNodeMetadata : public CircuitNodeMetadata { public: