Skip to content

Commit

Permalink
Improved piston direction checking
Browse files Browse the repository at this point in the history
Now uses AddFaceDirection, as suggested by xoft.
  • Loading branch information
tigerw committed Nov 30, 2013
1 parent 455686e commit d12106e
Showing 1 changed file with 8 additions and 62 deletions.
70 changes: 8 additions & 62 deletions src/Simulator/RedstoneSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,38 +854,11 @@ bool cRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_Block

if (!Change.a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; }

switch (a_Meta) // Pistons' metas are the directions they face; the source cannot be there
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Meta); // Piston meta is based on what direction they face, so we can do this

if (!Change.a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)))
{
case BLOCK_FACE_YM:
{
if (!Change.a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY - 1, a_BlockZ))) { return true; }
break;
}
case BLOCK_FACE_YP:
{
if (!Change.a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY + 1, a_BlockZ))) { return true; }
break;
}
case BLOCK_FACE_ZM:
{
if (!Change.a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; }
break;
}
case BLOCK_FACE_ZP:
{
if (!Change.a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; }
break;
}
case BLOCK_FACE_XM:
{
if (!Change.a_SourcePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; }
break;
}
case BLOCK_FACE_XP:
{
if (!Change.a_SourcePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; }
break;
}
return true;
}
}

Expand All @@ -895,38 +868,11 @@ bool cRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_Block

if (!Change.a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; }

switch (a_Meta)
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_Meta);

if (!Change.a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)))
{
case BLOCK_FACE_YM:
{
if (!Change.a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY - 1, a_BlockZ))) { return true; }
break;
}
case BLOCK_FACE_YP:
{
if (!Change.a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY + 1, a_BlockZ))) { return true; }
break;
}
case BLOCK_FACE_ZM:
{
if (!Change.a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; }
break;
}
case BLOCK_FACE_ZP:
{
if (!Change.a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; }
break;
}
case BLOCK_FACE_XM:
{
if (!Change.a_MiddlePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; }
break;
}
case BLOCK_FACE_XP:
{
if (!Change.a_MiddlePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; }
break;
}
return true;
}
}
return false; // Source was in front of the piston's front face
Expand Down

4 comments on commit d12106e

@madmaxoft
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this works? Because now the a_BlockX, Y, Z are changed, doesn't it affect the code later on?

@tigerw
Copy link
Member Author

@tigerw tigerw commented on d12106e Nov 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How strange! In theory it should, but pistons seem to still work. I'll correct this anyway, perhaps there was a scenario that I didn't test which doesn't work.

@tigerw
Copy link
Member Author

@tigerw tigerw commented on d12106e Nov 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, pistons wouldn't extend if there was a source in front of it, even if the source was breakable/pushable.

@tigerw
Copy link
Member Author

@tigerw tigerw commented on d12106e Nov 30, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mergey?

Please sign in to comment.