Added Arrow- and FireCharge-Dispensing to DispenserEntity.
This commit is contained in:
parent
2eca98a41a
commit
c9c2a4f479
@ -6,8 +6,10 @@
|
||||
#include "../Simulator/FluidSimulator.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) :
|
||||
@ -141,7 +143,57 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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)
|
||||
@ -216,7 +289,3 @@ bool cDispenserEntity::EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum
|
||||
m_Contents.AddItem(EmptyBucket);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -29,10 +29,9 @@ private:
|
||||
/// If such a bucket can fit, adds it to m_Contents and returns true
|
||||
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
|
||||
bool EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum);
|
||||
} ; // tolua_export
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user