diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-09-11 14:01:34 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-09-11 14:01:34 +0200 |
commit | 9eed83c33ae8c2bbb1781a01f05326dba667f4e3 (patch) | |
tree | 339ae563c07ba06b55a7f127dbd8c52f83e4dd66 | |
parent | Core's Web Chat should work on FireFox again. Apparently it appends "charset=utf-8" to the content type which was not properly handled. (diff) | |
download | cuberite-9eed83c33ae8c2bbb1781a01f05326dba667f4e3.tar cuberite-9eed83c33ae8c2bbb1781a01f05326dba667f4e3.tar.gz cuberite-9eed83c33ae8c2bbb1781a01f05326dba667f4e3.tar.bz2 cuberite-9eed83c33ae8c2bbb1781a01f05326dba667f4e3.tar.lz cuberite-9eed83c33ae8c2bbb1781a01f05326dba667f4e3.tar.xz cuberite-9eed83c33ae8c2bbb1781a01f05326dba667f4e3.tar.zst cuberite-9eed83c33ae8c2bbb1781a01f05326dba667f4e3.zip |
Diffstat (limited to '')
48 files changed, 334 insertions, 27 deletions
diff --git a/VC2008/MCServer.vcproj b/VC2008/MCServer.vcproj index 7c6b901b5..52ac9b5f3 100644 --- a/VC2008/MCServer.vcproj +++ b/VC2008/MCServer.vcproj @@ -1816,6 +1816,10 @@ >
</File>
<File
+ RelativePath="..\source\blocks\BlockGravel.h"
+ >
+ </File>
+ <File
RelativePath="..\source\blocks\BlockIce.h"
>
</File>
@@ -1876,6 +1880,10 @@ >
</File>
<File
+ RelativePath="..\source\blocks\BlockSand.h"
+ >
+ </File>
+ <File
RelativePath="..\source\blocks\BlockSapling.h"
>
</File>
diff --git a/source/Protocol.h b/source/Protocol.h index 44ef2cafc..0823b3189 100644 --- a/source/Protocol.h +++ b/source/Protocol.h @@ -70,6 +70,7 @@ public: virtual void SendPlayerPosition (void) = 0;
virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0;
virtual void SendRespawn (void) = 0;
+ virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) = 0; // a_Src coords are Block * 8
virtual void SendSpawnMob (const cMonster & a_Mob) = 0;
virtual void SendTeleportEntity (const cEntity & a_Entity) = 0;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
@@ -81,7 +82,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) = 0;
virtual void SendWindowClose (char a_WindowID) = 0;
virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0;
-
+
/// Returns the ServerID used for authentication through session.minecraft.net
virtual AString GetAuthServerID(void) = 0;
diff --git a/source/Protocol125.cpp b/source/Protocol125.cpp index da7e880ad..adea37824 100644 --- a/source/Protocol125.cpp +++ b/source/Protocol125.cpp @@ -577,6 +577,16 @@ void cProtocol125::SendRespawn(void) +void cProtocol125::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch)
+{
+ cCSLock Lock(m_CSPacket);
+ //TODO: Not needed in this protocol?
+}
+
+
+
+
+
void cProtocol125::SendSpawnMob(const cMonster & a_Mob)
{
cCSLock Lock(m_CSPacket);
diff --git a/source/Protocol125.h b/source/Protocol125.h index 2e94cdfbe..41bb8deb5 100644 --- a/source/Protocol125.h +++ b/source/Protocol125.h @@ -55,6 +55,7 @@ public: virtual void SendPlayerPosition (void) override;
virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
virtual void SendRespawn (void) override;
+ virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8
virtual void SendSpawnMob (const cMonster & a_Mob) override;
virtual void SendTeleportEntity (const cEntity & a_Entity) override;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
diff --git a/source/Protocol132.cpp b/source/Protocol132.cpp index e291c0c69..37343e443 100644 --- a/source/Protocol132.cpp +++ b/source/Protocol132.cpp @@ -59,6 +59,7 @@ enum PACKET_CHUNK_DATA = 0x33,
PACKET_BLOCK_CHANGE = 0x35,
PACKET_BLOCK_ACTION = 0x36,
+ PACKET_SOUND_EFFECT = 0x3e
} ;
@@ -310,6 +311,23 @@ void cProtocol132::SendPlayerSpawn(const cPlayer & a_Player) +void cProtocol132::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch)
+{
+ cCSLock Lock(m_CSPacket);
+ WriteByte (PACKET_SOUND_EFFECT);
+ WriteString (a_SoundName);
+ WriteInt (a_SrcX);
+ WriteInt (a_SrcY);
+ WriteInt (a_SrcZ);
+ WriteFloat (a_Volume);
+ WriteByte ((char)(a_Pitch * 63.0f));
+ Flush();
+}
+
+
+
+
+
void cProtocol132::SendSpawnMob(const cMonster & a_Mob)
{
cCSLock Lock(m_CSPacket);
diff --git a/source/Protocol132.h b/source/Protocol132.h index cca91c44b..3f21d4841 100644 --- a/source/Protocol132.h +++ b/source/Protocol132.h @@ -38,9 +38,10 @@ public: virtual void SendDestroyEntity(const cEntity & a_Entity) override;
virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override;
virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
+ virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8
virtual void SendSpawnMob (const cMonster & a_Mob) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
-
+
virtual AString GetAuthServerID(void) override;
// DEBUG:
diff --git a/source/ProtocolRecognizer.cpp b/source/ProtocolRecognizer.cpp index 669598923..31f74e608 100644 --- a/source/ProtocolRecognizer.cpp +++ b/source/ProtocolRecognizer.cpp @@ -347,6 +347,14 @@ void cProtocolRecognizer::SendRespawn(void) +void cProtocolRecognizer::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) {
+ ASSERT(m_Protocol != NULL);
+ m_Protocol->SendSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch);
+}
+
+
+
+
void cProtocolRecognizer::SendSpawnMob(const cMonster & a_Mob)
{
diff --git a/source/ProtocolRecognizer.h b/source/ProtocolRecognizer.h index eef89ec2e..a2941fc7a 100644 --- a/source/ProtocolRecognizer.h +++ b/source/ProtocolRecognizer.h @@ -65,6 +65,7 @@ public: virtual void SendPlayerPosition (void) override;
virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
virtual void SendRespawn (void) override;
+ virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override;
virtual void SendSpawnMob (const cMonster & a_Mob) override;
virtual void SendTeleportEntity (const cEntity & a_Entity) override;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
diff --git a/source/blocks/Block.cpp b/source/blocks/Block.cpp index 7764e2881..98868de7d 100644 --- a/source/blocks/Block.cpp +++ b/source/blocks/Block.cpp @@ -2,6 +2,8 @@ #include "Block.h"
#include "../cItem.h"
#include "../cWorld.h"
+#include "BlockSand.h"
+#include "BlockGravel.h"
#include "BlockDoor.h"
#include "BlockFire.h"
#include "BlockRedstone.h"
@@ -75,6 +77,10 @@ cBlockHandler *cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockID) {
switch(a_BlockID)
{
+ case E_BLOCK_SAND:
+ return new cBlockSandHandler(a_BlockID);
+ case E_BLOCK_GRAVEL:
+ return new cBlockGravelHandler(a_BlockID);
case E_BLOCK_WOODEN_DOOR:
case E_BLOCK_IRON_DOOR:
return new cBlockDoorHandler(a_BlockID);
@@ -349,6 +355,14 @@ void cBlockHandler::DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z) +AString cBlockHandler::GetStepSound() {
+ return "step.stone";
+}
+
+
+
+
+
bool cBlockHandler::CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir)
{
return CanBeAt(a_World, a_X, a_Y, a_Z);
diff --git a/source/blocks/Block.h b/source/blocks/Block.h index ef22e01b5..859870c4a 100644 --- a/source/blocks/Block.h +++ b/source/blocks/Block.h @@ -41,7 +41,8 @@ public: virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta);
// This function handles the dropping of a block based on the Drop id, drop count and drop meta. This will not destroy the block
virtual void DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z);
-
+ /// Returns step sound name of block
+ virtual AString GetStepSound();
// Indicates whether this block needs random ticks DEFAULT: False
virtual bool NeedsRandomTicks();
diff --git a/source/blocks/BlockCactus.h b/source/blocks/BlockCactus.h index e5bfdda03..9da9d796b 100644 --- a/source/blocks/BlockCactus.h +++ b/source/blocks/BlockCactus.h @@ -50,6 +50,13 @@ public: {
return false;
}
+
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.cloth";
+ }
+
};
diff --git a/source/blocks/BlockChest.h b/source/blocks/BlockChest.h index fd444a9d2..65c0ffa5c 100644 --- a/source/blocks/BlockChest.h +++ b/source/blocks/BlockChest.h @@ -18,5 +18,9 @@ public: OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockCloth.h b/source/blocks/BlockCloth.h index f2ce78fb5..d83b18ebb 100644 --- a/source/blocks/BlockCloth.h +++ b/source/blocks/BlockCloth.h @@ -14,5 +14,10 @@ public: {
return a_BlockMeta;
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.cloth";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockCrops.h b/source/blocks/BlockCrops.h index b5b543e76..ebf911131 100644 --- a/source/blocks/BlockCrops.h +++ b/source/blocks/BlockCrops.h @@ -55,5 +55,10 @@ public: {
return a_World->GetBlock(a_X, a_Y - 1, a_Z) == E_BLOCK_FARMLAND;
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.grass";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockDirt.h b/source/blocks/BlockDirt.h index f6ba1c887..28993d29c 100644 --- a/source/blocks/BlockDirt.h +++ b/source/blocks/BlockDirt.h @@ -63,5 +63,10 @@ public: }
} // for i - repeat twice
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.gravel";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockDoor.cpp b/source/blocks/BlockDoor.cpp index ecee2c12d..283f546b6 100644 --- a/source/blocks/BlockDoor.cpp +++ b/source/blocks/BlockDoor.cpp @@ -62,4 +62,13 @@ void cBlockDoorHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYP a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, a_BlockMeta);
OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
-}
\ No newline at end of file +}
+
+AString cBlockDoorHandler::GetStepSound(void)
+{
+ if (m_BlockID == E_BLOCK_WOODEN_DOOR)
+ return "step.wood";
+
+ else
+ return "step.stone";
+}
diff --git a/source/blocks/BlockDoor.h b/source/blocks/BlockDoor.h index 0ccc3fdac..6af8bd955 100644 --- a/source/blocks/BlockDoor.h +++ b/source/blocks/BlockDoor.h @@ -10,6 +10,7 @@ public: virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override;
virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override;
virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override;
+ virtual AString GetStepSound(void) override;
virtual char GetDropCount() override;
virtual bool IsUseable() override
{
diff --git a/source/blocks/BlockFire.h b/source/blocks/BlockFire.h index 3e605636b..1b9f68060 100644 --- a/source/blocks/BlockFire.h +++ b/source/blocks/BlockFire.h @@ -25,5 +25,9 @@ public: return true;
}
-
-};
\ No newline at end of file + virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
+
+};
diff --git a/source/blocks/BlockFlower.h b/source/blocks/BlockFlower.h index b94e6cb6d..920cf1c8f 100644 --- a/source/blocks/BlockFlower.h +++ b/source/blocks/BlockFlower.h @@ -29,4 +29,10 @@ public: {
return false;
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ return "step.grass";
+ }
+
+};
diff --git a/source/blocks/BlockGravel.h b/source/blocks/BlockGravel.h new file mode 100644 index 000000000..d4f36a894 --- /dev/null +++ b/source/blocks/BlockGravel.h @@ -0,0 +1,18 @@ +#pragma once
+#include "Block.h"
+
+
+class cBlockGravelHandler : public cBlockHandler
+{
+public:
+ cBlockGravelHandler(BLOCKTYPE a_BlockID)
+ : cBlockHandler(a_BlockID)
+ {
+ }
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.gravel";
+ }
+
+};
diff --git a/source/blocks/BlockLadder.h b/source/blocks/BlockLadder.h index 4c7f37b1f..e30fc884d 100644 --- a/source/blocks/BlockLadder.h +++ b/source/blocks/BlockLadder.h @@ -30,5 +30,11 @@ public: char Dir = cLadder::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir);
}
+
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockLeaves.h b/source/blocks/BlockLeaves.h index c7bca92ac..c2ec697ae 100644 --- a/source/blocks/BlockLeaves.h +++ b/source/blocks/BlockLeaves.h @@ -108,6 +108,11 @@ public: a_World->DigBlock(a_X, a_Y, a_Z);
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.grass";
+ }
};
diff --git a/source/blocks/BlockMelon.h b/source/blocks/BlockMelon.h index 0f1797a0b..3abcc6efb 100644 --- a/source/blocks/BlockMelon.h +++ b/source/blocks/BlockMelon.h @@ -21,4 +21,9 @@ public: MTRand r1;
return (char)(3 + r1.randInt(4));
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
+};
diff --git a/source/blocks/BlockMushroom.h b/source/blocks/BlockMushroom.h index 5ec429c5f..ca787dce6 100644 --- a/source/blocks/BlockMushroom.h +++ b/source/blocks/BlockMushroom.h @@ -39,4 +39,9 @@ public: {
return false;
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ return "step.grass";
+ }
+};
diff --git a/source/blocks/BlockRedstoneRepeater.h b/source/blocks/BlockRedstoneRepeater.h index 26b2b9877..c2ed30e2c 100644 --- a/source/blocks/BlockRedstoneRepeater.h +++ b/source/blocks/BlockRedstoneRepeater.h @@ -44,4 +44,9 @@ public: {
return false;
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
+};
diff --git a/source/blocks/BlockRedstoneTorch.h b/source/blocks/BlockRedstoneTorch.h index 88e884861..42d3a0366 100644 --- a/source/blocks/BlockRedstoneTorch.h +++ b/source/blocks/BlockRedstoneTorch.h @@ -20,4 +20,9 @@ public: {
return E_ITEM_REDSTONE_TORCH_ON;
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
+};
diff --git a/source/blocks/BlockSand.h b/source/blocks/BlockSand.h new file mode 100644 index 000000000..71096c5a7 --- /dev/null +++ b/source/blocks/BlockSand.h @@ -0,0 +1,18 @@ +#pragma once
+#include "Block.h"
+
+
+class cBlockSandHandler : public cBlockHandler
+{
+public:
+ cBlockSandHandler(BLOCKTYPE a_BlockID)
+ : cBlockHandler(a_BlockID)
+ {
+ }
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.sand";
+ }
+
+};
diff --git a/source/blocks/BlockSapling.h b/source/blocks/BlockSapling.h index 6bef614cf..e4ca998cb 100644 --- a/source/blocks/BlockSapling.h +++ b/source/blocks/BlockSapling.h @@ -48,4 +48,9 @@ public: {
return false;
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ return "step.grass";
+ }
+};
diff --git a/source/blocks/BlockSign.h b/source/blocks/BlockSign.h index 2a7ac2753..b0f9d7f7f 100644 --- a/source/blocks/BlockSign.h +++ b/source/blocks/BlockSign.h @@ -39,4 +39,9 @@ public: {
return false;
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
+};
diff --git a/source/blocks/BlockSlab.h b/source/blocks/BlockSlab.h index f6443ff91..11d1933c3 100644 --- a/source/blocks/BlockSlab.h +++ b/source/blocks/BlockSlab.h @@ -39,4 +39,13 @@ public: }
return result;
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ if (m_BlockID == E_BLOCK_WOODEN_SLAB || m_BlockID ==E_BLOCK_DOUBLE_WOODEN_SLAB)
+ return "step.wood";
+
+ else
+ return "step.stone";
+ }
+};
diff --git a/source/blocks/BlockSnow.h b/source/blocks/BlockSnow.h index ac0c0ac69..ba9d35183 100644 --- a/source/blocks/BlockSnow.h +++ b/source/blocks/BlockSnow.h @@ -35,5 +35,10 @@ public: {
return false;
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.cloth";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockStairs.h b/source/blocks/BlockStairs.h index b6898f8e1..4e06a6e3f 100644 --- a/source/blocks/BlockStairs.h +++ b/source/blocks/BlockStairs.h @@ -18,5 +18,5 @@ public: OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
-
-};
\ No newline at end of file + //TODO: step sound
+};
diff --git a/source/blocks/BlockStems.h b/source/blocks/BlockStems.h index a58a2bdf4..aa6229536 100644 --- a/source/blocks/BlockStems.h +++ b/source/blocks/BlockStems.h @@ -37,5 +37,10 @@ public: {
return a_World->GetBlock(a_X, a_Y - 1, a_Z) == E_BLOCK_FARMLAND;
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockSugarcane.h b/source/blocks/BlockSugarcane.h index b3db0a795..4b0cb5408 100644 --- a/source/blocks/BlockSugarcane.h +++ b/source/blocks/BlockSugarcane.h @@ -59,6 +59,11 @@ public: return false;
}
+ virtual AString GetStepSound(void) override
+ {
+ return "step.grass";
+ }
+
};
diff --git a/source/blocks/BlockTallGrass.h b/source/blocks/BlockTallGrass.h index ac66c1714..6e7854db8 100644 --- a/source/blocks/BlockTallGrass.h +++ b/source/blocks/BlockTallGrass.h @@ -32,4 +32,10 @@ public: {
return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR;
}
-};
\ No newline at end of file +
+ virtual AString GetStepSound(void) override
+ {
+ return "step.grass";
+ }
+
+};
diff --git a/source/blocks/BlockTorch.h b/source/blocks/BlockTorch.h index 9a124189f..f3b172bf9 100644 --- a/source/blocks/BlockTorch.h +++ b/source/blocks/BlockTorch.h @@ -154,6 +154,11 @@ public: {
return 0;
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
};
diff --git a/source/blocks/BlockVine.h b/source/blocks/BlockVine.h index 86f73b6b2..6b8d85339 100644 --- a/source/blocks/BlockVine.h +++ b/source/blocks/BlockVine.h @@ -26,5 +26,10 @@ public: {
return false;
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.grass";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockWood.h b/source/blocks/BlockWood.h index 453ee48a1..5e6615c1b 100644 --- a/source/blocks/BlockWood.h +++ b/source/blocks/BlockWood.h @@ -13,5 +13,10 @@ public: {
return a_BlockMeta;
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
-};
\ No newline at end of file +};
diff --git a/source/blocks/BlockWorkbench.h b/source/blocks/BlockWorkbench.h index 52c3ad738..6c5f0d3e8 100644 --- a/source/blocks/BlockWorkbench.h +++ b/source/blocks/BlockWorkbench.h @@ -21,6 +21,11 @@ public: {
return true;
}
+
+ virtual AString GetStepSound(void) override
+ {
+ return "step.wood";
+ }
-};
\ No newline at end of file +};
diff --git a/source/cChunk.cpp b/source/cChunk.cpp index 6295d4bba..7f9c4838c 100644 --- a/source/cChunk.cpp +++ b/source/cChunk.cpp @@ -1834,6 +1834,22 @@ void cChunk::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, cons +void cChunk::BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude) +{ + for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) + { + if (*itr == a_Exclude) + { + continue; + } + (*itr)->SendSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch); + } // for itr - LoadedByClient[] +} + + + + + void cChunk::BroadcastChunkData(cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude) { for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) diff --git a/source/cChunk.h b/source/cChunk.h index f7d53ee8c..d094a3a64 100644 --- a/source/cChunk.h +++ b/source/cChunk.h @@ -187,6 +187,7 @@ public: void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); void BroadcastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); + void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // a_Src coords are Block * 8 void BroadcastChunkData (cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); void SendBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client); diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp index 5f9724179..d88a82b0f 100644 --- a/source/cChunkMap.cpp +++ b/source/cChunkMap.cpp @@ -447,6 +447,25 @@ void cChunkMap::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, c +void cChunkMap::BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSLayers); + int ChunkX, ChunkZ; + + cChunkDef::BlockToChunk(a_SrcX / 8, a_SrcY / 8, a_SrcZ / 8, ChunkX, ChunkZ); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); + if (Chunk == NULL) + { + return; + } + // It's perfectly legal to broadcast packets even to invalid chunks! + Chunk->BroadcastSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch, a_Exclude); +} + + + + + void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); diff --git a/source/cChunkMap.h b/source/cChunkMap.h index 4996e1e04..4165be089 100644 --- a/source/cChunkMap.h +++ b/source/cChunkMap.h @@ -75,6 +75,8 @@ public: void BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); + void BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // a_Src coords are Block * 8 + void BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); /// Broadcasts the block entity, if it is at the coords specified, to all clients except a_Exclude diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 193b6b450..35e5a0ee4 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -677,6 +677,8 @@ void cClientHandle::HandleBlockPlace(int a_BlockX, int a_BlockY, int a_BlockZ, c if (NewBlock->CanBePlacedAt(World, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace)) { ItemHandler->PlaceBlock(World, m_Player, &m_Player->GetInventory().GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + // Step sound with 0.8f pitch is used as block placement sound + World->BroadcastSoundEffect(NewBlock->GetStepSound(),a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 1.0f, 0.8f); } else { @@ -1404,6 +1406,15 @@ void cClientHandle::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cClientHandle::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) +{ + m_Protocol->SendSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch); +} + + + + + void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { // Check chunks being sent, erase them from m_ChunksToSend: diff --git a/source/cClientHandle.h b/source/cClientHandle.h index 3ea94fa98..4668a2aa8 100644 --- a/source/cClientHandle.h +++ b/source/cClientHandle.h @@ -111,6 +111,7 @@ public: void SendWeather(eWeather a_Weather); void SendTimeUpdate(Int64 a_WorldTime); void SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ); + void SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch); // a_Src coords are Block * 8 void SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer); const AString & GetUsername(void) const; //tolua_export diff --git a/source/cNoteEntity.cpp b/source/cNoteEntity.cpp index 44f911dc4..f007433fc 100644 --- a/source/cNoteEntity.cpp +++ b/source/cNoteEntity.cpp @@ -37,6 +37,8 @@ void cNoteEntity::UsedBy( cPlayer * a_Player ) void cNoteEntity::MakeSound( void )
{
char instrument;
+ AString sampleName;
+
switch (m_World->GetBlock(m_PosX, m_PosY - 1, m_PosZ))
{
case E_BLOCK_PLANKS:
@@ -45,6 +47,7 @@ void cNoteEntity::MakeSound( void ) {
// TODO: add other wood-based blocks if needed
instrument = E_INST_DOUBLE_BASS;
+ sampleName = "note.db";
break;
}
@@ -53,6 +56,7 @@ void cNoteEntity::MakeSound( void ) case E_BLOCK_SOULSAND:
{
instrument = E_INST_SNARE_DRUM;
+ sampleName = "note.snare";
break;
}
@@ -61,6 +65,7 @@ void cNoteEntity::MakeSound( void ) case E_BLOCK_GLOWSTONE:
{
instrument = E_INST_CLICKS;
+ sampleName = "note.hat";
break;
}
@@ -74,17 +79,23 @@ void cNoteEntity::MakeSound( void ) {
// TODO: add other stone-based blocks if needed
instrument = E_INST_BASS_DRUM;
+ sampleName = "note.bassattack";
break;
}
default:
{
instrument = E_INST_HARP_PIANO;
+ sampleName = "note.harp";
break;
}
}
m_World->BroadcastBlockAction(m_PosX, m_PosY, m_PosZ, instrument, m_Pitch, E_BLOCK_NOTE_BLOCK);
+
+ // TODO: instead of calculating the power function over and over, make a precalculated table - there's only 24 pitches after all
+ float calcPitch = pow(2.0f, ((float)m_Pitch - 12.0f) / 12.0f);
+ m_World->BroadcastSoundEffect(sampleName, m_PosX * 8, m_PosY * 8, m_PosZ * 8, 3.0f, calcPitch);
}
diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 5e2317cbe..ba54ef961 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -1421,6 +1421,15 @@ void cWorld::BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, +void cWorld::BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude) +{ + m_ChunkMap->BroadcastSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch, a_Exclude); +} + + + + + void cWorld::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude) { m_ChunkMap->BroadcastBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Exclude); diff --git a/source/cWorld.h b/source/cWorld.h index 6a1058d5c..37577fcde 100644 --- a/source/cWorld.h +++ b/source/cWorld.h @@ -92,6 +92,7 @@ public: void BroadcastTimeUpdate (const cClientHandle * a_Exclude = NULL); void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL); + void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // a_Src coords are Block * 8 /// If there is a block entity at the specified coods, sends it to all clients except a_Exclude void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); |