commit
03ec64aee1
@ -1358,6 +1358,14 @@
|
|||||||
RelativePath="..\src\Entities\FallingBlock.h"
|
RelativePath="..\src\Entities\FallingBlock.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\Entities\Floater.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\Entities\Floater.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\Entities\Minecart.cpp"
|
RelativePath="..\src\Entities\Minecart.cpp"
|
||||||
>
|
>
|
||||||
@ -2566,6 +2574,10 @@
|
|||||||
RelativePath="..\src\items\ItemDye.h"
|
RelativePath="..\src\items\ItemDye.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\Items\ItemFishingRod.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\Items\ItemFlowerPot.h"
|
RelativePath="..\src\Items\ItemFlowerPot.h"
|
||||||
>
|
>
|
||||||
|
@ -75,6 +75,7 @@ public:
|
|||||||
etTNT,
|
etTNT,
|
||||||
etProjectile,
|
etProjectile,
|
||||||
etExpOrb,
|
etExpOrb,
|
||||||
|
etFloater,
|
||||||
|
|
||||||
// Common variations
|
// Common variations
|
||||||
etMob = etMonster, // DEPRECATED, use etMonster instead!
|
etMob = etMonster, // DEPRECATED, use etMonster instead!
|
||||||
@ -129,6 +130,8 @@ public:
|
|||||||
bool IsBoat (void) const { return (m_EntityType == etBoat); }
|
bool IsBoat (void) const { return (m_EntityType == etBoat); }
|
||||||
bool IsTNT (void) const { return (m_EntityType == etTNT); }
|
bool IsTNT (void) const { return (m_EntityType == etTNT); }
|
||||||
bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
|
bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
|
||||||
|
bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
|
||||||
|
bool IsFloater (void) const { return (m_EntityType == etFloater); }
|
||||||
|
|
||||||
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
|
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
|
||||||
virtual bool IsA(const char * a_ClassName) const;
|
virtual bool IsA(const char * a_ClassName) const;
|
||||||
|
58
src/Entities/Floater.cpp
Normal file
58
src/Entities/Floater.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "Globals.h"
|
||||||
|
|
||||||
|
#include "Floater.h"
|
||||||
|
#include "Player.h"
|
||||||
|
#include "../ClientHandle.h"
|
||||||
|
|
||||||
|
cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID) :
|
||||||
|
cEntity(etFloater, a_X, a_Y, a_Z, 0.98, 0.98),
|
||||||
|
m_PlayerID(a_PlayerID),
|
||||||
|
m_CanPickupItem(false),
|
||||||
|
m_PickupCountDown(0)
|
||||||
|
{
|
||||||
|
SetSpeed(a_Speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cFloater::SpawnOn(cClientHandle & a_Client)
|
||||||
|
{
|
||||||
|
a_Client.SendSpawnObject(*this, 90, m_PlayerID, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cFloater::Tick(float a_Dt, cChunk & a_Chunk)
|
||||||
|
{
|
||||||
|
HandlePhysics(a_Dt, a_Chunk);
|
||||||
|
if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())))
|
||||||
|
{
|
||||||
|
if (m_World->GetTickRandomNumber(100) == 0)
|
||||||
|
{
|
||||||
|
SetPosY(GetPosY() - 1);
|
||||||
|
m_CanPickupItem = true;
|
||||||
|
m_PickupCountDown = 20;
|
||||||
|
LOGD("Floater %i can be picked up", GetUniqueID());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetSpeedY(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SetSpeedX(GetSpeedX() * 0.95);
|
||||||
|
SetSpeedZ(GetSpeedZ() * 0.95);
|
||||||
|
if (CanPickup())
|
||||||
|
{
|
||||||
|
m_PickupCountDown--;
|
||||||
|
if (m_PickupCountDown == 0)
|
||||||
|
{
|
||||||
|
m_CanPickupItem = false;
|
||||||
|
LOGD("The fish is gone. Floater %i can not pick an item up.", GetUniqueID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BroadcastMovementUpdate();
|
||||||
|
}
|
29
src/Entities/Floater.h
Normal file
29
src/Entities/Floater.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cFloater :
|
||||||
|
public cEntity
|
||||||
|
{
|
||||||
|
typedef cFloater super;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID);
|
||||||
|
|
||||||
|
virtual void SpawnOn(cClientHandle & a_Client) override;
|
||||||
|
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||||
|
|
||||||
|
bool CanPickup(void) const { return m_CanPickupItem; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Vector3d m_Speed;
|
||||||
|
int m_PickupCountDown;
|
||||||
|
int m_PlayerID;
|
||||||
|
bool m_CanPickupItem;
|
||||||
|
} ;
|
@ -65,6 +65,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
|
|||||||
, m_IsSubmerged(false)
|
, m_IsSubmerged(false)
|
||||||
, m_IsFlying(false)
|
, m_IsFlying(false)
|
||||||
, m_CanFly(false)
|
, m_CanFly(false)
|
||||||
|
, m_IsFishing(false)
|
||||||
|
, m_FloaterID(-1)
|
||||||
, m_EatingFinishTick(-1)
|
, m_EatingFinishTick(-1)
|
||||||
, m_IsChargingBow(false)
|
, m_IsChargingBow(false)
|
||||||
, m_BowCharge(0)
|
, m_BowCharge(0)
|
||||||
|
@ -253,6 +253,14 @@ public:
|
|||||||
|
|
||||||
/// Returns true if the player is currently flying.
|
/// Returns true if the player is currently flying.
|
||||||
bool IsFlying(void) const { return m_IsFlying; }
|
bool IsFlying(void) const { return m_IsFlying; }
|
||||||
|
|
||||||
|
/// returns true if the player has thrown out a floater.
|
||||||
|
bool IsFishing(void) const { return m_IsFishing; }
|
||||||
|
|
||||||
|
void SetIsFishing(bool a_IsFishing, int a_FloaterID = -1) { m_IsFishing = a_IsFishing; m_FloaterID = a_FloaterID; }
|
||||||
|
|
||||||
|
int GetFloaterID(void) const { return m_FloaterID; }
|
||||||
|
|
||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
/// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet
|
/// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet
|
||||||
@ -429,6 +437,7 @@ protected:
|
|||||||
bool m_IsFlying;
|
bool m_IsFlying;
|
||||||
bool m_IsSwimming;
|
bool m_IsSwimming;
|
||||||
bool m_IsSubmerged;
|
bool m_IsSubmerged;
|
||||||
|
bool m_IsFishing;
|
||||||
|
|
||||||
bool m_CanFly; // If this is true the player can fly. Even if he is not in creative.
|
bool m_CanFly; // If this is true the player can fly. Even if he is not in creative.
|
||||||
|
|
||||||
@ -445,6 +454,7 @@ protected:
|
|||||||
bool m_IsChargingBow;
|
bool m_IsChargingBow;
|
||||||
int m_BowCharge;
|
int m_BowCharge;
|
||||||
|
|
||||||
|
int m_FloaterID;
|
||||||
|
|
||||||
virtual void Destroyed(void);
|
virtual void Destroyed(void);
|
||||||
|
|
||||||
|
78
src/Items/ItemFishingRod.h
Normal file
78
src/Items/ItemFishingRod.h
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
} ;
|
@ -17,6 +17,7 @@
|
|||||||
#include "ItemComparator.h"
|
#include "ItemComparator.h"
|
||||||
#include "ItemDoor.h"
|
#include "ItemDoor.h"
|
||||||
#include "ItemDye.h"
|
#include "ItemDye.h"
|
||||||
|
#include "ItemFishingRod.h"
|
||||||
#include "ItemFlowerPot.h"
|
#include "ItemFlowerPot.h"
|
||||||
#include "ItemFood.h"
|
#include "ItemFood.h"
|
||||||
#include "ItemHoe.h"
|
#include "ItemHoe.h"
|
||||||
@ -100,6 +101,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
|
|||||||
case E_ITEM_EGG: return new cItemEggHandler();
|
case E_ITEM_EGG: return new cItemEggHandler();
|
||||||
case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler();
|
case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler();
|
||||||
case E_ITEM_FIREWORK_ROCKET: return new cItemFireworkHandler();
|
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_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
|
||||||
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
|
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
|
||||||
case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType);
|
case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType);
|
||||||
|
Loading…
Reference in New Issue
Block a user