Block update on set - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Development (https://forum.cuberite.org/forum-13.html) +--- Thread: Block update on set (/thread-2018.html) |
Block update on set - Hax52 - 06-19-2015 Just getting started and looking through the code. I can't seem to find out where, if at all the OnUpdate gets called when a block is set? I'm trying to fix the button's sound clicking on and off, and thought OnUpdate would seem to be the best place, currently it only makes a sound when turned on. Any thoughts? Am I going about this all wrong? Thanks! RE: Block update on set - NiLSPACE - 06-19-2015 I believe you have to change things from here. Right now it only queues a block change, but you'll have to change this to a cWorld::ScheduleTask where both the block is changed and the sound is played. RE: Block update on set - Hax52 - 06-20-2015 Ok, I think i can see what your saying, just not sure how to implement it. I'm new to c++. I can see I'd have to create a class, inherit from cTask and implement the Run method, but I'm not sure how I can get the coordinates and other data necessary into that task to play the sound. RE: Block update on set - NiLSPACE - 06-20-2015 Something like this: class cScheduleBlock : public cWorld::cTask { public: int m_PosX, m_PosY, m_PosZ; cScheduleBlock(int a_PosX, int a_PosY, int a_PosZ): m_PosX(a_PosX), m_PosY(a_PosY), m_PosZ(a_PosZ) { } protected: virtual void Run(cWorld & a_World) override { // Execute code with m_PosX, m_PosY and m_PosZ } }; Then you can create the cScheduleBlock using: cScheduleBlock BlockChange = cScheduleBlock(a_BlockX, a_BlockY, a_BlockZ); a_World->ScheduleTask(NumTicks, BlockChange); I didn't test any of this, so there might be some syntax mistakes. RE: Block update on set - Hax52 - 06-21-2015 Thanks! That's a lot simpler than what I was thinking before. I crated a "cTaskPlaySound" so that others could use the schedule to schedule sounds. The only problem I ran into was finding a reference to cWorld. The on use button has a reference to cWorldInterface, so I pulled it from player->GetWorld, hope that's not wrong. Again thanks for you help. |