1
0

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
archshift 2014-04-25 10:50:10 -07:00
commit d64e46186f
18 changed files with 201 additions and 17 deletions

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(BlockEntities ${SOURCE})

View File

@ -123,6 +123,7 @@ if (NOT MSVC)
file(GLOB SOURCE
"*.cpp"
"*.h"
)
list(REMOVE_ITEM SOURCE "${PROJECT_SOURCE_DIR}/StackWalker.cpp" "${PROJECT_SOURCE_DIR}/LeakFinder.cpp")

View File

@ -1113,7 +1113,7 @@ 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())
else if (ItemHandler->IsFood() && !m_Player->IsGameModeCreative())
{
if (m_Player->IsSatiated())
{

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(Entities ${SOURCE})

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(Generating ${SOURCE})

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(Generating_Prefabs ${SOURCE})

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(HTTPServer ${SOURCE})

67
src/Items/ItemArmor.h Normal file
View File

@ -0,0 +1,67 @@
#pragma once
#include "ItemHandler.h"
#include "../World.h"
class cItemArmorHandler :
public cItemHandler
{
public:
cItemArmorHandler(int a_ItemType) :
cItemHandler(a_ItemType)
{
}
/** Move the armor to the armor slot of the player's inventory */
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
{
int SlotNum;
if (ItemCategory::IsHelmet(a_Item.m_ItemType))
{
SlotNum = 0;
}
else if (ItemCategory::IsChestPlate(a_Item.m_ItemType))
{
SlotNum = 1;
}
else if (ItemCategory::IsLeggings(a_Item.m_ItemType))
{
SlotNum = 2;
}
else if (ItemCategory::IsBoots(a_Item.m_ItemType))
{
SlotNum = 3;
}
else
{
LOGWARNING("Used unknown armor: %i", a_Item.m_ItemType);
return false;
}
if (!a_Player->GetInventory().GetArmorSlot(SlotNum).IsEmpty())
{
return false;
}
a_Player->GetInventory().SetArmorSlot(SlotNum, a_Item.CopyOne());
cItem Item(a_Item);
Item.m_ItemCount--;
if (Item.m_ItemCount <= 0)
{
Item.Empty();
}
a_Player->GetInventory().SetHotbarSlot(a_Player->GetInventory().GetEquippedSlotNum(), Item);
return true;
}
} ;

View File

@ -8,6 +8,7 @@
#include "../BlockInServerPluginInterface.h"
// Handlers:
#include "ItemArmor.h"
#include "ItemBed.h"
#include "ItemBoat.h"
#include "ItemBow.h"
@ -222,6 +223,31 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
{
return new cItemFoodHandler(a_ItemType);
}
// Armor:
case E_ITEM_LEATHER_CAP:
case E_ITEM_GOLD_HELMET:
case E_ITEM_CHAIN_HELMET:
case E_ITEM_IRON_HELMET:
case E_ITEM_DIAMOND_HELMET:
case E_ITEM_LEATHER_TUNIC:
case E_ITEM_GOLD_CHESTPLATE:
case E_ITEM_CHAIN_CHESTPLATE:
case E_ITEM_IRON_CHESTPLATE:
case E_ITEM_DIAMOND_CHESTPLATE:
case E_ITEM_LEATHER_PANTS:
case E_ITEM_GOLD_LEGGINGS:
case E_ITEM_CHAIN_LEGGINGS:
case E_ITEM_IRON_LEGGINGS:
case E_ITEM_DIAMOND_LEGGINGS:
case E_ITEM_LEATHER_BOOTS:
case E_ITEM_GOLD_BOOTS:
case E_ITEM_CHAIN_BOOTS:
case E_ITEM_IRON_BOOTS:
case E_ITEM_DIAMOND_BOOTS:
{
return new cItemArmorHandler(a_ItemType);
}
}
}

View File

@ -21,13 +21,13 @@ class cItemHandler
public:
cItemHandler(int a_ItemType);
// Force virtual destructor
/** Force virtual destructor */
virtual ~cItemHandler() {}
/// Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False
/** Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False */
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir);
/// Called when the client sends the SHOOT status in the lclk packet
/** Called when the client sends the SHOOT status in the lclk packet */
virtual void OnItemShoot(cPlayer *, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
{
UNUSED(a_BlockX);
@ -36,7 +36,7 @@ public:
UNUSED(a_BlockFace);
}
/// Called every tick while the item is on the player's inventory (Used by maps) - For now, called only for equipped items
/** Called every tick while the item is on the player's inventory (Used by maps) - For now, called only for equipped items */
virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item)
{
UNUSED(a_World);
@ -44,16 +44,16 @@ public:
UNUSED(a_Item);
}
/// Called while the player diggs a block using this item
/** Called while the player diggs a block using this item */
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace);
/// Called when the player destroys a block using this item. This also calls the drop function for the destroyed block
/** Called when the player destroys a block using this item. This also calls the drop function for the destroyed block */
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_X, int a_Y, int a_Z);
/// Called after the player has eaten this item.
/** Called after the player has eaten this item. */
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item);
/// Returns the maximum stack size for a given item
/** Returns the maximum stack size for a given item */
virtual char GetMaxStackSize(void);
struct FoodInfo
@ -70,22 +70,22 @@ public:
}
} ;
/// Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance)
/** Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance) */
virtual FoodInfo GetFoodInfo();
/// Lets the player eat a selected item. Returns true if the player ate the item
/** Lets the player eat a selected item. Returns true if the player ate the item */
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item);
/// Indicates if this item is a tool
/** Indicates if this item is a tool */
virtual bool IsTool(void);
/// Indicates if this item is food
/** Indicates if this item is food */
virtual bool IsFood(void);
/// Blocks simply get placed
/** Blocks simply get placed */
virtual bool IsPlaceable(void);
/** Called before a block is placed into a world.
/** Called before a block is placed into a world.
The handler should return true to allow placement, false to refuse.
Also, the handler should set a_BlockType and a_BlockMeta to correct values for the newly placed block.
*/
@ -96,7 +96,7 @@ public:
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
);
/// Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood can´t) DEFAULT: False
/** Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood can<EFBFBD>t) DEFAULT: False */
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType);
static cItemHandler * GetItemHandler(int a_ItemType);

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(Mobs ${SOURCE})

View File

@ -5,6 +5,7 @@ project (MCServer)
include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(OSSupport ${SOURCE})

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(Protocol ${SOURCE})

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(Simulator ${SOURCE})

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(UI ${SOURCE})

View File

@ -1091,6 +1091,80 @@ void cSlotAreaArmor::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bo
void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
{
ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots()));
bool bAsync = false;
if (GetSlot(a_SlotNum, a_Player) == NULL)
{
LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum);
return;
}
if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick))
{
ShiftClicked(a_Player, a_SlotNum, a_ClickedItem);
return;
}
// Armors haven't a dbl click
if (a_ClickAction == caDblClick)
{
return;
}
cItem Slot(*GetSlot(a_SlotNum, a_Player));
if (!Slot.IsSameType(a_ClickedItem))
{
LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots);
LOGWARNING("My item: %s", ItemToFullString(Slot).c_str());
LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str());
bAsync = true;
}
cItem & DraggingItem = a_Player.GetDraggingItem();
if ((a_ClickAction != caRightClick) && (a_ClickAction != caLeftClick))
{
LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction));
m_ParentWindow.BroadcastWholeWindow();
return;
}
if (DraggingItem.IsEmpty() || CanPlaceInSlot(a_SlotNum, DraggingItem))
{
// Swap contents
cItem tmp(DraggingItem);
DraggingItem = Slot;
Slot = tmp;
}
SetSlot(a_SlotNum, a_Player, Slot);
if (bAsync)
{
m_ParentWindow.BroadcastWholeWindow();
}
}
bool cSlotAreaArmor::CanPlaceInSlot(int a_SlotNum, const cItem & a_Item)
{
switch (a_SlotNum)
{
case 0: return ItemCategory::IsHelmet (a_Item.m_ItemType);
case 1: return ItemCategory::IsChestPlate(a_Item.m_ItemType);
case 2: return ItemCategory::IsLeggings (a_Item.m_ItemType);
case 3: return ItemCategory::IsBoots (a_Item.m_ItemType);
}
return false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaItemGrid:

View File

@ -145,8 +145,13 @@ public:
{
}
// Distributing the stack is allowed only for compatible items (helmets into helmet slot etc.)
/** Distributing the stack is allowed only for compatible items (helmets into helmet slot etc.) */
virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override;
/** Called when a player clicks in the window. Parameters taken from the click packet. */
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
bool CanPlaceInSlot(int a_SlotNum, const cItem & a_Item);
} ;

View File

@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
"*.h"
)
add_library(WorldStorage ${SOURCE})