1
0

Merge pull request #2645 from Gargaj/followedarray

Allow multiple followable items
This commit is contained in:
worktycho 2015-11-23 22:57:59 +00:00
commit 2d408e8647
11 changed files with 67 additions and 12 deletions

View File

@ -1550,6 +1550,8 @@ end
{ Params = "Index, ItemType, ItemCount, ItemDamage", Return = "", Notes = "Sets the item at the specified index to the specified item" },
},
Size = { Params = "", Return = "number", Notes = "Returns the number of items in the collection" },
Contains = { Params = "{{cItem|cItem}}", Return = "bool", Notes = "Returns true if the collection contains an item that is fully equivalent to the parameter" },
ContainsType = { Params = "{{cItem|cItem}}", Return = "bool", Notes = "Returns true if the collection contains an item that is the same type as the parameter" },
},
}, -- cItems

View File

@ -459,3 +459,33 @@ void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDama
bool cItems::Contains(const cItem & a_Item)
{
for (auto itr : *this)
{
if (a_Item.IsEqual(itr))
{
return true;
}
}
return false;
}
bool cItems::ContainsType(const cItem & a_Item)
{
for (auto itr : *this)
{
if (a_Item.IsSameType(itr))
{
return true;
}
}
return false;
}

View File

@ -239,6 +239,8 @@ public:
void Clear (void) {clear(); }
size_t Size (void) const { return size(); }
void Set (int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDamage);
bool Contains(const cItem & a_Item);
bool ContainsType(const cItem & a_Item);
void Add (short a_ItemType, char a_ItemCount, short a_ItemDamage)
{

View File

@ -19,7 +19,10 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_SEEDS); }
virtual void GetFollowedItems(cItems & a_Items) override
{
a_Items.Add(E_ITEM_SEEDS);
}
virtual void HandleFalling(void) override;

View File

@ -20,7 +20,10 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
virtual void GetFollowedItems(cItems & a_Items) override
{
a_Items.Add(E_ITEM_WHEAT);
}
} ;

View File

@ -20,7 +20,10 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
virtual void GetFollowedItems(cItems & a_Items) override
{
a_Items.Add(E_ITEM_WHEAT);
}
} ;

View File

@ -43,15 +43,17 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
CheckEventLostPlayer();
}
cItem FollowedItem = GetFollowedItem();
if (FollowedItem.IsEmpty())
cItems FollowedItems;
GetFollowedItems(FollowedItems);
if (FollowedItems.Size() <= 0)
{
return;
}
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast<float>(m_SightDistance));
if (a_Closest_Player != nullptr)
{
if (a_Closest_Player->GetEquippedItem().IsEqual(FollowedItem))
cItem EquippedItem = a_Closest_Player->GetEquippedItem();
if (FollowedItems.ContainsType(EquippedItem))
{
Vector3d PlayerPos = a_Closest_Player->GetPosition();
MoveToPosition(PlayerPos);

View File

@ -20,9 +20,8 @@ public:
/** When hit by someone, run away */
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
/** Returns the item that the animal of this class follows when a player holds it in hand
Return an empty item not to follow (default). */
virtual const cItem GetFollowedItem(void) const { return cItem(); }
/** Returns the items that the animal of this class follows when a player holds it in hand. */
virtual void GetFollowedItems(cItems & a_Items) { }
} ;

View File

@ -24,7 +24,10 @@ public:
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); }
virtual void GetFollowedItems(cItems & a_Items) override
{
a_Items.Add(E_ITEM_CARROT);
}
bool IsSaddled(void) const { return m_bIsSaddled; }

View File

@ -34,7 +34,12 @@ public:
CLASS_PROTODEF(cRabbit)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); }
virtual void GetFollowedItems(cItems & a_Items) override
{
a_Items.Add(E_ITEM_CARROT);
a_Items.Add(E_ITEM_GOLDEN_CARROT);
a_Items.Add(E_BLOCK_DANDELION);
}
eRabbitType GetRabbitType() const { return m_Type; }
UInt8 GetRabbitTypeAsNumber() const { return static_cast<UInt8>(GetRabbitType()); }

View File

@ -26,7 +26,10 @@ public:
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
virtual void GetFollowedItems(cItems & a_Items) override
{
a_Items.Add(E_ITEM_WHEAT);
}
/** Generates a random color for the sheep like the vanilla server.
The percent's where used are from the wiki: http://minecraft.gamepedia.com/Sheep#Breeding */