1
0
Fork 0

Implemented milk, added documentation to Pawn.h

This commit is contained in:
archshift 2014-06-07 13:45:00 -07:00
parent 615152eb8c
commit 1eb04a48ee
7 changed files with 86 additions and 5 deletions

View File

@ -850,7 +850,7 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
case DIG_STATUS_SHOOT_EAT:
{
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
if (ItemHandler->IsFood())
if (ItemHandler->IsFood() || ItemHandler->IsDrinkable())
{
m_Player->AbortEating();
return;
@ -1182,9 +1182,9 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
{
HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler);
}
else if (ItemHandler->IsFood() && !m_Player->IsGameModeCreative())
else if ((ItemHandler->IsFood() || ItemHandler->IsDrinkable()) && !m_Player->IsGameModeCreative())
{
if (m_Player->IsSatiated())
if (m_Player->IsSatiated() && !ItemHandler->IsDrinkable())
{
// The player is satiated, they cannot eat
return;

View File

@ -72,6 +72,26 @@ void cPawn::RemoveEntityEffect(cEntityEffect::eType a_EffectType)
void cPawn::ClearEntityEffects()
{
// Iterate through this entity's applied effects
for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
{
// Copy values to prevent pesky wrong erasures
cEntityEffect::eType effect_type = iter->first;
// Iterates (must be called before any possible erasure)
++iter;
// Remove effect
RemoveEntityEffect(effect_type);
}
}
void cPawn::HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect)
{
switch (a_EffectType)

View File

@ -22,13 +22,28 @@ public:
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
/** Applies an entity effect
* @param a_EffectType The entity effect to apply
* @param a_Effect The parameters of the effect
*/
void AddEntityEffect(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect);
/** Removes a currently applied entity effect
* @param a_EffectType The entity effect to remove
*/
void RemoveEntityEffect(cEntityEffect::eType a_EffectType);
/** Removes all currently applied entity effects (used when drinking milk) */
void ClearEntityEffects();
protected:
typedef std::map<cEntityEffect::eType, cEntityEffect> tEffectMap;
tEffectMap m_EntityEffects;
/** Applies entity effect effects
* @param a_EffectType The selected entity effect
* @param a_Effect The parameters of the selected entity effect
*/
virtual void HandleEntityEffects(cEntityEffect::eType a_EffectType, cEntityEffect a_Effect);
} ; // tolua_export

View File

@ -552,7 +552,7 @@ void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
bool cPlayer::Feed(int a_Food, double a_Saturation)
{
if (m_FoodLevel >= MAX_FOOD_LEVEL)
if (IsSatiated())
{
return false;
}

View File

@ -19,6 +19,7 @@
#include "ItemCloth.h"
#include "ItemComparator.h"
#include "ItemDoor.h"
#include "ItemMilk.h"
#include "ItemDye.h"
#include "ItemEmptyMap.h"
#include "ItemFishingRod.h"
@ -119,6 +120,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
case E_BLOCK_LILY_PAD: return new cItemLilypadHandler(a_ItemType);
case E_ITEM_MAP: return new cItemMapHandler();
case E_ITEM_MILK: return new cItemMilkHandler();
case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType);
case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType);
case E_ITEM_PAINTING: return new cItemPaintingHandler(a_ItemType);
@ -475,7 +477,6 @@ bool cItemHandler::IsFood(void)
case E_ITEM_BREAD:
case E_ITEM_RAW_PORKCHOP:
case E_ITEM_COOKED_PORKCHOP:
case E_ITEM_MILK:
case E_ITEM_RAW_FISH:
case E_ITEM_COOKED_FISH:
case E_ITEM_COOKIE:
@ -501,6 +502,22 @@ bool cItemHandler::IsFood(void)
bool cItemHandler::IsDrinkable(void)
{
switch (m_ItemType)
{
case E_ITEM_MILK:
{
return true;
}
} // switch (m_ItemType)
return false;
}
bool cItemHandler::IsPlaceable(void)
{
// We can place any block that has a corresponding E_BLOCK_TYPE:

View File

@ -82,6 +82,9 @@ public:
/** Indicates if this item is food */
virtual bool IsFood(void);
/** Indicates if this item is drinkable */
virtual bool IsDrinkable(void);
/** Blocks simply get placed */
virtual bool IsPlaceable(void);

26
src/Items/ItemMilk.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
class cItemMilkHandler:
public cItemHandler
{
typedef cItemHandler super;
public:
cItemMilkHandler():
super(E_ITEM_MILK)
{
}
virtual bool IsDrinkable(void) override
{
return true;
}
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
{
a_Player->ClearEntityEffects();
a_Player->GetInventory().RemoveOneEquippedItem();
a_Player->GetInventory().AddItem(E_ITEM_BUCKET);
return true;
}
};