diff options
author | Mattes D <github@xoft.cz> | 2013-12-19 22:51:21 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2013-12-19 22:51:21 +0100 |
commit | 03ec64aee153a4c217f0794e9310d80eda7629e6 (patch) | |
tree | cb5f0e532d5bcfc25324207f0c088507f6b6c6bc /src/Items | |
parent | Merge pull request #448 from mc-server/testbranch (diff) | |
parent | Fixed #include in Floater.cpp. (diff) | |
download | cuberite-03ec64aee153a4c217f0794e9310d80eda7629e6.tar cuberite-03ec64aee153a4c217f0794e9310d80eda7629e6.tar.gz cuberite-03ec64aee153a4c217f0794e9310d80eda7629e6.tar.bz2 cuberite-03ec64aee153a4c217f0794e9310d80eda7629e6.tar.lz cuberite-03ec64aee153a4c217f0794e9310d80eda7629e6.tar.xz cuberite-03ec64aee153a4c217f0794e9310d80eda7629e6.tar.zst cuberite-03ec64aee153a4c217f0794e9310d80eda7629e6.zip |
Diffstat (limited to 'src/Items')
-rw-r--r-- | src/Items/ItemFishingRod.h | 78 | ||||
-rw-r--r-- | src/Items/ItemHandler.cpp | 2 |
2 files changed, 80 insertions, 0 deletions
diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h new file mode 100644 index 000000000..91c0e9638 --- /dev/null +++ b/src/Items/ItemFishingRod.h @@ -0,0 +1,78 @@ + +// ItemFishingRod.h + +// Declares the various fishing rod ItemHandlers + + + + + +#pragma once + +#include "../Entities/Floater.h" +#include "../Entities/Entity.h" +#include "../Item.h" + + + + +class cItemFishingRodHandler : + public cItemHandler +{ + typedef cItemHandler super; + +public: + cItemFishingRodHandler(int a_ItemType) : + super(a_ItemType) + { + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override + { + if (a_Player->IsFishing()) + { + class cFloaterCallback : + public cEntityCallback + { + public: + cFloaterCallback(void) : + m_CanPickup(false) + { + } + + bool CanPickup(void) const { return m_CanPickup; } + Vector3d GetPos(void) const { return m_Pos; } + + virtual bool Item(cEntity * a_Entity) override + { + m_CanPickup = ((cFloater *)a_Entity)->CanPickup(); + m_Pos = Vector3d(a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ()); + a_Entity->Destroy(true); + return true; + } + protected: + bool m_CanPickup; + Vector3d m_Pos; + } Callbacks; + a_World->DoWithEntityByID(a_Player->GetFloaterID(), Callbacks); + a_Player->SetIsFishing(false); + + if (Callbacks.CanPickup()) + { + cItems Drops; + Drops.Add(cItem(E_ITEM_RAW_FISH)); + Vector3d FloaterPos(Callbacks.GetPos()); + Vector3d FlyDirection(a_Player->GetPosition() - FloaterPos); + a_World->SpawnItemPickups(Drops, FloaterPos.x, FloaterPos.y, FloaterPos.z, FlyDirection.x, FlyDirection.y, FlyDirection.z); + // TODO: More types of pickups. + } + } + else + { + cFloater * Floater = new cFloater(a_Player->GetPosX(), a_Player->GetStance(), a_Player->GetPosZ(), a_Player->GetLookVector() * 7, a_Player->GetUniqueID()); + Floater->Initialize(a_World); + a_Player->SetIsFishing(true, Floater->GetUniqueID()); + } + return true; + } +} ;
\ No newline at end of file diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 23b9a86d4..250e21dc4 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -17,6 +17,7 @@ #include "ItemComparator.h" #include "ItemDoor.h" #include "ItemDye.h" +#include "ItemFishingRod.h" #include "ItemFlowerPot.h" #include "ItemFood.h" #include "ItemHoe.h" @@ -100,6 +101,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_EGG: return new cItemEggHandler(); 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_NETHER_WART: return new cItemNetherWartHandler(a_ItemType); |