From a3a3a6ebe6bc7f861f08922754aa986505f56756 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 17 Sep 2013 20:59:36 +0100 Subject: Added wood directions + Added wood directions --- source/Blocks/BlockWood.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'source/Blocks') diff --git a/source/Blocks/BlockWood.h b/source/Blocks/BlockWood.h index 4e2246506..dd4544586 100644 --- a/source/Blocks/BlockWood.h +++ b/source/Blocks/BlockWood.h @@ -15,6 +15,51 @@ public: { } + + 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; + NIBBLETYPE Meta = a_Player->GetEquippedItem().m_ItemDamage; + a_BlockMeta = BlockFaceToMetaData(a_BlockFace, Meta); + return true; + } + + + inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace, NIBBLETYPE a_WoodMeta) + { + switch (a_BlockFace) + { + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + return a_WoodMeta; // Top or bottom, just return original + } + + case BLOCK_FACE_ZP: + case BLOCK_FACE_ZM: + { + return a_WoodMeta | 0x8; // North or south + } + + case BLOCK_FACE_XP: + case BLOCK_FACE_XM: + { + return a_WoodMeta | 0x4; // East or west + } + + default: + { + ASSERT(!"Unhandled block face!"); + return a_WoodMeta | 0xC; // No idea, give a special meta (all sides bark) + } + } + } + virtual const char * GetStepSound(void) override { -- cgit v1.2.3 From ab696c37c31dacb4bf830d71050a88659dc97946 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 17 Sep 2013 21:22:26 +0100 Subject: Snow now supports meta values Fixes #98 --- source/Blocks/BlockSnow.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'source/Blocks') diff --git a/source/Blocks/BlockSnow.h b/source/Blocks/BlockSnow.h index bdd9f0b87..b8d48362c 100644 --- a/source/Blocks/BlockSnow.h +++ b/source/Blocks/BlockSnow.h @@ -15,8 +15,28 @@ public: : 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; + NIBBLETYPE Meta = a_World->GetBlockMeta(Vector3i(a_BlockX, a_BlockY, a_BlockZ)); + + if ((Meta < 7) && (Meta != 0)) // Is height at maximum (7) or at mininum (0)? Don't do anything if so + { + Meta++; + } + + a_BlockMeta = Meta; + return true; + } + + virtual bool DoesIgnoreBuildCollision(void) override { return true; -- cgit v1.2.3 From 480991d1ac07c1715bf090a4d81e988a00803cf3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 18 Sep 2013 00:01:20 +0100 Subject: Multiple fixes [SEE DESC] - Removed two random block handling files in the item handling section that didn't do anything. (One was an attempt at making slabs work, but failed to realise that the coords would have to be the block CLICKED, and another was just a random empty file for handling wooden planks.) * Fixed placing repeater blocks not directioning properly * Fixed wood directions breaking plank metadata --- source/Blocks/BlockHandler.cpp | 3 ++- source/Blocks/BlockPlanks.h | 41 +++++++++++++++++++++++++++++++++ source/Blocks/BlockRedstoneRepeater.cpp | 16 +++++++++++++ source/Blocks/BlockRedstoneRepeater.h | 9 ++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 source/Blocks/BlockPlanks.h (limited to 'source/Blocks') diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp index 3e97d1e9d..e1cfebb56 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 "BlockPlanks.h" #include "BlockPumpkin.h" #include "BlockRail.h" #include "BlockRedstone.h" @@ -153,7 +154,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (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_PLANKS: return new cBlockPlanksHandler (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); diff --git a/source/Blocks/BlockPlanks.h b/source/Blocks/BlockPlanks.h new file mode 100644 index 000000000..b30164741 --- /dev/null +++ b/source/Blocks/BlockPlanks.h @@ -0,0 +1,41 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockPlanksHandler : public cBlockHandler +{ +public: + cBlockPlanksHandler(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; + NIBBLETYPE Meta = a_Player->GetEquippedItem().m_ItemDamage; + a_BlockMeta = Meta; + return true; + } + + + virtual const char * GetStepSound(void) override + { + return "step.wood"; + } +} ; + + + + diff --git a/source/Blocks/BlockRedstoneRepeater.cpp b/source/Blocks/BlockRedstoneRepeater.cpp index 3bc879435..5e491ee5a 100644 --- a/source/Blocks/BlockRedstoneRepeater.cpp +++ b/source/Blocks/BlockRedstoneRepeater.cpp @@ -4,6 +4,7 @@ #include "../Item.h" #include "../World.h" #include "../Simulator/RedstoneSimulator.h" +#include "../Entities/Player.h" @@ -44,3 +45,18 @@ void cBlockRedstoneRepeaterHandler::OnDigging(cWorld *a_World, cPlayer *a_Player +bool cBlockRedstoneRepeaterHandler::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 +) +{ + a_BlockType = m_BlockType; + a_BlockMeta = cRedstoneSimulator::RepeaterRotationToMetaData(a_Player->GetRotation()); + return true; +} + + + + diff --git a/source/Blocks/BlockRedstoneRepeater.h b/source/Blocks/BlockRedstoneRepeater.h index 24250ab86..21f227332 100644 --- a/source/Blocks/BlockRedstoneRepeater.h +++ b/source/Blocks/BlockRedstoneRepeater.h @@ -36,6 +36,15 @@ public: { return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); } + + + 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; + virtual const char * GetStepSound(void) override { -- cgit v1.2.3 From 846f1223f4da984b9992d60ef7c40a092dcd4ad7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 18 Sep 2013 18:27:21 +0100 Subject: Implemented redstone comparators They can be placed and toggled, but stills needs proper redstone support --- source/Blocks/BlockComparator.cpp | 64 +++++++++++++++++++++++++++++++++++++++ source/Blocks/BlockComparator.h | 57 ++++++++++++++++++++++++++++++++++ source/Blocks/BlockHandler.cpp | 7 +++-- 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 source/Blocks/BlockComparator.cpp create mode 100644 source/Blocks/BlockComparator.h (limited to 'source/Blocks') diff --git a/source/Blocks/BlockComparator.cpp b/source/Blocks/BlockComparator.cpp new file mode 100644 index 000000000..e6fa64e2c --- /dev/null +++ b/source/Blocks/BlockComparator.cpp @@ -0,0 +1,64 @@ + +#include "Globals.h" +#include "BlockComparator.h" +#include "../Item.h" +#include "../World.h" +#include "../Simulator/RedstoneSimulator.h" +#include "../Entities/Player.h" + + + + + +cBlockComparatorHandler::cBlockComparatorHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) +{ +} + + + + + +void cBlockComparatorHandler::OnDestroyed(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ) +{ + // Nothing needed yet +} + + + + + +void cBlockComparatorHandler::OnUse(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) +{ + NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + Meta ^= 0x04; // Toggle 3rd (addition/subtraction) bit with XOR + a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta); +} + + + + + +void cBlockComparatorHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) +{ + OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NONE, 8, 8, 8); +} + + + + +bool cBlockComparatorHandler::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 +) +{ + a_BlockType = m_BlockType; + a_BlockMeta = cRedstoneSimulator::RepeaterRotationToMetaData(a_Player->GetRotation()); + return true; +} + + + + diff --git a/source/Blocks/BlockComparator.h b/source/Blocks/BlockComparator.h new file mode 100644 index 000000000..208727107 --- /dev/null +++ b/source/Blocks/BlockComparator.h @@ -0,0 +1,57 @@ + +#pragma once + +#include "BlockHandler.h" +#include "../World.h" + + + + + +class cBlockComparatorHandler : + public cBlockHandler +{ +public: + cBlockComparatorHandler(BLOCKTYPE a_BlockType); + virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; + + virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void OnUse(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) override; + + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + // Reset meta to 0 + a_Pickups.push_back(cItem(E_ITEM_COMPARATOR, 1, 0)); + } + + + virtual bool IsUseable(void) override + { + return true; + } + + + virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + { + return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); + } + + + 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; + + + virtual const char * GetStepSound(void) override + { + return "step.wood"; + } +} ; + + + + diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp index e1cfebb56..43330befa 100644 --- a/source/Blocks/BlockHandler.cpp +++ b/source/Blocks/BlockHandler.cpp @@ -13,6 +13,7 @@ #include "BlockChest.h" #include "BlockCloth.h" #include "BlockCobWeb.h" +#include "BlockComparator.h" #include "BlockCrops.h" #include "BlockDeadBush.h" #include "BlockDirt.h" @@ -110,6 +111,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_CAULDRON: return new cBlockCauldronHandler (a_BlockType); case E_BLOCK_CHEST: return new cBlockChestHandler (a_BlockType); case E_BLOCK_COAL_ORE: return new cBlockOreHandler (a_BlockType); + case E_BLOCK_ACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); case E_BLOCK_COBBLESTONE: return new cBlockStoneHandler (a_BlockType); case E_BLOCK_COBBLESTONE_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_COBWEB: return new cBlockCobWebHandler (a_BlockType); @@ -124,7 +126,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_DROPPER: return new cBlockDropSpenserHandler (a_BlockType); case E_BLOCK_EMERALD_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_ENDER_CHEST: return new cBlockEnderchestHandler (a_BlockType); - case E_BLOCK_FARMLAND: return new cBlockFarmlandHandler; + case E_BLOCK_FARMLAND: return new cBlockFarmlandHandler ( ); case E_BLOCK_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType); case E_BLOCK_FIRE: return new cBlockFireHandler (a_BlockType); case E_BLOCK_FLOWER_POT: return new cBlockFlowerPotHandler (a_BlockType); @@ -136,6 +138,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); + case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); case E_BLOCK_IRON_DOOR: return new cBlockDoorHandler (a_BlockType); case E_BLOCK_IRON_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_JUKEBOX: return new cBlockEntityHandler (a_BlockType); @@ -153,7 +156,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType); case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType); - case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler (); + case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler ( ); case E_BLOCK_PLANKS: return new cBlockPlanksHandler (a_BlockType); case E_BLOCK_PUMPKIN: return new cBlockPumpkinHandler (a_BlockType); case E_BLOCK_JACK_O_LANTERN: return new cBlockPumpkinHandler (a_BlockType); -- cgit v1.2.3 From 198ac1892ca0751551206ca25164bc691386914b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 18 Sep 2013 22:20:08 +0100 Subject: Fixed pickups --- source/Blocks/BlockHandler.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source/Blocks') diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp index 43330befa..7d896f1b6 100644 --- a/source/Blocks/BlockHandler.cpp +++ b/source/Blocks/BlockHandler.cpp @@ -358,13 +358,17 @@ void cBlockHandler::DropBlock(cWorld * a_World, cEntity * a_Digger, int a_BlockX if (!Pickups.empty()) { - // Add random offset to the spawn position: - // Commented out until bug with pickups not spawning properly is fixed, see World.cpp - /* - int MicroX = (int)(a_BlockX * 32) + (r1.randInt(16) + r1.randInt(16) - 16); - int MicroY = (int)(a_BlockY * 32) + (r1.randInt(16) + r1.randInt(16) - 16); - int MicroZ = (int)(a_BlockZ * 32) + (r1.randInt(16) + r1.randInt(16) - 16); - */ + MTRand r1; + + // Mid-block position first + int MicroX = (int)(floor(a_BlockX) * 32) + 16; + int MicroY = (int)(floor(a_BlockY) * 32) + 16; + int MicroZ = (int)(floor(a_BlockZ) * 32) + 16; + + // Add random offset second + MicroX = (int)(a_BlockX * 32) + (r1.randInt(16) + r1.randInt(16) - 16); + MicroY = (int)(a_BlockY * 32) + (r1.randInt(16) + r1.randInt(16) - 16); + MicroZ = (int)(a_BlockZ * 32) + (r1.randInt(16) + r1.randInt(16) - 16); a_World->SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ); } -- cgit v1.2.3 From 0c58adb2b440a68ffdfd2967d21019912d390108 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 19 Sep 2013 21:46:39 +0100 Subject: Fixed pickup block spawning --- source/Blocks/BlockHandler.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source/Blocks') diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp index 7d896f1b6..b06171119 100644 --- a/source/Blocks/BlockHandler.cpp +++ b/source/Blocks/BlockHandler.cpp @@ -361,16 +361,17 @@ void cBlockHandler::DropBlock(cWorld * a_World, cEntity * a_Digger, int a_BlockX MTRand r1; // Mid-block position first - int MicroX = (int)(floor(a_BlockX) * 32) + 16; - int MicroY = (int)(floor(a_BlockY) * 32) + 16; - int MicroZ = (int)(floor(a_BlockZ) * 32) + 16; + double MicroX, MicroY, MicroZ; + MicroX = a_BlockX + 0.5; + MicroY = a_BlockY + 0.5; + MicroZ = a_BlockZ + 0.5; - // Add random offset second - MicroX = (int)(a_BlockX * 32) + (r1.randInt(16) + r1.randInt(16) - 16); - MicroY = (int)(a_BlockY * 32) + (r1.randInt(16) + r1.randInt(16) - 16); - MicroZ = (int)(a_BlockZ * 32) + (r1.randInt(16) + r1.randInt(16) - 16); + // Add random offset second (this causes pickups to spawn inside blocks most times, it's a little buggy) + //MicroX += (int)(r1.randInt(16) + r1.randInt(16) - 16); + //MicroY += (int)(r1.randInt(16) + r1.randInt(16) - 16); + //MicroZ += (int)(r1.randInt(16) + r1.randInt(16) - 16); - a_World->SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ); + a_World->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ); } } -- cgit v1.2.3 From 9d46fa6ae9718f51f9031111c4f28ffd7e6ecc0f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Sep 2013 18:18:04 +0100 Subject: Changed to SetBlockMeta --- source/Blocks/BlockComparator.cpp | 2 +- source/Blocks/BlockLever.cpp | 2 +- source/Blocks/BlockRedstoneRepeater.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source/Blocks') diff --git a/source/Blocks/BlockComparator.cpp b/source/Blocks/BlockComparator.cpp index e6fa64e2c..87a10dc88 100644 --- a/source/Blocks/BlockComparator.cpp +++ b/source/Blocks/BlockComparator.cpp @@ -32,7 +32,7 @@ void cBlockComparatorHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_Bl { NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); Meta ^= 0x04; // Toggle 3rd (addition/subtraction) bit with XOR - a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta); + a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); } diff --git a/source/Blocks/BlockLever.cpp b/source/Blocks/BlockLever.cpp index f2ca1805a..bd70cfd1b 100644 --- a/source/Blocks/BlockLever.cpp +++ b/source/Blocks/BlockLever.cpp @@ -23,7 +23,7 @@ void cBlockLeverHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, { // Flip the ON bit on/off. Using XOR bitwise operation to turn it on/off. NIBBLETYPE Meta = ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08) & 0x0f); - a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta); + a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); if (Meta & 0x08) { a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); diff --git a/source/Blocks/BlockRedstoneRepeater.cpp b/source/Blocks/BlockRedstoneRepeater.cpp index 5e491ee5a..8cfb48f4d 100644 --- a/source/Blocks/BlockRedstoneRepeater.cpp +++ b/source/Blocks/BlockRedstoneRepeater.cpp @@ -30,7 +30,7 @@ void cBlockRedstoneRepeaterHandler::OnDestroyed(cWorld *a_World, int a_BlockX, i void cBlockRedstoneRepeaterHandler::OnUse(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) { - a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); + a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) + 0x04) & 0x0f)); } -- cgit v1.2.3 From 5c22a9f5f0e1e072eb9034a79e3bfc465822deab Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Sep 2013 19:16:56 +0100 Subject: Removed OnDigging for Redstone devices --- source/Blocks/BlockComparator.cpp | 9 --------- source/Blocks/BlockComparator.h | 1 - source/Blocks/BlockLever.cpp | 10 +--------- source/Blocks/BlockLever.h | 1 - source/Blocks/BlockRedstoneRepeater.cpp | 9 --------- source/Blocks/BlockRedstoneRepeater.h | 1 - 6 files changed, 1 insertion(+), 30 deletions(-) (limited to 'source/Blocks') diff --git a/source/Blocks/BlockComparator.cpp b/source/Blocks/BlockComparator.cpp index 87a10dc88..72453a816 100644 --- a/source/Blocks/BlockComparator.cpp +++ b/source/Blocks/BlockComparator.cpp @@ -38,15 +38,6 @@ void cBlockComparatorHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_Bl - -void cBlockComparatorHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) -{ - OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NONE, 8, 8, 8); -} - - - - bool cBlockComparatorHandler::GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, diff --git a/source/Blocks/BlockComparator.h b/source/Blocks/BlockComparator.h index 208727107..b80c9c72c 100644 --- a/source/Blocks/BlockComparator.h +++ b/source/Blocks/BlockComparator.h @@ -15,7 +15,6 @@ public: cBlockComparatorHandler(BLOCKTYPE a_BlockType); virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void OnUse(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) override; diff --git a/source/Blocks/BlockLever.cpp b/source/Blocks/BlockLever.cpp index bd70cfd1b..96b5fc368 100644 --- a/source/Blocks/BlockLever.cpp +++ b/source/Blocks/BlockLever.cpp @@ -23,6 +23,7 @@ void cBlockLeverHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, { // Flip the ON bit on/off. Using XOR bitwise operation to turn it on/off. NIBBLETYPE Meta = ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08) & 0x0f); + a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); if (Meta & 0x08) { @@ -37,12 +38,3 @@ void cBlockLeverHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_BlockX, - -void cBlockLeverHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) -{ - OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NONE, 8, 8, 8); -} - - - - diff --git a/source/Blocks/BlockLever.h b/source/Blocks/BlockLever.h index ddf48297c..416d7685f 100644 --- a/source/Blocks/BlockLever.h +++ b/source/Blocks/BlockLever.h @@ -14,7 +14,6 @@ class cBlockLeverHandler : public: cBlockLeverHandler(BLOCKTYPE a_BlockType); - virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void OnUse(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) override; diff --git a/source/Blocks/BlockRedstoneRepeater.cpp b/source/Blocks/BlockRedstoneRepeater.cpp index 8cfb48f4d..672fdf55a 100644 --- a/source/Blocks/BlockRedstoneRepeater.cpp +++ b/source/Blocks/BlockRedstoneRepeater.cpp @@ -36,15 +36,6 @@ void cBlockRedstoneRepeaterHandler::OnUse(cWorld *a_World, cPlayer *a_Player, in - -void cBlockRedstoneRepeaterHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) -{ - OnUse(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NONE, 8, 8, 8); -} - - - - bool cBlockRedstoneRepeaterHandler::GetPlacementBlockTypeMeta( cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, diff --git a/source/Blocks/BlockRedstoneRepeater.h b/source/Blocks/BlockRedstoneRepeater.h index 21f227332..01d9de96d 100644 --- a/source/Blocks/BlockRedstoneRepeater.h +++ b/source/Blocks/BlockRedstoneRepeater.h @@ -15,7 +15,6 @@ public: cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockType); virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override; - virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void OnUse(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) override; -- cgit v1.2.3 From a8a45a4afc615926a705eee482c27ef166f2f9ec Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Sep 2013 19:34:42 +0100 Subject: Added button placement handler Also removed an unneeded variable in the stair handler --- source/Blocks/BlockButton.cpp | 40 ++++++++++++++++++++++++ source/Blocks/BlockButton.h | 69 ++++++++++++++++++++++++++++++++++++++++++ source/Blocks/BlockHandler.cpp | 3 ++ source/Blocks/BlockStairs.h | 1 - 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 source/Blocks/BlockButton.cpp create mode 100644 source/Blocks/BlockButton.h (limited to 'source/Blocks') diff --git a/source/Blocks/BlockButton.cpp b/source/Blocks/BlockButton.cpp new file mode 100644 index 000000000..8df399cf0 --- /dev/null +++ b/source/Blocks/BlockButton.cpp @@ -0,0 +1,40 @@ + +#include "Globals.h" +#include "BlockButton.h" +#include "../Simulator/RedstoneSimulator.h" + + + + + +cBlockButtonHandler::cBlockButtonHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) +{ +} + + + + + +void cBlockButtonHandler::OnUse(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) +{ + // Flip the ON bit on/off. Using XOR bitwise operation to turn it on/off. + NIBBLETYPE Meta = ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08) & 0x0f); + a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + + if (Meta & 0x08) + { + a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); + } + else + { + a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.5f); + } + + // Queue a button reset (unpress), with a GetBlock to prevent duplication of buttons (press, break, wait for reset) + a_World->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), ((a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08) & 0x0f), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 25); +} + + + + diff --git a/source/Blocks/BlockButton.h b/source/Blocks/BlockButton.h new file mode 100644 index 000000000..e3f655bfa --- /dev/null +++ b/source/Blocks/BlockButton.h @@ -0,0 +1,69 @@ +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockButtonHandler : + public cBlockHandler +{ +public: + cBlockButtonHandler(BLOCKTYPE a_BlockType); + + virtual void OnUse(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) override; + + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + // Reset meta to 0 + a_Pickups.push_back(cItem(m_BlockType == E_BLOCK_WOODEN_BUTTON ? E_BLOCK_WOODEN_BUTTON : E_BLOCK_STONE_BUTTON, 1, 0)); + } + + + virtual bool IsUseable(void) override + { + return true; + } + + + 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 = BlockFaceToMetaData(a_BlockFace); + return true; + } + + + virtual const char * GetStepSound(void) override + { + return m_BlockType == E_BLOCK_WOODEN_BUTTON ? "step.wood" : "step.stone"; + } + + + inline static NIBBLETYPE BlockFaceToMetaData(char a_BlockFace) + { + switch (a_BlockFace) + { + case BLOCK_FACE_ZP: { return 0x4; } + case BLOCK_FACE_ZM: { return 0x3; } + case BLOCK_FACE_XP: { return 0x2; } + case BLOCK_FACE_XM: { return 0x1; } + default: + { + ASSERT(!"Unhandled block face!"); + return 0x0; // No idea, give a special meta (button in centre of block) + } + } + } +} ; + + + + diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp index b06171119..e59fee8ee 100644 --- a/source/Blocks/BlockHandler.cpp +++ b/source/Blocks/BlockHandler.cpp @@ -7,6 +7,7 @@ #include "../PluginManager.h" #include "BlockBed.h" #include "BlockBrewingStand.h" +#include "BlockButton.h" #include "BlockCactus.h" #include "BlockCarpet.h" #include "BlockCauldron.h" @@ -185,6 +186,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_STICKY_PISTON: return new cBlockPistonHandler (a_BlockType); case E_BLOCK_STONE: return new cBlockStoneHandler (a_BlockType); case E_BLOCK_STONE_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); + case E_BLOCK_STONE_BUTTON: return new cBlockButtonHandler (a_BlockType); case E_BLOCK_STONE_SLAB: return new cBlockSlabHandler (a_BlockType); case E_BLOCK_SUGARCANE: return new cBlockSugarcaneHandler (a_BlockType); case E_BLOCK_TALL_GRASS: return new cBlockTallGrassHandler (a_BlockType); @@ -192,6 +194,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_VINES: return new cBlockVineHandler (a_BlockType); case E_BLOCK_WALLSIGN: return new cBlockSignHandler (a_BlockType); case E_BLOCK_WATER: return new cBlockFluidHandler (a_BlockType); + case E_BLOCK_WOODEN_BUTTON: return new cBlockButtonHandler (a_BlockType); case E_BLOCK_WOODEN_DOOR: return new cBlockDoorHandler (a_BlockType); case E_BLOCK_WOODEN_SLAB: return new cBlockSlabHandler (a_BlockType); case E_BLOCK_WOODEN_STAIRS: return new cBlockStairsHandler (a_BlockType); diff --git a/source/Blocks/BlockStairs.h b/source/Blocks/BlockStairs.h index 485ebda1a..8d259eee3 100644 --- a/source/Blocks/BlockStairs.h +++ b/source/Blocks/BlockStairs.h @@ -53,7 +53,6 @@ public: static NIBBLETYPE RotationToMetaData(double a_Rotation) { a_Rotation += 90 + 45; // So its not aligned with axis - NIBBLETYPE result = 0x0; if (a_Rotation > 360) { a_Rotation -= 360; -- cgit v1.2.3 From dad3648102c5861ed691ac90bd265bcc5667e787 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 22 Sep 2013 19:48:59 +0100 Subject: Removed some unneeded includes --- source/Blocks/BlockButton.cpp | 1 - source/Blocks/BlockComparator.cpp | 2 -- source/Blocks/BlockComparator.h | 1 - source/Blocks/BlockLever.cpp | 2 -- source/Blocks/BlockLever.h | 1 - source/Blocks/BlockRedstoneRepeater.cpp | 2 -- source/Blocks/BlockRedstoneRepeater.h | 1 - 7 files changed, 10 deletions(-) (limited to 'source/Blocks') diff --git a/source/Blocks/BlockButton.cpp b/source/Blocks/BlockButton.cpp index 8df399cf0..1011f9351 100644 --- a/source/Blocks/BlockButton.cpp +++ b/source/Blocks/BlockButton.cpp @@ -1,7 +1,6 @@ #include "Globals.h" #include "BlockButton.h" -#include "../Simulator/RedstoneSimulator.h" diff --git a/source/Blocks/BlockComparator.cpp b/source/Blocks/BlockComparator.cpp index 72453a816..b4e5a55d0 100644 --- a/source/Blocks/BlockComparator.cpp +++ b/source/Blocks/BlockComparator.cpp @@ -1,8 +1,6 @@ #include "Globals.h" #include "BlockComparator.h" -#include "../Item.h" -#include "../World.h" #include "../Simulator/RedstoneSimulator.h" #include "../Entities/Player.h" diff --git a/source/Blocks/BlockComparator.h b/source/Blocks/BlockComparator.h index b80c9c72c..cb2941d3c 100644 --- a/source/Blocks/BlockComparator.h +++ b/source/Blocks/BlockComparator.h @@ -2,7 +2,6 @@ #pragma once #include "BlockHandler.h" -#include "../World.h" diff --git a/source/Blocks/BlockLever.cpp b/source/Blocks/BlockLever.cpp index 96b5fc368..a9bd6c990 100644 --- a/source/Blocks/BlockLever.cpp +++ b/source/Blocks/BlockLever.cpp @@ -1,8 +1,6 @@ #include "Globals.h" #include "BlockLever.h" -#include "../Item.h" -#include "../World.h" #include "../Entities/Player.h" #include "../Simulator/RedstoneSimulator.h" diff --git a/source/Blocks/BlockLever.h b/source/Blocks/BlockLever.h index 416d7685f..5553170e2 100644 --- a/source/Blocks/BlockLever.h +++ b/source/Blocks/BlockLever.h @@ -1,7 +1,6 @@ #pragma once #include "BlockHandler.h" -#include "../World.h" #include "../Simulator/RedstoneSimulator.h" diff --git a/source/Blocks/BlockRedstoneRepeater.cpp b/source/Blocks/BlockRedstoneRepeater.cpp index 672fdf55a..72ea21012 100644 --- a/source/Blocks/BlockRedstoneRepeater.cpp +++ b/source/Blocks/BlockRedstoneRepeater.cpp @@ -1,8 +1,6 @@ #include "Globals.h" #include "BlockRedstoneRepeater.h" -#include "../Item.h" -#include "../World.h" #include "../Simulator/RedstoneSimulator.h" #include "../Entities/Player.h" diff --git a/source/Blocks/BlockRedstoneRepeater.h b/source/Blocks/BlockRedstoneRepeater.h index 01d9de96d..958841a34 100644 --- a/source/Blocks/BlockRedstoneRepeater.h +++ b/source/Blocks/BlockRedstoneRepeater.h @@ -2,7 +2,6 @@ #pragma once #include "BlockHandler.h" -#include "../World.h" -- cgit v1.2.3