From 74801f564775ae4c6b70834f76167a54b8a84826 Mon Sep 17 00:00:00 2001 From: JoannisO Date: Mon, 26 May 2014 14:47:04 +0200 Subject: [PATCH] - 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 --- src/BlockEntities/DispenserEntity.cpp | 82 ++++++++++++++------------- src/BlockEntities/DispenserEntity.h | 7 +++ 2 files changed, 51 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); + 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); + break; + } + case E_ITEM_SNOWBALL: + { + // Not working as there is no such entity yet? + spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball); - cArrowEntity* Arrow = new cArrowEntity(NULL /*was this*/, MobX, (double) DispY + 0.3, MobZ, Speed); + break; + } + case E_ITEM_EGG: + { + // Not working as there is no such entity yet? + spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg); - if (Arrow == NULL) - { - break; - } - if (!Arrow->Initialize(m_World)) - { + break; + } - delete Arrow; - break; - } - m_World->BroadcastSpawnEntity(*Arrow); - - 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; } + + + + diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h index 02a34be37..9290bee5c 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -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 + + + +