2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "RedstoneHandler.h"
|
2018-08-28 20:51:25 -04:00
|
|
|
#include "../../BlockEntities/NoteEntity.h"
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
class cNoteBlockHandler:
|
|
|
|
public cRedstoneHandler
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cRedstoneHandler;
|
|
|
|
|
2015-06-26 18:24:51 -04:00
|
|
|
public:
|
|
|
|
|
2017-09-07 04:25:34 -04:00
|
|
|
virtual unsigned char GetPowerDeliveredToPosition(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType) const override
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2017-07-14 22:09:55 -04:00
|
|
|
UNUSED(a_World);
|
|
|
|
UNUSED(a_World);
|
2015-06-26 18:24:51 -04:00
|
|
|
UNUSED(a_Position);
|
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
UNUSED(a_QueryPosition);
|
|
|
|
UNUSED(a_QueryBlockType);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-07 04:25:34 -04:00
|
|
|
virtual unsigned char GetPowerLevel(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const override
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2017-07-14 22:09:55 -04:00
|
|
|
UNUSED(a_World);
|
2015-06-26 18:24:51 -04:00
|
|
|
UNUSED(a_Position);
|
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-07 04:25:34 -04:00
|
|
|
virtual cVector3iArray Update(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2015-12-24 10:57:45 -05:00
|
|
|
// LOGD("Evaluating sparky the magical note block (%d %d %d) %i", a_Position.x, a_Position.y, a_Position.z, a_PoweringData.PowerLevel);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
auto Previous = static_cast<cIncrementalRedstoneSimulator *>(a_World.GetRedstoneSimulator())->GetChunkData()->ExchangeUpdateOncePowerData(a_Position, a_PoweringData);
|
2015-06-26 18:24:51 -04:00
|
|
|
if ((Previous.PowerLevel != 0) || (a_PoweringData.PowerLevel == 0))
|
|
|
|
{
|
|
|
|
// If we're already powered or received an update of no power, don't make a sound
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-09-11 17:20:49 -04:00
|
|
|
a_World.DoWithNoteBlockAt(a_Position.x, a_Position.y, a_Position.z, [](cNoteEntity & a_NoteBlock)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2017-09-11 17:20:49 -04:00
|
|
|
a_NoteBlock.MakeSound();
|
2015-06-26 18:24:51 -04:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-11 17:20:49 -04:00
|
|
|
);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-09-07 04:25:34 -04:00
|
|
|
virtual cVector3iArray GetValidSourcePositions(cWorld & a_World, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const override
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2017-07-14 22:09:55 -04:00
|
|
|
UNUSED(a_World);
|
2015-06-26 18:24:51 -04:00
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_Meta);
|
2017-09-07 04:25:34 -04:00
|
|
|
return GetAdjustedRelatives(a_Position, GetRelativeAdjacents());
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
};
|