From 0376b847d76d0b47cd86ac862f3b0554bcfbe6aa Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:23:27 +0000 Subject: Removed exporting of a torch function --- src/Blocks/BlockTorch.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 72a313126..2e7c5b814 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -55,8 +55,8 @@ public: } - static NIBBLETYPE DirectionToMetaData(char a_Direction) // tolua_export - { // tolua_export + static NIBBLETYPE DirectionToMetaData(char a_Direction) + { switch (a_Direction) { case BLOCK_FACE_BOTTOM: ASSERT(!"Shouldn't be getting this face"); return 0; @@ -72,7 +72,7 @@ public: } }; return 0x0; - } // tolua_export + } static char MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export -- cgit v1.2.3 From 73dd2e9bed39c5f902a82568805f4328a0a79526 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:24:45 +0000 Subject: Removed another export and inline'd stuff --- src/Blocks/BlockTorch.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 2e7c5b814..342d88b6c 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -55,7 +55,7 @@ public: } - static NIBBLETYPE DirectionToMetaData(char a_Direction) + inline static NIBBLETYPE DirectionToMetaData(char a_Direction) { switch (a_Direction) { @@ -75,11 +75,11 @@ public: } - static char MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export - { // tolua_export + inline static char MetaDataToDirection(NIBBLETYPE a_MetaData) + { switch (a_MetaData) { - case 0: return BLOCK_FACE_TOP; // by default, the torches stand on the ground + case 0: return BLOCK_FACE_TOP; // By default, the torches stand on the ground case E_META_TORCH_FLOOR: return BLOCK_FACE_TOP; case E_META_TORCH_EAST: return BLOCK_FACE_EAST; case E_META_TORCH_WEST: return BLOCK_FACE_WEST; @@ -92,7 +92,7 @@ public: } } return 0; - } // tolua_export + } static bool IsAttachedTo(const Vector3i & a_TorchPos, char a_TorchMeta, const Vector3i & a_BlockPos) -- cgit v1.2.3 From 77a7bfb3e546446412993fc0c30ba55298c76661 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:35:10 +0000 Subject: Cleaned up torch code and added comments --- src/Blocks/BlockTorch.h | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 342d88b6c..9e543dfd7 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -38,7 +38,8 @@ public: else { // Not top or bottom faces, try to preserve whatever face was clicked - if (!TorchCanBePlacedAt(a_World, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace)) + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); + if (!CanBePlacedOn(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace)) { // Torch couldn't be placed on whatever face was clicked, last ditch resort - find another face a_BlockFace = FindSuitableFace(a_World, a_BlockX, a_BlockY, a_BlockZ); @@ -95,31 +96,11 @@ public: } - static bool IsAttachedTo(const Vector3i & a_TorchPos, char a_TorchMeta, const Vector3i & a_BlockPos) - { - switch (a_TorchMeta) - { - case 0x0: - case E_META_TORCH_FLOOR: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 1, 0))); - case E_META_TORCH_EAST: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 0, -1))); - case E_META_TORCH_WEST: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 0, 1))); - case E_META_TORCH_NORTH: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(-1, 0, 0))); - case E_META_TORCH_SOUTH: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(1, 0, 0))); - default: - { - ASSERT(!"Unhandled torch meta!"); - break; - } - } - return false; - } - - static bool CanBePlacedOn(BLOCKTYPE a_BlockType, char a_BlockFace) { if ( !g_BlockIsTorchPlaceable[a_BlockType] ) { - return (a_BlockFace == BLOCK_FACE_TOP); // Allow placement only when torch upright + return (a_BlockFace == BLOCK_FACE_TOP); // Allow placement only when torch upright (for glass, etc.); exceptions won't even be sent by client, no need to handle } else { @@ -128,22 +109,15 @@ public: } - static bool TorchCanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) - { - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); - return CanBePlacedOn(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace); - } - - /// Finds a suitable face to place the torch, returning BLOCK_FACE_NONE on failure static char FindSuitableFace(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) { - for (int i = 0; i <= 5; i++) + for (int i = BLOCK_FACE_YM; i <= BLOCK_FACE_XP; i++) // Loop through all directions { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, true); BLOCKTYPE BlockInQuestion = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - if ( + if ( // If on a block that can only hold a torch if torch is standing on it, return that face ((BlockInQuestion == E_BLOCK_GLASS) || (BlockInQuestion == E_BLOCK_FENCE) || (BlockInQuestion == E_BLOCK_NETHER_BRICK_FENCE) || @@ -155,10 +129,12 @@ public: } else if ((g_BlockIsTorchPlaceable[BlockInQuestion]) && (i != BLOCK_FACE_BOTTOM)) { + // Otherwise, if block in that direction is torch placeable and we haven't gotten to it via the bottom face, return that face return i; } else { + // Reset coords in preparation for next iteration AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, false); } } -- cgit v1.2.3 From 008c515b4b4c0fd0bb519591c9a3054b971ccf35 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 20:01:52 +0000 Subject: Fixed trapdoors not overriding OnUse --- src/Blocks/BlockTrapdoor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 58d770d23..4682faa3b 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -32,7 +32,7 @@ public: return true; } - 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) + 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 { // Flip the ON bit on/off using the XOR bitwise operation NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); -- cgit v1.2.3 From b115f3d636809e3cfaab80d401347a2d6e6f7df0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 21:31:55 +0000 Subject: Added trapdoor cursor Y detection --- src/Blocks/BlockTrapdoor.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 4682faa3b..57718b45f 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -50,12 +50,10 @@ public: a_BlockType = m_BlockType; a_BlockMeta = BlockFaceToMetaData(a_BlockFace); - /* TODO: fix CursorY issues and uncomment this if (a_CursorY > 7) { a_BlockMeta |= 0x8; } - */ return true; } -- cgit v1.2.3 From b02873172639db2ac7a494389899c2175e0ddd8f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 22:29:15 +0000 Subject: Fixed duplication glitch with QueueSetBlock If a coordinate was queued, and then the block there was broken, it would reappear: double items! Also now just sets meta if previous and current blocktypes matched. --- src/Blocks/BlockButton.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index ec897835a..c898a0466 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -18,14 +18,14 @@ public: 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 { - // Flip the ON bit on/off using the XOR bitwise operation + // Set p the ON bit to on NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); // Queue a button reset (unpress) - a_World->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30); + a_World->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30, m_BlockType); } -- cgit v1.2.3 From 347e80bdd88f894394373745859f405dc82c1819 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 00:18:58 +0000 Subject: Added basic ender chests Note that they just mirror chests now, so no per player inventory. --- src/Blocks/BlockEnderchest.h | 49 +++++++++++++++++++++++++++++++++++++++++--- src/Blocks/BlockFurnace.h | 1 - 2 files changed, 46 insertions(+), 4 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index 0ce813f1c..50d8e38e0 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -1,18 +1,18 @@ #pragma once -#include "BlockHandler.h" +#include "BlockEntity.h" class cBlockEnderchestHandler : - public cBlockHandler + public cBlockEntityHandler { public: cBlockEnderchestHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cBlockEntityHandler(a_BlockType) { } @@ -21,6 +21,49 @@ public: //todo: Drop Ender Chest if using silk touch pickaxe a_Pickups.push_back(cItem(E_BLOCK_OBSIDIAN, 8, 0)); } + + 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 = RotationToMetaData(a_Player->GetRotation()); + return true; + } + + virtual const char * GetStepSound(void) override + { + return "step.stone"; + } + + static NIBBLETYPE RotationToMetaData(double a_Rotation) + { + a_Rotation += 90 + 45; // So its not aligned with axis + + if (a_Rotation > 360.f) + { + a_Rotation -= 360.f; + } + if ((a_Rotation >= 0.f) && (a_Rotation < 90.f)) + { + return 0x4; + } + else if ((a_Rotation >= 180) && (a_Rotation < 270)) + { + return 0x5; + } + else if ((a_Rotation >= 90) && (a_Rotation < 180)) + { + return 0x2; + } + else + { + return 0x3; + } + } } ; diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index fe35893d5..5b067d7b7 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -4,7 +4,6 @@ #include "BlockEntity.h" #include "../World.h" #include "../Piston.h" -#include "../Entities/Player.h" -- cgit v1.2.3 From 5bed85aba0720dc22db56dcaec28675c189491c4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 18:03:56 +0000 Subject: Fixed some new 1.7 client crash bugs Some technical blocks were removed; trying to render them as items caused a crash. --- src/Blocks/BlockHandler.cpp | 2 ++ src/Blocks/BlockPiston.h | 6 ++++++ src/Blocks/BlockRedstoneLamp.h | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/Blocks/BlockRedstoneLamp.h (limited to 'src/Blocks') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 4a6d49449..43f9eda37 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -48,6 +48,7 @@ #include "BlockPumpkin.h" #include "BlockRail.h" #include "BlockRedstone.h" +#include "BlockRedstoneLamp.h" #include "BlockRedstoneRepeater.h" #include "BlockRedstoneTorch.h" #include "BlockSand.h" @@ -171,6 +172,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE_GLOWING: return new cBlockOreHandler (a_BlockType); + case E_BLOCK_REDSTONE_LAMP_ON: return new cBlockRedstoneLampHandler (a_BlockType); case E_BLOCK_REDSTONE_REPEATER_OFF: return new cBlockRedstoneRepeaterHandler(a_BlockType); case E_BLOCK_REDSTONE_REPEATER_ON: return new cBlockRedstoneRepeaterHandler(a_BlockType); case E_BLOCK_REDSTONE_TORCH_OFF: return new cBlockRedstoneTorchHandler (a_BlockType); diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 109f5ea8b..36fa6a572 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -36,6 +36,12 @@ public: cBlockPistonHeadHandler(void); virtual void OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override; + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + // No pickups + // Also with 1.7, the item forms of these tecnical blocks have been removed, so giving someone this will crash their client... + } } ; diff --git a/src/Blocks/BlockRedstoneLamp.h b/src/Blocks/BlockRedstoneLamp.h new file mode 100644 index 000000000..69a2b27c2 --- /dev/null +++ b/src/Blocks/BlockRedstoneLamp.h @@ -0,0 +1,27 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockRedstoneLampHandler : + public cBlockHandler +{ +public: + cBlockRedstoneLampHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_BLOCK_REDSTONE_LAMP_OFF, 1, 0)); + } +}; + + + + -- cgit v1.2.3 From 405f67dac83db8f7805feca6747be3bec21559af Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 22:35:01 +0000 Subject: Fixed water starting fires --- src/Blocks/BlockHandler.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 43f9eda37..62b57139e 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -187,7 +187,6 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_SNOW: return new cBlockSnowHandler (a_BlockType); case E_BLOCK_SPRUCE_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_STATIONARY_LAVA: return new cBlockLavaHandler (a_BlockType); - case E_BLOCK_STATIONARY_WATER: return new cBlockLavaHandler (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); -- cgit v1.2.3 From 9c1b7c8b6e43d740c55e75ec594dce2ea482f11e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 8 Dec 2013 14:07:32 +0000 Subject: Readded redstone lamp handler --- src/Blocks/BlockHandler.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 37d948d79..99559ed02 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -48,6 +48,7 @@ #include "BlockPumpkin.h" #include "BlockRail.h" #include "BlockRedstone.h" +#include "BlockRedstoneLamp.h" #include "BlockRedstoneRepeater.h" #include "BlockRedstoneTorch.h" #include "BlockSand.h" @@ -169,6 +170,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType); case E_BLOCK_QUARTZ_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); + case E_BLOCK_REDSTONE_LAMP_ON: return new cBlockRedstoneLampHandler (a_BlockType); // We need this to change pickups to an off lamp; else 1.7+ clients crash case E_BLOCK_REDSTONE_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE_GLOWING: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_REPEATER_OFF: return new cBlockRedstoneRepeaterHandler(a_BlockType); -- cgit v1.2.3