Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Handler include processing for block states #5490

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Server/Plugins/APIDump/APIDesc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14877,6 +14877,40 @@ end
},
Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after mirroring it around the Y axis (or rotating 180 degrees around it).",
},
MirrorBlockFaceXY =
{
Params =
{
{
Name = "eBlockFace",
Type = "eBlockFace",
},
},
Returns =
{
{
Type = "eBlockFace",
},
},
Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after mirroring it around the XY plane (or rotating 180 degrees around it).",
Copy link
Member

Choose a reason for hiding this comment

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

So is it mirroring or rotating? In the general sense, those two operations are different, though for Minecraft they may be the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, this comment is wrong.

For most blocks, this applies. But if you want to rotate blocks with the ability to be asymmetric you don't have 180 degree rotation but mirroring. For examples vines.

Example viewed from the top:
_| should mirror to |_ but rotation does yield |^. Imagine the ^ is a horizontal line at the top.

},
MirrorBlockFaceYZ =
{
Params =
{
{
Name = "eBlockFace",
Type = "eBlockFace",
},
},
Returns =
{
{
Type = "eBlockFace",
},
},
Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after mirroring it around the YZ plane (or rotating 180 degrees around it).",
},
NoCaseCompare =
{
Params =
Expand Down Expand Up @@ -14992,6 +15026,23 @@ end
},
Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after rotating it around the Y axis 90 degrees clockwise.",
},
RotationToBlockFace =
{
Params =
{
{
Name = "Rotation",
Type = "number",
},
},
Returns =
{
{
Type = "eBlockFace",
},
},
Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given rotation. Used for example for {{Banners|banners}}.",
},
StringSplit =
{
Params =
Expand Down
12 changes: 12 additions & 0 deletions src/Blocks/BlockAir.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ class cBlockAirHandler final :

using cBlockHandler::cBlockHandler;

static inline bool IsBlockAir(BlockState a_Block)
{
switch (a_Block.Type())
{
case BlockType::Air:
case BlockType::CaveAir:
case BlockType::VoidAir:
return true;
default: return false;
}
}

private:

virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
Expand Down
45 changes: 41 additions & 4 deletions src/Blocks/BlockAnvil.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#pragma once

#include "BlockHandler.h"
#include "Mixins.h"
#include "../Entities/Player.h"
#include "../UI/AnvilWindow.h"
#include "Blocks/BlockHandler.h"
#include "Blocks/Mixins.h"
#include "Entities/Player.h"
#include "UI/AnvilWindow.h"



Expand All @@ -19,8 +19,45 @@ class cBlockAnvilHandler final :

using Super::Super;

static inline eBlockFace GetFacing(BlockState a_Block)
{
switch (a_Block.Type())
{
case BlockType::Anvil: return Block::Anvil::Facing(a_Block);
case BlockType::ChippedAnvil: return Block::ChippedAnvil::Facing(a_Block);
case BlockType::DamagedAnvil: return Block::DamagedAnvil::Facing(a_Block);
default: return BLOCK_FACE_NONE;
}
}

private:

/** Rotates a given block counter-clockwise. */
BlockState RotateCCW(BlockState a_Block) const
{
auto Facing = RotateBlockFaceCCW(GetFacing(a_Block));
switch (a_Block.Type())
{
case BlockType::Anvil: return Block::Anvil::Anvil(Facing);
case BlockType::ChippedAnvil: return Block::ChippedAnvil::ChippedAnvil(Facing);
case BlockType::DamagedAnvil: return Block::DamagedAnvil::DamagedAnvil(Facing);
default: return a_Block;
}
}

/** Rotates a given block clockwise. */
BlockState RotateCW(BlockState a_Block) const
{
auto Facing = RotateBlockFaceCW(GetFacing(a_Block));
switch (a_Block.Type())
{
case BlockType::Anvil: return Block::Anvil::Anvil(Facing);
case BlockType::ChippedAnvil: return Block::ChippedAnvil::ChippedAnvil(Facing);
case BlockType::DamagedAnvil: return Block::DamagedAnvil::DamagedAnvil(Facing);
default: return a_Block;
}
}

virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
{
return cItem(m_BlockType, 1, a_BlockMeta >> 2);
Expand Down
Loading