From 3d7813fdb29ada655914a46667ab21fd03c15e56 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Sep 2013 22:09:31 +0100 Subject: Pumpkin and JackOLantern support Fixes #99 --- source/Blocks/BlockHandler.cpp | 3 ++ source/Blocks/BlockPumpkin.h | 62 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 source/Blocks/BlockPumpkin.h diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp index 5134c1103..7104929bd 100644 --- a/source/Blocks/BlockHandler.cpp +++ b/source/Blocks/BlockHandler.cpp @@ -41,6 +41,7 @@ #include "BlockNote.h" #include "BlockOre.h" #include "BlockPiston.h" +#include "BlockPumpkin.h" #include "BlockRail.h" #include "BlockRedstone.h" #include "BlockRedstoneRepeater.h" @@ -153,6 +154,8 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType); case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler (); case E_BLOCK_PLANKS: return new cBlockWoodHandler (a_BlockType); + case E_BLOCK_PUMPKIN: return new cBlockPumpkinHandler (a_BlockType); + case E_BLOCK_JACK_O_LANTERN: return new cBlockPumpkinHandler (a_BlockType); case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType); case E_BLOCK_QUARTZ_STAIR: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); diff --git a/source/Blocks/BlockPumpkin.h b/source/Blocks/BlockPumpkin.h new file mode 100644 index 000000000..3c9bec43a --- /dev/null +++ b/source/Blocks/BlockPumpkin.h @@ -0,0 +1,62 @@ + +#pragma once + +#include "BlockHandler.h" + + + + +class cBlockPumpkinHandler : + public cBlockHandler +{ +public: + cBlockPumpkinHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = m_BlockType; + + a_BlockMeta = PlayerYawToMetaData(a_Player->GetRotation() - 180); + return true; + } + + inline static NIBBLETYPE PlayerYawToMetaData(double a_Yaw) + { + ASSERT((a_Yaw >= -180) && (a_Yaw < 180)); + + a_Yaw += 360 + 45; + if (a_Yaw > 360) + { + a_Yaw -= 360; + } + if ((a_Yaw >= 0) && (a_Yaw < 90)) + { + return 0x0; + } + else if ((a_Yaw >= 180) && (a_Yaw < 270)) + { + return 0x2; + } + else if ((a_Yaw >= 90) && (a_Yaw < 180)) + { + return 0x1; + } + else + { + return 0x3; + } + } + +} ; + + + + -- cgit v1.2.3 From 010bc94a342770e96a005353d23d7ebf6cc5aa39 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Sep 2013 22:51:07 +0100 Subject: Entities now maintain speed outside of world --- source/Entities/Entity.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 4066e81ab..0aaa2e899 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -491,8 +491,15 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) { // Outside of the world - // TODO: Current speed should still be added to the entity position - // Otherwise TNT explosions in the void will still effect the bottommost layers of the world + + cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX,BlockZ); + // See if we can commit our changes. If not, we will discard them. + if (NextChunk != NULL) + { + SetSpeed(NextSpeed); + NextPos += (NextSpeed * a_Dt); + SetPosition(NextPos); + } return; } -- cgit v1.2.3 From c8f8597774c47e755597eae4a120bea9479d0479 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Sep 2013 23:01:02 +0100 Subject: Added void damage --- source/Entities/Entity.cpp | 23 +++++++++++++++++++++++ source/Entities/Entity.h | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 0aaa2e899..846d756dd 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -55,6 +55,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_TicksSinceLastBurnDamage(0) , m_TicksSinceLastLavaDamage(0) , m_TicksSinceLastFireDamage(0) + , m_TicksSinceLastVoidDamage(0) , m_TicksLeftBurning(0) , m_WaterSpeed(0, 0, 0) , m_Width(a_Width) @@ -472,6 +473,11 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) { TickBurning(a_Chunk); } + if ((a_Chunk.IsValid()) && (GetPosY() < -46)) + { + TickInVoid(a_Chunk); + } + else { m_TicksSinceLastVoidDamage = 0; } } @@ -803,6 +809,23 @@ void cEntity::TickBurning(cChunk & a_Chunk) +void cEntity::TickInVoid(cChunk & a_Chunk) +{ + if (m_TicksSinceLastVoidDamage == 20) + { + TakeDamage(dtInVoid, NULL, 2, 0); + m_TicksSinceLastVoidDamage = 0; + } + else + { + m_TicksSinceLastVoidDamage++; + } +} + + + + + /// Called when the entity starts burning void cEntity::OnStartedBurning(void) { diff --git a/source/Entities/Entity.h b/source/Entities/Entity.h index b4777d249..df671a564 100644 --- a/source/Entities/Entity.h +++ b/source/Entities/Entity.h @@ -255,6 +255,9 @@ public: /// Updates the state related to this entity being on fire virtual void TickBurning(cChunk & a_Chunk); + + /// Handles when the entity is in the void + virtual void TickInVoid(cChunk & a_Chunk); /// Called when the entity starts burning virtual void OnStartedBurning(void); @@ -377,6 +380,9 @@ protected: /// Time, in ticks, until the entity extinguishes its fire int m_TicksLeftBurning; + + /// Time, in ticks, since the last damage dealt by the void. Reset to zero when moving out of the void. + int m_TicksSinceLastVoidDamage; virtual void Destroyed(void) {} // Called after the entity has been destroyed -- cgit v1.2.3 From cb167f78e3b2592fa26acb789d2dd34bd97c687d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Sep 2013 23:02:35 +0100 Subject: Added player void damage --- source/Entities/Player.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 0943f61ff..1f4f392ef 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -611,10 +611,13 @@ void cPlayer::SetSprint(bool a_IsSprinting) void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { - if (m_GameMode == eGameMode_Creative) + if (a_TDI.DamageType != dtInVoid) { - // No damage / health in creative mode - return; + if (m_GameMode == eGameMode_Creative) + { + // No damage / health in creative mode + return; + } } super::DoTakeDamage(a_TDI); -- cgit v1.2.3 From 3236364eeed10603e7aa9e2a50b82620d2703f7e Mon Sep 17 00:00:00 2001 From: worktycho Date: Wed, 11 Sep 2013 13:48:08 +0100 Subject: changed the subtaraction to a flip --- source/Blocks/BlockPumpkin.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Blocks/BlockPumpkin.h b/source/Blocks/BlockPumpkin.h index 3c9bec43a..5db4f98e9 100644 --- a/source/Blocks/BlockPumpkin.h +++ b/source/Blocks/BlockPumpkin.h @@ -1,4 +1,3 @@ - #pragma once #include "BlockHandler.h" @@ -23,8 +22,9 @@ public: ) override { a_BlockType = m_BlockType; - - a_BlockMeta = PlayerYawToMetaData(a_Player->GetRotation() - 180); + double a_Rotation = a_Player->GetRotation() + a_Rotation = -1 * a_Rotation; + a_BlockMeta = PlayerYawToMetaData(a_Rotation); return true; } -- cgit v1.2.3 From 37e0e684f41c7407ec0fc7227f6fda2b49443e21 Mon Sep 17 00:00:00 2001 From: worktycho Date: Wed, 11 Sep 2013 17:07:54 +0100 Subject: moved reflection code to PlayerYawToMetadata --- source/Blocks/BlockPumpkin.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/Blocks/BlockPumpkin.h b/source/Blocks/BlockPumpkin.h index 5db4f98e9..375740535 100644 --- a/source/Blocks/BlockPumpkin.h +++ b/source/Blocks/BlockPumpkin.h @@ -22,16 +22,15 @@ public: ) override { a_BlockType = m_BlockType; - double a_Rotation = a_Player->GetRotation() - a_Rotation = -1 * a_Rotation; - a_BlockMeta = PlayerYawToMetaData(a_Rotation); + a_BlockMeta = PlayerYawToMetaData(a_Player->GetRotation()); return true; } inline static NIBBLETYPE PlayerYawToMetaData(double a_Yaw) { - ASSERT((a_Yaw >= -180) && (a_Yaw < 180)); + ASSERT((a_Yaw >= -180) && (a_Yaw < 180)); + a_Yaw *= -1; a_Yaw += 360 + 45; if (a_Yaw > 360) { -- cgit v1.2.3 From e9321bc715b5298553b114666ccc3418591fbfdc Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Sep 2013 18:50:14 +0100 Subject: Better player gamemode detection --- source/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 1f4f392ef..bf96a6eaa 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -613,7 +613,7 @@ void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if (a_TDI.DamageType != dtInVoid) { - if (m_GameMode == eGameMode_Creative) + if (IsGameModeCreative()) { // No damage / health in creative mode return; -- cgit v1.2.3 From 8ef91817e93a98dd668c1d5b9e767dfe39d92f75 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Sep 2013 19:02:09 +0100 Subject: Pumpkins --- source/Blocks/BlockPumpkin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Blocks/BlockPumpkin.h b/source/Blocks/BlockPumpkin.h index 375740535..b74d60a85 100644 --- a/source/Blocks/BlockPumpkin.h +++ b/source/Blocks/BlockPumpkin.h @@ -30,7 +30,7 @@ public: { ASSERT((a_Yaw >= -180) && (a_Yaw < 180)); - a_Yaw *= -1; + a_Yaw -= 180; a_Yaw += 360 + 45; if (a_Yaw > 360) { -- cgit v1.2.3 From 3a1def2c905a8e6d8807d14c5953cceb04f6b8a6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Sep 2013 20:07:51 +0100 Subject: More changes [SEE DESC] * Improved (again) pumpkin direction handling * Fixed spacing in Entity.cpp --- source/Blocks/BlockPumpkin.h | 5 ++--- source/Entities/Entity.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/source/Blocks/BlockPumpkin.h b/source/Blocks/BlockPumpkin.h index b74d60a85..76abc6818 100644 --- a/source/Blocks/BlockPumpkin.h +++ b/source/Blocks/BlockPumpkin.h @@ -28,10 +28,9 @@ public: inline static NIBBLETYPE PlayerYawToMetaData(double a_Yaw) { - ASSERT((a_Yaw >= -180) && (a_Yaw < 180)); - a_Yaw -= 180; - a_Yaw += 360 + 45; + + a_Yaw += 180 + 45; if (a_Yaw > 360) { a_Yaw -= 360; diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 846d756dd..3d6c2887a 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -498,7 +498,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { // Outside of the world - cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX,BlockZ); + cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX, BlockZ); // See if we can commit our changes. If not, we will discard them. if (NextChunk != NULL) { -- cgit v1.2.3