From 4df23d19b7be2f274974e3dfe91e716e6296f11c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 29 Sep 2012 13:59:32 +0000 Subject: Unified folder name-casing git-svn-id: http://mc-server.googlecode.com/svn/trunk@902 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/items/ItemBed.h | 25 --- source/items/ItemBucket.h | 94 -------- source/items/ItemCloth.h | 23 -- source/items/ItemDoor.h | 26 --- source/items/ItemDye.h | 35 --- source/items/ItemFood.h | 56 ----- source/items/ItemHandler.cpp | 422 ------------------------------------ source/items/ItemHandler.h | 83 ------- source/items/ItemHoe.h | 31 --- source/items/ItemLeaves.h | 27 --- source/items/ItemLighter.h | 27 --- source/items/ItemPickaxe.h | 75 ------- source/items/ItemRedstoneDust.h | 36 --- source/items/ItemRedstoneRepeater.h | 36 --- source/items/ItemSapling.h | 28 --- source/items/ItemSeeds.h | 59 ----- source/items/ItemShears.h | 42 ---- source/items/ItemShovel.h | 41 ---- source/items/ItemSign.h | 26 --- source/items/ItemSlab.h | 45 ---- source/items/ItemSugarcane.h | 39 ---- source/items/ItemSword.h | 21 -- source/items/ItemWood.h | 22 -- 23 files changed, 1319 deletions(-) delete mode 100644 source/items/ItemBed.h delete mode 100644 source/items/ItemBucket.h delete mode 100644 source/items/ItemCloth.h delete mode 100644 source/items/ItemDoor.h delete mode 100644 source/items/ItemDye.h delete mode 100644 source/items/ItemFood.h delete mode 100644 source/items/ItemHandler.cpp delete mode 100644 source/items/ItemHandler.h delete mode 100644 source/items/ItemHoe.h delete mode 100644 source/items/ItemLeaves.h delete mode 100644 source/items/ItemLighter.h delete mode 100644 source/items/ItemPickaxe.h delete mode 100644 source/items/ItemRedstoneDust.h delete mode 100644 source/items/ItemRedstoneRepeater.h delete mode 100644 source/items/ItemSapling.h delete mode 100644 source/items/ItemSeeds.h delete mode 100644 source/items/ItemShears.h delete mode 100644 source/items/ItemShovel.h delete mode 100644 source/items/ItemSign.h delete mode 100644 source/items/ItemSlab.h delete mode 100644 source/items/ItemSugarcane.h delete mode 100644 source/items/ItemSword.h delete mode 100644 source/items/ItemWood.h (limited to 'source/items') diff --git a/source/items/ItemBed.h b/source/items/ItemBed.h deleted file mode 100644 index b49df65a3..000000000 --- a/source/items/ItemBed.h +++ /dev/null @@ -1,25 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - -class cItemBedHandler : public cItemHandler -{ -public: - cItemBedHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return E_BLOCK_BED; - } -}; \ No newline at end of file diff --git a/source/items/ItemBucket.h b/source/items/ItemBucket.h deleted file mode 100644 index 736112960..000000000 --- a/source/items/ItemBucket.h +++ /dev/null @@ -1,94 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - -class cItemBucketHandler : public cItemHandler -{ -public: - cItemBucketHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - switch(m_ItemID) - { - case E_ITEM_BUCKET: - { - if (a_Dir >= 0) - { - AddDirection(a_X, a_Y, a_Z, a_Dir); - } - BLOCKTYPE ClickedBlock = a_World->GetBlock(a_X, a_Y, a_Z); - LOG("Bucket Clicked BlockID: %d", ClickedBlock); - ENUM_ITEM_ID NewItem = E_ITEM_EMPTY; - switch (ClickedBlock) - { - case E_BLOCK_WATER: - case E_BLOCK_STATIONARY_WATER: - { - NewItem = E_ITEM_WATER_BUCKET; - break; - } - case E_BLOCK_LAVA: - case E_BLOCK_STATIONARY_LAVA: - { - NewItem = E_ITEM_LAVA_BUCKET; - break; - } - } - cItem Item(a_Item->m_ItemID, 1); - if ( - (NewItem != E_ITEM_EMPTY) && - ( - ((a_Player->GetGameMode() == 1) || - a_Player->GetInventory().RemoveItem(Item)) - ) - ) - { - // Give New Bucket - cItem Item(NewItem, 1); - a_Player->GetInventory().AddItem(Item); - // Remove water / lava block - a_Player->GetWorld()->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); - return true; - } - break; - } - - case E_ITEM_WATER_BUCKET: - case E_ITEM_LAVA_BUCKET: - { - BLOCKTYPE NewBlock = (m_ItemID == E_ITEM_LAVA_BUCKET) ? E_BLOCK_LAVA : E_BLOCK_WATER; - if (a_Dir >= 0) - { - AddDirection(a_X, a_Y, a_Z, a_Dir); - } - if(a_World->GetBlock(a_X, a_Y, a_Z) == E_BLOCK_AIR) - { - cItem Item(a_Item->m_ItemID, 1); - if ((a_Player->GetGameMode() == 1) || (a_Player->GetInventory().RemoveItem(Item))) - { - a_World->SetBlock(a_X, a_Y, a_Z, NewBlock, 0); - - if (a_Player->GetGameMode() == 1) - { - break; //No new Bucket for creative players - } - cItem Item(E_ITEM_BUCKET, 1); - a_Player->GetInventory().AddItem(Item); - return true; - } - } - } - break; - } - - return false; - } - -}; \ No newline at end of file diff --git a/source/items/ItemCloth.h b/source/items/ItemCloth.h deleted file mode 100644 index 5de064397..000000000 --- a/source/items/ItemCloth.h +++ /dev/null @@ -1,23 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemClothHandler : - public cItemHandler -{ -public: - cItemClothHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } -} ; - - - - diff --git a/source/items/ItemDoor.h b/source/items/ItemDoor.h deleted file mode 100644 index 6e841333f..000000000 --- a/source/items/ItemDoor.h +++ /dev/null @@ -1,26 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - -class cItemDoorHandler : public cItemHandler -{ -public: - cItemDoorHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return (m_ItemID == E_ITEM_WOODEN_DOOR) ? E_BLOCK_WOODEN_DOOR : E_BLOCK_IRON_DOOR; - } - -}; \ No newline at end of file diff --git a/source/items/ItemDye.h b/source/items/ItemDye.h deleted file mode 100644 index 5b21a501c..000000000 --- a/source/items/ItemDye.h +++ /dev/null @@ -1,35 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemDyeHandler : public cItemHandler -{ -public: - cItemDyeHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - // TODO: Handle coloring the sheep, too (OnItemUseOnEntity maybe) - // Handle growing the plants: - if (a_Item->m_ItemHealth == E_META_DYE_WHITE) - { - if(a_World->GrowPlant(a_X, a_Y, a_Z, true)) - { - if (a_Player->GetGameMode() == eGameMode_Survival) - { - cItem Item(a_Item->m_ItemID, 1, a_Item->m_ItemHealth); - a_Player->GetInventory().RemoveItem(Item); - return true; - } - } - } - return false; - } -}; \ No newline at end of file diff --git a/source/items/ItemFood.h b/source/items/ItemFood.h deleted file mode 100644 index 6e5a27d5d..000000000 --- a/source/items/ItemFood.h +++ /dev/null @@ -1,56 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - -class cItemFoodHandler : public cItemHandler -{ -public: - cItemFoodHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } - - virtual bool IsFood() override - { - return true; - } - - virtual FoodInfo GetFoodInfo() override - { - switch(m_ItemID) - { - case E_ITEM_BREAD: - return FoodInfo(5, 6.f); - case E_ITEM_COOKIE: - return FoodInfo(2, 0.4f); - case E_ITEM_MELON_SLICE: - return FoodInfo(2, 1.2f); - case E_ITEM_RAW_CHICKEN: - return FoodInfo(2, 1.2f, 30); - case E_ITEM_COOKED_CHICKEN: - return FoodInfo(6, 7.2f); - case E_ITEM_RAW_BEEF: - case E_ITEM_RAW_MEAT: - return FoodInfo(3, 1.8f); - case E_ITEM_STEAK: - case E_ITEM_COOKED_MEAT: - return FoodInfo(8, 12.8f); - case E_ITEM_RAW_FISH: - return FoodInfo(2, 1.2f); - case E_ITEM_COOKED_FISH: - return FoodInfo(5, 6.f); - case E_ITEM_RED_APPLE: - return FoodInfo(4, 2.4f); - case E_ITEM_GOLDEN_APPLE: - return FoodInfo(4, 9.6f); - case E_ITEM_ROTTEN_FLESH: - return FoodInfo(4, 0.8f, 80); - case E_ITEM_SPIDER_EYE: - return FoodInfo(2, 3.2f, 100); - } - return FoodInfo(0, 0.f); - } - -}; \ No newline at end of file diff --git a/source/items/ItemHandler.cpp b/source/items/ItemHandler.cpp deleted file mode 100644 index 63d4f4258..000000000 --- a/source/items/ItemHandler.cpp +++ /dev/null @@ -1,422 +0,0 @@ - -#include "Globals.h" -#include "ItemHandler.h" -#include "../Item.h" -#include "../World.h" -#include "../Player.h" - -//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" -#include "ItemRedstoneRepeater.h" -#include "ItemSeeds.h" -#include "ItemDye.h" -#include "ItemSugarcane.h" -#include "ItemPickaxe.h" -#include "ItemShovel.h" -#include "ItemSword.h" -#include "ItemDoor.h" -#include "ItemFood.h" -#include "ItemSign.h" -#include "ItemBed.h" - -#include "../blocks/BlockHandler.h" - - - - - -bool cItemHandler::m_HandlerInitialized = false; -cItemHandler * cItemHandler::m_ItemHandler[2266]; - - - - - -cItemHandler *cItemHandler::GetItemHandler(int a_ItemID) -{ - if(a_ItemID < 0) a_ItemID = 0; - - if(!m_HandlerInitialized) - { //We have to initialize - memset(m_ItemHandler, 0, sizeof(m_ItemHandler)); - m_HandlerInitialized = true; - } - if(m_ItemHandler[a_ItemID]) - return m_ItemHandler[a_ItemID]; - m_ItemHandler[a_ItemID] = CreateItemHandler(a_ItemID); - return m_ItemHandler[a_ItemID]; -} - - - - - -cItemHandler *cItemHandler::CreateItemHandler(int a_ItemID) -{ - switch(a_ItemID) - { - default: return new cItemHandler(a_ItemID); - - // Single item per handler: - case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemID); - case E_ITEM_LEAVES: return new cItemLeavesHandler(a_ItemID); - case E_ITEM_SAPLING: return new cItemSaplingHandler(a_ItemID); - case E_ITEM_DYE: return new cItemDyeHandler(a_ItemID); - case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemID); - case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemID); - case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemID); - case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemID); - case E_ITEM_WOOL: return new cItemClothHandler(a_ItemID); - - 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: - { - return new cItemHoeHandler(a_ItemID); - } - - 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: - { - return new cItemPickaxeHandler(a_ItemID); - } - - 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: - { - return new cItemShovelHandler(a_ItemID); - } - - 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: - { - return new cItemSwordHandler(a_ItemID); - } - - case E_ITEM_STONE_SLAB: - case E_ITEM_WOODEN_SLAB: - { - return new cItemSlabHandler(a_ItemID); - } - - case E_ITEM_LOG: - case E_ITEM_PLANKS: - { - return new cItemWoodHandler(a_ItemID); - } - - case E_ITEM_BUCKET: - case E_ITEM_WATER_BUCKET: - case E_ITEM_LAVA_BUCKET: - { - return new cItemBucketHandler(a_ItemID); - } - - case E_ITEM_PUMPKIN_SEEDS: - case E_ITEM_MELON_SEEDS: - case E_ITEM_SEEDS: - { - return new cItemSeedsHandler(a_ItemID); - } - - case E_ITEM_IRON_DOOR: - case E_ITEM_WOODEN_DOOR: - { - return new cItemDoorHandler(a_ItemID); - } - - // 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: - { - return new cItemFoodHandler(a_ItemID); - } - - case E_ITEM_SIGN: - return new cItemSignHandler(a_ItemID); - - case E_ITEM_BED: - return new cItemBedHandler(a_ItemID); - } -} - - - - - -void cItemHandler::Deinit() -{ - for(int i = 0; i < 2266; i++) - { - delete m_ItemHandler[i]; - } - m_HandlerInitialized = false; -} - - - - - -cItemHandler::cItemHandler(int a_ItemID) -{ - m_ItemID = a_ItemID; -} - - - - - -bool cItemHandler::OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) -{ - return false; -} - - - - - -bool cItemHandler::OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) -{ - return false; -} - - - - - -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(); -} - - - - - -void cItemHandler::OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item) -{ - -} - - - - - -char cItemHandler::GetMaxStackSize(void) -{ - if (m_ItemID < 256) - { - // All blocks can stack up to 64 - return 64; - } - - switch (m_ItemID) - { - 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_BOWL: return 64; - case E_ITEM_BREAD: return 64; - case E_ITEM_BROWN_MUSHROOM: return 64; - case E_ITEM_BUCKET: return 1; // TODO: change this to 16 when turning compatibility to 1.3 - case E_ITEM_COAL: 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_DIAMOND: return 64; - case E_ITEM_FEATHER: return 64; - case E_ITEM_FLINT: return 64; - case E_ITEM_GOLD: return 64; - case E_ITEM_GUNPOWDER: return 64; - case E_ITEM_IRON: return 64; - case E_ITEM_RAW_PORKCHOP: return 64; - case E_ITEM_SEEDS: return 64; - case E_ITEM_STICK: return 64; - case E_ITEM_STRING: return 64; - case E_ITEM_WHEAT: return 64; - } - // By default items don't stack: - return 1; -} - - - - - -bool cItemHandler::IsTool() -{ - return - (m_ItemID >= 256 && m_ItemID <= 259) - || (m_ItemID == 261) - || (m_ItemID >= 267 && m_ItemID <= 279) - || (m_ItemID >= 283 && m_ItemID <= 286) - || (m_ItemID >= 290 && m_ItemID <= 294) - || (m_ItemID >= 256 && m_ItemID <= 259) - || (m_ItemID == 325) - || (m_ItemID == 346); -} - - - - - -bool cItemHandler::IsFood() -{ - return - (m_ItemID == 260) - || (m_ItemID == 282) - || (m_ItemID == 297) - || (m_ItemID >= 319 && m_ItemID <= 320) - || (m_ItemID == 335) - || (m_ItemID >= 349 && m_ItemID <= 350) - || (m_ItemID == 357) - || (m_ItemID == 360) - || (m_ItemID >= 363 && m_ItemID <= 366); -} - - - - - -bool cItemHandler::IsPlaceable() -{ - return m_ItemID >= 1 && m_ItemID <= 136; -} - - - - - -bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockID) -{ - return false; -} - - - - - -BLOCKTYPE cItemHandler::GetBlockType() -{ - ASSERT(m_ItemID < 256); // Items with IDs above 255 should all be handled by specific handlers - - #ifdef _DEBUG - if (m_ItemID > 256) - { - LOGERROR("Item %d has no valid block!", m_ItemID); - } - #endif // _DEBUG - - return (BLOCKTYPE) m_ItemID; -} - - - - - -NIBBLETYPE cItemHandler::GetBlockMeta(short a_ItemDamage) -{ - return (NIBBLETYPE)a_ItemDamage & 0x0f; // This keeps most textures. The few other items have to override this -} - - - - - -void cItemHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) -{ - BLOCKTYPE Block = GetBlockType(); - cBlockHandler *Handler = cBlockHandler::GetBlockHandler(Block); - Handler->PlaceBlock(a_World, a_Player, GetBlockMeta(a_Item->m_ItemHealth), a_X, a_Y, a_Z, a_Dir); - if(a_Player->GetGameMode() == eGameMode_Survival) - { - cItem Item(a_Item->m_ItemID, 1); - a_Player->GetInventory().RemoveItem(Item); - } -} - - - - - -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; -} - - - - - -cItemHandler::FoodInfo cItemHandler::GetFoodInfo() -{ - return FoodInfo(0, 0.f); -} - - - - diff --git a/source/items/ItemHandler.h b/source/items/ItemHandler.h deleted file mode 100644 index 67935ecb4..000000000 --- a/source/items/ItemHandler.h +++ /dev/null @@ -1,83 +0,0 @@ - -#pragma once -#include "../Defines.h" - - - - - -// fwd: -class cWorld; -class cPlayer; - - - - - -class cItemHandler -{ -public: - cItemHandler(int a_ItemID); - // Called when the player tries to use the item. Return false to make the item unusable. DEFAULT: False - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir); //eg for fishing or hoes - // Called while the player diggs a block using this item - virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace); - // 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, cItem *a_Item, int a_X, int a_Y, int a_Z); - // 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 - virtual char GetMaxStackSize(void); - - struct FoodInfo - { - FoodInfo(short a_FoodLevel, float a_Saturation, char a_PoisionChance = 0) - { - FoodLevel = a_FoodLevel; - Saturation = a_Saturation; - PoisionChance = a_PoisionChance; - } - short FoodLevel; - float Saturation; - char PoisionChance; //0 - 100 - }; - - // 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 - virtual bool EatItem(cPlayer *a_Player, cItem *a_Item); - - // Places the current block and removes the item from the player inventory - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir); - - // Indicates if this item is a tool - virtual bool IsTool(); - // Indicates if this item is food - virtual bool IsFood(); - //Blocks simply get placed - virtual bool IsPlaceable(); - - // Returns the block type on placement - virtual BLOCKTYPE GetBlockType(); - //Returns the block meta on placement - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage); - // Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood canīt) DEFAULT: False - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID); - - static cItemHandler *GetItemHandler(int a_ItemID); - - static void Deinit(); - - -protected: - int m_ItemID; - static cItemHandler *CreateItemHandler(int m_ItemID); - - static cItemHandler *m_ItemHandler[2266]; - static bool m_HandlerInitialized; //used to detect if the itemhandlers are initialized -}; - -//Short function -inline cItemHandler *ItemHandler(int a_ItemID) { return cItemHandler::GetItemHandler(a_ItemID); } \ No newline at end of file diff --git a/source/items/ItemHoe.h b/source/items/ItemHoe.h deleted file mode 100644 index e7ea9135c..000000000 --- a/source/items/ItemHoe.h +++ /dev/null @@ -1,31 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemHoeHandler : public cItemHandler -{ -public: - cItemHoeHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); - - if(Block == E_BLOCK_DIRT || Block == E_BLOCK_GRASS) - { - a_World->FastSetBlock(a_X, a_Y, a_Z, E_BLOCK_FARMLAND, 0); - - a_Player->UseEquippedItem(); - return true; - - } - return false; - } -}; \ No newline at end of file diff --git a/source/items/ItemLeaves.h b/source/items/ItemLeaves.h deleted file mode 100644 index f96adb0b8..000000000 --- a/source/items/ItemLeaves.h +++ /dev/null @@ -1,27 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemLeavesHandler : - public cItemHandler -{ -public: - cItemLeavesHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - return (NIBBLETYPE)(a_ItemDamage & 0x0f) | 0x4; //0x4 bit set means this is a player-placed leaves block, not to be decayed - } -} ; - - - - diff --git a/source/items/ItemLighter.h b/source/items/ItemLighter.h deleted file mode 100644 index 92279aafa..000000000 --- a/source/items/ItemLighter.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemLighterHandler : public cItemHandler -{ -public: - cItemLighterHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - a_Player->UseEquippedItem(); - - AddDirection(a_X, a_Y, a_Z, a_Dir); - - a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0); //0 -> new fire TODO: Make Firesimulator use this - - return false; - } - -}; \ No newline at end of file diff --git a/source/items/ItemPickaxe.h b/source/items/ItemPickaxe.h deleted file mode 100644 index 158aca44f..000000000 --- a/source/items/ItemPickaxe.h +++ /dev/null @@ -1,75 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemPickaxeHandler : public cItemHandler -{ -public: - cItemPickaxeHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - char PickaxeLevel() - { - switch(m_ItemID) - { - case E_ITEM_WOODEN_PICKAXE: - case E_ITEM_GOLD_PICKAXE: - return 1; - case E_ITEM_STONE_PICKAXE: - return 2; - case E_ITEM_IRON_PICKAXE: - return 3; - case E_ITEM_DIAMOND_PICKAXE: - return 4; - default: - return 0; - } - } - - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override - { - switch(a_BlockID) - { - case E_BLOCK_OBSIDIAN: - return PickaxeLevel() >= 4; - case E_BLOCK_DIAMOND_BLOCK: - case E_BLOCK_DIAMOND_ORE: - case E_BLOCK_GOLD_BLOCK: - case E_BLOCK_GOLD_ORE: - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: - case E_BLOCK_EMERALD_ORE: - return PickaxeLevel() >= 3; - case E_BLOCK_IRON_BLOCK: - case E_BLOCK_IRON_ORE: - case E_BLOCK_LAPIS_ORE: - case E_BLOCK_LAPIS_BLOCK: - return PickaxeLevel() >= 2; - case E_BLOCK_COAL_ORE: - case E_BLOCK_STONE: - case E_BLOCK_COBBLESTONE: - case E_BLOCK_END_STONE: - case E_BLOCK_MOSSY_COBBLESTONE: - case E_BLOCK_SANDSTONE_STAIRS: - case E_BLOCK_SANDSTONE: - case E_BLOCK_STONE_BRICKS: - case E_BLOCK_NETHER_BRICK: - case E_BLOCK_NETHERRACK: - case E_BLOCK_STONE_SLAB: - case E_BLOCK_DOUBLE_STONE_SLAB: - case E_BLOCK_STONE_PRESSURE_PLATE: - case E_BLOCK_BRICK: - case E_BLOCK_COBBLESTONE_STAIRS: - case E_BLOCK_STONE_BRICK_STAIRS: - case E_BLOCK_NETHER_BRICK_STAIRS: - return PickaxeLevel() >= 1; - } - return false; - } -}; \ No newline at end of file diff --git a/source/items/ItemRedstoneDust.h b/source/items/ItemRedstoneDust.h deleted file mode 100644 index 1ce316d9e..000000000 --- a/source/items/ItemRedstoneDust.h +++ /dev/null @@ -1,36 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemRedstoneDustHandler : public cItemHandler -{ -public: - cItemRedstoneDustHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return E_BLOCK_REDSTONE_WIRE; - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - return 0; - } -} ; - - - - diff --git a/source/items/ItemRedstoneRepeater.h b/source/items/ItemRedstoneRepeater.h deleted file mode 100644 index c31c2af53..000000000 --- a/source/items/ItemRedstoneRepeater.h +++ /dev/null @@ -1,36 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemRedstoneRepeaterHandler : public cItemHandler -{ -public: - cItemRedstoneRepeaterHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return ::E_BLOCK_REDSTONE_REPEATER_OFF; - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemMeta) override - { - return 0; - } -} ; - - - - diff --git a/source/items/ItemSapling.h b/source/items/ItemSapling.h deleted file mode 100644 index b0c223f29..000000000 --- a/source/items/ItemSapling.h +++ /dev/null @@ -1,28 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemSaplingHandler : public cItemHandler -{ -public: - cItemSaplingHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - // Only the lowest 3 bits are important - return (NIBBLETYPE)(a_ItemDamage & 0x07); - } -} ; - - - - diff --git a/source/items/ItemSeeds.h b/source/items/ItemSeeds.h deleted file mode 100644 index 3eb9d6e86..000000000 --- a/source/items/ItemSeeds.h +++ /dev/null @@ -1,59 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - - - - - -class cItemSeedsHandler : - public cItemHandler -{ -public: - cItemSeedsHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - switch(m_ItemID) - { - case E_ITEM_SEEDS: return E_BLOCK_CROPS; - case E_ITEM_MELON_SEEDS: return E_BLOCK_MELON_STEM; - case E_ITEM_PUMPKIN_SEEDS: return E_BLOCK_PUMPKIN_STEM; - default: return E_BLOCK_AIR; - } - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - return 0; //Not grown yet - } - - virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - int X = a_X, - Y = a_Y, - Z = a_Z; - - AddDirection(X, Y, Z, a_Dir, true); - - if(a_World->GetBlock(X, Y, Z) != E_BLOCK_FARMLAND) - return; - - return cItemHandler::PlaceBlock(a_World, a_Player, a_Item, a_X, a_Y, a_Z, a_Dir); - } -} ; - - - - diff --git a/source/items/ItemShears.h b/source/items/ItemShears.h deleted file mode 100644 index 2f3476735..000000000 --- a/source/items/ItemShears.h +++ /dev/null @@ -1,42 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemShearsHandler : public cItemHandler -{ -public: - cItemShearsHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - virtual bool IsTool() override - { - return true; - } - virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); - if(Block == E_BLOCK_LEAVES) - { - cItems Drops; - Drops.push_back(cItem(E_ITEM_LEAVES, 1, a_World->GetBlockMeta(a_X, a_Y, a_Z))); - a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); - - a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); - a_Player->UseEquippedItem(); - return true; - } - return false; - } - - - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override - { - return a_BlockID == E_BLOCK_COBWEB - || a_BlockID == E_BLOCK_VINES; - } -}; \ No newline at end of file diff --git a/source/items/ItemShovel.h b/source/items/ItemShovel.h deleted file mode 100644 index 24928efb8..000000000 --- a/source/items/ItemShovel.h +++ /dev/null @@ -1,41 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -#include "../blocks/BlockHandler.h" - - - - - -class cItemShovelHandler : public cItemHandler -{ -public: - cItemShovelHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block = a_World->GetBlock(a_X, a_Y, a_Z); - if(Block == E_BLOCK_SNOW) - { - BlockHandler(Block)->DropBlock(a_World, a_X, a_Y, a_Z); - - a_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_AIR, 0); - a_Player->UseEquippedItem(); - return true; - } - return false; - } - - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override - { - return a_BlockID == E_BLOCK_SNOW; - } -}; \ No newline at end of file diff --git a/source/items/ItemSign.h b/source/items/ItemSign.h deleted file mode 100644 index a0c6aaa9c..000000000 --- a/source/items/ItemSign.h +++ /dev/null @@ -1,26 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - -class cItemSignHandler : public cItemHandler -{ -public: - cItemSignHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return E_BLOCK_SIGN_POST; - } - -}; \ No newline at end of file diff --git a/source/items/ItemSlab.h b/source/items/ItemSlab.h deleted file mode 100644 index 0bab038a2..000000000 --- a/source/items/ItemSlab.h +++ /dev/null @@ -1,45 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - - - - - -class cItemSlabHandler : public cItemHandler -{ -public: - cItemSlabHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_X, int a_Y, int a_Z, char a_Dir) override - { - BLOCKTYPE Block; - NIBBLETYPE Meta; - a_World->GetBlockTypeMeta(a_X, a_Y, a_Z, Block, Meta); - - if ( - (a_Dir == 0 || a_Dir == 1) // Only when clicking on top or on bottom of the block - && (Block == E_BLOCK_WOODEN_SLAB || Block == E_BLOCK_STONE_SLAB) // It is a slab - && (Block == a_Item->m_ItemID) // Same slab - && ((Meta & 0x7) == (a_Item->m_ItemHealth & 0x7))) // Same Texture - { - cItem Item(a_Item->m_ItemID, 1); - if (a_Player->GetInventory().RemoveItem(Item)) - { - a_World->SetBlock(a_X, a_Y, a_Z, Block - 1, Meta); //Block - 1 simple hack to save one if statement - return true; - } - } - return false; - } -} ; - - - - diff --git a/source/items/ItemSugarcane.h b/source/items/ItemSugarcane.h deleted file mode 100644 index 4fdf43428..000000000 --- a/source/items/ItemSugarcane.h +++ /dev/null @@ -1,39 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" - - - - - -class cItemSugarcaneHandler : - public cItemHandler -{ -public: - cItemSugarcaneHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool IsPlaceable() override - { - return true; - } - - virtual BLOCKTYPE GetBlockType() override - { - return E_BLOCK_SUGARCANE; - } - - virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override - { - return 0; //Not grown yet - } -} ; - - - - diff --git a/source/items/ItemSword.h b/source/items/ItemSword.h deleted file mode 100644 index eb4aa0ef9..000000000 --- a/source/items/ItemSword.h +++ /dev/null @@ -1,21 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" -#include "../World.h" -#include "../Player.h" - -class cItemSwordHandler : public cItemHandler -{ -public: - cItemSwordHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - - } - - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override - { - return a_BlockID == E_BLOCK_COBWEB; - } -}; \ No newline at end of file diff --git a/source/items/ItemWood.h b/source/items/ItemWood.h deleted file mode 100644 index d6f66d1c5..000000000 --- a/source/items/ItemWood.h +++ /dev/null @@ -1,22 +0,0 @@ - -#pragma once - -#include "ItemHandler.h" - - - - - -class cItemWoodHandler : - public cItemHandler -{ -public: - cItemWoodHandler(int a_ItemID) - : cItemHandler(a_ItemID) - { - } -} ; - - - - -- cgit v1.2.3