2020-09-17 10:16:20 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ItemHandler.h"
|
|
|
|
#include "../BlockEntities/EnchantingTableEntity.h"
|
|
|
|
#include "../World.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cItemEnchantingTableHandler:
|
|
|
|
public cItemHandler
|
|
|
|
{
|
|
|
|
using Super = cItemHandler;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
using Super::Super;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
2020-09-17 10:16:20 -04:00
|
|
|
{
|
2021-05-05 09:25:10 -04:00
|
|
|
if (!Super::CommitPlacement(a_Player, a_HeldItem, a_PlacePosition, a_ClickedBlockFace, a_CursorPosition))
|
2020-09-17 10:16:20 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
if (a_HeldItem.IsCustomNameEmpty())
|
2020-09-17 10:16:20 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
a_Player.GetWorld()->DoWithBlockEntityAt(a_PlacePosition, [&a_HeldItem](cBlockEntity & a_BlockEntity)
|
2020-09-17 10:16:20 -04:00
|
|
|
{
|
2021-05-05 09:25:10 -04:00
|
|
|
ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_ENCHANTMENT_TABLE);
|
2020-09-17 10:16:20 -04:00
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
static_cast<cEnchantingTableEntity &>(a_BlockEntity).SetCustomName(a_HeldItem.m_CustomName);
|
2021-03-28 09:40:57 -04:00
|
|
|
return false;
|
2020-09-17 10:16:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-05 09:25:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
virtual bool IsPlaceable(void) override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2020-09-17 10:16:20 -04:00
|
|
|
} ;
|