summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemEnchantingTable.h
diff options
context:
space:
mode:
author12xx12 <12xx12100@gmail.com>2020-09-17 16:16:20 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-09-20 02:40:20 +0200
commitf8de67aace4e65ff4c34a1f46f6d8b258b6839aa (patch)
tree51f60dd89e5abb7bcf14e11f087ef2d49c1fa096 /src/Items/ItemEnchantingTable.h
parentFixed missing case: in entity damaging crashin the server (#4899) (diff)
downloadcuberite-f8de67aace4e65ff4c34a1f46f6d8b258b6839aa.tar
cuberite-f8de67aace4e65ff4c34a1f46f6d8b258b6839aa.tar.gz
cuberite-f8de67aace4e65ff4c34a1f46f6d8b258b6839aa.tar.bz2
cuberite-f8de67aace4e65ff4c34a1f46f6d8b258b6839aa.tar.lz
cuberite-f8de67aace4e65ff4c34a1f46f6d8b258b6839aa.tar.xz
cuberite-f8de67aace4e65ff4c34a1f46f6d8b258b6839aa.tar.zst
cuberite-f8de67aace4e65ff4c34a1f46f6d8b258b6839aa.zip
Diffstat (limited to '')
-rw-r--r--src/Items/ItemEnchantingTable.h63
1 files changed, 63 insertions, 0 deletions
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<cEnchantingTableEntity &>(a_Entity);
+ EnchantingTable.SetCustomName(a_EquippedItem.m_CustomName);
+ return true;
+ });
+
+ return true;
+ }
+} ;