2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "RedstoneHandler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cRedstoneWireHandler : public cRedstoneHandler
|
|
|
|
{
|
|
|
|
typedef cRedstoneHandler super;
|
|
|
|
public:
|
|
|
|
|
|
|
|
inline static bool IsDirectlyConnectingMechanism(BLOCKTYPE a_Block)
|
|
|
|
{
|
|
|
|
switch (a_Block)
|
|
|
|
{
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
|
|
|
case E_BLOCK_ACTIVE_COMPARATOR:
|
|
|
|
case E_BLOCK_INACTIVE_COMPARATOR:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
|
|
|
case E_BLOCK_REDSTONE_WIRE: return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 04:25:34 -04:00
|
|
|
cVector3iArray GetTerracingConnectionOffsets(cWorld & a_World, Vector3i a_Position) const
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
cVector3iArray RelativePositions;
|
2017-07-14 22:09:55 -04:00
|
|
|
auto YPTerraceBlock = a_World.GetBlock(a_Position + OffsetYP());
|
2016-01-10 20:53:02 -05:00
|
|
|
bool IsYPTerracingBlocked = cBlockInfo::IsSolid(YPTerraceBlock) && !cBlockInfo::IsTransparent(YPTerraceBlock);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
2015-12-19 16:41:17 -05:00
|
|
|
for (const auto & Adjacent : GetRelativeLaterals())
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
!IsYPTerracingBlocked &&
|
2017-07-14 22:09:55 -04:00
|
|
|
(a_World.GetBlock(a_Position + Adjacent + OffsetYP()) == E_BLOCK_REDSTONE_WIRE)
|
2015-06-26 18:24:51 -04:00
|
|
|
)
|
|
|
|
{
|
|
|
|
RelativePositions.emplace_back(Adjacent + OffsetYP());
|
|
|
|
}
|
2017-07-14 22:09:55 -04:00
|
|
|
auto YMTerraceBlock = a_World.GetBlock(a_Position + Adjacent);
|
2015-06-26 18:24:51 -04:00
|
|
|
if (
|
2016-01-10 20:53:02 -05:00
|
|
|
// IsYMTerracingBlocked (i.e. check block above lower terracing position, a.k.a. just the plain adjacent)
|
|
|
|
(!cBlockInfo::IsSolid(YMTerraceBlock) || cBlockInfo::IsTransparent(YMTerraceBlock)) &&
|
2017-07-14 22:09:55 -04:00
|
|
|
(a_World.GetBlock(a_Position + Adjacent + OffsetYM()) == E_BLOCK_REDSTONE_WIRE)
|
2015-06-26 18:24:51 -04:00
|
|
|
)
|
|
|
|
{
|
|
|
|
RelativePositions.emplace_back(Adjacent + OffsetYM());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RelativePositions;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (a_QueryPosition == (a_Position + OffsetYP()))
|
|
|
|
{
|
|
|
|
// Wires do not power things above them
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_QueryBlockType != E_BLOCK_REDSTONE_WIRE)
|
|
|
|
{
|
|
|
|
// For mechanisms, wire of power one will still power them
|
|
|
|
a_Meta++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((a_QueryPosition != (a_Position + OffsetYM())) && !IsDirectlyConnectingMechanism(a_QueryBlockType))
|
|
|
|
{
|
|
|
|
Vector3i PotentialOffset;
|
|
|
|
bool FoundOneBorderingMechanism = false;
|
|
|
|
|
2017-07-14 22:09:55 -04:00
|
|
|
for (const auto & Offset : StaticAppend(GetRelativeLaterals(), GetTerracingConnectionOffsets(a_World, a_Position)))
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2017-07-14 22:09:55 -04:00
|
|
|
if (IsDirectlyConnectingMechanism(a_World.GetBlock(Offset + a_Position)))
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
|
|
|
if (FoundOneBorderingMechanism)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FoundOneBorderingMechanism = true;
|
|
|
|
PotentialOffset = { -Offset.x, 0, -Offset.z };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FoundOneBorderingMechanism && (a_QueryPosition != (a_Position + PotentialOffset)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (a_Meta != 0) ? --a_Meta : a_Meta;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return a_Meta;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
UNUSED(a_BlockType);
|
2015-12-24 10:57:45 -05:00
|
|
|
// LOGD("Evaluating dusty the wire (%d %d %d) %i", a_Position.x, a_Position.y, a_Position.z, a_PoweringData.PowerLevel);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
if (a_Meta != a_PoweringData.PowerLevel)
|
|
|
|
{
|
2017-07-14 22:09:55 -04:00
|
|
|
a_World.SetBlockMeta(a_Position, a_PoweringData.PowerLevel);
|
|
|
|
return GetAdjustedRelatives(a_Position, StaticAppend(StaticAppend(GetRelativeLaterals(), GetTerracingConnectionOffsets(a_World, a_Position)), cVector3iArray{ OffsetYM() }));
|
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-07-14 22:09:55 -04:00
|
|
|
return GetAdjustedRelatives(a_Position, StaticAppend(GetRelativeAdjacents(), GetTerracingConnectionOffsets(a_World, a_Position)));
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
};
|