change from single followable item to multiple
This commit is contained in:
parent
5d5f5c9fba
commit
853e6e6882
@ -1550,6 +1550,8 @@ end
|
|||||||
{ Params = "Index, ItemType, ItemCount, ItemDamage", Return = "", Notes = "Sets the item at the specified index to the specified item" },
|
{ 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" },
|
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
|
}, -- cItems
|
||||||
|
|
||||||
|
30
src/Item.cpp
30
src/Item.cpp
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,6 +239,8 @@ public:
|
|||||||
void Clear (void) {clear(); }
|
void Clear (void) {clear(); }
|
||||||
size_t Size (void) const { return size(); }
|
size_t Size (void) const { return size(); }
|
||||||
void Set (int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDamage);
|
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)
|
void Add (short a_ItemType, char a_ItemCount, short a_ItemDamage)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,10 @@ public:
|
|||||||
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
|
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
|
||||||
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) 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;
|
virtual void HandleFalling(void) override;
|
||||||
|
|
||||||
|
@ -20,7 +20,10 @@ public:
|
|||||||
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
|
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
|
||||||
virtual void OnRightClicked(cPlayer & a_Player) 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);
|
||||||
|
}
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -20,7 +20,10 @@ public:
|
|||||||
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
|
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
|
||||||
virtual void OnRightClicked(cPlayer & a_Player) 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);
|
||||||
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,15 +43,17 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
|||||||
{
|
{
|
||||||
CheckEventLostPlayer();
|
CheckEventLostPlayer();
|
||||||
}
|
}
|
||||||
cItem FollowedItem = GetFollowedItem();
|
cItems FollowedItems;
|
||||||
if (FollowedItem.IsEmpty())
|
GetFollowedItems(FollowedItems);
|
||||||
|
if (FollowedItems.Size() <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast<float>(m_SightDistance));
|
cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast<float>(m_SightDistance));
|
||||||
if (a_Closest_Player != nullptr)
|
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();
|
Vector3d PlayerPos = a_Closest_Player->GetPosition();
|
||||||
MoveToPosition(PlayerPos);
|
MoveToPosition(PlayerPos);
|
||||||
|
@ -20,9 +20,8 @@ public:
|
|||||||
/** When hit by someone, run away */
|
/** When hit by someone, run away */
|
||||||
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
|
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
|
||||||
|
|
||||||
/** Returns the item that the animal of this class follows when a player holds it in hand
|
/** Returns the items that the animal of this class follows when a player holds it in hand. */
|
||||||
Return an empty item not to follow (default). */
|
virtual void GetFollowedItems(cItems & a_Items) { }
|
||||||
virtual const cItem GetFollowedItem(void) const { return cItem(); }
|
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -24,7 +24,10 @@ public:
|
|||||||
virtual void OnRightClicked(cPlayer & a_Player) override;
|
virtual void OnRightClicked(cPlayer & a_Player) override;
|
||||||
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) 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; }
|
bool IsSaddled(void) const { return m_bIsSaddled; }
|
||||||
|
|
||||||
|
@ -34,7 +34,12 @@ public:
|
|||||||
CLASS_PROTODEF(cRabbit)
|
CLASS_PROTODEF(cRabbit)
|
||||||
|
|
||||||
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
|
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; }
|
eRabbitType GetRabbitType() const { return m_Type; }
|
||||||
UInt8 GetRabbitTypeAsNumber() const { return static_cast<UInt8>(GetRabbitType()); }
|
UInt8 GetRabbitTypeAsNumber() const { return static_cast<UInt8>(GetRabbitType()); }
|
||||||
|
@ -26,7 +26,10 @@ public:
|
|||||||
virtual void OnRightClicked(cPlayer & a_Player) override;
|
virtual void OnRightClicked(cPlayer & a_Player) override;
|
||||||
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) 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.
|
/** 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 */
|
The percent's where used are from the wiki: http://minecraft.gamepedia.com/Sheep#Breeding */
|
||||||
|
Loading…
Reference in New Issue
Block a user