diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-26 19:50:42 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-26 19:50:42 +0200 |
commit | 6ad8553a3a9095bd5a8c25085fa0bb209d411048 (patch) | |
tree | c6ba74fd34eb0f599e2037ac120bfae30314f0dd /source/cNoteEntity.cpp | |
parent | Removed old makefile; use GNUmakefile instead (diff) | |
download | cuberite-6ad8553a3a9095bd5a8c25085fa0bb209d411048.tar cuberite-6ad8553a3a9095bd5a8c25085fa0bb209d411048.tar.gz cuberite-6ad8553a3a9095bd5a8c25085fa0bb209d411048.tar.bz2 cuberite-6ad8553a3a9095bd5a8c25085fa0bb209d411048.tar.lz cuberite-6ad8553a3a9095bd5a8c25085fa0bb209d411048.tar.xz cuberite-6ad8553a3a9095bd5a8c25085fa0bb209d411048.tar.zst cuberite-6ad8553a3a9095bd5a8c25085fa0bb209d411048.zip |
Diffstat (limited to '')
-rw-r--r-- | source/cNoteEntity.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/source/cNoteEntity.cpp b/source/cNoteEntity.cpp new file mode 100644 index 000000000..4feb9223c --- /dev/null +++ b/source/cNoteEntity.cpp @@ -0,0 +1,148 @@ +
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "cNoteEntity.h"
+#include "cWorld.h"
+#include <json/json.h>
+
+
+cNoteEntity::cNoteEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World)
+ : cBlockEntity(E_BLOCK_NOTE_BLOCK, a_BlockX, a_BlockY, a_BlockZ, a_World)
+ , m_Pitch( 0 )
+{
+}
+
+
+
+
+
+cNoteEntity::~cNoteEntity()
+{
+}
+
+
+
+
+
+void cNoteEntity::UsedBy( cPlayer * a_Player )
+{
+ IncrementPitch();
+ MakeSound();
+}
+
+
+
+
+
+void cNoteEntity::MakeSound( void )
+{
+ char instrument;
+ switch (m_World->GetBlock(m_PosX, m_PosY - 1, m_PosZ))
+ {
+ case E_BLOCK_PLANKS:
+ case E_BLOCK_LOG:
+ case E_BLOCK_NOTE_BLOCK:
+ {
+ // TODO: add other wood-based blocks if needed
+ instrument = E_INST_DOUBLE_BASS;
+ break;
+ }
+
+ case E_BLOCK_SAND:
+ case E_BLOCK_GRAVEL:
+ case E_BLOCK_SOULSAND:
+ {
+ instrument = E_INST_SNARE_DRUM;
+ break;
+ }
+
+ case E_BLOCK_GLASS:
+ case E_BLOCK_GLASS_PANE:
+ case E_BLOCK_GLOWSTONE:
+ {
+ instrument = E_INST_CLICKS;
+ break;
+ }
+
+ case E_BLOCK_STONE:
+ case E_BLOCK_STONE_BRICKS:
+ case E_BLOCK_COBBLESTONE:
+ case E_BLOCK_OBSIDIAN:
+ case E_BLOCK_NETHERRACK:
+ case E_BLOCK_BRICK:
+ case E_BLOCK_NETHER_BRICK:
+ {
+ // TODO: add other stone-based blocks if needed
+ instrument = E_INST_BASS_DRUM;
+ break;
+ }
+
+ default:
+ {
+ instrument = E_INST_HARP_PIANO;
+ break;
+ }
+ }
+
+ m_World->BroadcastBlockAction(m_PosX, m_PosY, m_PosZ, instrument, m_Pitch);
+}
+
+
+
+
+
+char cNoteEntity::GetPitch( void )
+{
+ return m_Pitch;
+}
+
+
+
+
+
+void cNoteEntity::SetPitch( char a_Pitch )
+{
+ m_Pitch = a_Pitch % 25;
+}
+
+
+
+
+
+void cNoteEntity::IncrementPitch( void )
+{
+ SetPitch( m_Pitch + 1 );
+}
+
+
+
+
+
+bool cNoteEntity::LoadFromJson( const Json::Value & a_Value )
+{
+
+ m_PosX = a_Value.get("x", 0).asInt();
+ m_PosY = a_Value.get("y", 0).asInt();
+ m_PosZ = a_Value.get("z", 0).asInt();
+
+ m_Pitch = (char)a_Value.get("p", 0).asInt();
+
+ return true;
+}
+
+
+
+
+
+void cNoteEntity::SaveToJson( Json::Value & a_Value )
+{
+ a_Value["x"] = m_PosX;
+ a_Value["y"] = m_PosY;
+ a_Value["z"] = m_PosZ;
+
+ a_Value["p"] = m_Pitch;
+}
+
+
+
+
|