2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-08-28 20:51:25 -04:00
|
|
|
#include "../../Blocks/BlockButton.h"
|
|
|
|
#include "../../Blocks/BlockLever.h"
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-19 16:14:40 -04:00
|
|
|
namespace RedstoneToggleHandler
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2020-08-19 16:14:40 -04:00
|
|
|
inline Vector3i GetOffsetAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_LEVER:
|
|
|
|
{
|
|
|
|
switch (a_Meta & 0x7)
|
|
|
|
{
|
|
|
|
case 0x0:
|
2020-08-08 13:22:16 -04:00
|
|
|
case 0x7: return { 0, 1, 0 };
|
|
|
|
case 0x1: return { -1, 0, 0 };
|
|
|
|
case 0x2: return { 1, 0, 0 };
|
|
|
|
case 0x3: return { 0, 0, -1 };
|
|
|
|
case 0x4: return { 0, 0, 1 };
|
2015-06-26 18:24:51 -04:00
|
|
|
case 0x5:
|
2020-08-08 13:22:16 -04:00
|
|
|
case 0x6: return { 0, -1, 0 };
|
2015-06-26 18:24:51 -04:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled lever metadata!");
|
|
|
|
return { 0, 0, 0 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case E_BLOCK_STONE_BUTTON:
|
|
|
|
case E_BLOCK_WOODEN_BUTTON:
|
|
|
|
{
|
|
|
|
switch (a_Meta & 0x7)
|
|
|
|
{
|
2020-08-08 13:22:16 -04:00
|
|
|
case 0x0: return { 0, 1, 0 };
|
|
|
|
case 0x1: return { -1, 0, 0 };
|
|
|
|
case 0x2: return { 1, 0, 0 };
|
|
|
|
case 0x3: return { 0, 0, -1 };
|
|
|
|
case 0x4: return { 0, 0, 1 };
|
|
|
|
case 0x5: return { 0, -1, 0 };
|
2015-06-26 18:24:51 -04:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled button metadata!");
|
|
|
|
return { 0, 0, 0 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unexpected block passed to button/lever handler");
|
|
|
|
return { 0, 0, 0 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 16:14:40 -04:00
|
|
|
inline unsigned char GetPowerLevel(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_LEVER: return cBlockLeverHandler::IsLeverOn(a_Meta) ? 15 : 0;
|
|
|
|
case E_BLOCK_STONE_BUTTON:
|
|
|
|
case E_BLOCK_WOODEN_BUTTON: return cBlockButtonHandler::IsButtonOn(a_Meta) ? 15 : 0;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unexpected block passed to button/lever handler");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-20 15:04:28 -04:00
|
|
|
inline PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
2020-08-19 16:14:40 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_QueryBlockType);
|
|
|
|
|
|
|
|
const auto Meta = a_Chunk.GetMeta(a_Position);
|
|
|
|
const auto QueryOffset = a_QueryPosition - a_Position;
|
|
|
|
|
|
|
|
if (IsLinked && (QueryOffset != GetOffsetAttachedTo(a_Position, a_BlockType, Meta)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetPowerLevel(a_BlockType, Meta);
|
|
|
|
}
|
|
|
|
|
2020-08-20 15:04:28 -04:00
|
|
|
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2015-12-24 10:57:45 -05:00
|
|
|
// LOGD("Evaluating templatio<> the lever/button (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
|
2020-08-19 16:14:40 -04:00
|
|
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
UNUSED(a_Chunk);
|
2015-06-26 18:24:51 -04:00
|
|
|
UNUSED(a_Position);
|
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_Meta);
|
2020-07-26 09:15:00 -04:00
|
|
|
UNUSED(Callback);
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
};
|