summaryrefslogtreecommitdiffstats
path: root/src/Items
diff options
context:
space:
mode:
authorarchshift <admin@archshift.com>2014-07-10 08:28:27 +0200
committerarchshift <admin@archshift.com>2014-07-10 08:28:27 +0200
commite824cd09b369c47a7f316fccc7577cd923164466 (patch)
treed8efa178a29955525458a38b1351ea0b609a2a09 /src/Items
parentEntityEffects.x -> EntityEffect.x, Object-Oriented effects (diff)
parentMerge pull request #1157 from Howaner/Window (diff)
downloadcuberite-e824cd09b369c47a7f316fccc7577cd923164466.tar
cuberite-e824cd09b369c47a7f316fccc7577cd923164466.tar.gz
cuberite-e824cd09b369c47a7f316fccc7577cd923164466.tar.bz2
cuberite-e824cd09b369c47a7f316fccc7577cd923164466.tar.lz
cuberite-e824cd09b369c47a7f316fccc7577cd923164466.tar.xz
cuberite-e824cd09b369c47a7f316fccc7577cd923164466.tar.zst
cuberite-e824cd09b369c47a7f316fccc7577cd923164466.zip
Diffstat (limited to 'src/Items')
-rw-r--r--src/Items/ItemBow.h17
-rw-r--r--src/Items/ItemHandler.cpp5
-rw-r--r--src/Items/ItemItemFrame.h1
-rw-r--r--src/Items/ItemString.h39
-rw-r--r--src/Items/ItemThrowable.h11
5 files changed, 62 insertions, 11 deletions
diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h
index e0ab339d3..185f17fee 100644
--- a/src/Items/ItemBow.h
+++ b/src/Items/ItemBow.h
@@ -46,20 +46,17 @@ public:
{
// Actual shot - produce the arrow with speed based on the ticks that the bow was charged
ASSERT(a_Player != NULL);
-
+
int BowCharge = a_Player->FinishChargingBow();
- double Force = (double)BowCharge / 20;
- Force = (Force * Force + 2 * Force) / 3; // This formula is used by the 1.6.2 client
+ double Force = (double)BowCharge / 20.0;
+ Force = (Force * Force + 2.0 * Force) / 3.0; // This formula is used by the 1.6.2 client
if (Force < 0.1)
{
// Too little force, ignore the shot
return;
}
- if (Force > 1)
- {
- Force = 1;
- }
-
+ Force = std::min(Force, 1.0);
+
// Create the arrow entity:
cArrowEntity * Arrow = new cArrowEntity(*a_Player, Force * 2);
if (Arrow == NULL)
@@ -69,11 +66,11 @@ public:
if (!Arrow->Initialize(*a_Player->GetWorld()))
{
delete Arrow;
+ Arrow = NULL;
return;
}
- a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow);
- a_Player->GetWorld()->BroadcastSoundEffect("random.bow", (int)a_Player->GetPosX() * 8, (int)a_Player->GetPosY() * 8, (int)a_Player->GetPosZ() * 8, 0.5, (float)Force);
+ a_Player->GetWorld()->BroadcastSoundEffect("random.bow", (int)a_Player->GetPosX() * 8, (int)a_Player->GetPosY() * 8, (int)a_Player->GetPosZ() * 8, 0.5, (float)Force);
if (!a_Player->IsGameModeCreative())
{
a_Player->UseEquippedItem();
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index 3d13af3a7..7fae2d395 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -46,6 +46,7 @@
#include "ItemSign.h"
#include "ItemMobHead.h"
#include "ItemSpawnEgg.h"
+#include "ItemString.h"
#include "ItemSugarcane.h"
#include "ItemSword.h"
@@ -64,7 +65,7 @@ cItemHandler * cItemHandler::m_ItemHandler[2268];
cItemHandler * cItemHandler::GetItemHandler(int a_ItemType)
{
- if (a_ItemType < 0)
+ if ((a_ItemType < 0) || ((unsigned long)a_ItemType >= ARRAYCOUNT(m_ItemHandler)))
{
// Either nothing (-1), or bad value, both cases should return the air handler
if (a_ItemType < -1)
@@ -133,6 +134,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_HEAD: return new cItemMobHeadHandler(a_ItemType);
case E_ITEM_SNOWBALL: return new cItemSnowballHandler();
case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType);
+ case E_ITEM_STRING: return new cItemStringHandler(a_ItemType);
case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType);
case E_ITEM_WOODEN_HOE:
@@ -264,6 +266,7 @@ void cItemHandler::Deinit()
for(int i = 0; i < 2267; i++)
{
delete m_ItemHandler[i];
+ m_ItemHandler[i] = NULL;
}
memset(m_ItemHandler, 0, sizeof(m_ItemHandler)); // Don't leave any dangling pointers around, just in case
m_HandlerInitialized = false;
diff --git a/src/Items/ItemItemFrame.h b/src/Items/ItemItemFrame.h
index 097f04d0b..b258b4aea 100644
--- a/src/Items/ItemItemFrame.h
+++ b/src/Items/ItemItemFrame.h
@@ -37,6 +37,7 @@ public:
if (!ItemFrame->Initialize(*a_World))
{
delete ItemFrame;
+ ItemFrame = NULL;
return false;
}
diff --git a/src/Items/ItemString.h b/src/Items/ItemString.h
new file mode 100644
index 000000000..a97fbe0ce
--- /dev/null
+++ b/src/Items/ItemString.h
@@ -0,0 +1,39 @@
+
+#pragma once
+
+#include "ItemHandler.h"
+
+
+
+
+
+class cItemStringHandler :
+ public cItemHandler
+{
+public:
+ cItemStringHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
+ {
+ }
+
+ virtual bool IsPlaceable(void) override
+ {
+ return true;
+ }
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
+ {
+ a_BlockType = E_BLOCK_TRIPWIRE;
+ a_BlockMeta = 0;
+ return true;
+ }
+};
+
+
+
+
diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h
index 35c2b8731..25935a1bc 100644
--- a/src/Items/ItemThrowable.h
+++ b/src/Items/ItemThrowable.h
@@ -31,6 +31,17 @@ public:
Vector3d Pos = a_Player->GetThrowStartPos();
Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff;
+ // Play sound
+ cFastRandom Random;
+ a_World->BroadcastSoundEffect(
+ "random.bow",
+ (int)std::floor(a_Player->GetPosX() * 8.0),
+ (int)std::floor((a_Player->GetPosY() - a_Player->GetHeight()) * 8.0),
+ (int)std::floor(a_Player->GetPosZ() * 8.0),
+ 0.5F,
+ 0.4F / (Random.NextFloat(1.0F) * 0.4F + 0.8F)
+ );
+
if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed) < 0)
{
return false;