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 (limited to 'source/Blocks') 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 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(-) (limited to 'source/Blocks') 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(-) (limited to 'source/Blocks') 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 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(-) (limited to 'source/Blocks') 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 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source/Blocks') 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; -- cgit v1.2.3