1
0

- Added support for more types of projectiles in the Dispenser

- Improved the method of spawning projectiles in the world
- Added another method for spawning the projectiles
This commit is contained in:
JoannisO 2014-05-26 14:47:04 +02:00
parent c9c2a4f479
commit 74801f5647
2 changed files with 51 additions and 38 deletions

View File

@ -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);
spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow);
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;
case E_ITEM_SNOWBALL:
{
// Not working as there is no such entity yet?
spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball);
break;
}
m_World->BroadcastSpawnEntity(*Arrow);
m_Contents.ChangeSlotCount(a_SlotNum, -1);
case E_ITEM_EGG:
{
// Not working as there is no such entity yet?
spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg);
break;
}
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;
}

View File

@ -29,9 +29,16 @@ private:
/// If such a bucket can fit, adds it to m_Contents and returns true
bool ScoopUpLiquid(int a_SlotNum, short a_BucketItemType);
// Spawns a projectile of the given kind in front of the dispenser
void spawnProjectileFromDispenser(cChunk& a_Chunk, int& DispX, int& DispY, int& DispZ, cProjectileEntity::eKind kind);
// 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