2015-06-26 22:24:51 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-08-29 00:51:25 +00:00
|
|
|
#include "../../BlockEntities/DropSpenserEntity.h"
|
2015-06-26 22:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-19 20:14:40 +00:00
|
|
|
namespace DropSpenserHandler
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2021-01-21 22:51:55 +00:00
|
|
|
static bool IsActivated(NIBBLETYPE a_Meta)
|
2016-06-04 12:16:35 +00:00
|
|
|
{
|
|
|
|
return (a_Meta & E_META_DROPSPENSER_ACTIVATED) != 0;
|
|
|
|
}
|
2020-07-26 13:15:00 +00:00
|
|
|
|
2021-01-21 22:51:55 +00:00
|
|
|
static NIBBLETYPE SetActivationState(NIBBLETYPE a_Meta, bool IsOn)
|
2016-06-04 12:16:35 +00:00
|
|
|
{
|
|
|
|
if (IsOn)
|
|
|
|
{
|
|
|
|
return a_Meta | E_META_DROPSPENSER_ACTIVATED; // set the bit
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return a_Meta & ~E_META_DROPSPENSER_ACTIVATED; // clear the bit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-21 22:51:55 +00:00
|
|
|
static PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2020-07-26 13:15:00 +00:00
|
|
|
UNUSED(a_Chunk);
|
2015-06-26 22:24:51 +00:00
|
|
|
UNUSED(a_Position);
|
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_QueryPosition);
|
|
|
|
UNUSED(a_QueryBlockType);
|
2020-08-08 17:22:16 +00:00
|
|
|
UNUSED(IsLinked);
|
2015-06-26 22:24:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-21 22:51:55 +00:00
|
|
|
static void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2015-12-24 15:57:45 +00:00
|
|
|
// LOGD("Evaluating spencer the dropspenser (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
2020-07-26 13:15:00 +00:00
|
|
|
|
2020-08-20 19:04:28 +00:00
|
|
|
const bool IsPoweredNow = (Power > 0);
|
2020-07-26 13:15:00 +00:00
|
|
|
const bool WasPoweredPreviously = IsActivated(a_Meta);
|
|
|
|
|
2016-06-04 12:16:35 +00:00
|
|
|
if (IsPoweredNow && !WasPoweredPreviously)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2021-03-28 13:40:57 +00:00
|
|
|
a_Chunk.DoWithBlockEntityAt(a_Position, [](cBlockEntity & a_BlockEntity)
|
2020-07-26 13:15:00 +00:00
|
|
|
{
|
2021-04-30 13:23:46 +00:00
|
|
|
ASSERT((a_BlockEntity.GetBlockType() == E_BLOCK_DISPENSER) || (a_BlockEntity.GetBlockType() == E_BLOCK_DROPPER));
|
2021-03-28 13:40:57 +00:00
|
|
|
|
|
|
|
static_cast<cDropSpenserEntity &>(a_BlockEntity).Activate();
|
2020-07-26 13:15:00 +00:00
|
|
|
return false;
|
|
|
|
});
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 12:16:35 +00:00
|
|
|
// Update the internal dropspenser state if necessary
|
|
|
|
if (IsPoweredNow != WasPoweredPreviously)
|
|
|
|
{
|
2020-07-26 13:15:00 +00:00
|
|
|
a_Chunk.SetMeta(a_Position, SetActivationState(a_Meta, IsPoweredNow));
|
2016-06-04 12:16:35 +00:00
|
|
|
}
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 22:51:55 +00:00
|
|
|
static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2020-07-26 13:15:00 +00:00
|
|
|
UNUSED(a_Chunk);
|
2015-06-26 22:24:51 +00:00
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_Meta);
|
2020-09-21 19:39:58 +00:00
|
|
|
|
|
|
|
// Consider indirect power:
|
|
|
|
Callback.CheckIndirectPower();
|
|
|
|
|
|
|
|
// Consider normal adjacents:
|
2020-07-26 13:15:00 +00:00
|
|
|
InvokeForAdjustedRelatives(Callback, a_Position, RelativeAdjacents);
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
};
|