1
0

Added Arrow- and FireCharge-Dispensing to DispenserEntity.

This commit is contained in:
JoannisO 2014-05-26 08:44:16 +02:00
parent 2eca98a41a
commit c9c2a4f479
2 changed files with 95 additions and 27 deletions

View File

@ -6,8 +6,10 @@
#include "../Simulator/FluidSimulator.h" #include "../Simulator/FluidSimulator.h"
#include "../Chunk.h" #include "../Chunk.h"
#include "../World.h"
#include "../Entities/ArrowEntity.h"
#include "../Entities/FireChargeEntity.h"
#include "../Matrix4.h"
cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
@ -141,7 +143,57 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
case E_ITEM_FIRE_CHARGE: case E_ITEM_FIRE_CHARGE:
{ {
// TODO: Spawn fireball entity 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);
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);
cArrowEntity* Arrow = new cArrowEntity(NULL /*was this*/, MobX, (double) DispY + 0.3, MobZ, Speed);
if (Arrow == NULL)
{
break;
}
if (!Arrow->Initialize(m_World))
{
delete Arrow;
break;
}
m_World->BroadcastSpawnEntity(*Arrow);
m_Contents.ChangeSlotCount(a_SlotNum, -1);
break; break;
} }
@ -154,8 +206,29 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
} }
Vector3d cDispenserEntity::GetProjectileLookVector(cChunk & a_Chunk)
{
NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ);
int Direction = 0;
switch (Meta)
{
case E_META_DROPSPENSER_FACING_YP: Direction = 0; break; // YP & YM don't have associated smoke dirs, just do 4 (centre of block)
case E_META_DROPSPENSER_FACING_YM: Direction = 0; break;
case E_META_DROPSPENSER_FACING_XM: Direction = 90; break; // WEST
case E_META_DROPSPENSER_FACING_XP: Direction = 270; break; // EAST
case E_META_DROPSPENSER_FACING_ZM: Direction = 180; break;
case E_META_DROPSPENSER_FACING_ZP: Direction = 0; break;
}
Matrix4d m;
m.Init(Vector3d(), 0, Direction, 0);
Vector3d Look = m.Transform(Vector3d(0, 0, 1));
Vector3d Speed = Look * 20;
Speed.y = Speed.y + 1;
return Speed;
}
bool cDispenserEntity::ScoopUpLiquid(int a_SlotNum, short a_BucketItemType) bool cDispenserEntity::ScoopUpLiquid(int a_SlotNum, short a_BucketItemType)
@ -216,7 +289,3 @@ bool cDispenserEntity::EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum
m_Contents.AddItem(EmptyBucket); m_Contents.AddItem(EmptyBucket);
return true; return true;
} }

View File

@ -29,10 +29,9 @@ private:
/// If such a bucket can fit, adds it to m_Contents and returns true /// If such a bucket can fit, adds it to m_Contents and returns true
bool ScoopUpLiquid(int a_SlotNum, short a_BucketItemType); bool ScoopUpLiquid(int a_SlotNum, short a_BucketItemType);
// Returns how to aim the projectile
Vector3d GetProjectileLookVector(cChunk & a_Chunk);
/// If the a_BlockInFront is liquidable and the empty bucket can fit, does the m_Contents processing and returns true /// If the a_BlockInFront is liquidable and the empty bucket can fit, does the m_Contents processing and returns true
bool EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum); bool EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum);
} ; // tolua_export } ; // tolua_export