diff options
author | Pablo Beltrán <spekdrum@gmail.com> | 2017-08-21 10:46:41 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-08-21 10:46:41 +0200 |
commit | b18f6637b6c58db20353cd3e77584b646ab36b5c (patch) | |
tree | 77b1dcf42aec23ef4aa64a04c906282c5f61ba19 /src/Blocks/BlockFence.h | |
parent | Changed MoveToWorld to ScheduleMoveToWorld in cPlayer::Respawn (#3922) (diff) | |
download | cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.gz cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.bz2 cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.lz cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.xz cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.zst cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.zip |
Diffstat (limited to 'src/Blocks/BlockFence.h')
-rw-r--r-- | src/Blocks/BlockFence.h | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/src/Blocks/BlockFence.h b/src/Blocks/BlockFence.h index 736466e99..2f2d4e46d 100644 --- a/src/Blocks/BlockFence.h +++ b/src/Blocks/BlockFence.h @@ -3,7 +3,10 @@ #include "BlockHandler.h" #include "../BoundingBox.h" - +#include "../EffectID.h" +#include "Entities/LeashKnot.h" +#include "BoundingBox.h" +#include "../Mobs/PassiveMonster.h" @@ -72,6 +75,63 @@ public: return PlacementBox; } + + virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override + { + auto LeashKnot = cLeashKnot::FindKnotAtPos(*a_Player.GetWorld(), { a_BlockX, a_BlockY, a_BlockZ }); + auto KnotAlreadyExists = (LeashKnot != nullptr); + + if (KnotAlreadyExists) + { + // Check leashed nearby mobs to leash them to the knot + LeashKnot->TiePlayersLeashedMobs(a_Player, KnotAlreadyExists); + } + // New knot? needs to init and produce sound effect + else + { + auto NewLeashKnot = cpp14::make_unique<cLeashKnot>(a_BlockFace, a_BlockX, a_BlockY, a_BlockZ); + auto NewLeashKnotPtr = NewLeashKnot.get(); + + NewLeashKnotPtr->TiePlayersLeashedMobs(a_Player, KnotAlreadyExists); + + // Only put the knot in the world if any mob has been leashed to + if (NewLeashKnotPtr->HasAnyMobLeashed()) + { + if (!NewLeashKnotPtr->Initialize(std::move(NewLeashKnot), *a_Player.GetWorld())) + { + return false; + } + a_Player.GetWorld()->BroadcastSoundEffect("entity.leashknot.place", a_Player.GetPosX(), a_Player.GetPosY(), a_Player.GetPosZ(), 1, 1); + } + else + { + return false; + } + } + + return true; + } + + virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override + { + a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player); + } + + virtual bool IsUseable(void) override + { + return true; + } + + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) + { + auto LeashKnot = cLeashKnot::FindKnotAtPos(a_WorldInterface, { a_BlockX, a_BlockY, a_BlockZ }); + + if (LeashKnot != nullptr) + { + LeashKnot->SetShouldSelfDestroy(); + } + } + }; |