From 86a991c5a85a9771143320de91d87f6e986300a9 Mon Sep 17 00:00:00 2001 From: "lapayo94@gmail.com" Date: Mon, 16 Jul 2012 19:20:37 +0000 Subject: Some code improvements git-svn-id: http://mc-server.googlecode.com/svn/trunk@677 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/items/Item.cpp | 10 ++++++++-- source/items/Item.h | 2 +- source/items/ItemBucket.h | 2 +- source/items/ItemCloth.h | 2 +- source/items/ItemDoor.h | 4 ++-- source/items/ItemDye.h | 4 ++-- source/items/ItemHoe.h | 4 ++-- source/items/ItemLeaves.h | 4 ++-- source/items/ItemLighter.h | 2 +- source/items/ItemPickaxe.h | 2 +- source/items/ItemRedstoneDust.h | 6 +++--- source/items/ItemRedstoneRepeater.h | 6 +++--- source/items/ItemSapling.h | 2 +- source/items/ItemSeeds.h | 13 ++++--------- source/items/ItemShears.h | 4 ++-- source/items/ItemShovel.h | 4 ++-- source/items/ItemSlab.h | 4 ++-- source/items/ItemSugarcane.h | 11 +++-------- source/items/ItemSword.h | 2 +- source/items/ItemWood.h | 2 +- 20 files changed, 43 insertions(+), 47 deletions(-) (limited to 'source/items') diff --git a/source/items/Item.cpp b/source/items/Item.cpp index e6129bbd2..3dd0a4218 100644 --- a/source/items/Item.cpp +++ b/source/items/Item.cpp @@ -209,10 +209,16 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockID) BLOCKTYPE cItemHandler::GetBlockType() { - return m_ItemID; +#ifdef _DEBUG + if(m_ItemID > 256) + { + LOGERROR("Item %d has no valid block!", m_ItemID); + } +#endif + return (BLOCKTYPE) m_ItemID; } -NIBBLETYPE cItemHandler::GetBlockMeta(char a_ItemMeta) +NIBBLETYPE cItemHandler::GetBlockMeta(NIBBLETYPE a_ItemMeta) { return a_ItemMeta; //This keeps most textures. The few other items have to override this } diff --git a/source/items/Item.h b/source/items/Item.h index 14780e6ee..96f957fcf 100644 --- a/source/items/Item.h +++ b/source/items/Item.h @@ -24,7 +24,7 @@ public: virtual bool IsPlaceable(); virtual BLOCKTYPE GetBlockType(); - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta); + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta); virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID); diff --git a/source/items/ItemBucket.h b/source/items/ItemBucket.h index e223d47f1..c74fc68ee 100644 --- a/source/items/ItemBucket.h +++ b/source/items/ItemBucket.h @@ -12,7 +12,7 @@ public: } - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) + 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) { diff --git a/source/items/ItemCloth.h b/source/items/ItemCloth.h index e3ab0c74b..ead4ee84a 100644 --- a/source/items/ItemCloth.h +++ b/source/items/ItemCloth.h @@ -11,7 +11,7 @@ public: { } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) override { return a_ItemMeta; } diff --git a/source/items/ItemDoor.h b/source/items/ItemDoor.h index 5b656ce17..ac5bc6872 100644 --- a/source/items/ItemDoor.h +++ b/source/items/ItemDoor.h @@ -12,12 +12,12 @@ public: } - virtual bool IsPlaceable() + virtual bool IsPlaceable() override { return true; } - virtual BLOCKTYPE GetBlockType() + virtual BLOCKTYPE GetBlockType() override { return (m_ItemID == E_ITEM_WOODEN_DOOR) ? E_BLOCK_WOODEN_DOOR : E_BLOCK_IRON_DOOR; } diff --git a/source/items/ItemDye.h b/source/items/ItemDye.h index 60a1ed289..5cf470e04 100644 --- a/source/items/ItemDye.h +++ b/source/items/ItemDye.h @@ -7,12 +7,12 @@ class cItemDyeHandler : public cItemHandler { public: cItemDyeHandler(int a_ItemID) - : cItemHandler(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) + 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: diff --git a/source/items/ItemHoe.h b/source/items/ItemHoe.h index dd73f4ac9..64dc4ca34 100644 --- a/source/items/ItemHoe.h +++ b/source/items/ItemHoe.h @@ -7,12 +7,12 @@ class cItemHoeHandler : public cItemHandler { public: cItemHoeHandler(int a_ItemID) - : cItemHandler(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) + 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); diff --git a/source/items/ItemLeaves.h b/source/items/ItemLeaves.h index 03f0ce8f3..bc1519806 100644 --- a/source/items/ItemLeaves.h +++ b/source/items/ItemLeaves.h @@ -10,8 +10,8 @@ public: : cItemHandler(a_ItemID) { } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) override { - return a_ItemMeta | 0x4; //0x4 bit set means this is a player-placed leaves block, not to be decayed + return a_ItemMeta | 0x4; //0x4 bit set means this is a player places leave } }; \ No newline at end of file diff --git a/source/items/ItemLighter.h b/source/items/ItemLighter.h index 287a7742f..213677e4e 100644 --- a/source/items/ItemLighter.h +++ b/source/items/ItemLighter.h @@ -13,7 +13,7 @@ public: } - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) + 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(); diff --git a/source/items/ItemPickaxe.h b/source/items/ItemPickaxe.h index c9b36ae7b..a179d154f 100644 --- a/source/items/ItemPickaxe.h +++ b/source/items/ItemPickaxe.h @@ -30,7 +30,7 @@ public: } } - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override { switch(a_BlockID) { diff --git a/source/items/ItemRedstoneDust.h b/source/items/ItemRedstoneDust.h index ccae0fd13..a0aee1e5e 100644 --- a/source/items/ItemRedstoneDust.h +++ b/source/items/ItemRedstoneDust.h @@ -10,17 +10,17 @@ public: { } - virtual bool IsPlaceable() + virtual bool IsPlaceable() override { return true; } - virtual BLOCKTYPE GetBlockType() + virtual BLOCKTYPE GetBlockType() override { return E_BLOCK_REDSTONE_WIRE; } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) override { return 0; } diff --git a/source/items/ItemRedstoneRepeater.h b/source/items/ItemRedstoneRepeater.h index 57f6eeb77..8dd309a91 100644 --- a/source/items/ItemRedstoneRepeater.h +++ b/source/items/ItemRedstoneRepeater.h @@ -10,17 +10,17 @@ public: { } - virtual bool IsPlaceable() + virtual bool IsPlaceable() override { return true; } - virtual BLOCKTYPE GetBlockType() + virtual BLOCKTYPE GetBlockType() override { return ::E_BLOCK_REDSTONE_REPEATER_OFF; } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) override { return 0; } diff --git a/source/items/ItemSapling.h b/source/items/ItemSapling.h index 35a201f81..23894b812 100644 --- a/source/items/ItemSapling.h +++ b/source/items/ItemSapling.h @@ -12,7 +12,7 @@ public: } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) override { //Only the first 2 bits are important return a_ItemMeta & 3; diff --git a/source/items/ItemSeeds.h b/source/items/ItemSeeds.h index bf0c38789..1d7f93613 100644 --- a/source/items/ItemSeeds.h +++ b/source/items/ItemSeeds.h @@ -12,17 +12,12 @@ public: } - virtual bool IsPlaceable() + virtual bool IsPlaceable() override { return true; } - - virtual bool AllowBlockOnTop() - { - return false; - } - virtual BLOCKTYPE GetBlockType() + virtual BLOCKTYPE GetBlockType() override { switch(m_ItemID) { @@ -37,12 +32,12 @@ public: } } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) 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) + 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, diff --git a/source/items/ItemShears.h b/source/items/ItemShears.h index 786ea5f5e..ab2981aae 100644 --- a/source/items/ItemShears.h +++ b/source/items/ItemShears.h @@ -12,7 +12,7 @@ public: { } - virtual bool IsTool() + virtual bool IsTool() override { return true; } @@ -33,7 +33,7 @@ public: } - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override { return a_BlockID == E_BLOCK_COBWEB || a_BlockID == E_BLOCK_VINES; diff --git a/source/items/ItemShovel.h b/source/items/ItemShovel.h index 5fd21cc26..3279ef419 100644 --- a/source/items/ItemShovel.h +++ b/source/items/ItemShovel.h @@ -9,7 +9,7 @@ class cItemShovelHandler : public cItemHandler { public: cItemShovelHandler(int a_ItemID) - : cItemHandler(a_ItemID) + : cItemHandler(a_ItemID) { } @@ -28,7 +28,7 @@ public: return false; } - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override { return a_BlockID == E_BLOCK_SNOW; } diff --git a/source/items/ItemSlab.h b/source/items/ItemSlab.h index 54186d704..38b0aa213 100644 --- a/source/items/ItemSlab.h +++ b/source/items/ItemSlab.h @@ -12,7 +12,7 @@ public: } - virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z, char a_Dir) + 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; @@ -32,7 +32,7 @@ public: return false; } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) override { return a_ItemMeta; } diff --git a/source/items/ItemSugarcane.h b/source/items/ItemSugarcane.h index b79a3c6c7..778a20dbf 100644 --- a/source/items/ItemSugarcane.h +++ b/source/items/ItemSugarcane.h @@ -12,22 +12,17 @@ public: } - virtual bool IsPlaceable() + virtual bool IsPlaceable() override { return true; } - virtual bool AllowBlockOnTop() - { - return false; - } - - virtual BLOCKTYPE GetBlockType() + virtual BLOCKTYPE GetBlockType() override { return E_BLOCK_SUGARCANE; } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) override { return 0; //Not grown yet } diff --git a/source/items/ItemSword.h b/source/items/ItemSword.h index f49436d51..cbe172c8f 100644 --- a/source/items/ItemSword.h +++ b/source/items/ItemSword.h @@ -12,7 +12,7 @@ public: } - virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) + virtual bool CanHarvestBlock(BLOCKTYPE a_BlockID) override { return a_BlockID == E_BLOCK_COBWEB; } diff --git a/source/items/ItemWood.h b/source/items/ItemWood.h index 3254b70ed..13aba198d 100644 --- a/source/items/ItemWood.h +++ b/source/items/ItemWood.h @@ -10,7 +10,7 @@ public: : cItemHandler(a_ItemID) { } - virtual NIBBLETYPE GetBlockMeta(char a_ItemMeta) override + virtual NIBBLETYPE GetBlockMeta(NIBBLETYPE a_ItemMeta) override { return a_ItemMeta; } -- cgit v1.2.3