From 53ff372624e31028e61cdf72a82945fe935bb420 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 19 Dec 2013 15:57:35 +0000 Subject: Fixed dust from being placed on nonsolids --- src/Items/ItemRedstoneDust.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/Items') diff --git a/src/Items/ItemRedstoneDust.h b/src/Items/ItemRedstoneDust.h index b7860b187..38bf00ba6 100644 --- a/src/Items/ItemRedstoneDust.h +++ b/src/Items/ItemRedstoneDust.h @@ -27,6 +27,11 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { + if (!g_BlockIsTorchPlaceable[a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)]) // Some solid blocks, such as cocoa beans, are not suitable for dust + { + return false; + } + a_BlockType = E_BLOCK_REDSTONE_WIRE; a_BlockMeta = 0; return true; -- cgit v1.2.3 From d9c8ae37cf332d4be93b7727f0c1899f40362aef Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 19 Dec 2013 17:34:03 +0100 Subject: Implented cItemFishingRodHandler. --- src/Items/ItemFishingRod.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++ src/Items/ItemHandler.cpp | 2 ++ 2 files changed, 65 insertions(+) create mode 100644 src/Items/ItemFishingRod.h (limited to 'src/Items') diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h new file mode 100644 index 000000000..722c48c04 --- /dev/null +++ b/src/Items/ItemFishingRod.h @@ -0,0 +1,63 @@ + +// ItemFishingRod.h + +// Declares the various fishing rod ItemHandlers + + + + + +#pragma once + +#include "../Entities/Floater.h" +#include "../Entities/Entity.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 Callbacks : public cEntityCallback + { + public: + bool CanPickup; + virtual bool Item(cEntity * a_Entity) override + { + CanPickup = ((cFloater *)a_Entity)->CanPickup(); + a_Entity->Destroy(true); + return true; + } + Callbacks(void) : CanPickup(false) {} + } Callback; + a_World->DoWithEntityByID(a_Player->GetFloaterID(), Callback); + a_Player->SetIsFishing(false); + if (Callback.CanPickup) + { + a_Player->SendMessage("TODO: Spawn Items."); + // TODO: Pickups if fishing went correct. + } + + } + else + { + cFloater * Floater = new cFloater(a_Player->GetPosX(), a_Player->GetStance(), a_Player->GetPosZ(), a_Player->GetLookVector() * 5, 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); -- cgit v1.2.3 From 018c65b4e3d1e5674e3134281ced640b0e85871f Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 19 Dec 2013 22:16:15 +0100 Subject: You can get fish from fishing :D. Only one type of fish though. --- src/Items/ItemFishingRod.h | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index 722c48c04..91c0e9638 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -11,7 +11,7 @@ #include "../Entities/Floater.h" #include "../Entities/Entity.h" - +#include "../Item.h" @@ -31,30 +31,45 @@ public: { if (a_Player->IsFishing()) { - class Callbacks : public cEntityCallback + class cFloaterCallback : + public cEntityCallback { public: - bool CanPickup; + 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 { - CanPickup = ((cFloater *)a_Entity)->CanPickup(); + m_CanPickup = ((cFloater *)a_Entity)->CanPickup(); + m_Pos = Vector3d(a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ()); a_Entity->Destroy(true); return true; } - Callbacks(void) : CanPickup(false) {} - } Callback; - a_World->DoWithEntityByID(a_Player->GetFloaterID(), Callback); + protected: + bool m_CanPickup; + Vector3d m_Pos; + } Callbacks; + a_World->DoWithEntityByID(a_Player->GetFloaterID(), Callbacks); a_Player->SetIsFishing(false); - if (Callback.CanPickup) + + if (Callbacks.CanPickup()) { - a_Player->SendMessage("TODO: Spawn Items."); - // TODO: Pickups if fishing went correct. + 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() * 5, a_Player->GetUniqueID()); + 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()); } -- cgit v1.2.3