1
0
Fork 0

Note Block Left Click Fix V2 (#5052)

+ Add function to play note block on left click
This commit is contained in:
Derek Qu 2020-11-25 19:58:35 -05:00 committed by GitHub
parent 3d044d2dde
commit 280f7a81f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 1 deletions

View File

@ -61,6 +61,7 @@
#include "BlockMycelium.h"
#include "BlockNetherWart.h"
#include "BlockNetherrack.h"
#include "BlockNoteBlock.h"
#include "BlockObserver.h"
#include "BlockOre.h"
#include "BlockPackedIce.h"
@ -344,7 +345,7 @@ namespace
constexpr cBlockNetherrack BlockNetherrackHandler (E_BLOCK_NETHERRACK);
constexpr cBlockLeavesHandler BlockNewLeavesHandler (E_BLOCK_NEW_LEAVES);
constexpr cBlockSidewaysHandler BlockNewLogHandler (E_BLOCK_NEW_LOG);
constexpr cDefaultBlockEntityHandler BlockNoteBlockHandler (E_BLOCK_NOTE_BLOCK);
constexpr cBlockNoteBlockHandler BlockNoteBlockHandler (E_BLOCK_NOTE_BLOCK);
constexpr cBlockDoorHandler BlockOakDoorHandler (E_BLOCK_OAK_DOOR);
constexpr cBlockFenceGateHandler BlockOakFenceGateHandler (E_BLOCK_OAK_FENCE_GATE);
constexpr cBlockStairsHandler BlockOakWoodStairsHandler (E_BLOCK_OAK_WOOD_STAIRS);

View File

@ -0,0 +1,43 @@
#pragma once
#include "BlockEntity.h"
#include "../BlockEntities/NoteEntity.h"
class cBlockNoteBlockHandler final :
public cBlockEntityHandler
{
using Super = cBlockEntityHandler;
public:
using Super::Super;
private:
virtual void OnDigging(
cChunkInterface & a_ChunkInterface,
cWorldInterface & a_WorldInterface,
cPlayer & a_Player,
const Vector3i a_BlockPos
) const override
{
a_WorldInterface.DoWithBlockEntityAt(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, [](cBlockEntity & a_BlockEntity)
{
if (a_BlockEntity.GetBlockType() != E_BLOCK_NOTE_BLOCK)
{
return false;
}
auto & NoteEntity = static_cast<cNoteEntity &>(a_BlockEntity);
NoteEntity.MakeSound();
return true;
});
}
};

View File

@ -64,6 +64,7 @@ target_sources(
BlockMycelium.h
BlockNetherrack.h
BlockNetherWart.h
BlockNoteBlock.h
BlockObserver.h
BlockOre.h
BlockPackedIce.h