summaryrefslogtreecommitdiffstats
path: root/src/Items
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-24 11:28:34 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-24 11:28:34 +0100
commitf77720c43f22e347ae9e66302a58b5e3f6a6de58 (patch)
tree06bb29a7e50aec777969ead2f5ccdf02393c9e1e /src/Items
parentRemoved an unused member variable from cChunk. (diff)
parentMaps: Improvements (diff)
downloadcuberite-f77720c43f22e347ae9e66302a58b5e3f6a6de58.tar
cuberite-f77720c43f22e347ae9e66302a58b5e3f6a6de58.tar.gz
cuberite-f77720c43f22e347ae9e66302a58b5e3f6a6de58.tar.bz2
cuberite-f77720c43f22e347ae9e66302a58b5e3f6a6de58.tar.lz
cuberite-f77720c43f22e347ae9e66302a58b5e3f6a6de58.tar.xz
cuberite-f77720c43f22e347ae9e66302a58b5e3f6a6de58.tar.zst
cuberite-f77720c43f22e347ae9e66302a58b5e3f6a6de58.zip
Diffstat (limited to 'src/Items')
-rw-r--r--src/Items/ItemEmptyMap.h62
-rw-r--r--src/Items/ItemHandler.cpp4
-rw-r--r--src/Items/ItemHandler.h8
-rw-r--r--src/Items/ItemMap.h43
4 files changed, 117 insertions, 0 deletions
diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h
new file mode 100644
index 000000000..db28511f3
--- /dev/null
+++ b/src/Items/ItemEmptyMap.h
@@ -0,0 +1,62 @@
+
+// ItemEmptyMap.h
+
+
+
+
+
+#pragma once
+
+#include "../Entities/Entity.h"
+#include "../Item.h"
+
+
+
+
+
+class cItemEmptyMapHandler :
+ public cItemHandler
+{
+ typedef cItemHandler super;
+
+ static const unsigned int DEFAULT_SCALE = 0;
+
+public:
+ cItemEmptyMapHandler() :
+ super(E_ITEM_EMPTY_MAP)
+ {
+ }
+
+ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
+ {
+ UNUSED(a_Item);
+ UNUSED(a_BlockX);
+ UNUSED(a_BlockZ);
+ UNUSED(a_Dir);
+
+ // The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it.
+
+ const int RegionWidth = cChunkDef::Width * 8 * pow(2, DEFAULT_SCALE);
+
+ int CenterX = round(a_Player->GetPosX() / (float) RegionWidth) * RegionWidth;
+ int CenterZ = round(a_Player->GetPosZ() / (float) RegionWidth) * RegionWidth;
+
+ cMap * NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE);
+
+ // Remove empty map from inventory
+ if (!a_Player->GetInventory().RemoveOneEquippedItem())
+ {
+ ASSERT(!"Inventory mismatch");
+ return true;
+ }
+
+ if (NewMap == NULL)
+ {
+ return true;
+ }
+
+ a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, NewMap->GetID()), true, true);
+
+ return true;
+ }
+} ;
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index e9bb616a6..c10d13edc 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -18,6 +18,7 @@
#include "ItemComparator.h"
#include "ItemDoor.h"
#include "ItemDye.h"
+#include "ItemEmptyMap.h"
#include "ItemFishingRod.h"
#include "ItemFlowerPot.h"
#include "ItemFood.h"
@@ -25,6 +26,7 @@
#include "ItemHoe.h"
#include "ItemLeaves.h"
#include "ItemLighter.h"
+#include "ItemMap.h"
#include "ItemMinecart.h"
#include "ItemNetherWart.h"
#include "ItemPainting.h"
@@ -103,11 +105,13 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_COMPARATOR: return new cItemComparatorHandler(a_ItemType);
case E_ITEM_DYE: return new cItemDyeHandler(a_ItemType);
case E_ITEM_EGG: return new cItemEggHandler();
+ case E_ITEM_EMPTY_MAP: return new cItemEmptyMapHandler();
case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler();
case E_ITEM_FIREWORK_ROCKET: return new cItemFireworkHandler();
case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType);
case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
+ case E_ITEM_MAP: return new cItemMapHandler();
case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType);
case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType);
case E_ITEM_PAINTING: return new cItemPaintingHandler(a_ItemType);
diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h
index 1a6bb044f..ef3f37a7a 100644
--- a/src/Items/ItemHandler.h
+++ b/src/Items/ItemHandler.h
@@ -32,6 +32,14 @@ public:
UNUSED(a_BlockZ);
UNUSED(a_BlockFace);
}
+
+ /// Called every tick while the item is on the player's inventory (Used by maps) - For now, called only for equipped items
+ virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item)
+ {
+ UNUSED(a_World);
+ UNUSED(a_Player);
+ UNUSED(a_Item);
+ }
/// Called while the player diggs a block using this item
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace);
diff --git a/src/Items/ItemMap.h b/src/Items/ItemMap.h
new file mode 100644
index 000000000..e8ff9da88
--- /dev/null
+++ b/src/Items/ItemMap.h
@@ -0,0 +1,43 @@
+
+// ItemMap.h
+
+
+
+
+
+#pragma once
+
+#include "../Entities/Entity.h"
+#include "../Item.h"
+
+
+
+
+
+class cItemMapHandler :
+ public cItemHandler
+{
+ typedef cItemHandler super;
+
+ static const unsigned int DEFAULT_RADIUS = 128;
+
+public:
+ cItemMapHandler() :
+ super(E_ITEM_MAP)
+ {
+ }
+
+ virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item)
+ {
+ cMap * Map = a_World->GetMapManager().GetMapData(a_Item.m_ItemDamage);
+
+ if (Map == NULL)
+ {
+ return;
+ }
+
+ Map->UpdateRadius(*a_Player, DEFAULT_RADIUS);
+
+ Map->UpdateClient(a_Player);
+ }
+} ;