From f8de67aace4e65ff4c34a1f46f6d8b258b6839aa Mon Sep 17 00:00:00 2001 From: 12xx12 <12xx12100@gmail.com> Date: Thu, 17 Sep 2020 16:16:20 +0200 Subject: Added end portal and enchanting table block entities --- src/Items/ItemEnchantingTable.h | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/Items/ItemEnchantingTable.h (limited to 'src/Items/ItemEnchantingTable.h') diff --git a/src/Items/ItemEnchantingTable.h b/src/Items/ItemEnchantingTable.h new file mode 100644 index 000000000..c8eb42cac --- /dev/null +++ b/src/Items/ItemEnchantingTable.h @@ -0,0 +1,63 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../BlockEntities/EnchantingTableEntity.h" +#include "../World.h" + + + + + +class cItemEnchantingTableHandler: + public cItemHandler +{ + using Super = cItemHandler; + +public: + + using Super::Super; + +private: + + virtual bool IsPlaceable(void) override + { + return true; + } + + + virtual bool OnPlayerPlace( + cWorld & a_World, + cPlayer & a_Player, + const cItem & a_EquippedItem, + const Vector3i a_ClickedBlockPos, + eBlockFace a_ClickedBlockFace, + const Vector3i a_CursorPos + ) override + { + if (!Super::OnPlayerPlace(a_World, a_Player, a_EquippedItem, a_ClickedBlockPos, a_ClickedBlockFace, a_CursorPos)) + { + return false; + } + + if (a_EquippedItem.IsCustomNameEmpty()) + { + return true; + } + + const auto PlacePos = AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace); + a_World.DoWithBlockEntityAt(PlacePos.x, PlacePos.y, PlacePos.z, [&a_EquippedItem](cBlockEntity & a_Entity) + { + if (a_Entity.GetBlockType() != E_BLOCK_ENCHANTMENT_TABLE) + { + return true; + } + + auto & EnchantingTable = static_cast(a_Entity); + EnchantingTable.SetCustomName(a_EquippedItem.m_CustomName); + return true; + }); + + return true; + } +} ; -- cgit v1.2.3