2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "RedstoneHandler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
class cPoweredRailHandler final : public cRedstoneHandler
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
static Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta) // Not in cBlockRailHandler since specific to powered rails
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
switch (a_Meta & 0x7)
|
|
|
|
{
|
|
|
|
case E_META_RAIL_ZM_ZP: return { 0, 0, 1 };
|
|
|
|
case E_META_RAIL_XM_XP: return { 1, 0, 0 };
|
|
|
|
case E_META_RAIL_ASCEND_XP: return { 1, 1, 0 };
|
|
|
|
case E_META_RAIL_ASCEND_XM: return { 1, 1, 0 };
|
|
|
|
case E_META_RAIL_ASCEND_ZM: return { 0, 1, 1 };
|
|
|
|
case E_META_RAIL_ASCEND_ZP: return { 0, 1, 1 };
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Impossible rail meta! wat wat wat");
|
|
|
|
return { 0, 0, 0 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
virtual unsigned char GetPowerDeliveredToPosition(cChunk & a_Chunk, 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
|
|
|
{
|
|
|
|
UNUSED(a_QueryBlockType);
|
|
|
|
|
|
|
|
auto Offset = GetPoweredRailAdjacentXZCoordinateOffset(a_Meta);
|
|
|
|
if (((Offset + a_Position) == a_QueryPosition) || ((-Offset + a_Position) == a_QueryPosition))
|
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
auto Power = DataForChunk(a_Chunk).GetCachedPowerData(a_Position).PowerLevel;
|
2015-06-26 18:24:51 -04:00
|
|
|
return (Power <= 7) ? 0 : --Power;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTickingChunk, 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 tracky the rail (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_DETECTOR_RAIL:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if ((m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x08) == 0x08)
|
|
|
|
{
|
|
|
|
SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_MyType);
|
|
|
|
}
|
|
|
|
*/
|
2020-07-26 09:15:00 -04:00
|
|
|
return;
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
case E_BLOCK_ACTIVATOR_RAIL:
|
|
|
|
case E_BLOCK_POWERED_RAIL:
|
|
|
|
{
|
|
|
|
auto Offset = GetPoweredRailAdjacentXZCoordinateOffset(a_Meta);
|
2020-07-26 09:15:00 -04:00
|
|
|
if (a_PoweringData != DataForChunk(a_Chunk).ExchangeUpdateOncePowerData(a_Position, a_PoweringData))
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
a_Chunk.SetMeta(a_Position, (a_PoweringData.PowerLevel == 0) ? (a_Meta & 0x07) : (a_Meta | 0x08));
|
|
|
|
|
2020-07-27 19:13:07 -04:00
|
|
|
UpdateAdjustedRelative(a_Chunk, CurrentlyTickingChunk, a_Position + Offset);
|
|
|
|
UpdateAdjustedRelative(a_Chunk, CurrentlyTickingChunk, a_Position + -Offset);
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
return;
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled type of rail in passed to rail handler!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
virtual void ForValidSourcePositions(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
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_Meta);
|
2020-07-26 09:15:00 -04:00
|
|
|
|
|
|
|
if ((a_BlockType == E_BLOCK_POWERED_RAIL) || (a_BlockType == E_BLOCK_ACTIVATOR_RAIL))
|
|
|
|
{
|
|
|
|
InvokeForAdjustedRelatives(Callback, a_Position, RelativeAdjacents);
|
|
|
|
}
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
};
|