summaryrefslogtreecommitdiffstats
path: root/src/Items
diff options
context:
space:
mode:
authormohe2015 <mohe2015@users.noreply.github.com>2016-11-06 19:30:19 +0100
committerMattes D <github@xoft.cz>2016-11-06 19:30:19 +0100
commit32b38fb2649fb282b6446c4e544866c0161aa7da (patch)
tree51d2fd4d507b9f46e80d90f357a6fee78d2f5ffa /src/Items
parentMerge pull request #3416 from cuberite/JsonSerializerErrorReport (diff)
downloadcuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.gz
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.bz2
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.lz
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.xz
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.tar.zst
cuberite-32b38fb2649fb282b6446c4e544866c0161aa7da.zip
Diffstat (limited to 'src/Items')
-rw-r--r--src/Items/CMakeLists.txt1
-rw-r--r--src/Items/ItemAxe.h48
-rw-r--r--src/Items/ItemHandler.cpp20
-rw-r--r--src/Items/ItemHandler.h4
-rw-r--r--src/Items/ItemPickaxe.h23
-rw-r--r--src/Items/ItemShears.h22
-rw-r--r--src/Items/ItemShovel.h31
-rw-r--r--src/Items/ItemSword.h28
8 files changed, 177 insertions, 0 deletions
diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt
index eacc1e53f..72858591a 100644
--- a/src/Items/CMakeLists.txt
+++ b/src/Items/CMakeLists.txt
@@ -55,6 +55,7 @@ SET (HDRS
ItemSugarcane.h
ItemSword.h
ItemThrowable.h
+ ItemAxe.h
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
diff --git a/src/Items/ItemAxe.h b/src/Items/ItemAxe.h
new file mode 100644
index 000000000..656497199
--- /dev/null
+++ b/src/Items/ItemAxe.h
@@ -0,0 +1,48 @@
+
+#pragma once
+
+#include "ItemHandler.h"
+#include "../World.h"
+#include "../Entities/Player.h"
+
+
+
+
+
+class cItemAxeHandler :
+ public cItemHandler
+{
+ typedef cItemHandler super;
+public:
+ cItemAxeHandler(int a_ItemType)
+ : cItemHandler(a_ItemType)
+ {
+ }
+
+
+ virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
+ {
+ if (!IsBlockMaterialWood(a_Block) && !IsBlockMaterialPlants(a_Block) && !IsBlockMaterialVine(a_Block))
+ {
+ return super::GetBlockBreakingStrength(a_Block);
+ }
+ else
+ {
+ switch (m_ItemType)
+ {
+ case E_ITEM_WOODEN_AXE: return 2.0f;
+ case E_ITEM_STONE_AXE: return 4.0f;
+ case E_ITEM_IRON_AXE: return 6.0f;
+ case E_ITEM_GOLD_AXE: return 12.0f;
+ case E_ITEM_DIAMOND_AXE: return 8.0f;
+ }
+ }
+ ASSERT(!"Something is wrong here... Maybe they are axes out of a new material?");
+ return 1.0f;
+ }
+
+} ;
+
+
+
+
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index 8a05149b0..6984b6111 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -56,6 +56,7 @@
#include "ItemSugarcane.h"
#include "ItemSword.h"
#include "ItemThrowable.h"
+#include "ItemAxe.h"
#include "../Blocks/BlockHandler.h"
@@ -180,6 +181,15 @@ cItemHandler * cItemHandler::CreateItemHandler(int a_ItemType)
return new cItemShovelHandler(a_ItemType);
}
+ case E_ITEM_WOODEN_AXE:
+ case E_ITEM_STONE_AXE:
+ case E_ITEM_IRON_AXE:
+ case E_ITEM_GOLD_AXE:
+ case E_ITEM_DIAMOND_AXE:
+ {
+ return new cItemAxeHandler(a_ItemType);
+ }
+
case E_ITEM_WOODEN_SWORD:
case E_ITEM_STONE_SWORD:
case E_ITEM_IRON_SWORD:
@@ -866,3 +876,13 @@ cItemHandler::FoodInfo cItemHandler::GetFoodInfo()
+
+
+
+
+
+float cItemHandler::GetBlockBreakingStrength(BLOCKTYPE a_Block)
+{
+ return 1.0f;
+}
+
diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h
index a2b825fb7..8141bfb23 100644
--- a/src/Items/ItemHandler.h
+++ b/src/Items/ItemHandler.h
@@ -154,6 +154,10 @@ public:
Defaults to false unless overridden. */
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType);
+ /** Returns the strength to break a specific block.
+ Defaults to 1 unless overriden. */
+ virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block);
+
static cItemHandler * GetItemHandler(int a_ItemType);
static cItemHandler * GetItemHandler(const cItem & a_Item) { return GetItemHandler(a_Item.m_ItemType); }
diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h
index dba4926db..6e8452cd9 100644
--- a/src/Items/ItemPickaxe.h
+++ b/src/Items/ItemPickaxe.h
@@ -107,6 +107,29 @@ public:
}
return false;
}
+
+
+ virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
+ {
+ if (!IsBlockMaterialIron(a_Block) && !IsBlockMaterialAnvil(a_Block) && !IsBlockMaterialRock(a_Block))
+ {
+ return super::GetBlockBreakingStrength(a_Block);
+ }
+ else
+ {
+ switch (m_ItemType)
+ {
+ case E_ITEM_WOODEN_PICKAXE: return 2.0f;
+ case E_ITEM_STONE_PICKAXE: return 4.0f;
+ case E_ITEM_IRON_PICKAXE: return 6.0f;
+ case E_ITEM_GOLD_PICKAXE: return 12.0f;
+ case E_ITEM_DIAMOND_PICKAXE: return 8.0f;
+ }
+ }
+ ASSERT(!"Something is wrong here... Maybe they are pickaxes out of a new material?");
+ return 1.0f;
+ }
+
} ;
diff --git a/src/Items/ItemShears.h b/src/Items/ItemShears.h
index c8034b112..745432ca0 100644
--- a/src/Items/ItemShears.h
+++ b/src/Items/ItemShears.h
@@ -90,6 +90,28 @@ public:
}
}
}
+
+
+
+ virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
+ {
+ if (IsBlocksWeb(a_Block) || IsBlockMaterialLeaves(a_Block))
+ {
+ return 15.0f;
+ }
+ else
+ {
+ if (IsBlocksWool(a_Block))
+ {
+ return 5.0f;
+ }
+ else
+ {
+ return super::GetBlockBreakingStrength(a_Block);
+ }
+ }
+ }
+
} ;
diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h
index 739ed833e..e5aae26a7 100644
--- a/src/Items/ItemShovel.h
+++ b/src/Items/ItemShovel.h
@@ -59,4 +59,35 @@ public:
return false;
}
+ virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
+ {
+ switch (a_Block)
+ {
+ case E_BLOCK_CLAY:
+ case E_BLOCK_DIRT:
+ case E_BLOCK_FARMLAND:
+ case E_BLOCK_GRASS:
+ case E_BLOCK_GRAVEL:
+ case E_BLOCK_MYCELIUM:
+ case E_BLOCK_SAND:
+ case E_BLOCK_SNOW:
+ case E_BLOCK_SNOW_BLOCK:
+ case E_BLOCK_SOULSAND:
+ case E_BLOCK_GRASS_PATH:
+ {
+ switch (m_ItemType)
+ {
+ case E_ITEM_WOODEN_SHOVEL: return 2.0f;
+ case E_ITEM_STONE_SHOVEL: return 4.0f;
+ case E_ITEM_IRON_SHOVEL: return 6.0f;
+ case E_ITEM_GOLD_SHOVEL: return 12.0f;
+ case E_ITEM_DIAMOND_SHOVEL: return 8.0f;
+ }
+ break;
+ }
+ default: return super::GetBlockBreakingStrength(a_Block);
+ }
+ ASSERT(!"Something is wrong here... Maybe they are shovels out of a new material?");
+ return 1.0f;
+ }
};
diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h
index a15a9e3db..26372cc40 100644
--- a/src/Items/ItemSword.h
+++ b/src/Items/ItemSword.h
@@ -56,6 +56,34 @@ public:
return 0;
#endif
}
+
+
+
+ virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
+ {
+ if (a_Block == E_BLOCK_COBWEB)
+ {
+ return 15.0f;
+ }
+ else
+ {
+ if (
+ IsBlockMaterialPlants(a_Block) ||
+ IsBlockMaterialVine(a_Block) ||
+ IsBlockMaterialCoral(a_Block) ||
+ IsBlockMaterialLeaves(a_Block) ||
+ IsBlockMaterialGourd(a_Block)
+ )
+ {
+ return 1.5f;
+ }
+ else
+ {
+ return 1.0f;
+ }
+ }
+ }
+
} ;