2012-07-29 05:07:22 -07:00
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
#include "Globals.h"
|
2012-09-23 15:09:57 -07:00
|
|
|
#include "ItemHandler.h"
|
|
|
|
#include "../Item.h"
|
|
|
|
#include "../World.h"
|
|
|
|
#include "../Player.h"
|
2012-07-15 13:36:34 -07:00
|
|
|
|
|
|
|
//Handler
|
|
|
|
#include "ItemCloth.h"
|
|
|
|
#include "ItemHoe.h"
|
|
|
|
#include "ItemSlab.h"
|
|
|
|
#include "ItemWood.h"
|
|
|
|
#include "ItemShears.h"
|
|
|
|
#include "ItemLeaves.h"
|
|
|
|
#include "ItemSapling.h"
|
|
|
|
#include "ItemBucket.h"
|
|
|
|
#include "ItemLighter.h"
|
|
|
|
#include "ItemRedstoneDust.h"
|
2012-07-16 11:19:25 -07:00
|
|
|
#include "ItemRedstoneRepeater.h"
|
2012-07-15 13:36:34 -07:00
|
|
|
#include "ItemSeeds.h"
|
|
|
|
#include "ItemDye.h"
|
|
|
|
#include "ItemSugarcane.h"
|
|
|
|
#include "ItemPickaxe.h"
|
|
|
|
#include "ItemShovel.h"
|
|
|
|
#include "ItemSword.h"
|
|
|
|
#include "ItemDoor.h"
|
2012-07-17 05:02:03 -07:00
|
|
|
#include "ItemFood.h"
|
2012-08-23 13:41:48 -07:00
|
|
|
#include "ItemSign.h"
|
2012-09-29 06:41:47 -07:00
|
|
|
#include "ItemBed.h"
|
2012-10-18 02:36:30 -07:00
|
|
|
#include "ItemSpawnEgg.h"
|
2012-07-15 13:36:34 -07:00
|
|
|
|
2012-09-29 06:59:32 -07:00
|
|
|
#include "../Blocks/BlockHandler.h"
|
2012-07-15 13:36:34 -07:00
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
bool cItemHandler::m_HandlerInitialized = false;
|
2012-07-29 05:07:22 -07:00
|
|
|
cItemHandler * cItemHandler::m_ItemHandler[2266];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
|
2012-10-18 12:41:29 -07:00
|
|
|
cItemHandler *cItemHandler::GetItemHandler(int a_ItemType)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
if(a_ItemType < 0) a_ItemType = 0;
|
2012-07-15 13:36:34 -07:00
|
|
|
|
|
|
|
if(!m_HandlerInitialized)
|
|
|
|
{ //We have to initialize
|
|
|
|
memset(m_ItemHandler, 0, sizeof(m_ItemHandler));
|
|
|
|
m_HandlerInitialized = true;
|
|
|
|
}
|
2012-10-18 12:41:29 -07:00
|
|
|
if(m_ItemHandler[a_ItemType])
|
|
|
|
return m_ItemHandler[a_ItemType];
|
|
|
|
m_ItemHandler[a_ItemType] = CreateItemHandler(a_ItemType);
|
|
|
|
return m_ItemHandler[a_ItemType];
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 12:41:29 -07:00
|
|
|
cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
switch(a_ItemType)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
default: return new cItemHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
|
2012-10-18 02:36:30 -07:00
|
|
|
// Single item per handler, alphabetically sorted:
|
2012-10-18 12:41:29 -07:00
|
|
|
case E_ITEM_BED: return new cItemBedHandler(a_ItemType);
|
|
|
|
case E_ITEM_DYE: return new cItemDyeHandler(a_ItemType);
|
|
|
|
case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
|
|
|
|
case E_ITEM_LEAVES: return new cItemLeavesHandler(a_ItemType);
|
|
|
|
case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType);
|
|
|
|
case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType);
|
|
|
|
case E_ITEM_SAPLING: return new cItemSaplingHandler(a_ItemType);
|
|
|
|
case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType);
|
|
|
|
case E_ITEM_SIGN: return new cItemSignHandler(a_ItemType);
|
|
|
|
case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType);
|
|
|
|
case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType);
|
|
|
|
case E_ITEM_WOOL: return new cItemClothHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
case E_ITEM_WOODEN_HOE:
|
|
|
|
case E_ITEM_STONE_HOE:
|
|
|
|
case E_ITEM_IRON_HOE:
|
|
|
|
case E_ITEM_GOLD_HOE:
|
|
|
|
case E_ITEM_DIAMOND_HOE:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemHoeHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_WOODEN_PICKAXE:
|
|
|
|
case E_ITEM_STONE_PICKAXE:
|
|
|
|
case E_ITEM_IRON_PICKAXE:
|
|
|
|
case E_ITEM_GOLD_PICKAXE:
|
|
|
|
case E_ITEM_DIAMOND_PICKAXE:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemPickaxeHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_WOODEN_SHOVEL:
|
|
|
|
case E_ITEM_STONE_SHOVEL:
|
|
|
|
case E_ITEM_IRON_SHOVEL:
|
|
|
|
case E_ITEM_GOLD_SHOVEL:
|
|
|
|
case E_ITEM_DIAMOND_SHOVEL:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemShovelHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_WOODEN_SWORD:
|
|
|
|
case E_ITEM_STONE_SWORD:
|
|
|
|
case E_ITEM_IRON_SWORD:
|
|
|
|
case E_ITEM_GOLD_SWORD:
|
|
|
|
case E_ITEM_DIAMOND_SWORD:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemSwordHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_STONE_SLAB:
|
|
|
|
case E_ITEM_WOODEN_SLAB:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemSlabHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_LOG:
|
|
|
|
case E_ITEM_PLANKS:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemWoodHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_BUCKET:
|
|
|
|
case E_ITEM_WATER_BUCKET:
|
|
|
|
case E_ITEM_LAVA_BUCKET:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemBucketHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_PUMPKIN_SEEDS:
|
|
|
|
case E_ITEM_MELON_SEEDS:
|
|
|
|
case E_ITEM_SEEDS:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemSeedsHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_IRON_DOOR:
|
|
|
|
case E_ITEM_WOODEN_DOOR:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemDoorHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Food:
|
|
|
|
case E_ITEM_BREAD:
|
|
|
|
case E_ITEM_COOKIE:
|
|
|
|
case E_ITEM_MELON_SLICE:
|
|
|
|
case E_ITEM_RAW_CHICKEN:
|
|
|
|
case E_ITEM_COOKED_CHICKEN:
|
|
|
|
case E_ITEM_RAW_BEEF:
|
|
|
|
case E_ITEM_RAW_MEAT:
|
|
|
|
case E_ITEM_STEAK:
|
|
|
|
case E_ITEM_COOKED_MEAT:
|
|
|
|
case E_ITEM_RAW_FISH:
|
|
|
|
case E_ITEM_COOKED_FISH:
|
|
|
|
case E_ITEM_RED_APPLE:
|
|
|
|
case E_ITEM_GOLDEN_APPLE:
|
|
|
|
case E_ITEM_ROTTEN_FLESH:
|
|
|
|
case E_ITEM_SPIDER_EYE:
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return new cItemFoodHandler(a_ItemType);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
void cItemHandler::Deinit()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 2266; i++)
|
|
|
|
{
|
|
|
|
delete m_ItemHandler[i];
|
|
|
|
}
|
2012-09-04 08:07:08 -07:00
|
|
|
m_HandlerInitialized = false;
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 12:41:29 -07:00
|
|
|
cItemHandler::cItemHandler(int a_ItemType)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
m_ItemType = a_ItemType;
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 12:41:29 -07:00
|
|
|
bool cItemHandler::OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 12:41:29 -07:00
|
|
|
bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
void cItemHandler::OnBlockDestroyed(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z)
|
|
|
|
{
|
|
|
|
char Block = a_World->GetBlock(a_X, a_Y, a_Z);
|
|
|
|
cBlockHandler *Handler = cBlockHandler::GetBlockHandler(Block);
|
|
|
|
|
|
|
|
if(a_Player->GetGameMode() == eGameMode_Survival)
|
|
|
|
{
|
|
|
|
if(!BlockRequiresSpecialTool(Block) || CanHarvestBlock(Block))
|
|
|
|
{
|
|
|
|
Handler->DropBlock(a_World, a_X, a_Y, a_Z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a_Player->UseEquippedItem();
|
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
void cItemHandler::OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-11 05:46:09 -07:00
|
|
|
char cItemHandler::GetMaxStackSize(void)
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
if (m_ItemType < 256)
|
2012-08-11 05:46:09 -07:00
|
|
|
{
|
|
|
|
// All blocks can stack up to 64
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
2012-10-21 12:32:40 -07:00
|
|
|
switch (m_ItemType) //sorted by id
|
2012-08-11 12:45:03 -07:00
|
|
|
{
|
2012-10-21 12:32:40 -07:00
|
|
|
case E_ITEM_APPLE: return 64;
|
|
|
|
case E_ITEM_ARROW: return 64;
|
|
|
|
case E_ITEM_BLAZE_POWDER: return 64;
|
|
|
|
case E_ITEM_BLAZE_ROD: return 64;
|
|
|
|
case E_ITEM_BONE: return 64;
|
|
|
|
case E_ITEM_BOOK: return 64;
|
|
|
|
case E_ITEM_BOTTLE_O_ENCHANTING: return 64;
|
|
|
|
case E_ITEM_BOWL: return 64;
|
|
|
|
case E_ITEM_BREAD: return 64;
|
|
|
|
case E_ITEM_BREWING_STAND: return 64;
|
|
|
|
case E_ITEM_BUCKET: return 1; // TODO: change this to 16 when turning compatibility to 1.3
|
|
|
|
case E_ITEM_CLAY: return 64;
|
|
|
|
case E_ITEM_CLAY_BRICK: return 64;
|
|
|
|
case E_ITEM_CLOCK: return 64;
|
|
|
|
case E_ITEM_COAL: return 64;
|
|
|
|
case E_ITEM_COMPASS: return 64;
|
|
|
|
case E_ITEM_COOKED_CHICKEN: return 64;
|
|
|
|
case E_ITEM_COOKED_FISH: return 64;
|
|
|
|
case E_ITEM_COOKED_PORKCHOP: return 64;
|
|
|
|
case E_ITEM_COOKIE: return 64;
|
|
|
|
case E_ITEM_DIAMOND: return 64;
|
|
|
|
case E_ITEM_DYE: return 64;
|
|
|
|
case E_ITEM_EGG: return 16;
|
|
|
|
case E_ITEM_EMERALD: return 64;
|
|
|
|
case E_ITEM_ENDER_PEARL: return 16;
|
|
|
|
case E_ITEM_EYE_OF_ENDER: return 64;
|
|
|
|
case E_ITEM_FEATHER: return 64;
|
|
|
|
case E_ITEM_FERMENTED_SPIDER_EYE: return 64;
|
|
|
|
case E_ITEM_FIRE_CHARGE: return 64;
|
|
|
|
case E_ITEM_FLINT: return 64;
|
|
|
|
case E_ITEM_GHAST_TEAR: return 64;
|
|
|
|
case E_ITEM_GLASS_BOTTLE: return 64;
|
|
|
|
case E_ITEM_GLISTERING_MELON: return 64;
|
|
|
|
case E_ITEM_GLOWSTONE_DUST: return 64;
|
|
|
|
case E_ITEM_GOLD: return 64;
|
|
|
|
case E_ITEM_GOLDEN_APPLE: return 64;
|
|
|
|
case E_ITEM_GOLD_NUGGET: return 64;
|
|
|
|
case E_ITEM_GUNPOWDER: return 64;
|
|
|
|
case E_ITEM_IRON: return 64;
|
|
|
|
case E_ITEM_LEATHER: return 64;
|
|
|
|
case E_ITEM_MAGMA_CREAM: return 64;
|
|
|
|
case E_ITEM_MELON_SEEDS: return 64;
|
|
|
|
case E_ITEM_MELON_SLICE: return 64;
|
|
|
|
case E_ITEM_PAINTINGS: return 64;
|
|
|
|
case E_ITEM_PAPER: return 64;
|
|
|
|
case E_ITEM_PUMPKIN_SEEDS: return 64;
|
|
|
|
case E_ITEM_RAW_BEEF: return 64;
|
|
|
|
case E_ITEM_RAW_CHICKEN: return 64;
|
|
|
|
case E_ITEM_RAW_FISH: return 64;
|
|
|
|
case E_ITEM_RAW_PORKCHOP: return 64;
|
|
|
|
case E_ITEM_REDSTONE_DUST: return 64;
|
|
|
|
case E_ITEM_REDSTONE_REPEATER: return 64;
|
|
|
|
case E_ITEM_ROTTEN_FLESH: return 64;
|
|
|
|
case E_ITEM_SEEDS: return 64;
|
|
|
|
case E_ITEM_SIGN: return 16;
|
|
|
|
case E_ITEM_SLIMEBALL: return 64;
|
|
|
|
case E_ITEM_SNOWBALL: return 16;
|
|
|
|
case E_ITEM_SPIDER_EYE: return 64;
|
|
|
|
case E_ITEM_STEAK: return 64;
|
|
|
|
case E_ITEM_STICK: return 64;
|
|
|
|
case E_ITEM_STRING: return 64;
|
|
|
|
case E_ITEM_SUGAR: return 64;
|
|
|
|
case E_ITEM_SUGAR_CANE: return 64;
|
|
|
|
case E_ITEM_WHEAT: return 64;
|
2012-08-11 12:45:03 -07:00
|
|
|
}
|
2012-08-11 05:46:09 -07:00
|
|
|
// By default items don't stack:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
bool cItemHandler::IsTool()
|
|
|
|
{
|
|
|
|
return
|
2012-10-18 12:41:29 -07:00
|
|
|
(m_ItemType >= 256 && m_ItemType <= 259)
|
|
|
|
|| (m_ItemType == 261)
|
|
|
|
|| (m_ItemType >= 267 && m_ItemType <= 279)
|
|
|
|
|| (m_ItemType >= 283 && m_ItemType <= 286)
|
|
|
|
|| (m_ItemType >= 290 && m_ItemType <= 294)
|
|
|
|
|| (m_ItemType >= 256 && m_ItemType <= 259)
|
|
|
|
|| (m_ItemType == 325)
|
|
|
|
|| (m_ItemType == 346);
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
bool cItemHandler::IsFood()
|
|
|
|
{
|
|
|
|
return
|
2012-10-18 12:41:29 -07:00
|
|
|
(m_ItemType == 260)
|
|
|
|
|| (m_ItemType == 282)
|
|
|
|
|| (m_ItemType == 297)
|
|
|
|
|| (m_ItemType >= 319 && m_ItemType <= 320)
|
|
|
|
|| (m_ItemType == 335)
|
|
|
|
|| (m_ItemType >= 349 && m_ItemType <= 350)
|
|
|
|
|| (m_ItemType == 357)
|
|
|
|
|| (m_ItemType == 360)
|
|
|
|
|| (m_ItemType >= 363 && m_ItemType <= 366);
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
bool cItemHandler::IsPlaceable()
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
return m_ItemType >= 1 && m_ItemType <= 136;
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 01:52:11 -07:00
|
|
|
bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 13:36:34 -07:00
|
|
|
BLOCKTYPE cItemHandler::GetBlockType()
|
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
ASSERT(m_ItemType < 256); // Items with IDs above 255 should all be handled by specific handlers
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2012-10-18 12:41:29 -07:00
|
|
|
if (m_ItemType > 256)
|
2012-07-16 12:20:37 -07:00
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
LOGERROR("Item %d has no valid block!", m_ItemType);
|
2012-07-16 12:20:37 -07:00
|
|
|
}
|
2012-07-29 05:07:22 -07:00
|
|
|
#endif // _DEBUG
|
|
|
|
|
2012-10-18 12:41:29 -07:00
|
|
|
return (BLOCKTYPE) m_ItemType;
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cItemHandler::GetBlockMeta(short a_ItemDamage)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
2012-07-29 05:07:22 -07:00
|
|
|
return (NIBBLETYPE)a_ItemDamage & 0x0f; // This keeps most textures. The few other items have to override this
|
2012-07-15 13:36:34 -07:00
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 12:41:29 -07:00
|
|
|
void cItemHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
|
2012-07-15 13:36:34 -07:00
|
|
|
{
|
|
|
|
BLOCKTYPE Block = GetBlockType();
|
|
|
|
cBlockHandler *Handler = cBlockHandler::GetBlockHandler(Block);
|
2012-10-18 12:41:29 -07:00
|
|
|
Handler->PlaceBlock(a_World, a_Player, GetBlockMeta(a_Item->m_ItemHealth), a_BlockX, a_BlockY, a_BlockZ, a_Dir);
|
2012-07-15 13:36:34 -07:00
|
|
|
if(a_Player->GetGameMode() == eGameMode_Survival)
|
2012-07-17 07:33:51 -07:00
|
|
|
{
|
2012-10-18 12:41:29 -07:00
|
|
|
cItem Item(a_Item->m_ItemType, 1);
|
2012-07-17 07:33:51 -07:00
|
|
|
a_Player->GetInventory().RemoveItem(Item);
|
|
|
|
}
|
2012-07-17 05:02:03 -07:00
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-17 05:02:03 -07:00
|
|
|
bool cItemHandler::EatItem(cPlayer *a_Player, cItem *a_Item)
|
|
|
|
{
|
|
|
|
FoodInfo Info = GetFoodInfo();
|
|
|
|
|
|
|
|
if(Info.FoodLevel > 0 || Info.Saturation > 0.f)
|
|
|
|
{
|
|
|
|
bool Success = a_Player->Feed(Info.FoodLevel, Info.Saturation);
|
|
|
|
if(Success && Info.PoisionChance > 0)
|
|
|
|
{
|
|
|
|
MTRand r1;
|
|
|
|
if((r1.randInt(100) - Info.PoisionChance) <= 0)
|
|
|
|
{ //Unlucky guy :D
|
|
|
|
//TODO: Make player ill
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-29 05:07:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-17 05:02:03 -07:00
|
|
|
cItemHandler::FoodInfo cItemHandler::GetFoodInfo()
|
|
|
|
{
|
|
|
|
return FoodInfo(0, 0.f);
|
2012-07-29 05:07:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|