2014-02-17 18:00:03 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ItemHandler.h"
|
2018-08-28 20:51:25 -04:00
|
|
|
#include "../Entities/ItemFrame.h"
|
2014-02-17 18:00:03 -05:00
|
|
|
#include "../Entities/Player.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
class cItemItemFrameHandler:
|
2014-02-17 18:00:03 -05:00
|
|
|
public cItemHandler
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
using Super = cItemHandler;
|
|
|
|
|
2014-02-17 18:00:03 -05:00
|
|
|
public:
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
cItemItemFrameHandler(int a_ItemType):
|
|
|
|
Super(a_ItemType)
|
|
|
|
{
|
2014-02-17 18:00:03 -05:00
|
|
|
}
|
|
|
|
|
2015-04-14 04:49:01 -04:00
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
2015-04-14 04:49:01 -04:00
|
|
|
virtual bool OnItemUse(
|
2020-04-21 16:19:22 -04:00
|
|
|
cWorld * a_World,
|
|
|
|
cPlayer * a_Player,
|
|
|
|
cBlockPluginInterface & a_PluginInterface,
|
|
|
|
const cItem & a_HeldItem,
|
|
|
|
const Vector3i a_ClickedBlockPos,
|
|
|
|
eBlockFace a_ClickedBlockFace
|
2015-04-14 04:49:01 -04:00
|
|
|
) override
|
2014-02-17 18:00:03 -05:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
// Can only place on a side face:
|
|
|
|
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_YP) || (a_ClickedBlockFace == BLOCK_FACE_YM))
|
2014-02-17 18:00:03 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
// Make sure block that will be occupied by the item frame is free now:
|
2020-04-20 15:46:04 -04:00
|
|
|
const auto PlacePos = AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace);
|
2020-04-21 16:19:22 -04:00
|
|
|
BLOCKTYPE Block = a_World->GetBlock(PlacePos);
|
|
|
|
if (Block != E_BLOCK_AIR)
|
2014-02-17 18:00:03 -05:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-17 18:00:03 -05:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
// Place the item frame:
|
2020-04-20 15:46:04 -04:00
|
|
|
auto ItemFrame = cpp14::make_unique<cItemFrame>(a_ClickedBlockFace, PlacePos);
|
2020-04-21 16:19:22 -04:00
|
|
|
auto ItemFramePtr = ItemFrame.get();
|
|
|
|
if (!ItemFramePtr->Initialize(std::move(ItemFrame), *a_World))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-17 18:00:03 -05:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
if (!a_Player->IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
2014-02-17 18:00:03 -05:00
|
|
|
}
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
return true;
|
2014-02-17 18:00:03 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|