From c9c2a4f479474fe03acce598ba2687a0f4817083 Mon Sep 17 00:00:00 2001 From: JoannisO Date: Mon, 26 May 2014 08:44:16 +0200 Subject: Added Arrow- and FireCharge-Dispensing to DispenserEntity. --- src/BlockEntities/DispenserEntity.cpp | 107 ++++++++++++++++++++++++++++------ src/BlockEntities/DispenserEntity.h | 15 +++-- 2 files changed, 95 insertions(+), 27 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 2a32f69d9..7257513df 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -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) : @@ -69,7 +71,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) } break; } // E_ITEM_BUCKET - + case E_ITEM_WATER_BUCKET: { LOGD("Dispensing water bucket in slot %d; DispBlock is \"%s\" (%d).", a_SlotNum, ItemTypeToString(DispBlock).c_str(), DispBlock); @@ -83,7 +85,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) } break; } - + case E_ITEM_LAVA_BUCKET: { LOGD("Dispensing lava bucket in slot %d; DispBlock is \"%s\" (%d).", a_SlotNum, ItemTypeToString(DispBlock).c_str(), DispBlock); @@ -97,7 +99,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) } break; } - + case E_ITEM_SPAWN_EGG: { double MobX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width); @@ -108,7 +110,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) } break; } - + case E_BLOCK_TNT: { // Spawn a primed TNT entity, if space allows: @@ -128,7 +130,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) if (DispChunk->GetBlock(DispX, DispY, DispZ) == E_BLOCK_AIR) { DispChunk->SetBlock(DispX, DispY, DispZ, E_BLOCK_FIRE, 0); - + bool ItemBroke = m_Contents.DamageItem(a_SlotNum, 1); if (ItemBroke) @@ -138,13 +140,63 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) } break; } - + 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; } - + default: { DropFromSlot(a_Chunk, a_SlotNum); @@ -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) @@ -167,14 +240,14 @@ bool cDispenserEntity::ScoopUpLiquid(int a_SlotNum, short a_BucketItemType) m_Contents.SetSlot(a_SlotNum, LiquidBucket); return true; } - + // There are stacked buckets at the selected slot, see if a full bucket will fit somewhere else if (m_Contents.HowManyCanFit(LiquidBucket) < 1) { // Cannot fit into m_Contents return false; } - + m_Contents.ChangeSlotCount(a_SlotNum, -1); m_Contents.AddItem(LiquidBucket); return true; @@ -195,7 +268,7 @@ bool cDispenserEntity::EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum // Not a suitable block in front return false; } - + cItem EmptyBucket(E_ITEM_BUCKET, 1); if (m_Contents.GetSlot(a_SlotNum).m_ItemCount == 1) { @@ -203,20 +276,16 @@ bool cDispenserEntity::EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum m_Contents.SetSlot(a_SlotNum, EmptyBucket); return true; } - + // There are full buckets stacked at this slot, check if we can fit in the empty bucket if (m_Contents.HowManyCanFit(EmptyBucket) < 1) { // The empty bucket wouldn't fit into m_Contents return false; } - + // The empty bucket fits in, remove one full bucket and add the empty one m_Contents.ChangeSlotCount(a_SlotNum, -1); m_Contents.AddItem(EmptyBucket); return true; } - - - - diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h index fdfe4e5b4..02a34be37 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -12,11 +12,11 @@ class cDispenserEntity : public cDropSpenserEntity { typedef cDropSpenserEntity super; - + public: // tolua_end - + /// Constructor used for normal operation cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); @@ -25,14 +25,13 @@ public: private: // cDropSpenser overrides: virtual void DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) override; - + /// 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 - - - - -- cgit v1.2.3 From 74801f564775ae4c6b70834f76167a54b8a84826 Mon Sep 17 00:00:00 2001 From: JoannisO Date: Mon, 26 May 2014 14:47:04 +0200 Subject: - 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(-) (limited to 'src/BlockEntities') 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; } + + + + 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 + + + + -- cgit v1.2.3 From 1128dc783f4ee0913f3395c0a79ebdbbce2cfdee Mon Sep 17 00:00:00 2001 From: Joannis Date: Tue, 27 May 2014 11:08:06 +0200 Subject: - Fixed the ampersands and asterisks to fit the format. - Fixed the method "SpawnProjectileFromDispenser" to use CamelCasing. --- src/BlockEntities/DispenserEntity.cpp | 14 +++++++------- src/BlockEntities/DispenserEntity.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index e2032a041..0f64118ef 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -146,14 +146,14 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIRE_CHARGE: { - spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge); + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge); break; } case E_ITEM_ARROW: { - spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow); + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow); break; } @@ -161,7 +161,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_SNOWBALL: { // Not working as there is no such entity yet? - spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball); + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball); break; } @@ -169,14 +169,14 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_EGG: { // Not working as there is no such entity yet? - spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg); + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg); break; } case E_ITEM_FIREWORK_ROCKET: { - spawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFirework); + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFirework); break; } @@ -191,7 +191,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) -void cDispenserEntity::spawnProjectileFromDispenser(cChunk& a_Chunk, int& DispX, int& DispY, int& DispZ, cProjectileEntity::eKind kind) +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); @@ -199,7 +199,7 @@ void cDispenserEntity::spawnProjectileFromDispenser(cChunk& a_Chunk, int& DispX, 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); + m_World->CreateProjectile((double) EntityX, (double) DispY, (double) EntityZ, cProjectileEntity::pkArrow, NULL, NULL, & Speed); } diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h index 9290bee5c..8bc2475c9 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -30,7 +30,7 @@ private: 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); + 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); -- cgit v1.2.3 From e5fd782524cdf4b838ad689baef44a61aa4933c2 Mon Sep 17 00:00:00 2001 From: Joannis Date: Wed, 28 May 2014 09:10:09 +0200 Subject: - Implemented vertical dispensing for projectiles. - Fixed some terrible commit issues on my side. --- src/BlockEntities/DispenserEntity.cpp | 54 +++++++++++++++++++++++++---------- src/BlockEntities/DispenserEntity.h | 2 +- 2 files changed, 40 insertions(+), 16 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 0f64118ef..638a844e6 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -147,6 +147,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIRE_CHARGE: { SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge); + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; } @@ -154,6 +155,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_ARROW: { SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow); + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; } @@ -162,6 +164,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) { // Not working as there is no such entity yet? SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball); + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; } @@ -170,6 +173,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) { // Not working as there is no such entity yet? SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg); + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; } @@ -177,6 +181,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIREWORK_ROCKET: { SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFirework); + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; } @@ -199,7 +204,7 @@ void cDispenserEntity::SpawnProjectileFromDispenser(cChunk & a_Chunk, int & Disp 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); + m_World->CreateProjectile((double) EntityX, (double) DispY + 0.5, (double) EntityZ, cProjectileEntity::pkArrow, NULL, NULL, &Speed); } @@ -210,22 +215,45 @@ Vector3d cDispenserEntity::GetProjectileLookVector(cChunk & a_Chunk) 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_YP: Direction = -1; break; // UP + case E_META_DROPSPENSER_FACING_YM: Direction = -2; break; // DOWN + 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)); + if(Direction >= 0) + { + 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; + + } else if(Direction == -1) + { + Matrix4d m; + m.Init(Vector3d(), 0, 180, 0); + Vector3d Look = m.Transform(Vector3d(0, 1, 0)); + + Vector3d Speed = Look * 20; + + return Speed; - Vector3d Speed = Look * 20; - Speed.y = Speed.y + 1; + } else { - return Speed; + Matrix4d m; + m.Init(Vector3d(), 0, -360, 0); + Vector3d Look = m.Transform(Vector3d(0, -1, 0)); + + Vector3d Speed = Look * 20; + + return Speed; + } } @@ -291,7 +319,3 @@ 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 8bc2475c9..0b7cd6bea 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -30,7 +30,7 @@ private: 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); + 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); -- cgit v1.2.3 From 4bc02781af063456db438885d7f3cc8830d5cd92 Mon Sep 17 00:00:00 2001 From: JoannisO Date: Wed, 28 May 2014 14:34:33 +0200 Subject: - Fixed an issue where dispensers would only shoot arrows (appearantly some commits didn't come through) - Cleaned up the code according to suggestions. --- src/BlockEntities/DispenserEntity.cpp | 57 +++++++++++++++-------------------- 1 file changed, 24 insertions(+), 33 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 638a844e6..2b0487c4a 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -198,13 +198,13 @@ 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); + Vector3d Angle = 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 + 0.5, (double) EntityZ, cProjectileEntity::pkArrow, NULL, NULL, &Speed); + m_World->CreateProjectile((double) EntityX, (double) DispY + 0.5, (double) EntityZ, kind, NULL, NULL, &Angle); } @@ -213,47 +213,38 @@ Vector3d cDispenserEntity::GetProjectileLookVector(cChunk & a_Chunk) { NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ); int Direction = 0; + Matrix4d m; + Vector3d Look; + switch (Meta) { - case E_META_DROPSPENSER_FACING_YP: Direction = -1; break; // UP - case E_META_DROPSPENSER_FACING_YM: Direction = -2; break; // DOWN + case E_META_DROPSPENSER_FACING_YP: + m.Init(Vector3d(), 0, 180, 0); + Look = m.Transform(Vector3d(0, 1, 0)); + + return Look * 20; // UP + break; + + case E_META_DROPSPENSER_FACING_YM: + m.Init(Vector3d(), 0, -360, 0); + Look = m.Transform(Vector3d(0, -1, 0)); + + return Look * 20;; // DOWN + 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; } - if(Direction >= 0) - { - 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; + m.Init(Vector3d(), 0, Direction, 0); + Look = m.Transform(Vector3d(0, 0, 1)); - return Speed; + Vector3d Angle = Look * 20; + Angle.y = Angle.y + 1; - } else if(Direction == -1) - { - Matrix4d m; - m.Init(Vector3d(), 0, 180, 0); - Vector3d Look = m.Transform(Vector3d(0, 1, 0)); - - Vector3d Speed = Look * 20; - - return Speed; - - } else { - - Matrix4d m; - m.Init(Vector3d(), 0, -360, 0); - Vector3d Look = m.Transform(Vector3d(0, -1, 0)); - - Vector3d Speed = Look * 20; - - return Speed; - } + return Angle; } -- cgit v1.2.3 From 427bddc18970bb66aa1f396c4fd19e52e3ad602d Mon Sep 17 00:00:00 2001 From: JoannisO Date: Wed, 28 May 2014 15:16:45 +0200 Subject: - Removed breaks. I thought it wouldn't compile without them but the issue was appearantly solved with an earlier commit. --- src/BlockEntities/DispenserEntity.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 2b0487c4a..341994be8 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -223,14 +223,12 @@ Vector3d cDispenserEntity::GetProjectileLookVector(cChunk & a_Chunk) Look = m.Transform(Vector3d(0, 1, 0)); return Look * 20; // UP - break; case E_META_DROPSPENSER_FACING_YM: m.Init(Vector3d(), 0, -360, 0); Look = m.Transform(Vector3d(0, -1, 0)); return Look * 20;; // DOWN - break; case E_META_DROPSPENSER_FACING_XM: Direction = 90; break; // WEST case E_META_DROPSPENSER_FACING_XP: Direction = 270; break; // EAST -- cgit v1.2.3 From d8072da61f8a098ea30f579034ad976cf86408f3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 28 May 2014 15:54:43 +0200 Subject: Fix skull bugs. --- src/BlockEntities/MobHeadEntity.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp index dc9c18d58..60d6a123f 100644 --- a/src/BlockEntities/MobHeadEntity.cpp +++ b/src/BlockEntities/MobHeadEntity.cpp @@ -70,6 +70,11 @@ void cMobHeadEntity::SetOwner(const AString & a_Owner) void cMobHeadEntity::SendTo(cClientHandle & a_Client) { + BLOCKTYPE Block; + NIBBLETYPE Meta; + a_Client.GetPlayer()->GetWorld()->GetBlockTypeMeta(m_PosX, m_PosY, m_PosZ, Block, Meta); + + a_Client.SendBlockChange(m_PosX, m_PosY, m_PosZ, Block, Meta); a_Client.SendUpdateBlockEntity(*this); } -- cgit v1.2.3 From 142fa83124fc3b766916ac79fb037fea91a19a1e Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 28 May 2014 19:32:20 +0200 Subject: Code improvements --- src/BlockEntities/MobHeadEntity.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp index 60d6a123f..ce895eb6f 100644 --- a/src/BlockEntities/MobHeadEntity.cpp +++ b/src/BlockEntities/MobHeadEntity.cpp @@ -70,11 +70,8 @@ void cMobHeadEntity::SetOwner(const AString & a_Owner) void cMobHeadEntity::SendTo(cClientHandle & a_Client) { - BLOCKTYPE Block; - NIBBLETYPE Meta; - a_Client.GetPlayer()->GetWorld()->GetBlockTypeMeta(m_PosX, m_PosY, m_PosZ, Block, Meta); - - a_Client.SendBlockChange(m_PosX, m_PosY, m_PosZ, Block, Meta); + cWorld * World = a_Client.GetPlayer()->GetWorld(); + a_Client.SendBlockChange(m_PosX, m_PosY, m_PosZ, m_BlockType, World->GetBlockMeta(m_PosX, m_PosY, m_PosZ)); a_Client.SendUpdateBlockEntity(*this); } -- cgit v1.2.3 From ab633c8bd65b333630053334cb1119f38788698d Mon Sep 17 00:00:00 2001 From: JoannisO Date: Thu, 29 May 2014 20:19:36 +0200 Subject: - Prefixed all args with "a_" - Added braces around the cases. --- src/BlockEntities/DispenserEntity.cpp | 14 +++++++++----- src/BlockEntities/DispenserEntity.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 341994be8..799d41a1e 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -196,15 +196,15 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) -void cDispenserEntity::SpawnProjectileFromDispenser(cChunk & a_Chunk, int & DispX, int & DispY, int & DispZ, cProjectileEntity::eKind kind) +void cDispenserEntity::SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind) { Vector3d Angle = GetProjectileLookVector(a_Chunk); - cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); + cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(a_DispX, a_DispZ); - double EntityX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width); - double EntityZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); + double EntityX = 0.5 + (a_DispX + DispChunk->GetPosX() * cChunkDef::Width); + double EntityZ = 0.5 + (a_DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - m_World->CreateProjectile((double) EntityX, (double) DispY + 0.5, (double) EntityZ, kind, NULL, NULL, &Angle); + m_World->CreateProjectile((double) EntityX, (double) a_DispY + 0.5, (double) EntityZ, a_kind, NULL, NULL, &Angle); } @@ -219,16 +219,20 @@ Vector3d cDispenserEntity::GetProjectileLookVector(cChunk & a_Chunk) switch (Meta) { case E_META_DROPSPENSER_FACING_YP: + { m.Init(Vector3d(), 0, 180, 0); Look = m.Transform(Vector3d(0, 1, 0)); return Look * 20; // UP + } case E_META_DROPSPENSER_FACING_YM: + { m.Init(Vector3d(), 0, -360, 0); Look = m.Transform(Vector3d(0, -1, 0)); return Look * 20;; // DOWN + } case E_META_DROPSPENSER_FACING_XM: Direction = 90; break; // WEST case E_META_DROPSPENSER_FACING_XP: Direction = 270; break; // EAST diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h index 0b7cd6bea..76aaccd3c 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -30,7 +30,7 @@ private: 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); + void SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind); // Returns how to aim the projectile Vector3d GetProjectileLookVector(cChunk & a_Chunk); -- cgit v1.2.3 From b436359237a9faa1dc5709e4359b73aa6faf4f78 Mon Sep 17 00:00:00 2001 From: JoannisO Date: Sat, 31 May 2014 16:08:15 +0200 Subject: - Changed the name of the ProjectileLookVector method. Note: I still think the new name is unclear. Any other suggestions are welcome. --- src/BlockEntities/DispenserEntity.cpp | 4 ++-- src/BlockEntities/DispenserEntity.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 799d41a1e..db1b405cd 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -198,7 +198,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) void cDispenserEntity::SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind) { - Vector3d Angle = GetProjectileLookVector(a_Chunk); + Vector3d Angle = GetShootVector(a_Chunk); cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(a_DispX, a_DispZ); double EntityX = 0.5 + (a_DispX + DispChunk->GetPosX() * cChunkDef::Width); @@ -209,7 +209,7 @@ void cDispenserEntity::SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_Di -Vector3d cDispenserEntity::GetProjectileLookVector(cChunk & a_Chunk) +Vector3d cDispenserEntity::GetShootVector(cChunk & a_Chunk) { NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ); int Direction = 0; diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h index 76aaccd3c..adbe2070c 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -33,7 +33,7 @@ private: void SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind); // Returns how to aim the projectile - Vector3d GetProjectileLookVector(cChunk & a_Chunk); + Vector3d GetShootVector(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); -- cgit v1.2.3 From 545478802b7a8b81ecb9d20ad3355eff1427f575 Mon Sep 17 00:00:00 2001 From: Joannis Date: Tue, 3 Jun 2014 09:26:14 +0200 Subject: - Added doxy comments and exported to lua - Manipulation of the ShootVector is not to be done by the function that wants to spawn a projectile. --- src/BlockEntities/DispenserEntity.cpp | 74 +++++++++++++++++++++++++++-------- src/BlockEntities/DispenserEntity.h | 12 +++--- 2 files changed, 64 insertions(+), 22 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index db1b405cd..043a140e3 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -146,7 +146,18 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIRE_CHARGE: { - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge); + if(Meta == E_META_DROPSPENSER_FACING_YP || Meta == E_META_DROPSPENSER_FACING_YM) + { + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge, GetShootVector(a_Chunk) * 20); + } + else + { + Vector3d ShootVector = GetShootVector(a_Chunk); + ShootVector = ShootVector * 20; + + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge, ShootVector); + } + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -154,7 +165,19 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_ARROW: { - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow); + if(Meta == E_META_DROPSPENSER_FACING_YP || Meta == E_META_DROPSPENSER_FACING_YM) + { + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow, GetShootVector(a_Chunk) * 20); + } + else + { + Vector3d ShootVector = GetShootVector(a_Chunk); + ShootVector = ShootVector * 20; + ShootVector.y = ShootVector.y + 1; + + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow, ShootVector); + } + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -162,8 +185,19 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_SNOWBALL: { - // Not working as there is no such entity yet? - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball); + if(Meta == E_META_DROPSPENSER_FACING_YP || Meta == E_META_DROPSPENSER_FACING_YM) + { + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball, GetShootVector(a_Chunk) * 20); + } + else + { + Vector3d ShootVector = GetShootVector(a_Chunk); + ShootVector = ShootVector * 20; + ShootVector.y = ShootVector.y + 1; + + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball, ShootVector); + } + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -171,8 +205,19 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_EGG: { - // Not working as there is no such entity yet? - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg); + if(Meta == E_META_DROPSPENSER_FACING_YP || Meta == E_META_DROPSPENSER_FACING_YM) + { + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg, GetShootVector(a_Chunk) * 20); + } + else + { + Vector3d ShootVector = GetShootVector(a_Chunk); + ShootVector = ShootVector * 20; + ShootVector.y = ShootVector.y + 1; + + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg, ShootVector); + } + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -180,7 +225,8 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIREWORK_ROCKET: { - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFirework); + SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFirework, GetShootVector(a_Chunk) * 0); + m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -196,15 +242,14 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) -void cDispenserEntity::SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind) +void cDispenserEntity::SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector) { - Vector3d Angle = GetShootVector(a_Chunk); cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(a_DispX, a_DispZ); double EntityX = 0.5 + (a_DispX + DispChunk->GetPosX() * cChunkDef::Width); double EntityZ = 0.5 + (a_DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - m_World->CreateProjectile((double) EntityX, (double) a_DispY + 0.5, (double) EntityZ, a_kind, NULL, NULL, &Angle); + m_World->CreateProjectile((double) EntityX, (double) a_DispY + 0.5, (double) EntityZ, a_kind, NULL, NULL, &a_ShootVector); } @@ -223,7 +268,7 @@ Vector3d cDispenserEntity::GetShootVector(cChunk & a_Chunk) m.Init(Vector3d(), 0, 180, 0); Look = m.Transform(Vector3d(0, 1, 0)); - return Look * 20; // UP + return Look; // UP } case E_META_DROPSPENSER_FACING_YM: @@ -231,7 +276,7 @@ Vector3d cDispenserEntity::GetShootVector(cChunk & a_Chunk) m.Init(Vector3d(), 0, -360, 0); Look = m.Transform(Vector3d(0, -1, 0)); - return Look * 20;; // DOWN + return Look; // DOWN } case E_META_DROPSPENSER_FACING_XM: Direction = 90; break; // WEST @@ -243,10 +288,7 @@ Vector3d cDispenserEntity::GetShootVector(cChunk & a_Chunk) m.Init(Vector3d(), 0, Direction, 0); Look = m.Transform(Vector3d(0, 0, 1)); - Vector3d Angle = Look * 20; - Angle.y = Angle.y + 1; - - return Angle; + return Look; } diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h index adbe2070c..558cf41c5 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -22,6 +22,12 @@ public: static const char * GetClassStatic(void) { return "cDispenserEntity"; } + /** Spawns a projectile of the given kind in front of the dispenser */ + void SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector); // tolua_export + + /** Returns how to aim the projectile */ + Vector3d GetShootVector(cChunk & a_Chunk); // tolua_export + private: // cDropSpenser overrides: virtual void DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) override; @@ -29,12 +35,6 @@ 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 & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind); - - // Returns how to aim the projectile - Vector3d GetShootVector(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 -- cgit v1.2.3 From daae75b30b7d5e70a26e1518cd7c75988dbfdf9f Mon Sep 17 00:00:00 2001 From: JoannisO Date: Tue, 3 Jun 2014 17:21:38 +0200 Subject: - Cleaned up the code massively - Stopped using cChunk in the GetShootVector class. Parameter is now the Metadata of the block - Stopped using cChunk in the SpawnProjectileFromDispenser method now using coordinates and finding the chunk by itself. - Removed the matrix calculations from GetShootVector. --- src/BlockEntities/DispenserEntity.cpp | 113 +++++++++------------------------- src/BlockEntities/DispenserEntity.h | 8 +-- 2 files changed, 31 insertions(+), 90 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 043a140e3..2ac7c085c 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -146,17 +146,11 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIRE_CHARGE: { - if(Meta == E_META_DROPSPENSER_FACING_YP || Meta == E_META_DROPSPENSER_FACING_YM) - { - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge, GetShootVector(a_Chunk) * 20); - } - else - { - Vector3d ShootVector = GetShootVector(a_Chunk); - ShootVector = ShootVector * 20; + cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); + int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); + int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFireCharge, ShootVector); - } + SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkFireCharge, GetShootVector(Meta) * 20); m_Contents.ChangeSlotCount(a_SlotNum, -1); @@ -165,18 +159,11 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_ARROW: { - if(Meta == E_META_DROPSPENSER_FACING_YP || Meta == E_META_DROPSPENSER_FACING_YM) - { - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow, GetShootVector(a_Chunk) * 20); - } - else - { - Vector3d ShootVector = GetShootVector(a_Chunk); - ShootVector = ShootVector * 20; - ShootVector.y = ShootVector.y + 1; + cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); + int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); + int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkArrow, ShootVector); - } + SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkArrow, GetShootVector(Meta) * 20); m_Contents.ChangeSlotCount(a_SlotNum, -1); @@ -185,18 +172,11 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_SNOWBALL: { - if(Meta == E_META_DROPSPENSER_FACING_YP || Meta == E_META_DROPSPENSER_FACING_YM) - { - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball, GetShootVector(a_Chunk) * 20); - } - else - { - Vector3d ShootVector = GetShootVector(a_Chunk); - ShootVector = ShootVector * 20; - ShootVector.y = ShootVector.y + 1; + cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); + int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); + int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkSnowball, ShootVector); - } + SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkSnowball, GetShootVector(Meta) * 20); m_Contents.ChangeSlotCount(a_SlotNum, -1); @@ -205,27 +185,18 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_EGG: { - if(Meta == E_META_DROPSPENSER_FACING_YP || Meta == E_META_DROPSPENSER_FACING_YM) - { - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg, GetShootVector(a_Chunk) * 20); - } - else - { - Vector3d ShootVector = GetShootVector(a_Chunk); - ShootVector = ShootVector * 20; - ShootVector.y = ShootVector.y + 1; + cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); + int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); + int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkEgg, ShootVector); - } - - m_Contents.ChangeSlotCount(a_SlotNum, -1); + SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkEgg, GetShootVector(Meta) * 20); break; } case E_ITEM_FIREWORK_ROCKET: { - SpawnProjectileFromDispenser(a_Chunk, DispX, DispY, DispZ, cProjectileEntity::pkFirework, GetShootVector(a_Chunk) * 0); + // TODO: Add the fireworks entity m_Contents.ChangeSlotCount(a_SlotNum, -1); @@ -242,60 +213,34 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) -void cDispenserEntity::SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector) +void cDispenserEntity::SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector) { - cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(a_DispX, a_DispZ); - - double EntityX = 0.5 + (a_DispX + DispChunk->GetPosX() * cChunkDef::Width); - double EntityZ = 0.5 + (a_DispZ + DispChunk->GetPosZ() * cChunkDef::Width); + if(a_kind != E_ITEM_FIRE_CHARGE) + a_ShootVector.y = a_ShootVector.y + 1; - m_World->CreateProjectile((double) EntityX, (double) a_DispY + 0.5, (double) EntityZ, a_kind, NULL, NULL, &a_ShootVector); + m_World->CreateProjectile((double) a_BlockX + 0.5, (double) a_BlockY + 0.5, (double) a_BlockZ + 0.5, a_kind, NULL, NULL, &a_ShootVector); } - -Vector3d cDispenserEntity::GetShootVector(cChunk & a_Chunk) +Vector3d cDispenserEntity::GetShootVector(NIBBLETYPE & a_Meta) { - NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ); - int Direction = 0; - Matrix4d m; - Vector3d Look; - - switch (Meta) + switch(a_Meta) { - case E_META_DROPSPENSER_FACING_YP: - { - m.Init(Vector3d(), 0, 180, 0); - Look = m.Transform(Vector3d(0, 1, 0)); + case E_META_DROPSPENSER_FACING_YP: return Vector3d(0, 1, 0); // UP + case E_META_DROPSPENSER_FACING_YM: return Vector3d(0, -1, 0); // DOWN - return Look; // UP - } - - case E_META_DROPSPENSER_FACING_YM: - { - m.Init(Vector3d(), 0, -360, 0); - Look = m.Transform(Vector3d(0, -1, 0)); - - return Look; // DOWN - } + case E_META_DROPSPENSER_FACING_XM: return Vector3d(-1, 0, 0); // WEST + case E_META_DROPSPENSER_FACING_XP: return Vector3d(1, 0, 0); // EAST - 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; + case E_META_DROPSPENSER_FACING_ZM: return Vector3d(0, 0, -1); + case E_META_DROPSPENSER_FACING_ZP: return Vector3d(0, 0, 1); } - - m.Init(Vector3d(), 0, Direction, 0); - Look = m.Transform(Vector3d(0, 0, 1)); - - return Look; } - bool cDispenserEntity::ScoopUpLiquid(int a_SlotNum, short a_BucketItemType) { cItem LiquidBucket(a_BucketItemType, 1); diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h index 558cf41c5..5a2de7965 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -23,10 +23,10 @@ public: static const char * GetClassStatic(void) { return "cDispenserEntity"; } /** Spawns a projectile of the given kind in front of the dispenser */ - void SpawnProjectileFromDispenser(cChunk & a_Chunk, int & a_DispX, int & a_DispY, int & a_DispZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector); // tolua_export + void SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector); /** Returns how to aim the projectile */ - Vector3d GetShootVector(cChunk & a_Chunk); // tolua_export + Vector3d GetShootVector(NIBBLETYPE & a_Meta); private: // cDropSpenser overrides: @@ -38,7 +38,3 @@ private: /// 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 - - - - -- cgit v1.2.3 From 2ecf425c39452a96398346d114525eeff7cbf50a Mon Sep 17 00:00:00 2001 From: JoannisO Date: Tue, 3 Jun 2014 18:19:06 +0200 Subject: - Fixed a bug where I used the FireCharge ITEM instead of the Projectile ENUM --- src/BlockEntities/DispenserEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 2ac7c085c..904ab871b 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -215,7 +215,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) void cDispenserEntity::SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector) { - if(a_kind != E_ITEM_FIRE_CHARGE) + if(a_kind != cProjectileEntity::pkFireCharge) a_ShootVector.y = a_ShootVector.y + 1; m_World->CreateProjectile((double) a_BlockX + 0.5, (double) a_BlockY + 0.5, (double) a_BlockZ + 0.5, a_kind, NULL, NULL, &a_ShootVector); -- cgit v1.2.3 From c0716bfcf6cce720f41e98544eb4a4532a694a0a Mon Sep 17 00:00:00 2001 From: JoannisO Date: Tue, 3 Jun 2014 19:39:56 +0200 Subject: - Fixed a bug where I didn't return anything in the GetShootVector function. This was however passed as "working" by GCC. --- src/BlockEntities/DispenserEntity.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 904ab871b..bbf924417 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -235,6 +235,8 @@ Vector3d cDispenserEntity::GetShootVector(NIBBLETYPE & a_Meta) case E_META_DROPSPENSER_FACING_ZM: return Vector3d(0, 0, -1); case E_META_DROPSPENSER_FACING_ZP: return Vector3d(0, 0, 1); } + + return Vector3d(0, 1, 0); } -- cgit v1.2.3 From 7993caa553e3317da21763226bf6bd5c2e965f8c Mon Sep 17 00:00:00 2001 From: JoannisO Date: Tue, 3 Jun 2014 19:43:15 +0200 Subject: - Fixed an issue where there were 2 "DispChunk"-s in the same function. Resused the initial one. --- src/BlockEntities/DispenserEntity.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index bbf924417..a4a660034 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -38,7 +38,10 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) // Would dispense into / interact with a non-loaded chunk, ignore the tick return; } + BLOCKTYPE DispBlock = DispChunk->GetBlock(DispX, DispY, DispZ); + int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); + int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); // Dispense the item: switch (m_Contents.GetSlot(a_SlotNum).m_ItemType) @@ -146,10 +149,6 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIRE_CHARGE: { - cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); - int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); - int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkFireCharge, GetShootVector(Meta) * 20); m_Contents.ChangeSlotCount(a_SlotNum, -1); @@ -159,10 +158,6 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_ARROW: { - cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); - int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); - int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkArrow, GetShootVector(Meta) * 20); m_Contents.ChangeSlotCount(a_SlotNum, -1); @@ -172,10 +167,6 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_SNOWBALL: { - cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); - int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); - int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkSnowball, GetShootVector(Meta) * 20); m_Contents.ChangeSlotCount(a_SlotNum, -1); @@ -185,12 +176,10 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_EGG: { - cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ); - int BlockX = (DispX + DispChunk->GetPosX() * cChunkDef::Width); - int BlockZ = (DispZ + DispChunk->GetPosZ() * cChunkDef::Width); - SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkEgg, GetShootVector(Meta) * 20); + m_Contents.ChangeSlotCount(a_SlotNum, -1); + break; } -- cgit v1.2.3 From 2c103a713e0ce77ccb8b86c98e2571d5ba6dd9c0 Mon Sep 17 00:00:00 2001 From: JoannisO Date: Wed, 4 Jun 2014 12:35:45 +0200 Subject: - Fixed a lot of astethics --- src/BlockEntities/DispenserEntity.cpp | 26 +++++++++++++------------- src/BlockEntities/DispenserEntity.h | 5 ++++- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index a4a660034..242ac4024 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -10,7 +10,6 @@ #include "../Entities/ArrowEntity.h" #include "../Entities/FireChargeEntity.h" #include "../Entities/ProjectileEntity.h" -#include "../Matrix4.h" @@ -150,7 +149,6 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIRE_CHARGE: { SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkFireCharge, GetShootVector(Meta) * 20); - m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -159,7 +157,6 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_ARROW: { SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkArrow, GetShootVector(Meta) * 20); - m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -168,7 +165,6 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_SNOWBALL: { SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkSnowball, GetShootVector(Meta) * 20); - m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -177,7 +173,6 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_EGG: { SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkEgg, GetShootVector(Meta) * 20); - m_Contents.ChangeSlotCount(a_SlotNum, -1); break; @@ -202,10 +197,12 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) -void cDispenserEntity::SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector) +void cDispenserEntity::SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_Kind, Vector3d a_ShootVector) { - if(a_kind != cProjectileEntity::pkFireCharge) + if( a_kind != cProjectileEntity::pkFireCharge ) + { a_ShootVector.y = a_ShootVector.y + 1; + } m_World->CreateProjectile((double) a_BlockX + 0.5, (double) a_BlockY + 0.5, (double) a_BlockZ + 0.5, a_kind, NULL, NULL, &a_ShootVector); } @@ -215,14 +212,14 @@ Vector3d cDispenserEntity::GetShootVector(NIBBLETYPE & a_Meta) { switch(a_Meta) { - case E_META_DROPSPENSER_FACING_YP: return Vector3d(0, 1, 0); // UP - case E_META_DROPSPENSER_FACING_YM: return Vector3d(0, -1, 0); // DOWN + case E_META_DROPSPENSER_FACING_YP: return Vector3d(0, 1, 0); // UP + case E_META_DROPSPENSER_FACING_YM: return Vector3d(0, -1, 0); // DOWN - case E_META_DROPSPENSER_FACING_XM: return Vector3d(-1, 0, 0); // WEST - case E_META_DROPSPENSER_FACING_XP: return Vector3d(1, 0, 0); // EAST + case E_META_DROPSPENSER_FACING_XM: return Vector3d(-1, 0, 0); // WEST + case E_META_DROPSPENSER_FACING_XP: return Vector3d(1, 0, 0); // EAST - case E_META_DROPSPENSER_FACING_ZM: return Vector3d(0, 0, -1); - case E_META_DROPSPENSER_FACING_ZP: return Vector3d(0, 0, 1); + case E_META_DROPSPENSER_FACING_ZM: return Vector3d(0, 0, -1); + case E_META_DROPSPENSER_FACING_ZP: return Vector3d(0, 0, 1); } return Vector3d(0, 1, 0); @@ -290,3 +287,6 @@ 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 5a2de7965..9410a1129 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -23,7 +23,7 @@ public: static const char * GetClassStatic(void) { return "cDispenserEntity"; } /** Spawns a projectile of the given kind in front of the dispenser */ - void SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_kind, Vector3d a_ShootVector); + void SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_Kind, Vector3d a_ShootVector); /** Returns how to aim the projectile */ Vector3d GetShootVector(NIBBLETYPE & a_Meta); @@ -38,3 +38,6 @@ private: /// 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 + + + -- cgit v1.2.3 From e5b345a9c95225c18728f5692bf12ffae82ba4cd Mon Sep 17 00:00:00 2001 From: JoannisO Date: Wed, 4 Jun 2014 12:37:51 +0200 Subject: - Fixed variable names in a function. --- src/BlockEntities/DispenserEntity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 242ac4024..7b468bdea 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -199,12 +199,12 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) void cDispenserEntity::SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_Kind, Vector3d a_ShootVector) { - if( a_kind != cProjectileEntity::pkFireCharge ) + if( a_Kind != cProjectileEntity::pkFireCharge ) { a_ShootVector.y = a_ShootVector.y + 1; } - m_World->CreateProjectile((double) a_BlockX + 0.5, (double) a_BlockY + 0.5, (double) a_BlockZ + 0.5, a_kind, NULL, NULL, &a_ShootVector); + m_World->CreateProjectile((double) a_BlockX + 0.5, (double) a_BlockY + 0.5, (double) a_BlockZ + 0.5, a_Kind, NULL, NULL, &a_ShootVector); } -- cgit v1.2.3 From 852e162f95742d5c5454e458ed7883e4b0209a73 Mon Sep 17 00:00:00 2001 From: JoannisO Date: Wed, 4 Jun 2014 12:40:01 +0200 Subject: - Removed the code that removed fireworks from a dispenser even thought they weren't launched. --- src/BlockEntities/DispenserEntity.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 7b468bdea..475125719 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -181,9 +181,6 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) case E_ITEM_FIREWORK_ROCKET: { // TODO: Add the fireworks entity - - m_Contents.ChangeSlotCount(a_SlotNum, -1); - break; } -- cgit v1.2.3 From 720ae4f75777a8286014e9934429ab248df6d9e9 Mon Sep 17 00:00:00 2001 From: JoannisO Date: Thu, 5 Jun 2014 12:26:27 +0200 Subject: - Fixed a lot of alignment --- src/BlockEntities/DispenserEntity.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 475125719..97e25ca6d 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -196,7 +196,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) void cDispenserEntity::SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_Kind, Vector3d a_ShootVector) { - if( a_Kind != cProjectileEntity::pkFireCharge ) + if (a_Kind != cProjectileEntity::pkFireCharge) { a_ShootVector.y = a_ShootVector.y + 1; } @@ -209,14 +209,14 @@ Vector3d cDispenserEntity::GetShootVector(NIBBLETYPE & a_Meta) { switch(a_Meta) { - case E_META_DROPSPENSER_FACING_YP: return Vector3d(0, 1, 0); // UP - case E_META_DROPSPENSER_FACING_YM: return Vector3d(0, -1, 0); // DOWN + case E_META_DROPSPENSER_FACING_YP: return Vector3d( 0, 1, 0); // UP + case E_META_DROPSPENSER_FACING_YM: return Vector3d( 0, -1, 0); // DOWN - case E_META_DROPSPENSER_FACING_XM: return Vector3d(-1, 0, 0); // WEST - case E_META_DROPSPENSER_FACING_XP: return Vector3d(1, 0, 0); // EAST + case E_META_DROPSPENSER_FACING_XM: return Vector3d(-1, 0, 0); // WEST + case E_META_DROPSPENSER_FACING_XP: return Vector3d( 1, 0, 0); // EAST - case E_META_DROPSPENSER_FACING_ZM: return Vector3d(0, 0, -1); - case E_META_DROPSPENSER_FACING_ZP: return Vector3d(0, 0, 1); + case E_META_DROPSPENSER_FACING_ZM: return Vector3d( 0, 0, -1); + case E_META_DROPSPENSER_FACING_ZP: return Vector3d( 0, 0, 1); } return Vector3d(0, 1, 0); -- cgit v1.2.3 From 220e6f5880354c9984e18718f723331bb904df45 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 11 Jun 2014 19:46:24 +0200 Subject: DispenserEntity code cleanup after PR merge. --- src/BlockEntities/DispenserEntity.cpp | 41 +++++++++++++++-------------------- src/BlockEntities/DispenserEntity.h | 19 ++++++++++------ 2 files changed, 30 insertions(+), 30 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index 97e25ca6d..c02c68afa 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -150,31 +150,27 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) { SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkFireCharge, GetShootVector(Meta) * 20); m_Contents.ChangeSlotCount(a_SlotNum, -1); - break; } case E_ITEM_ARROW: { - SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkArrow, GetShootVector(Meta) * 20); + SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkArrow, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0)); m_Contents.ChangeSlotCount(a_SlotNum, -1); - break; } case E_ITEM_SNOWBALL: { - SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkSnowball, GetShootVector(Meta) * 20); + SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkSnowball, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0)); m_Contents.ChangeSlotCount(a_SlotNum, -1); - break; } case E_ITEM_EGG: { - SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkEgg, GetShootVector(Meta) * 20); + SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkEgg, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0)); m_Contents.ChangeSlotCount(a_SlotNum, -1); - break; } @@ -194,31 +190,30 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) -void cDispenserEntity::SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_Kind, Vector3d a_ShootVector) -{ - if (a_Kind != cProjectileEntity::pkFireCharge) - { - a_ShootVector.y = a_ShootVector.y + 1; - } - m_World->CreateProjectile((double) a_BlockX + 0.5, (double) a_BlockY + 0.5, (double) a_BlockZ + 0.5, a_Kind, NULL, NULL, &a_ShootVector); + +void cDispenserEntity::SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_ShootVector) +{ + m_World->CreateProjectile((double)a_BlockX + 0.5, (double)a_BlockY + 0.5, (double)a_BlockZ + 0.5, a_Kind, NULL, NULL, &a_ShootVector); } -Vector3d cDispenserEntity::GetShootVector(NIBBLETYPE & a_Meta) -{ - switch(a_Meta) - { - case E_META_DROPSPENSER_FACING_YP: return Vector3d( 0, 1, 0); // UP - case E_META_DROPSPENSER_FACING_YM: return Vector3d( 0, -1, 0); // DOWN - case E_META_DROPSPENSER_FACING_XM: return Vector3d(-1, 0, 0); // WEST - case E_META_DROPSPENSER_FACING_XP: return Vector3d( 1, 0, 0); // EAST + +Vector3d cDispenserEntity::GetShootVector(NIBBLETYPE a_Meta) +{ + switch (a_Meta) + { + case E_META_DROPSPENSER_FACING_YP: return Vector3d( 0, 1, 0); + case E_META_DROPSPENSER_FACING_YM: return Vector3d( 0, -1, 0); + case E_META_DROPSPENSER_FACING_XM: return Vector3d(-1, 0, 0); + case E_META_DROPSPENSER_FACING_XP: return Vector3d( 1, 0, 0); case E_META_DROPSPENSER_FACING_ZM: return Vector3d( 0, 0, -1); case E_META_DROPSPENSER_FACING_ZP: return Vector3d( 0, 0, 1); } - + LOGWARNING("Unhandled dispenser meta: %d", a_Meta); + ASSERT(!"Unhandled dispenser facing"); return Vector3d(0, 1, 0); } diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h index 9410a1129..b33d08342 100644 --- a/src/BlockEntities/DispenserEntity.h +++ b/src/BlockEntities/DispenserEntity.h @@ -17,25 +17,30 @@ public: // tolua_end - /// Constructor used for normal operation + /** Constructor used for normal operation */ cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); static const char * GetClassStatic(void) { return "cDispenserEntity"; } - /** Spawns a projectile of the given kind in front of the dispenser */ - void SpawnProjectileFromDispenser(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cProjectileEntity::eKind a_Kind, Vector3d a_ShootVector); + // tolua_begin + + /** Spawns a projectile of the given kind in front of the dispenser with the specified speed. */ + void SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_Speed); - /** Returns how to aim the projectile */ - Vector3d GetShootVector(NIBBLETYPE & a_Meta); + /** Returns a unit vector in the cardinal direction of where the dispenser is facing. */ + Vector3d GetShootVector(NIBBLETYPE a_Meta); + + // tolua_end private: // cDropSpenser overrides: virtual void DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) override; - /// 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); - /// If the a_BlockInFront is liquidable and the empty bucket can fit, does the m_Contents processing and returns true + /** If the a_BlockInFront can be washed away by liquid and the empty bucket can fit, + does the m_Contents processing and returns true. Returns false otherwise. */ bool EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum); } ; // tolua_export -- cgit v1.2.3 From b2bf4661222f9dd8c234716ac2b81ccf6a09217c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Jun 2014 14:47:05 +0100 Subject: Chests don't open if obstructed * Fixes FS383 --- src/BlockEntities/ChestEntity.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index dfbe6ae87..cb9cc89bf 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -122,6 +122,13 @@ void cChestEntity::UsedBy(cPlayer * a_Player) void cChestEntity::OpenNewWindow(void) { + // TODO: cats are an obstruction + if ((GetPosY() + 1 < cChunkDef::Height) && cBlockInfo::IsSolid(GetWorld()->GetBlock(GetPosX(), GetPosY() + 1, GetPosZ()))) + { + // Obstruction, don't open + return; + } + // Callback for opening together with neighbor chest: class cOpenDouble : public cChestCallback @@ -135,6 +142,12 @@ void cChestEntity::OpenNewWindow(void) virtual bool Item(cChestEntity * a_Chest) override { + if ((a_Chest->GetPosY() + 1 < cChunkDef::Height) && cBlockInfo::IsSolid(a_Chest->GetWorld()->GetBlock(a_Chest->GetPosX(), a_Chest->GetPosY() + 1, a_Chest->GetPosZ()))) + { + // Obstruction, don't open + return false; + } + // The primary chest should eb the one with lesser X or Z coord: cChestEntity * Primary = a_Chest; cChestEntity * Secondary = m_ThisChest; -- cgit v1.2.3 From 742370497a4210bff18e4e2c65a3ef7772bc1cc5 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 24 Jun 2014 09:46:04 +0200 Subject: Fixed crashes in HopperEntity. Some of the coords were off and some functions were assuming too much. Fixes the crash reported in http://forum.mc-server.org/showthread.php?tid=1497 --- src/BlockEntities/HopperEntity.cpp | 77 ++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 19 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 7f001c739..5856f20d1 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -294,23 +294,24 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) return false; } - int bx, by, bz; + // Get the coords of the block where to output items: + int OutX, OutY, OutZ; NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ); - if (!GetOutputBlockPos(Meta, bx, by, bz)) + if (!GetOutputBlockPos(Meta, OutX, OutY, OutZ)) { // Not attached to another container return false; } - if (by < 0) + if (OutY < 0) { // Cannot output below the zero-th block level return false; } // Convert coords to relative: - int rx = bx - a_Chunk.GetPosX() * cChunkDef::Width; - int rz = bz - a_Chunk.GetPosZ() * cChunkDef::Width; - cChunk * DestChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(rx, rz); + int OutRelX = OutX - a_Chunk.GetPosX() * cChunkDef::Width; + int OutRelZ = OutZ - a_Chunk.GetPosZ() * cChunkDef::Width; + cChunk * DestChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(OutRelX, OutRelZ); if (DestChunk == NULL) { // The destination chunk has been unloaded, don't tick @@ -319,26 +320,32 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) // Call proper moving function, based on the blocktype present at the coords: bool res = false; - switch (DestChunk->GetBlock(rx, by, rz)) + switch (DestChunk->GetBlock(OutRelX, OutY, OutRelZ)) { case E_BLOCK_CHEST: { // Chests have special handling because of double-chests - res = MoveItemsToChest(*DestChunk, bx, by, bz); + res = MoveItemsToChest(*DestChunk, OutX, OutY, OutZ); break; } case E_BLOCK_LIT_FURNACE: case E_BLOCK_FURNACE: { // Furnaces have special handling because of the direction-to-slot relation - res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); + res = MoveItemsToFurnace(*DestChunk, OutX, OutY, OutZ, Meta); break; } case E_BLOCK_DISPENSER: case E_BLOCK_DROPPER: case E_BLOCK_HOPPER: { - res = MoveItemsToGrid(*(cBlockEntityWithItems *)DestChunk->GetBlockEntity(bx, by, bz)); + cBlockEntityWithItems * BlockEntity = (cBlockEntityWithItems *)DestChunk->GetBlockEntity(OutX, OutY, OutZ); + if (BlockEntity == NULL) + { + LOGWARNING("%s: A block entity was not found where expected at {%d, %d, %d}", __FUNCTION__, OutX, OutY, OutZ); + return false; + } + res = MoveItemsToGrid(*BlockEntity); break; } } @@ -359,7 +366,13 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) /// Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed. bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) { - if (MoveItemsFromGrid(*(cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))) + cChestEntity * Chest = (cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); + if (Chest == NULL) + { + LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); + return false; + } + if (MoveItemsFromGrid(*Chest)) { // Moved the item from the chest directly above the hopper return true; @@ -389,9 +402,17 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) { continue; } - if (MoveItemsFromGrid(*(cChestEntity *)Neighbor->GetBlockEntity(x, m_PosY, z))) + Chest = (cChestEntity *)Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); + if (Chest == NULL) { - return true; + LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); + } + else + { + if (MoveItemsFromGrid(*Chest)) + { + return true; + } } return false; } @@ -408,7 +429,11 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk) { cFurnaceEntity * Furnace = (cFurnaceEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); - ASSERT(Furnace != NULL); + if (Furnace == NULL) + { + LOGWARNING("%s: A furnace entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); + return false; + } // Try move from the output slot: if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsOutput, true)) @@ -517,7 +542,13 @@ bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_Sl bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ) { // Try the chest directly connected to the hopper: - if (MoveItemsToGrid(*(cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ))) + cChestEntity * Chest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ); + if (Chest == NULL) + { + LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ); + return false; + } + if (MoveItemsToGrid(*Chest)) { return true; } @@ -534,19 +565,27 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block {0, 1}, {0, -1}, } ; + int RelX = a_BlockX - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = a_BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width; for (size_t i = 0; i < ARRAYCOUNT(Coords); i++) { - int x = m_RelX + Coords[i].x; - int z = m_RelZ + Coords[i].z; + int x = RelX + Coords[i].x; + int z = RelZ + Coords[i].z; cChunk * Neighbor = a_Chunk.GetRelNeighborChunkAdjustCoords(x, z); if ( (Neighbor == NULL) || - (Neighbor->GetBlock(x, m_PosY + 1, z) != E_BLOCK_CHEST) + (Neighbor->GetBlock(x, a_BlockY, z) != E_BLOCK_CHEST) ) { continue; } - if (MoveItemsToGrid(*(cChestEntity *)Neighbor->GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ))) + Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z); + if (Chest == NULL) + { + LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z); + continue; + } + if (MoveItemsToGrid(*Chest)) { return true; } -- cgit v1.2.3 From dde641ce83de474187102f0efbbced826673f54d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 29 Jun 2014 11:36:38 +0100 Subject: Properly implemented enderchests --- src/BlockEntities/EnderChestEntity.cpp | 93 +++++++++++----------------------- src/BlockEntities/EnderChestEntity.h | 44 +++++----------- 2 files changed, 44 insertions(+), 93 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/EnderChestEntity.cpp b/src/BlockEntities/EnderChestEntity.cpp index e53930798..17816d63e 100644 --- a/src/BlockEntities/EnderChestEntity.cpp +++ b/src/BlockEntities/EnderChestEntity.cpp @@ -12,9 +12,8 @@ cEnderChestEntity::cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - super(E_BLOCK_ENDER_CHEST, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World) + super(E_BLOCK_ENDER_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World) { - cBlockEntityWindowOwner::SetBlockEntity(this); } @@ -34,95 +33,63 @@ cEnderChestEntity::~cEnderChestEntity() -bool cEnderChestEntity::LoadFromJson(const Json::Value & a_Value) +void cEnderChestEntity::UsedBy(cPlayer * a_Player) { - m_PosX = a_Value.get("x", 0).asInt(); - m_PosY = a_Value.get("y", 0).asInt(); - m_PosZ = a_Value.get("z", 0).asInt(); - - Json::Value AllSlots = a_Value.get("Slots", 0); - int SlotIdx = 0; - for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr) + // If the window is not created, open it anew: + cWindow * Window = GetWindow(); + if (Window == NULL) { - cItem Item; - Item.FromJson(*itr); - SetSlot(SlotIdx, Item); - SlotIdx++; + OpenNewWindow(); + Window = GetWindow(); } - return true; -} - - - - - -void cEnderChestEntity::SaveToJson(Json::Value & a_Value) -{ - a_Value["x"] = m_PosX; - a_Value["y"] = m_PosY; - a_Value["z"] = m_PosZ; - - Json::Value AllSlots; - for (int i = m_Contents.GetNumSlots() - 1; i >= 0; i--) + + // Open the window for the player: + if (Window != NULL) { - Json::Value Slot; - m_Contents.GetSlot(i).GetJson(Slot); - AllSlots.append(Slot); + if (a_Player->GetWindow() != Window) + { + a_Player->OpenWindow(Window); + } } - a_Value["Slots"] = AllSlots; } -void cEnderChestEntity::SendTo(cClientHandle & a_Client) +void cEnderChestEntity::OpenNewWindow() { - // The chest entity doesn't need anything sent to the client when it's created / gets in the viewdistance - // All the actual handling is in the cWindow UI code that gets called when the chest is rclked - - UNUSED(a_Client); + OpenWindow(new cEnderChestWindow(this)); } -void cEnderChestEntity::UsedBy(cPlayer * a_Player) +void cEnderChestEntity::LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid) { - // If the window is not created, open it anew: - cWindow * Window = GetWindow(); - if (Window == NULL) - { - OpenNewWindow(); - Window = GetWindow(); - } - - // Open the window for the player: - if (Window != NULL) + int SlotIdx = 0; + for (Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr) { - if (a_Player->GetWindow() != Window) - { - a_Player->OpenWindow(Window); - } + cItem Item; + Item.FromJson(*itr); + a_Grid.SetSlot(SlotIdx, Item); + SlotIdx++; } - - // This is rather a hack - // Instead of marking the chunk as dirty upon chest contents change, we mark it dirty now - // We cannot properly detect contents change, but such a change doesn't happen without a player opening the chest first. - // The few false positives aren't much to worry about - int ChunkX, ChunkZ; - cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ); - m_World->MarkChunkDirty(ChunkX, ChunkZ); } -void cEnderChestEntity::OpenNewWindow(void) +void cEnderChestEntity::SaveToJson(Json::Value & a_Value, const cItemGrid & a_Grid) { - OpenWindow(new cEnderChestWindow(this)); + for (int i = 0; i < a_Grid.GetNumSlots(); i++) + { + Json::Value Slot; + a_Grid.GetSlot(i).GetJson(Slot); + a_Value.append(Slot); + } } diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h index 45beee45f..04af67683 100644 --- a/src/BlockEntities/EnderChestEntity.h +++ b/src/BlockEntities/EnderChestEntity.h @@ -1,20 +1,9 @@ #pragma once -#include "BlockEntityWithItems.h" - - - - - -namespace Json -{ - class Value; -}; - -class cClientHandle; -class cServer; -class cNBTData; +#include "BlockEntity.h" +#include "UI/WindowOwner.h" +#include "json/json.h" @@ -22,33 +11,28 @@ class cNBTData; // tolua_begin class cEnderChestEntity : - public cBlockEntityWithItems + public cBlockEntity, + public cBlockEntityWindowOwner { - typedef cBlockEntityWithItems super; - -public: - enum { - ContentsHeight = 3, - ContentsWidth = 9, - } ; + typedef cBlockEntity super; +public: // tolua_end - /// Constructor used for normal operation - cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); - + cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); virtual ~cEnderChestEntity(); static const char * GetClassStatic(void) { return "cEnderChestEntity"; } - - bool LoadFromJson(const Json::Value & a_Value); // cBlockEntity overrides: - virtual void SaveToJson(Json::Value & a_Value) override; - virtual void SendTo(cClientHandle & a_Client) override; virtual void UsedBy(cPlayer * a_Player) override; + virtual void SaveToJson(Json::Value & a_Value) override { UNUSED(a_Value); } + virtual void SendTo(cClientHandle & a_Client) override { UNUSED(a_Client); } + + static void LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid); + static void SaveToJson(Json::Value & a_Value, const cItemGrid & a_Grid); - /// Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. + /** Opens a new enderchest window for this enderchest */ void OpenNewWindow(void); } ; // tolua_export -- cgit v1.2.3 From 9e44b0aae164f2456a452714f869cc9670732d8e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 6 Jul 2014 23:50:22 +0100 Subject: Implemented trapped chests & others + Added trapped chests * Fixed a bunch of bugs in the redstone simulator concerning wires and repeaters * Other potential bugfixes --- src/BlockEntities/BlockEntity.cpp | 3 ++- src/BlockEntities/ChestEntity.cpp | 7 ++++--- src/BlockEntities/ChestEntity.h | 13 ++++++++++++- src/BlockEntities/HopperEntity.cpp | 26 ++++++++++++++++++-------- 4 files changed, 36 insertions(+), 13 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 430f04551..1e2a176ef 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -28,7 +28,8 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE switch (a_BlockType) { case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_TRAPPED_CHEST: + case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World, a_BlockType); case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index cb9cc89bf..8626f3cad 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -11,8 +11,9 @@ -cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World) +cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, BLOCKTYPE a_Type) : + super(a_Type, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World), + m_ActivePlayers(0) { cBlockEntityWindowOwner::SetBlockEntity(this); } @@ -113,7 +114,7 @@ void cChestEntity::UsedBy(cPlayer * a_Player) // The few false positives aren't much to worry about int ChunkX, ChunkZ; cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ); - m_World->MarkChunkDirty(ChunkX, ChunkZ); + m_World->MarkChunkDirty(ChunkX, ChunkZ, true); } diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h index ce16f84d7..42cf7657c 100644 --- a/src/BlockEntities/ChestEntity.h +++ b/src/BlockEntities/ChestEntity.h @@ -35,7 +35,7 @@ public: // tolua_end /// Constructor used for normal operation - cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); + cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, BLOCKTYPE a_Type); virtual ~cChestEntity(); @@ -50,6 +50,17 @@ public: /// Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. void OpenNewWindow(void); + + /** Gets the number of players who currently have this chest open */ + int GetNumberOfPlayers(void) const { return m_ActivePlayers; } + + /** Gets the number of players who currently have this chest open */ + void SetNumberOfPlayers(int a_Amount) { m_ActivePlayers = a_Amount; } + +private: + + /** Holds the number of players who currently have this chest open */ + int m_ActivePlayers; } ; // tolua_export diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 5856f20d1..bcaf26701 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -157,6 +157,7 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick) bool res = false; switch (a_Chunk.GetBlock(m_RelX, m_PosY + 1, m_RelZ)) { + case E_BLOCK_TRAPPED_CHEST: case E_BLOCK_CHEST: { // Chests have special handling because of double-chests @@ -322,6 +323,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) bool res = false; switch (DestChunk->GetBlock(OutRelX, OutY, OutRelZ)) { + case E_BLOCK_TRAPPED_CHEST: case E_BLOCK_CHEST: { // Chests have special handling because of double-chests @@ -395,13 +397,17 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) int x = m_RelX + Coords[i].x; int z = m_RelZ + Coords[i].z; cChunk * Neighbor = a_Chunk.GetRelNeighborChunkAdjustCoords(x, z); - if ( - (Neighbor == NULL) || - (Neighbor->GetBlock(x, m_PosY + 1, z) != E_BLOCK_CHEST) - ) + if (Neighbor == NULL) { continue; } + + BLOCKTYPE Block = Neighbor->GetBlock(x, m_PosY + 1, z); + if ((Block != E_BLOCK_CHEST) && (Block != E_BLOCK_TRAPPED_CHEST)) + { + continue; + } + Chest = (cChestEntity *)Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); if (Chest == NULL) { @@ -572,13 +578,17 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block int x = RelX + Coords[i].x; int z = RelZ + Coords[i].z; cChunk * Neighbor = a_Chunk.GetRelNeighborChunkAdjustCoords(x, z); - if ( - (Neighbor == NULL) || - (Neighbor->GetBlock(x, a_BlockY, z) != E_BLOCK_CHEST) - ) + if (Neighbor == NULL) { continue; } + + BLOCKTYPE Block = Neighbor->GetBlock(x, a_BlockY, z); + if ((Block != E_BLOCK_CHEST) && (Block != E_BLOCK_TRAPPED_CHEST)) + { + continue; + } + Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z); if (Chest == NULL) { -- cgit v1.2.3 From 164ffe50adbadd4bc123f11d585fef5c447d776e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 8 Jul 2014 12:34:39 +0100 Subject: Made things consistent --- src/BlockEntities/BlockEntity.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 1e2a176ef..1deddb0e9 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -27,22 +27,23 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE { switch (a_BlockType) { - case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_TRAPPED_CHEST: case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World, a_BlockType); + case E_BLOCK_LIT_FURNACE: + case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + + case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_FLOWER_POT: return new cFlowerPotEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_NOTE_BLOCK: return new cNoteEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); } LOGD("%s: Requesting creation of an unknown block entity - block type %d (%s)", __FUNCTION__, a_BlockType, ItemTypeToString(a_BlockType).c_str() -- cgit v1.2.3 From 6a33fa84ae03ada5ddeb5861094a4030e612f827 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 11 Jul 2014 12:43:24 +0100 Subject: Suggestions --- src/BlockEntities/BlockEntity.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 1deddb0e9..feef088a9 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -27,10 +27,10 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE { switch (a_BlockType) { - case E_BLOCK_TRAPPED_CHEST: - case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World, a_BlockType); - case E_BLOCK_LIT_FURNACE: - case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_CHEST: + case E_BLOCK_TRAPPED_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World, a_BlockType); + case E_BLOCK_FURNACE: + case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_World); -- cgit v1.2.3 From e71e432633a26d0ab24d2da7e3707e4ab7060296 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 12 Jul 2014 22:06:25 +0100 Subject: Suggestions and bug fix * Fixed hoppers pushing/pulling to/from (trapped)chests that do not form a double-chest with the chest type directly connected to said hopper; thank you, @madmaxoft --- src/BlockEntities/BlockEntity.cpp | 11 +++++------ src/BlockEntities/HopperEntity.cpp | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index feef088a9..2910c735e 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -27,21 +27,20 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE { switch (a_BlockType) { - case E_BLOCK_CHEST: - case E_BLOCK_TRAPPED_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World, a_BlockType); - case E_BLOCK_FURNACE: - case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World, a_BlockType); case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_FLOWER_POT: return new cFlowerPotEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_FURNACE: return new cFurnaceEntity(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_TRAPPED_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World, a_BlockType); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_NOTE_BLOCK: return new cNoteEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); } diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index bcaf26701..181b6a2ce 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -380,7 +380,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) return true; } - // Check if the chest is a double-chest, if so, try to move from there: + // Check if the chest is a double-chest (chest directly above was empty), if so, try to move from there: static const struct { int x, z; @@ -403,7 +403,11 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) } BLOCKTYPE Block = Neighbor->GetBlock(x, m_PosY + 1, z); - if ((Block != E_BLOCK_CHEST) && (Block != E_BLOCK_TRAPPED_CHEST)) + if ( + ((Block != E_BLOCK_CHEST) && (Block != E_BLOCK_TRAPPED_CHEST)) || + ((Block == E_BLOCK_CHEST) && (Chest->GetBlockType() != E_BLOCK_CHEST)) || + ((Block == E_BLOCK_TRAPPED_CHEST) && (Chest->GetBlockType() != E_BLOCK_TRAPPED_CHEST)) + ) { continue; } @@ -556,10 +560,11 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block } if (MoveItemsToGrid(*Chest)) { + // Chest block directly connected was not full return true; } - // Check if the chest is a double-chest, if so, try to move into the other half: + // Check if the chest is a double-chest (chest block directly connected was full), if so, try to move into the other half: static const struct { int x, z; @@ -584,7 +589,11 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block } BLOCKTYPE Block = Neighbor->GetBlock(x, a_BlockY, z); - if ((Block != E_BLOCK_CHEST) && (Block != E_BLOCK_TRAPPED_CHEST)) + if ( + ((Block != E_BLOCK_CHEST) && (Block != E_BLOCK_TRAPPED_CHEST)) || + ((Block == E_BLOCK_CHEST) && (Chest->GetBlockType() != E_BLOCK_CHEST)) || + ((Block == E_BLOCK_TRAPPED_CHEST) && (Chest->GetBlockType() != E_BLOCK_TRAPPED_CHEST)) + ) { continue; } -- cgit v1.2.3 From 9ab0f259c763d72f6af2560007d4f5cd7b5694cd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 12 Jul 2014 23:25:59 +0200 Subject: Fixed alignment. --- src/BlockEntities/BlockEntity.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 2910c735e..05ad03a3d 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -34,11 +34,11 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_FLOWER_POT: return new cFlowerPotEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_FURNACE: return new cFurnaceEntity(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_TRAPPED_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World, a_BlockType); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); @@ -47,6 +47,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE LOGD("%s: Requesting creation of an unknown block entity - block type %d (%s)", __FUNCTION__, a_BlockType, ItemTypeToString(a_BlockType).c_str() ); + ASSERT(!"Requesting creation of an unknown block entity"); return NULL; } -- cgit v1.2.3 From c4f1284d9cca12f77184b7a0b9521e87f6533974 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 12 Jul 2014 23:30:34 +0200 Subject: cChestEntity: Renamed a member to avoid confusion. --- src/BlockEntities/ChestEntity.cpp | 2 +- src/BlockEntities/ChestEntity.h | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index 8626f3cad..ca164464c 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -13,7 +13,7 @@ cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, BLOCKTYPE a_Type) : super(a_Type, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World), - m_ActivePlayers(0) + m_NumActivePlayers(0) { cBlockEntityWindowOwner::SetBlockEntity(this); } diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h index 42cf7657c..310618504 100644 --- a/src/BlockEntities/ChestEntity.h +++ b/src/BlockEntities/ChestEntity.h @@ -34,7 +34,7 @@ public: // tolua_end - /// Constructor used for normal operation + /** Constructor used for normal operation */ cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, BLOCKTYPE a_Type); virtual ~cChestEntity(); @@ -48,19 +48,20 @@ public: virtual void SendTo(cClientHandle & a_Client) override; virtual void UsedBy(cPlayer * a_Player) override; - /// Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. + /** Opens a new chest window for this chest. + Scans for neighbors to open a double chest window, if appropriate. */ void OpenNewWindow(void); /** Gets the number of players who currently have this chest open */ - int GetNumberOfPlayers(void) const { return m_ActivePlayers; } + int GetNumberOfPlayers(void) const { return m_NumActivePlayers; } - /** Gets the number of players who currently have this chest open */ - void SetNumberOfPlayers(int a_Amount) { m_ActivePlayers = a_Amount; } + /** Sets the number of players who currently have this chest open */ + void SetNumberOfPlayers(int a_NumActivePlayers) { m_NumActivePlayers = a_NumActivePlayers; } private: - /** Holds the number of players who currently have this chest open */ - int m_ActivePlayers; + /** Number of players who currently have this chest open */ + int m_NumActivePlayers; } ; // tolua_export -- cgit v1.2.3 From d72a81cb8e135695b947bea4bac320e21c9af278 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 12 Jul 2014 23:34:32 +0200 Subject: cHopperEntity: Simplified chest conditions. --- src/BlockEntities/HopperEntity.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 181b6a2ce..aaf82d150 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -403,12 +403,9 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) } BLOCKTYPE Block = Neighbor->GetBlock(x, m_PosY + 1, z); - if ( - ((Block != E_BLOCK_CHEST) && (Block != E_BLOCK_TRAPPED_CHEST)) || - ((Block == E_BLOCK_CHEST) && (Chest->GetBlockType() != E_BLOCK_CHEST)) || - ((Block == E_BLOCK_TRAPPED_CHEST) && (Chest->GetBlockType() != E_BLOCK_TRAPPED_CHEST)) - ) + if (Block != Chest->GetBlockType()) { + // Not the same kind of chest continue; } @@ -589,12 +586,9 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block } BLOCKTYPE Block = Neighbor->GetBlock(x, a_BlockY, z); - if ( - ((Block != E_BLOCK_CHEST) && (Block != E_BLOCK_TRAPPED_CHEST)) || - ((Block == E_BLOCK_CHEST) && (Chest->GetBlockType() != E_BLOCK_CHEST)) || - ((Block == E_BLOCK_TRAPPED_CHEST) && (Chest->GetBlockType() != E_BLOCK_TRAPPED_CHEST)) - ) + if (Block != Chest->GetBlockType()) { + // Not the same kind of chest continue; } -- cgit v1.2.3 From d529971e279609ae928d9077404b95bd595b5e52 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 13 Jul 2014 02:08:02 +0200 Subject: Changed BroadcastSoundEffect function to take floating pos. --- src/BlockEntities/NoteEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp index 58b05a324..95145c117 100644 --- a/src/BlockEntities/NoteEntity.cpp +++ b/src/BlockEntities/NoteEntity.cpp @@ -91,7 +91,7 @@ void cNoteEntity::MakeSound(void) // TODO: instead of calculating the power function over and over, make a precalculated table - there's only 24 pitches after all float calcPitch = pow(2.0f, ((float)m_Pitch - 12.0f) / 12.0f); - m_World->BroadcastSoundEffect(sampleName, m_PosX * 8, m_PosY * 8, m_PosZ * 8, 3.0f, calcPitch); + m_World->BroadcastSoundEffect(sampleName, (double)m_PosX, (double)m_PosY, (double)m_PosZ, 3.0f, calcPitch); } -- cgit v1.2.3 From e1a561286a47ab52f4402ae9d08f143d26c60402 Mon Sep 17 00:00:00 2001 From: worktycho Date: Sun, 13 Jul 2014 15:01:49 +0100 Subject: Fixed Issue with Comparing agast the wrong chest, potentially causing crashes. --- src/BlockEntities/HopperEntity.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index aaf82d150..7af4b9d5d 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -368,13 +368,13 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) /// Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed. bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) { - cChestEntity * Chest = (cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); - if (Chest == NULL) + cChestEntity * MainChest = (cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); + if (MainChest == NULL) { LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); return false; } - if (MoveItemsFromGrid(*Chest)) + if (MoveItemsFromGrid(*MainChest)) { // Moved the item from the chest directly above the hopper return true; @@ -403,20 +403,20 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) } BLOCKTYPE Block = Neighbor->GetBlock(x, m_PosY + 1, z); - if (Block != Chest->GetBlockType()) + if (Block != MainChest->GetBlockType()) { // Not the same kind of chest continue; } - Chest = (cChestEntity *)Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); - if (Chest == NULL) + cChestEntity * SideChest = (cChestEntity *)Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); + if (SideChest == NULL) { LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); } else { - if (MoveItemsFromGrid(*Chest)) + if (MoveItemsFromGrid(*SideChest)) { return true; } -- cgit v1.2.3 From e2a1118f88a32bd2912fc8abc81db0dacbb42531 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 15 Jul 2014 08:48:12 +0200 Subject: Pass cItem by reference. Fixes CID 66445. --- src/BlockEntities/FlowerPotEntity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h index da3fe9b7e..e3570eb9a 100644 --- a/src/BlockEntities/FlowerPotEntity.h +++ b/src/BlockEntities/FlowerPotEntity.h @@ -53,7 +53,7 @@ public: cItem GetItem(void) const { return m_Item; } /** Set the item in the flower pot */ - void SetItem(const cItem a_Item) { m_Item = a_Item; } + void SetItem(const cItem & a_Item) { m_Item = a_Item; } // tolua_end -- cgit v1.2.3 From 1df5a1f237cd4b620ada8aa9706d052ec54f1519 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 15 Jul 2014 22:53:44 +0100 Subject: Fixed a DropSpenser AddFace bug --- src/BlockEntities/DropSpenserEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index 0012742fb..108c2ce1b 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -42,7 +42,7 @@ cDropSpenserEntity::~cDropSpenserEntity() void cDropSpenserEntity::AddDropSpenserDir(int & a_BlockX, int & a_BlockY, int & a_BlockZ, NIBBLETYPE a_Direction) { - switch (a_Direction) + switch (a_Direction & 0x07) // Vanilla uses the 8th bit to determine power state - we don't { case E_META_DROPSPENSER_FACING_YM: a_BlockY--; return; case E_META_DROPSPENSER_FACING_YP: a_BlockY++; return; -- cgit v1.2.3 From 2423fbf2efa39e28cc348acc11b9269e573dcdef Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 22:15:34 +0200 Subject: Normalized comments. This was mostly done automatically and then visually inspected for obvious errors. All //-style comments should have a 2-space separation from the code, and 1 space after the comment sign. --- src/BlockEntities/BlockEntityWithItems.h | 2 +- src/BlockEntities/CommandBlockEntity.cpp | 2 +- src/BlockEntities/DropSpenserEntity.cpp | 8 ++++---- src/BlockEntities/HopperEntity.cpp | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h index 918781a00..5f1639d45 100644 --- a/src/BlockEntities/BlockEntityWithItems.h +++ b/src/BlockEntities/BlockEntityWithItems.h @@ -50,7 +50,7 @@ public: cItems Pickups; m_Contents.CopyToItems(Pickups); m_Contents.Clear(); - m_World->SpawnItemPickups(Pickups, m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); // Spawn in centre of block + m_World->SpawnItemPickups(Pickups, m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); // Spawn in centre of block } // tolua_begin diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index 146ad915b..45f8a3e4d 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -11,7 +11,7 @@ #include "../CommandOutput.h" #include "../Root.h" -#include "../Server.h" // ExecuteConsoleCommand() +#include "../Server.h" // ExecuteConsoleCommand() #include "../Chunk.h" diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index 108c2ce1b..0fa6bbe69 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -42,7 +42,7 @@ cDropSpenserEntity::~cDropSpenserEntity() void cDropSpenserEntity::AddDropSpenserDir(int & a_BlockX, int & a_BlockY, int & a_BlockZ, NIBBLETYPE a_Direction) { - switch (a_Direction & 0x07) // Vanilla uses the 8th bit to determine power state - we don't + switch (a_Direction & 0x07) // Vanilla uses the 8th bit to determine power state - we don't { case E_META_DROPSPENSER_FACING_YM: a_BlockY--; return; case E_META_DROPSPENSER_FACING_YP: a_BlockY++; return; @@ -90,7 +90,7 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk) int SmokeDir = 0; switch (Meta) { - case E_META_DROPSPENSER_FACING_YP: SmokeDir = 4; break; // YP & YM don't have associated smoke dirs, just do 4 (centre of block) + case E_META_DROPSPENSER_FACING_YP: SmokeDir = 4; break; // YP & YM don't have associated smoke dirs, just do 4 (centre of block) case E_META_DROPSPENSER_FACING_YM: SmokeDir = 4; break; case E_META_DROPSPENSER_FACING_XM: SmokeDir = 3; break; case E_META_DROPSPENSER_FACING_XP: SmokeDir = 5; break; @@ -235,7 +235,7 @@ void cDropSpenserEntity::DropFromSlot(cChunk & a_Chunk, int a_SlotNum) cItems Pickups; Pickups.push_back(m_Contents.RemoveOneItem(a_SlotNum)); - const int PickupSpeed = m_World->GetTickRandomNumber(4) + 2; // At least 2, at most 6 + const int PickupSpeed = m_World->GetTickRandomNumber(4) + 2; // At least 2, at most 6 int PickupSpeedX = 0, PickupSpeedY = 0, PickupSpeedZ = 0; switch (Meta) { @@ -249,7 +249,7 @@ void cDropSpenserEntity::DropFromSlot(cChunk & a_Chunk, int a_SlotNum) double MicroX, MicroY, MicroZ; MicroX = DispX + 0.5; - MicroY = DispY + 0.4; // Slightly less than half, to accomodate actual texture hole on DropSpenser + MicroY = DispY + 0.4; // Slightly less than half, to accomodate actual texture hole on DropSpenser MicroZ = DispZ + 0.5; diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 7af4b9d5d..48d3b8dcc 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -219,7 +219,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) } Vector3f EntityPos = a_Entity->GetPosition(); - Vector3f BlockPos(m_Pos.x + 0.5f, (float)m_Pos.y + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards + Vector3f BlockPos(m_Pos.x + 0.5f, (float)m_Pos.y + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards double Distance = (EntityPos - BlockPos).Length(); if (Distance < 0.5) @@ -243,7 +243,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) { m_bFoundPickupsAbove = true; m_Contents.SetSlot(i, Item); - a_Pickup->Destroy(); // Kill pickup + a_Pickup->Destroy(); // Kill pickup return true; } @@ -253,11 +253,11 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) int PreviousCount = m_Contents.GetSlot(i).m_ItemCount; - Item.m_ItemCount -= m_Contents.ChangeSlotCount(i, Item.m_ItemCount) - PreviousCount; // Set count to however many items were added + Item.m_ItemCount -= m_Contents.ChangeSlotCount(i, Item.m_ItemCount) - PreviousCount; // Set count to however many items were added if (Item.IsEmpty()) { - a_Pickup->Destroy(); // Kill pickup if all items were added + a_Pickup->Destroy(); // Kill pickup if all items were added } return true; } -- cgit v1.2.3 From 5e198c673009cf8ca9d92cf59848999bc96bbc37 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 22:50:58 +0200 Subject: Basic style fixes. --- src/BlockEntities/BeaconEntity.cpp | 2 +- src/BlockEntities/ChestEntity.cpp | 2 +- src/BlockEntities/CommandBlockEntity.h | 2 +- src/BlockEntities/DropSpenserEntity.cpp | 2 +- src/BlockEntities/EnderChestEntity.h | 4 ++-- src/BlockEntities/FlowerPotEntity.h | 2 +- src/BlockEntities/JukeboxEntity.h | 2 +- src/BlockEntities/MobHeadEntity.h | 2 +- src/BlockEntities/NoteEntity.h | 2 +- src/BlockEntities/SignEntity.h | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index 0914353eb..9a6d85f1d 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -32,7 +32,7 @@ int cBeaconEntity::GetPyramidLevel(void) } Area.Read( - m_World, + m_World, GetPosX() - 4, GetPosX() + 4, MinY, MaxY, GetPosZ() - 4, GetPosZ() + 4, diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index ca164464c..9f50365e9 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -177,7 +177,7 @@ void cChestEntity::OpenNewWindow(void) return; } - // There is no chest neighbor, open a single-chest window: + // There is no chest neighbor, open a single-chest window: OpenWindow(new cChestWindow(this)); } diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h index 12157670f..d7c4eaabe 100644 --- a/src/BlockEntities/CommandBlockEntity.h +++ b/src/BlockEntities/CommandBlockEntity.h @@ -26,7 +26,7 @@ namespace Json // tolua_begin -class cCommandBlockEntity : +class cCommandBlockEntity : public cBlockEntity { typedef cBlockEntity super; diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index 0fa6bbe69..dc38e3e9b 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -99,7 +99,7 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk) } m_World->BroadcastSoundParticleEffect(2000, m_PosX, m_PosY, m_PosZ, SmokeDir); m_World->BroadcastSoundEffect("random.click", m_PosX * 8, m_PosY * 8, m_PosZ * 8, 1.0f, 1.0f); -} +} diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h index 04af67683..ed178f6fc 100644 --- a/src/BlockEntities/EnderChestEntity.h +++ b/src/BlockEntities/EnderChestEntity.h @@ -16,10 +16,10 @@ class cEnderChestEntity : { typedef cBlockEntity super; -public: +public: // tolua_end - cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); + cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); virtual ~cEnderChestEntity(); static const char * GetClassStatic(void) { return "cEnderChestEntity"; } diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h index e3570eb9a..85cb810ad 100644 --- a/src/BlockEntities/FlowerPotEntity.h +++ b/src/BlockEntities/FlowerPotEntity.h @@ -27,7 +27,7 @@ namespace Json // tolua_begin -class cFlowerPotEntity : +class cFlowerPotEntity : public cBlockEntity { typedef cBlockEntity super; diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 3d1d604f7..8bb3009eb 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -19,7 +19,7 @@ namespace Json // tolua_begin -class cJukeboxEntity : +class cJukeboxEntity : public cBlockEntity { typedef cBlockEntity super; diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h index 367eb15e7..2bc072d69 100644 --- a/src/BlockEntities/MobHeadEntity.h +++ b/src/BlockEntities/MobHeadEntity.h @@ -25,7 +25,7 @@ namespace Json // tolua_begin -class cMobHeadEntity : +class cMobHeadEntity : public cBlockEntity { typedef cBlockEntity super; diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index b698899c0..07b8fd259 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -28,7 +28,7 @@ enum ENUM_NOTE_INSTRUMENTS // tolua_begin -class cNoteEntity : +class cNoteEntity : public cBlockEntity { typedef cBlockEntity super; diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h index 80c7bbfdf..16e0e23bc 100644 --- a/src/BlockEntities/SignEntity.h +++ b/src/BlockEntities/SignEntity.h @@ -25,7 +25,7 @@ namespace Json // tolua_begin -class cSignEntity : +class cSignEntity : public cBlockEntity { typedef cBlockEntity super; -- cgit v1.2.3 From 2df5e26d3b7f08ef7d120511705fa0b75a44783e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 18 Jul 2014 09:57:34 +0200 Subject: Fixed spaces before commas. --- src/BlockEntities/ChestEntity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index 9f50365e9..21e1f6ba2 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -169,8 +169,8 @@ void cChestEntity::OpenNewWindow(void) if ( m_World->DoWithChestAt(m_PosX - 1, m_PosY, m_PosZ, OpenDbl) || m_World->DoWithChestAt(m_PosX + 1, m_PosY, m_PosZ, OpenDbl) || - m_World->DoWithChestAt(m_PosX , m_PosY, m_PosZ - 1, OpenDbl) || - m_World->DoWithChestAt(m_PosX , m_PosY, m_PosZ + 1, OpenDbl) + m_World->DoWithChestAt(m_PosX, m_PosY, m_PosZ - 1, OpenDbl) || + m_World->DoWithChestAt(m_PosX, m_PosY, m_PosZ + 1, OpenDbl) ) { // The double-chest window has been opened in the callback -- cgit v1.2.3 From 1a05b7c5d70f1a57dd09d6ae9d35d4c1fb10128e Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 18 Jul 2014 00:14:15 -0700 Subject: BlockEntities/CMakeLists.txt: Replaced glob with list of files --- src/BlockEntities/CMakeLists.txt | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index 3e3d17f86..4cd49c52d 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -4,9 +4,39 @@ project (MCServer) include_directories ("${PROJECT_SOURCE_DIR}/../") -file(GLOB SOURCE - "*.cpp" - "*.h" -) +SET (SRCS + BeaconEntity.cpp + BlockEntity.cpp + ChestEntity.cpp + CommandBlockEntity.cpp + DispenserEntity.cpp + DropSpenserEntity.cpp + DropperEntity.cpp + EnderChestEntity.cpp + FlowerPotEntity.cpp + FurnaceEntity.cpp + HopperEntity.cpp + JukeboxEntity.cpp + MobHeadEntity.cpp + NoteEntity.cpp + SignEntity.cpp) -add_library(BlockEntities ${SOURCE}) +SET (HDRS + BeaconEntity.h + BlockEntity.h + BlockEntityWithItems.h + ChestEntity.h + CommandBlockEntity.h + DispenserEntity.h + DropSpenserEntity.h + DropperEntity.h + EnderChestEntity.h + FlowerPotEntity.h + FurnaceEntity.h + HopperEntity.h + JukeboxEntity.h + MobHeadEntity.h + NoteEntity.h + SignEntity.h) + +add_library(BlockEntities ${SRCS} ${HDRS}) -- cgit v1.2.3 From 725d1fd1e2995b1720673c280fea1125ac338b3c Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 18 Jul 2014 13:26:43 -0700 Subject: Subdirs: Only add_library if not using MSVC --- src/BlockEntities/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index 4cd49c52d..d87594b0d 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -39,4 +39,6 @@ SET (HDRS NoteEntity.h SignEntity.h) -add_library(BlockEntities ${SRCS} ${HDRS}) +if(NOT MSVC) + add_library(BlockEntities ${SRCS} ${HDRS}) +endif() -- cgit v1.2.3 From 08748bafe26145cd61a179abd131a9dba6065450 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 19 Jul 2014 15:23:40 +0200 Subject: Code style: Fixed braces on separate lines. --- src/BlockEntities/ChestEntity.h | 3 ++- src/BlockEntities/DropSpenserEntity.h | 3 ++- src/BlockEntities/HopperEntity.h | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h index 310618504..cd06b3e2c 100644 --- a/src/BlockEntities/ChestEntity.h +++ b/src/BlockEntities/ChestEntity.h @@ -27,7 +27,8 @@ class cChestEntity : typedef cBlockEntityWithItems super; public: - enum { + enum + { ContentsHeight = 3, ContentsWidth = 9, } ; diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h index 47d3bd492..9f58d0b07 100644 --- a/src/BlockEntities/DropSpenserEntity.h +++ b/src/BlockEntities/DropSpenserEntity.h @@ -35,7 +35,8 @@ class cDropSpenserEntity : typedef cBlockEntityWithItems super; public: - enum { + enum + { ContentsHeight = 3, ContentsWidth = 3, } ; diff --git a/src/BlockEntities/HopperEntity.h b/src/BlockEntities/HopperEntity.h index 6ef98f43a..8e856fcda 100644 --- a/src/BlockEntities/HopperEntity.h +++ b/src/BlockEntities/HopperEntity.h @@ -22,7 +22,8 @@ class cHopperEntity : typedef cBlockEntityWithItems super; public: - enum { + enum + { ContentsHeight = 1, ContentsWidth = 5, TICKS_PER_TRANSFER = 8, ///< How many ticks at minimum between two item transfers to or from the hopper -- cgit v1.2.3 From 93d29555e58df172bafba530afbc593c16ec66a3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 21 Jul 2014 15:19:48 +0200 Subject: Style: Normalized to no spaces before closing parenthesis. --- src/BlockEntities/BeaconEntity.cpp | 2 +- src/BlockEntities/BeaconEntity.h | 2 +- src/BlockEntities/BlockEntity.h | 2 +- src/BlockEntities/CommandBlockEntity.h | 4 ++-- src/BlockEntities/FlowerPotEntity.h | 4 ++-- src/BlockEntities/FurnaceEntity.cpp | 2 +- src/BlockEntities/MobHeadEntity.h | 4 ++-- src/BlockEntities/SignEntity.h | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index 9a6d85f1d..4b9662797 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -66,7 +66,7 @@ int cBeaconEntity::GetPyramidLevel(void) bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType) { - switch(a_BlockType) + switch (a_BlockType) { case E_BLOCK_DIAMOND_BLOCK: case E_BLOCK_GOLD_BLOCK: diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h index b1df68bc4..ee1eda391 100644 --- a/src/BlockEntities/BeaconEntity.h +++ b/src/BlockEntities/BeaconEntity.h @@ -33,7 +33,7 @@ public: static bool IsMineralBlock(BLOCKTYPE a_BlockType); // cBlockEntity overrides: - virtual void SaveToJson(Json::Value& a_Value ) override; + virtual void SaveToJson(Json::Value& a_Value) override; virtual void SendTo(cClientHandle & a_Client) override; virtual void UsedBy(cPlayer * a_Player) override; virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */) override; diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 7c6688f8d..24c25e729 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -79,7 +79,7 @@ public: virtual void SaveToJson (Json::Value & a_Value) = 0; /// Called when a player uses this entity; should open the UI window - virtual void UsedBy( cPlayer * a_Player ) = 0; + virtual void UsedBy( cPlayer * a_Player) = 0; /** Sends the packet defining the block entity to the client specified. To send to all eligible clients, use cWorld::BroadcastBlockEntity() diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h index d7c4eaabe..d02bf7d7b 100644 --- a/src/BlockEntities/CommandBlockEntity.h +++ b/src/BlockEntities/CommandBlockEntity.h @@ -38,8 +38,8 @@ public: /// Creates a new empty command block entity cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_World); - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson(Json::Value& a_Value ) override; + bool LoadFromJson( const Json::Value& a_Value); + virtual void SaveToJson(Json::Value& a_Value) override; virtual bool Tick(float a_Dt, cChunk & a_Chunk) override; virtual void SendTo(cClientHandle & a_Client) override; diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h index 85cb810ad..89901cf2d 100644 --- a/src/BlockEntities/FlowerPotEntity.h +++ b/src/BlockEntities/FlowerPotEntity.h @@ -39,8 +39,8 @@ public: /** Creates a new flowerpot entity at the specified block coords. a_World may be NULL */ cFlowerPotEntity(int a_BlocX, int a_BlockY, int a_BlockZ, cWorld * a_World); - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson(Json::Value& a_Value ) override; + bool LoadFromJson( const Json::Value& a_Value); + virtual void SaveToJson(Json::Value& a_Value) override; virtual void Destroy(void) override; diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index 1b1741713..72fd7f2b3 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -160,7 +160,7 @@ bool cFurnaceEntity::LoadFromJson(const Json::Value & a_Value) -void cFurnaceEntity::SaveToJson( Json::Value& a_Value ) +void cFurnaceEntity::SaveToJson( Json::Value& a_Value) { a_Value["x"] = m_PosX; a_Value["y"] = m_PosY; diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h index 2bc072d69..f91a3cc9e 100644 --- a/src/BlockEntities/MobHeadEntity.h +++ b/src/BlockEntities/MobHeadEntity.h @@ -37,8 +37,8 @@ public: /** Creates a new mob head entity at the specified block coords. a_World may be NULL */ cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson(Json::Value& a_Value ) override; + bool LoadFromJson( const Json::Value& a_Value); + virtual void SaveToJson(Json::Value& a_Value) override; // tolua_begin diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h index 16e0e23bc..33af100a4 100644 --- a/src/BlockEntities/SignEntity.h +++ b/src/BlockEntities/SignEntity.h @@ -37,8 +37,8 @@ public: /// Creates a new empty sign entity at the specified block coords and block type (wall or standing). a_World may be NULL cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World); - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson(Json::Value& a_Value ) override; + bool LoadFromJson( const Json::Value& a_Value); + virtual void SaveToJson(Json::Value& a_Value) override; // tolua_begin -- cgit v1.2.3 From 4191be7ddba820af4ed0c505a8d62416c2b7a8b4 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 22 Jul 2014 15:36:13 -0700 Subject: Removed redundant semicolons and re-added warning --- src/BlockEntities/BlockEntity.h | 4 ++-- src/BlockEntities/JukeboxEntity.h | 2 +- src/BlockEntities/NoteEntity.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 24c25e729..5710f8543 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -38,9 +38,9 @@ protected: public: // tolua_end - virtual ~cBlockEntity() {}; // force a virtual destructor in all descendants + virtual ~cBlockEntity() {} // force a virtual destructor in all descendants - virtual void Destroy(void) {}; + virtual void Destroy(void) {} void SetWorld(cWorld * a_World) { diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 8bb3009eb..d677d340f 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -58,7 +58,7 @@ public: static const char * GetClassStatic(void) { return "cJukeboxEntity"; } virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle &) override { }; + virtual void SendTo(cClientHandle &) override {} private: int m_Record; diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index 07b8fd259..e8497da3e 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -52,7 +52,7 @@ public: // tolua_end virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle &) override { }; + virtual void SendTo(cClientHandle &) override {} static const char * GetClassStatic(void) { return "cNoteEntity"; } -- cgit v1.2.3