diff options
author | madmaxoft <github@xoft.cz> | 2013-08-30 14:32:07 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-08-30 14:32:07 +0200 |
commit | c28ccdc9d56497d42c2a97554a96de76e0d2ee68 (patch) | |
tree | f1a1f5629ae7e2565330580ab4e6fe76466acf6e /source/Items/ItemBow.h | |
parent | Added the login sequence of a vanilla client to the docs. (diff) | |
parent | Shooting a bow kinda works. (diff) | |
download | cuberite-c28ccdc9d56497d42c2a97554a96de76e0d2ee68.tar cuberite-c28ccdc9d56497d42c2a97554a96de76e0d2ee68.tar.gz cuberite-c28ccdc9d56497d42c2a97554a96de76e0d2ee68.tar.bz2 cuberite-c28ccdc9d56497d42c2a97554a96de76e0d2ee68.tar.lz cuberite-c28ccdc9d56497d42c2a97554a96de76e0d2ee68.tar.xz cuberite-c28ccdc9d56497d42c2a97554a96de76e0d2ee68.tar.zst cuberite-c28ccdc9d56497d42c2a97554a96de76e0d2ee68.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Items/ItemBow.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/source/Items/ItemBow.h b/source/Items/ItemBow.h new file mode 100644 index 000000000..845192ef7 --- /dev/null +++ b/source/Items/ItemBow.h @@ -0,0 +1,80 @@ + +// ItemBow.h + +// Declares the cItemBowHandler class representing the itemhandler for bows + + + + + +#pragma once + +#include "../Entities/ProjectileEntity.h" + + + + + +class cItemBowHandler : + public cItemHandler +{ + typedef cItemHandler super; + +public: + cItemBowHandler(void) : + super(E_ITEM_BOW) + { + } + + + 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 + { + ASSERT(a_Player != NULL); + + // Check if the player has an arrow in the inventory, or is in Creative: + if (!(a_Player->IsGameModeCreative() || a_Player->GetInventory().HasItems(cItem(E_ITEM_ARROW)))) + { + return false; + } + a_Player->StartChargingBow(); + return true; + } + + + virtual void OnItemShoot(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override + { + // Actual shot - produce the arrow with speed based on the ticks that the bow was charged + ASSERT(a_Player != NULL); + + int BowCharge = a_Player->FinishChargingBow(); + double Force = (double)BowCharge / 20; + Force = (Force * Force + 2 * Force) / 3; // This formula is used by the 1.6.2 client + if (Force < 0.1) + { + // Too little force, ignore the shot + return; + } + if (Force > 1) + { + Force = 1; + } + + // Create the arrow entity: + cArrowEntity * Arrow = new cArrowEntity(*a_Player, Force * 2); + if (Arrow == NULL) + { + return; + } + if (!Arrow->Initialize(a_Player->GetWorld())) + { + delete Arrow; + return; + } + a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow); + } +} ; + + + + + |