diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-02 09:45:06 +0200 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2017-09-02 09:50:23 +0200 |
commit | 49c443896dcac8c4eaf08c4024e8bd2366ad899a (patch) | |
tree | b1ec46cab2b4e5731860c7136f1bbfca6fe9d458 /src/Items | |
parent | SetSwimState now takes into account head height (diff) | |
download | cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.gz cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.bz2 cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.lz cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.xz cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.tar.zst cuberite-49c443896dcac8c4eaf08c4024e8bd2366ad899a.zip |
Diffstat (limited to 'src/Items')
-rw-r--r-- | src/Items/ItemFishingRod.h | 52 | ||||
-rw-r--r-- | src/Items/ItemMobHead.h | 75 |
2 files changed, 88 insertions, 39 deletions
diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index 0720cb3e1..012f13a6c 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -20,7 +20,8 @@ //////////////////////////////////////////////////////////////////////////////// // cFloaterCallback -class cFloaterCallback +class cFloaterCallback : + public cEntityCallback { public: cFloaterCallback(void) : @@ -29,14 +30,13 @@ public: { } - bool operator () (cEntity & a_Entity) + virtual bool Item(cEntity * a_Entity) override { - auto & Floater = static_cast<cFloater &>(a_Entity); - m_CanPickup = Floater.CanPickup(); - m_Pos = Floater.GetPosition(); - m_BitePos = Floater.GetBitePos(); - m_AttachedMobID = Floater.GetAttachedMobID(); - Floater.Destroy(true); + m_CanPickup = reinterpret_cast<cFloater *>(a_Entity)->CanPickup(); + m_Pos = Vector3d(a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ()); + m_BitePos = reinterpret_cast<cFloater *>(a_Entity)->GetBitePos(); + m_AttachedMobID = reinterpret_cast<cFloater *>(a_Entity)->GetAttachedMobID(); + a_Entity->Destroy(true); return true; } @@ -57,6 +57,33 @@ protected: +//////////////////////////////////////////////////////////////////////////////// +// cSweepEntityCallback: + +class cSweepEntityCallback : + public cEntityCallback +{ +public: + cSweepEntityCallback(Vector3d a_PlayerPos) : + m_PlayerPos(a_PlayerPos) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + Vector3d Speed = m_PlayerPos - a_Entity->GetPosition(); + a_Entity->AddSpeed(Speed); + return true; + } + +protected: + Vector3d m_PlayerPos; +} ; + + + + + class cItemFishingRodHandler : public cItemHandler { @@ -90,13 +117,8 @@ public: if (FloaterInfo.IsAttached()) { - a_World->DoWithEntityByID(FloaterInfo.GetAttachedMobID(), [=](cEntity & a_Entity) - { - Vector3d Speed = a_Player->GetPosition() - a_Entity.GetPosition(); - a_Entity.AddSpeed(Speed); - return true; - } - ); + cSweepEntityCallback SweepEntity(a_Player->GetPosition()); + a_World->DoWithEntityByID(FloaterInfo.GetAttachedMobID(), SweepEntity); } else if (FloaterInfo.CanPickup()) { diff --git a/src/Items/ItemMobHead.h b/src/Items/ItemMobHead.h index 5cbcf52f7..fdecabbbf 100644 --- a/src/Items/ItemMobHead.h +++ b/src/Items/ItemMobHead.h @@ -62,30 +62,42 @@ public: int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace ) { - auto HeadType = static_cast<eMobHeadType>(a_EquippedItem.m_ItemDamage); - auto BlockMeta = static_cast<NIBBLETYPE>(a_BlockFace); - // Use a callback to set the properties of the mob head block entity: - a_World.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, [&](cBlockEntity & a_BlockEntity) + class cCallback : public cBlockEntityCallback + { + cPlayer & m_Player; + eMobHeadType m_HeadType; + NIBBLETYPE m_BlockMeta; + + virtual bool Item(cBlockEntity * a_BlockEntity) { - if (a_BlockEntity.GetBlockType() != E_BLOCK_HEAD) + if (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD) { return false; } - auto & MobHeadEntity = static_cast<cMobHeadEntity &>(a_BlockEntity); + auto MobHeadEntity = static_cast<cMobHeadEntity *>(a_BlockEntity); int Rotation = 0; - if (BlockMeta == 1) + if (m_BlockMeta == 1) { - Rotation = FloorC(a_Player.GetYaw() * 16.0f / 360.0f + 0.5f) & 0x0f; + Rotation = FloorC(m_Player.GetYaw() * 16.0f / 360.0f + 0.5f) & 0x0f; } - MobHeadEntity.SetType(HeadType); - MobHeadEntity.SetRotation(static_cast<eMobHeadRotation>(Rotation)); - MobHeadEntity.GetWorld()->BroadcastBlockEntity(MobHeadEntity.GetPosX(), MobHeadEntity.GetPosY(), MobHeadEntity.GetPosZ()); + MobHeadEntity->SetType(m_HeadType); + MobHeadEntity->SetRotation(static_cast<eMobHeadRotation>(Rotation)); + MobHeadEntity->GetWorld()->BroadcastBlockEntity(MobHeadEntity->GetPosX(), MobHeadEntity->GetPosY(), MobHeadEntity->GetPosZ()); return false; } - ); + + public: + cCallback (cPlayer & a_CBPlayer, eMobHeadType a_HeadType, NIBBLETYPE a_BlockMeta) : + m_Player(a_CBPlayer), + m_HeadType(a_HeadType), + m_BlockMeta(a_BlockMeta) + {} + }; + cCallback Callback(a_Player, static_cast<eMobHeadType>(a_EquippedItem.m_ItemDamage), static_cast<NIBBLETYPE>(a_BlockFace)); + a_World.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, Callback); } @@ -231,16 +243,24 @@ public: // If it is a mob head, check the correct head type using the block entity: if (BlockType == E_BLOCK_HEAD) { - bool IsWitherHead = false; - a_World.DoWithBlockEntityAt(BlockX, BlockY, BlockZ, [&](cBlockEntity & a_Entity) + class cHeadCallback: public cBlockEntityCallback + { + virtual bool Item(cBlockEntity * a_Entity) override { - ASSERT(a_Entity.GetBlockType() == E_BLOCK_HEAD); - auto & MobHead = static_cast<cMobHeadEntity &>(a_Entity); - IsWitherHead = (MobHead.GetType() == SKULL_TYPE_WITHER); + ASSERT(a_Entity->GetBlockType() == E_BLOCK_HEAD); + cMobHeadEntity * MobHead = static_cast<cMobHeadEntity *>(a_Entity); + m_IsWitherHead = (MobHead->GetType() == SKULL_TYPE_WITHER); return true; } - ); - if (!IsWitherHead) + public: + cHeadCallback(void): + m_IsWitherHead(false) + { + } + bool m_IsWitherHead; + } callback; + a_World.DoWithBlockEntityAt(BlockX, BlockY, BlockZ, callback); + if (!callback.m_IsWitherHead) { return false; } @@ -267,18 +287,25 @@ public: /** Awards the achievement to all players close to the specified point. */ void AwardSpawnWitherAchievement(cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ) { - Vector3f Pos{ static_cast<float>(a_BlockX), static_cast<float>(a_BlockY), static_cast<float>(a_BlockZ) }; - a_World.ForEachPlayer([=](cPlayer & a_Player) + class cPlayerCallback : public cPlayerListCallback + { + Vector3f m_Pos; + + virtual bool Item(cPlayer * a_Player) { // If player is close, award achievement: - double Dist = (a_Player.GetPosition() - Pos).Length(); + double Dist = (a_Player->GetPosition() - m_Pos).Length(); if (Dist < 50.0) { - a_Player.AwardAchievement(achSpawnWither); + a_Player->AwardAchievement(achSpawnWither); } return false; } - ); + + public: + cPlayerCallback(const Vector3f & a_Pos) : m_Pos(a_Pos) {} + } PlayerCallback(Vector3f(static_cast<float>(a_BlockX), static_cast<float>(a_BlockY), static_cast<float>(a_BlockZ))); + a_World.ForEachPlayer(PlayerCallback); } |