summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities/DispenserEntity.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/DispenserEntity.cpp82
1 files changed, 44 insertions, 38 deletions
diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp
index 7257513df..e2032a041 100644
--- a/src/BlockEntities/DispenserEntity.cpp
+++ b/src/BlockEntities/DispenserEntity.cpp
@@ -9,9 +9,12 @@
#include "../World.h"
#include "../Entities/ArrowEntity.h"
#include "../Entities/FireChargeEntity.h"
+#include "../Entities/ProjectileEntity.h"
#include "../Matrix4.h"
+
+
cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, a_World)
{
@@ -143,56 +146,37 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
case E_ITEM_FIRE_CHARGE:
{
- Vector3d Speed = GetProjectileLookVector(a_Chunk);
-
- double MobX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
- double MobZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
-
-
- cFireChargeEntity* fireCharge = new cFireChargeEntity(NULL /*was this*/, MobX, (double) DispY + 0.3, MobZ, Speed);
-
-
- if (fireCharge == NULL)
- {
- break;
- }
- if (!fireCharge->Initialize(m_World))
- {
-
- delete fireCharge;
- break;
- }
- m_World->BroadcastSpawnEntity(*fireCharge);
-
- m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge);
break;
}
case E_ITEM_ARROW:
{
- Vector3d Speed = GetProjectileLookVector(a_Chunk);
-
- double MobX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
- double MobZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
+ spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow);
+ break;
+ }
- cArrowEntity* Arrow = new cArrowEntity(NULL /*was this*/, MobX, (double) DispY + 0.3, MobZ, Speed);
+ case E_ITEM_SNOWBALL:
+ {
+ // Not working as there is no such entity yet?
+ spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball);
+ break;
+ }
- if (Arrow == NULL)
- {
- break;
- }
- if (!Arrow->Initialize(m_World))
- {
+ case E_ITEM_EGG:
+ {
+ // Not working as there is no such entity yet?
+ spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg);
- delete Arrow;
- break;
- }
- m_World->BroadcastSpawnEntity(*Arrow);
+ break;
+ }
- m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ case E_ITEM_FIREWORK_ROCKET:
+ {
+ spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFirework);
break;
}
@@ -206,6 +190,20 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
}
+
+void cDispenserEntity::spawnProjectileFromDispenser(cChunk& a_Chunk, int& DispX, int& DispY, int& DispZ, cProjectileEntity::eKind kind)
+{
+ Vector3d Speed = GetProjectileLookVector(a_Chunk);
+ cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ);
+
+ double EntityX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
+ double EntityZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
+
+ m_World->CreateProjectile((double) EntityX, (double) DispY, (double) EntityZ, cProjectileEntity::pkArrow, NULL, NULL, &Speed);
+}
+
+
+
Vector3d cDispenserEntity::GetProjectileLookVector(cChunk & a_Chunk)
{
NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ);
@@ -231,6 +229,10 @@ Vector3d cDispenserEntity::GetProjectileLookVector(cChunk & a_Chunk)
}
+
+
+
+
bool cDispenserEntity::ScoopUpLiquid(int a_SlotNum, short a_BucketItemType)
{
cItem LiquidBucket(a_BucketItemType, 1);
@@ -289,3 +291,7 @@ bool cDispenserEntity::EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum
m_Contents.AddItem(EmptyBucket);
return true;
}
+
+
+
+