diff options
author | peterbell10 <peterbell10@live.co.uk> | 2020-10-05 12:27:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-05 12:27:14 +0200 |
commit | a9031b6bae742b333b1b390192fa590f2ecb07ea (patch) | |
tree | b2802c81d24d339c201a0747d66ba44e9ea8b1b0 | |
parent | Fixed current end generator (#4968) (diff) | |
download | cuberite-a9031b6bae742b333b1b390192fa590f2ecb07ea.tar cuberite-a9031b6bae742b333b1b390192fa590f2ecb07ea.tar.gz cuberite-a9031b6bae742b333b1b390192fa590f2ecb07ea.tar.bz2 cuberite-a9031b6bae742b333b1b390192fa590f2ecb07ea.tar.lz cuberite-a9031b6bae742b333b1b390192fa590f2ecb07ea.tar.xz cuberite-a9031b6bae742b333b1b390192fa590f2ecb07ea.tar.zst cuberite-a9031b6bae742b333b1b390192fa590f2ecb07ea.zip |
144 files changed, 886 insertions, 862 deletions
diff --git a/SetFlags.cmake b/SetFlags.cmake index cf8cacd47..f5c8a282b 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -111,6 +111,14 @@ function(set_global_flags) endif() endfunction() +function (try_add_flag TARGET FLAG) + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("${FLAG}" "HAS_FLAG_${FLAG}") + if ("${HAS_FLAG_${FLAG}}") + target_compile_options(${TARGET} PRIVATE "${FLAG}") + endif() +endfunction() + function(set_exe_flags TARGET) if (MSVC) # TODO: MSVC level 4, warnings as errors @@ -134,7 +142,7 @@ function(set_exe_flags TARGET) -Wno-unused-parameter ) - if(CMAKE_CXX_COMPILE_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_compile_options( ${TARGET} PRIVATE @@ -155,5 +163,10 @@ function(set_exe_flags TARGET) -Wno-documentation -Wno-documentation-unknown-command -Wno-reserved-id-macro -Wno-error=unused-command-line-argument ) + + # We aren't using C++11 + try_add_flag(${TARGET} -Wno-return-std-move-in-c++11) + # int to float conversions happen a lot, not worth fixing all warnings + try_add_flag(${TARGET} -Wno-implicit-int-float-conversion) endif() endfunction() diff --git a/src/Blocks/BlockAir.h b/src/Blocks/BlockAir.h new file mode 100644 index 000000000..529e25302 --- /dev/null +++ b/src/Blocks/BlockAir.h @@ -0,0 +1,22 @@ + +#pragma once + + + + + +class cBlockAirHandler final : + public cBlockHandler +{ +public: + + using cBlockHandler::cBlockHandler; + +private: + + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override + { + // Don't drop anything: + return {}; + } +}; diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h index 8eaed870c..7c821e20d 100644 --- a/src/Blocks/BlockAnvil.h +++ b/src/Blocks/BlockAnvil.h @@ -10,7 +10,7 @@ -class cBlockAnvilHandler: +class cBlockAnvilHandler final : public cYawRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x01, 0x02> { using Super = cYawRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x01, 0x02>; diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 8aac898df..eb36ede5c 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -15,7 +15,7 @@ class cWorldInterface; -class cBlockBedHandler : +class cBlockBedHandler final : public cYawRotator<cBlockEntityHandler, 0x03, 0x02, 0x03, 0x00, 0x01> { using Super = cYawRotator<cBlockEntityHandler, 0x03, 0x02, 0x03, 0x00, 0x01>; diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index 5df20dedf..e6e7f58fa 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -9,7 +9,7 @@ -class cBlockBigFlowerHandler: +class cBlockBigFlowerHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockBookShelf.h b/src/Blocks/BlockBookShelf.h index dcc29eab0..ecd85733e 100644 --- a/src/Blocks/BlockBookShelf.h +++ b/src/Blocks/BlockBookShelf.h @@ -6,7 +6,7 @@ -class cBlockBookShelfHandler : +class cBlockBookShelfHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockBrewingStand.h b/src/Blocks/BlockBrewingStand.h index 27ba33ca7..6640dea03 100644 --- a/src/Blocks/BlockBrewingStand.h +++ b/src/Blocks/BlockBrewingStand.h @@ -7,7 +7,7 @@ -class cBlockBrewingStandHandler : +class cBlockBrewingStandHandler final : public cBlockEntityHandler { using Super = cBlockEntityHandler; diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 1ce0e619a..062bd5057 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -9,7 +9,7 @@ -class cBlockButtonHandler : +class cBlockButtonHandler final : public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, true>> { using Super = cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, true>>; diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 64feac77d..2e7cc7db2 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -7,7 +7,7 @@ -class cBlockCactusHandler : +class cBlockCactusHandler final : public cClearMetaOnDrop<cBlockPlant<false>> { using Super = cClearMetaOnDrop<cBlockPlant<false>>; diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h index 639015df2..b67da5222 100644 --- a/src/Blocks/BlockCake.h +++ b/src/Blocks/BlockCake.h @@ -6,7 +6,7 @@ -class cBlockCakeHandler: +class cBlockCakeHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockCarpet.h b/src/Blocks/BlockCarpet.h index fff31d8fe..d4c172810 100644 --- a/src/Blocks/BlockCarpet.h +++ b/src/Blocks/BlockCarpet.h @@ -14,7 +14,7 @@ -class cBlockCarpetHandler: +class cBlockCarpetHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index f5471ded7..ab9fc2d7e 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -8,7 +8,7 @@ -class cBlockCauldronHandler : +class cBlockCauldronHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index e3a6fb623..88476c82d 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -9,7 +9,7 @@ -class cBlockChestHandler : +class cBlockChestHandler final : public cYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05> { using Super = cYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05>; diff --git a/src/Blocks/BlockCloth.h b/src/Blocks/BlockCloth.h index 0e24e7d37..8c0607f36 100644 --- a/src/Blocks/BlockCloth.h +++ b/src/Blocks/BlockCloth.h @@ -7,7 +7,7 @@ -class cBlockClothHandler : +class cBlockClothHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockCobWeb.h b/src/Blocks/BlockCobWeb.h index c8b0433d4..7a48c88c1 100644 --- a/src/Blocks/BlockCobWeb.h +++ b/src/Blocks/BlockCobWeb.h @@ -9,7 +9,7 @@ -class cBlockCobWebHandler : +class cBlockCobWebHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockCocoaPod.h b/src/Blocks/BlockCocoaPod.h index 557367dcf..d78164ea6 100644 --- a/src/Blocks/BlockCocoaPod.h +++ b/src/Blocks/BlockCocoaPod.h @@ -7,7 +7,7 @@ -class cBlockCocoaPodHandler : +class cBlockCocoaPodHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockCommandBlock.h b/src/Blocks/BlockCommandBlock.h index 03b20aba2..a122ce8e0 100644 --- a/src/Blocks/BlockCommandBlock.h +++ b/src/Blocks/BlockCommandBlock.h @@ -7,7 +7,7 @@ -class cBlockCommandBlockHandler : +class cBlockCommandBlockHandler final : public cBlockEntityHandler { using Super = cBlockEntityHandler; diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index d20c70aeb..667b61c50 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -9,7 +9,7 @@ -class cBlockComparatorHandler : +class cBlockComparatorHandler final : public cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03> { using Super = cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>; diff --git a/src/Blocks/BlockConcretePowder.h b/src/Blocks/BlockConcretePowder.h index 83a475b88..a69001a65 100644 --- a/src/Blocks/BlockConcretePowder.h +++ b/src/Blocks/BlockConcretePowder.h @@ -7,7 +7,7 @@ -class cBlockConcretePowderHandler : +class cBlockConcretePowderHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index 827b26881..aab2c18cd 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -10,7 +10,7 @@ /** Common class that takes care of beetroots, carrots, potatoes and wheat */ template <NIBBLETYPE RipeMeta> -class cBlockCropsHandler: +class cBlockCropsHandler final : public cBlockPlant<true> { using Super = cBlockPlant<true>; @@ -22,10 +22,10 @@ public: private: /** Calculate the number of seeds to drop when the crop is broken. */ - static char CalculateSeedCount(char a_Min, char a_BaseRolls, char a_FortuneLevel) + static char CalculateSeedCount(char a_Min, char a_BaseRolls, unsigned char a_FortuneLevel) { - std::binomial_distribution Binomial(a_BaseRolls + a_FortuneLevel, 0.57); - return a_Min + Binomial(GetRandomProvider().Engine()); + std::binomial_distribution<> Binomial(a_BaseRolls + a_FortuneLevel, 0.57); + return static_cast<char>(a_Min + Binomial(GetRandomProvider().Engine())); } diff --git a/src/Blocks/BlockDeadBush.h b/src/Blocks/BlockDeadBush.h index f7ae8bb96..a476e9734 100644 --- a/src/Blocks/BlockDeadBush.h +++ b/src/Blocks/BlockDeadBush.h @@ -7,7 +7,7 @@ -class cBlockDeadBushHandler: +class cBlockDeadBushHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockDefaultBlock.h b/src/Blocks/BlockDefaultBlock.h new file mode 100644 index 000000000..5aed0749b --- /dev/null +++ b/src/Blocks/BlockDefaultBlock.h @@ -0,0 +1,14 @@ + +#pragma once + + + + + +class cDefaultBlockHandler final : + public cBlockHandler +{ +public: + + using cBlockHandler::cBlockHandler; +}; diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index fade1f992..bcbf93f97 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -7,7 +7,7 @@ -class cBlockDirtHandler : +class cBlockDirtHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index ee511a290..097bdba40 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -11,7 +11,7 @@ -class cBlockDoorHandler : +class cBlockDoorHandler final : public cYawRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x01, 0x02> { using Super = cYawRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x01, 0x02>; diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index 793cc0be9..0f6863ea4 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -11,7 +11,7 @@ -class cBlockDropSpenserHandler : +class cBlockDropSpenserHandler final : public cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00> { using Super = cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>; diff --git a/src/Blocks/BlockEnchantingTable.h b/src/Blocks/BlockEnchantingTable.h index 5edf9fdda..c921d8f27 100644 --- a/src/Blocks/BlockEnchantingTable.h +++ b/src/Blocks/BlockEnchantingTable.h @@ -11,7 +11,7 @@ -class cBlockEnchantingTableHandler : +class cBlockEnchantingTableHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockEndPortalFrame.h b/src/Blocks/BlockEndPortalFrame.h index 2aa0327cf..0b5e84da2 100644 --- a/src/Blocks/BlockEndPortalFrame.h +++ b/src/Blocks/BlockEndPortalFrame.h @@ -7,7 +7,7 @@ -class cBlockEndPortalFrameHandler: +class cBlockEndPortalFrameHandler final : public cMetaRotator<cBlockHandler, 0x03, E_META_END_PORTAL_FRAME_ZM, E_META_END_PORTAL_FRAME_XP, diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index fe5835f9a..5620e9ade 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -6,7 +6,7 @@ -class cBlockEnderchestHandler : +class cBlockEnderchestHandler final : public cYawRotator<cBlockEntityHandler, 0x07, 0x03, 0x04, 0x02, 0x05> { using Super = cYawRotator<cBlockEntityHandler, 0x07, 0x03, 0x04, 0x02, 0x05>; diff --git a/src/Blocks/BlockEntity.h b/src/Blocks/BlockEntity.h index 4b9de1f12..c10f5d769 100644 --- a/src/Blocks/BlockEntity.h +++ b/src/Blocks/BlockEntity.h @@ -11,7 +11,7 @@ /** Wrapper for blocks that have a cBlockEntity descendant attached to them and can be "used" by the player. Forwards the "use" event to the block entity. */ -class cBlockEntityHandler: +class cBlockEntityHandler : public cBlockHandler { using Super = cBlockHandler; @@ -20,6 +20,10 @@ public: using Super::Super; +protected: + + ~cBlockEntityHandler() = default; + private: virtual bool OnUse( @@ -34,12 +38,20 @@ private: return a_ChunkInterface.UseBlockEntity(&a_Player, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z); } - - - - virtual bool IsUseable() const override { return true; } }; + + + + + +class cDefaultBlockEntityHandler final : + public cBlockEntityHandler +{ +public: + + using cBlockEntityHandler::cBlockEntityHandler; +}; diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h index 27ec7e89c..f7003a650 100644 --- a/src/Blocks/BlockFarmland.h +++ b/src/Blocks/BlockFarmland.h @@ -16,7 +16,7 @@ -class cBlockFarmlandHandler : +class cBlockFarmlandHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockFence.h b/src/Blocks/BlockFence.h index 13c4a6979..c6cad0198 100644 --- a/src/Blocks/BlockFence.h +++ b/src/Blocks/BlockFence.h @@ -10,7 +10,7 @@ -class cBlockFenceHandler: +class cBlockFenceHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index 2f691790d..f52d8df9c 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -8,7 +8,7 @@ -class cBlockFenceGateHandler : +class cBlockFenceGateHandler final : public cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x02, 0x03, 0x00, 0x01>> { using Super = cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x02, 0x03, 0x00, 0x01>>; diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index 4227c67a0..280b24a03 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -7,7 +7,7 @@ -class cBlockFireHandler : +class cBlockFireHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockFlower.h b/src/Blocks/BlockFlower.h index b5bc6f957..590d00145 100644 --- a/src/Blocks/BlockFlower.h +++ b/src/Blocks/BlockFlower.h @@ -7,7 +7,7 @@ -class cBlockFlowerHandler: +class cBlockFlowerHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockFlowerPot.h b/src/Blocks/BlockFlowerPot.h index d5e37c243..6535894c4 100644 --- a/src/Blocks/BlockFlowerPot.h +++ b/src/Blocks/BlockFlowerPot.h @@ -5,7 +5,7 @@ -class cBlockFlowerPotHandler : +class cBlockFlowerPotHandler final : public cBlockEntityHandler { using Super = cBlockEntityHandler; diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index 05a7c0d62..70aa57a0d 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -7,7 +7,7 @@ -class cBlockFluidHandler: +class cBlockFluidHandler : public cBlockHandler { using Super = cBlockHandler; @@ -16,6 +16,10 @@ public: using Super::Super; +protected: + + ~cBlockFluidHandler() = default; + private: virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override @@ -32,44 +36,13 @@ private: { return true; } - - - - - - virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override - { - UNUSED(a_Meta); - if (IsBlockWater(m_BlockType)) - { - return 12; - } - ASSERT(!"Unhandled blocktype in fluid/water handler!"); - return 0; - } - - - - - - virtual bool CanSustainPlant(BLOCKTYPE a_Plant) const override - { - return ( - (a_Plant == E_BLOCK_BEETROOTS) || - (a_Plant == E_BLOCK_CROPS) || - (a_Plant == E_BLOCK_CARROTS) || - (a_Plant == E_BLOCK_POTATOES) || - (a_Plant == E_BLOCK_MELON_STEM) || - (a_Plant == E_BLOCK_PUMPKIN_STEM) - ); - } } ; -class cBlockLavaHandler: +class cBlockLavaHandler final : public cBlockFluidHandler { using Super = cBlockFluidHandler; @@ -173,3 +146,36 @@ private: + +class cBlockWaterHandler final : + public cBlockFluidHandler +{ +public: + + using cBlockFluidHandler::cBlockFluidHandler; + +private: + + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override + { + UNUSED(a_Meta); + if (IsBlockWater(m_BlockType)) + { + return 12; + } + ASSERT(!"Unhandled blocktype in fluid/water handler!"); + return 0; + } + + virtual bool CanSustainPlant(BLOCKTYPE a_Plant) const override + { + return ( + (a_Plant == E_BLOCK_BEETROOTS) || + (a_Plant == E_BLOCK_CROPS) || + (a_Plant == E_BLOCK_CARROTS) || + (a_Plant == E_BLOCK_POTATOES) || + (a_Plant == E_BLOCK_MELON_STEM) || + (a_Plant == E_BLOCK_PUMPKIN_STEM) + ); + } +}; diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index 2c88cfafd..f8b145d58 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -6,7 +6,7 @@ -class cBlockFurnaceHandler : +class cBlockFurnaceHandler final : public cYawRotator<cBlockEntityHandler, 0x07, 0x03, 0x04, 0x02, 0x05> { using Super = cYawRotator<cBlockEntityHandler, 0x07, 0x03, 0x04, 0x02, 0x05>; diff --git a/src/Blocks/BlockGlass.h b/src/Blocks/BlockGlass.h index 6dc82c1a5..c08265060 100644 --- a/src/Blocks/BlockGlass.h +++ b/src/Blocks/BlockGlass.h @@ -7,7 +7,7 @@ -class cBlockGlassHandler : +class cBlockGlassHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockGlazedTerracotta.h b/src/Blocks/BlockGlazedTerracotta.h new file mode 100644 index 000000000..0975f1ecd --- /dev/null +++ b/src/Blocks/BlockGlazedTerracotta.h @@ -0,0 +1,18 @@ + +#pragma once + +#include "Mixins.h" + + + + + +class cBlockGlazedTerracottaHandler final : + public cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>> +{ + using Super = cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>>; + +public: + + using Super::Super; +}; diff --git a/src/Blocks/BlockGlowstone.h b/src/Blocks/BlockGlowstone.h index 395233b44..e8670a71b 100644 --- a/src/Blocks/BlockGlowstone.h +++ b/src/Blocks/BlockGlowstone.h @@ -7,7 +7,7 @@ -class cBlockGlowstoneHandler : +class cBlockGlowstoneHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockGrass.h b/src/Blocks/BlockGrass.h index 4999ee27b..9d2e37899 100644 --- a/src/Blocks/BlockGrass.h +++ b/src/Blocks/BlockGrass.h @@ -10,7 +10,7 @@ -class cBlockGrassHandler : +class cBlockGrassHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockGravel.h b/src/Blocks/BlockGravel.h index 2e145f5e5..2561af094 100644 --- a/src/Blocks/BlockGravel.h +++ b/src/Blocks/BlockGravel.h @@ -7,7 +7,7 @@ -class cBlockGravelHandler : +class cBlockGravelHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index a10c5e48d..8925449e6 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -5,6 +5,7 @@ #include "../World.h" #include "../Chunk.h" #include "BlockPluginInterface.h" +#include "BlockAir.h" #include "BlockAnvil.h" #include "BlockBed.h" #include "BlockBigFlower.h" @@ -24,12 +25,13 @@ #include "BlockConcretePowder.h" #include "BlockCrops.h" #include "BlockDeadBush.h" +#include "BlockDefaultBlock.h" #include "BlockDirt.h" #include "BlockDoor.h" #include "BlockDropSpenser.h" #include "BlockEnchantingTable.h" -#include "BlockEnderchest.h" #include "BlockEndPortalFrame.h" +#include "BlockEnderchest.h" #include "BlockEntity.h" #include "BlockFarmland.h" #include "BlockFence.h" @@ -40,41 +42,38 @@ #include "BlockFluid.h" #include "BlockFurnace.h" #include "BlockGlass.h" +#include "BlockGlazedTerracotta.h" #include "BlockGlowstone.h" #include "BlockGrass.h" #include "BlockGravel.h" -#include "BlockMobHead.h" #include "BlockHopper.h" #include "BlockIce.h" #include "BlockJukebox.h" #include "BlockLadder.h" #include "BlockLeaves.h" -#include "BlockLilypad.h" #include "BlockLever.h" +#include "BlockLilypad.h" #include "BlockMelon.h" +#include "BlockMobHead.h" #include "BlockMobSpawner.h" #include "BlockMushroom.h" #include "BlockMycelium.h" -#include "BlockNetherrack.h" #include "BlockNetherWart.h" +#include "BlockNetherrack.h" #include "BlockObserver.h" #include "BlockOre.h" #include "BlockPackedIce.h" #include "BlockPiston.h" #include "BlockPlanks.h" #include "BlockPortal.h" -#include "BlockPumpkin.h" #include "BlockPressurePlate.h" +#include "BlockPumpkin.h" #include "BlockQuartz.h" #include "BlockRail.h" #include "BlockRedstone.h" #include "BlockRedstoneLamp.h" #include "BlockRedstoneOre.h" #include "BlockRedstoneRepeater.h" -#include "BlockRedstoneTorch.h" -#include "BlockTNT.h" -#include "BlockTripwire.h" -#include "BlockTripwireHook.h" #include "BlockSand.h" #include "BlockSapling.h" #include "BlockSeaLantern.h" @@ -88,9 +87,12 @@ #include "BlockStems.h" #include "BlockStone.h" #include "BlockSugarcane.h" +#include "BlockTNT.h" #include "BlockTallGrass.h" #include "BlockTorch.h" #include "BlockTrapdoor.h" +#include "BlockTripwire.h" +#include "BlockTripwireHook.h" #include "BlockVine.h" #include "BlockWallSign.h" #include "BlockWorkbench.h" @@ -99,12 +101,6 @@ -using cBlockGlazedTerracottaHandler = cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>>; - - - - - /* // Tests the meta rotation and mirroring. // Note that the cMetaRotator needs to have its assert paths disabled for this test to work! @@ -200,12 +196,12 @@ namespace constexpr cBlockStairsHandler BlockAcaciaWoodStairsHandler (E_BLOCK_ACACIA_WOOD_STAIRS); constexpr cBlockRailHandler BlockActivatorRailHandler (E_BLOCK_ACTIVATOR_RAIL); constexpr cBlockComparatorHandler BlockActiveComparatorHandler (E_BLOCK_ACTIVE_COMPARATOR); - constexpr cBlockWithNoDrops<> BlockAirHandler (E_BLOCK_AIR); + constexpr cBlockAirHandler BlockAirHandler (E_BLOCK_AIR); constexpr cBlockAnvilHandler BlockAnvilHandler (E_BLOCK_ANVIL); - constexpr cBlockHandler BlockBarrierHandler (E_BLOCK_BARRIER); - constexpr cBlockEntityHandler BlockBeaconHandler (E_BLOCK_BEACON); + constexpr cDefaultBlockHandler BlockBarrierHandler (E_BLOCK_BARRIER); + constexpr cDefaultBlockEntityHandler BlockBeaconHandler (E_BLOCK_BEACON); constexpr cBlockBedHandler BlockBedHandler (E_BLOCK_BED); - constexpr cBlockHandler BlockBedrockHandler (E_BLOCK_BEDROCK); + constexpr cDefaultBlockHandler BlockBedrockHandler (E_BLOCK_BEDROCK); constexpr cBlockCropsHandler<3> BlockBeetrootsHandler (E_BLOCK_BEETROOTS); // 4 stages of growth constexpr cBlockBigFlowerHandler BlockBigFlowerHandler (E_BLOCK_BIG_FLOWER); constexpr cBlockDoorHandler BlockBirchDoorHandler (E_BLOCK_BIRCH_DOOR); @@ -213,19 +209,19 @@ namespace constexpr cBlockFenceHandler BlockBirchFenceHandler (E_BLOCK_BIRCH_FENCE); constexpr cBlockStairsHandler BlockBirchWoodStairsHandler (E_BLOCK_BIRCH_WOOD_STAIRS); constexpr cBlockGlazedTerracottaHandler BlockBlackGlazedTerracottaHandler (E_BLOCK_BLACK_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockBlackShulkerBoxHandler (E_BLOCK_BLACK_SHULKER_BOX); - constexpr cBlockHandler BlockBlockOfCoalHandler (E_BLOCK_BLOCK_OF_COAL); - constexpr cBlockHandler BlockBlockOfRedstoneHandler (E_BLOCK_BLOCK_OF_REDSTONE); + constexpr cDefaultBlockHandler BlockBlackShulkerBoxHandler (E_BLOCK_BLACK_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockBlockOfCoalHandler (E_BLOCK_BLOCK_OF_COAL); + constexpr cDefaultBlockHandler BlockBlockOfRedstoneHandler (E_BLOCK_BLOCK_OF_REDSTONE); constexpr cBlockGlazedTerracottaHandler BlockBlueGlazedTerracottaHandler (E_BLOCK_BLUE_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockBlueShulkerBoxHandler (E_BLOCK_BLUE_SHULKER_BOX); - constexpr cBlockHandler BlockBoneBlockHandler (E_BLOCK_BONE_BLOCK); + constexpr cDefaultBlockHandler BlockBlueShulkerBoxHandler (E_BLOCK_BLUE_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockBoneBlockHandler (E_BLOCK_BONE_BLOCK); constexpr cBlockBookShelfHandler BlockBookcaseHandler (E_BLOCK_BOOKCASE); constexpr cBlockBrewingStandHandler BlockBrewingStandHandler (E_BLOCK_BREWING_STAND); - constexpr cBlockHandler BlockBrickHandler (E_BLOCK_BRICK); + constexpr cDefaultBlockHandler BlockBrickHandler (E_BLOCK_BRICK); constexpr cBlockStairsHandler BlockBrickStairsHandler (E_BLOCK_BRICK_STAIRS); constexpr cBlockGlazedTerracottaHandler BlockBrownGlazedTerracottaHandler (E_BLOCK_BROWN_GLAZED_TERRACOTTA); constexpr cBlockMushroomHandler BlockBrownMushroomHandler (E_BLOCK_BROWN_MUSHROOM); - constexpr cBlockHandler BlockBrownShulkerBoxHandler (E_BLOCK_BROWN_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockBrownShulkerBoxHandler (E_BLOCK_BROWN_SHULKER_BOX); constexpr cBlockCactusHandler BlockCactusHandler (E_BLOCK_CACTUS); constexpr cBlockCakeHandler BlockCakeHandler (E_BLOCK_CAKE); constexpr cBlockCarpetHandler BlockCarpetHandler (E_BLOCK_CARPET); @@ -233,46 +229,46 @@ namespace constexpr cBlockCauldronHandler BlockCauldronHandler (E_BLOCK_CAULDRON); constexpr cBlockCommandBlockHandler BlockChainCommandBlockHandler (E_BLOCK_CHAIN_COMMAND_BLOCK); constexpr cBlockChestHandler BlockChestHandler (E_BLOCK_CHEST); - constexpr cBlockHandler BlockChorusFlowerHandler (E_BLOCK_CHORUS_FLOWER); - constexpr cBlockHandler BlockChorusPlantHandler (E_BLOCK_CHORUS_PLANT); - constexpr cBlockOreHandler BlockClayHandler (E_BLOCK_CLAY); - constexpr cBlockOreHandler BlockCoalOreHandler (E_BLOCK_COAL_ORE); + constexpr cDefaultBlockHandler BlockChorusFlowerHandler (E_BLOCK_CHORUS_FLOWER); + constexpr cDefaultBlockHandler BlockChorusPlantHandler (E_BLOCK_CHORUS_PLANT); + constexpr cDefaultOreHandler BlockClayHandler (E_BLOCK_CLAY); + constexpr cDefaultOreHandler BlockCoalOreHandler (E_BLOCK_COAL_ORE); constexpr cBlockStoneHandler BlockCobblestoneHandler (E_BLOCK_COBBLESTONE); constexpr cBlockStairsHandler BlockCobblestoneStairsHandler (E_BLOCK_COBBLESTONE_STAIRS); - constexpr cBlockHandler BlockCobblestoneWallHandler (E_BLOCK_COBBLESTONE_WALL); + constexpr cDefaultBlockHandler BlockCobblestoneWallHandler (E_BLOCK_COBBLESTONE_WALL); constexpr cBlockCobWebHandler BlockCobwebHandler (E_BLOCK_COBWEB); constexpr cBlockCocoaPodHandler BlockCocoaPodHandler (E_BLOCK_COCOA_POD); constexpr cBlockCommandBlockHandler BlockCommandBlockHandler (E_BLOCK_COMMAND_BLOCK); - constexpr cBlockHandler BlockConcreteHandler (E_BLOCK_CONCRETE); + constexpr cDefaultBlockHandler BlockConcreteHandler (E_BLOCK_CONCRETE); constexpr cBlockConcretePowderHandler BlockConcretePowderHandler (E_BLOCK_CONCRETE_POWDER); constexpr cBlockCropsHandler<7> BlockCropsHandler (E_BLOCK_CROPS); // 8 stages of growth constexpr cBlockGlazedTerracottaHandler BlockCyanGlazedTerracottaHandler (E_BLOCK_CYAN_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockCyanShulkerBoxHandler (E_BLOCK_CYAN_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockCyanShulkerBoxHandler (E_BLOCK_CYAN_SHULKER_BOX); constexpr cBlockDoorHandler BlockDarkOakDoorHandler (E_BLOCK_DARK_OAK_DOOR); constexpr cBlockFenceGateHandler BlockDarkOakFenceGateHandler (E_BLOCK_DARK_OAK_FENCE_GATE); constexpr cBlockFenceHandler BlockDarkOakFenceHandler (E_BLOCK_DARK_OAK_FENCE); constexpr cBlockStairsHandler BlockDarkOakWoodStairsHandler (E_BLOCK_DARK_OAK_WOOD_STAIRS); - constexpr cBlockHandler BlockDaylightSensorHandler (E_BLOCK_DAYLIGHT_SENSOR); + constexpr cDefaultBlockHandler BlockDaylightSensorHandler (E_BLOCK_DAYLIGHT_SENSOR); constexpr cBlockDeadBushHandler BlockDeadBushHandler (E_BLOCK_DEAD_BUSH); constexpr cBlockRailHandler BlockDetectorRailHandler (E_BLOCK_DETECTOR_RAIL); - constexpr cBlockHandler BlockDiamondBlockHandler (E_BLOCK_DIAMOND_BLOCK); - constexpr cBlockOreHandler BlockDiamondOreHandler (E_BLOCK_DIAMOND_ORE); + constexpr cDefaultBlockHandler BlockDiamondBlockHandler (E_BLOCK_DIAMOND_BLOCK); + constexpr cDefaultOreHandler BlockDiamondOreHandler (E_BLOCK_DIAMOND_ORE); constexpr cBlockDirtHandler BlockDirtHandler (E_BLOCK_DIRT); constexpr cBlockDropSpenserHandler BlockDispenserHandler (E_BLOCK_DISPENSER); constexpr cBlockDoubleSlabHandler BlockDoubleRedSandstoneSlabHandler(E_BLOCK_DOUBLE_RED_SANDSTONE_SLAB); constexpr cBlockDoubleSlabHandler BlockDoubleStoneSlabHandler (E_BLOCK_DOUBLE_STONE_SLAB); constexpr cBlockDoubleSlabHandler BlockDoubleWoodenSlabHandler (E_BLOCK_DOUBLE_WOODEN_SLAB); - constexpr cBlockHandler BlockDragonEggHandler (E_BLOCK_DRAGON_EGG); + constexpr cDefaultBlockHandler BlockDragonEggHandler (E_BLOCK_DRAGON_EGG); constexpr cBlockDropSpenserHandler BlockDropperHandler (E_BLOCK_DROPPER); - constexpr cBlockHandler BlockEmeraldBlockHandler (E_BLOCK_EMERALD_BLOCK); - constexpr cBlockOreHandler BlockEmeraldOreHandler (E_BLOCK_EMERALD_ORE); + constexpr cDefaultBlockHandler BlockEmeraldBlockHandler (E_BLOCK_EMERALD_BLOCK); + constexpr cDefaultOreHandler BlockEmeraldOreHandler (E_BLOCK_EMERALD_ORE); constexpr cBlockEnchantingTableHandler BlockEnchantingTableHandler (E_BLOCK_ENCHANTMENT_TABLE); - constexpr cBlockHandler BlockEndBricksHandler (E_BLOCK_END_BRICKS); - constexpr cBlockHandler BlockEndGatewayHandler (E_BLOCK_END_GATEWAY); + constexpr cDefaultBlockHandler BlockEndBricksHandler (E_BLOCK_END_BRICKS); + constexpr cDefaultBlockHandler BlockEndGatewayHandler (E_BLOCK_END_GATEWAY); constexpr cBlockEndPortalFrameHandler BlockEndPortalFrameHandler (E_BLOCK_END_PORTAL_FRAME); - constexpr cBlockHandler BlockEndPortalHandler (E_BLOCK_END_PORTAL); - constexpr cBlockHandler BlockEndRodHandler (E_BLOCK_END_ROD); - constexpr cBlockHandler BlockEndStoneHandler (E_BLOCK_END_STONE); + constexpr cDefaultBlockHandler BlockEndPortalHandler (E_BLOCK_END_PORTAL); + constexpr cDefaultBlockHandler BlockEndRodHandler (E_BLOCK_END_ROD); + constexpr cDefaultBlockHandler BlockEndStoneHandler (E_BLOCK_END_STONE); constexpr cBlockEnderchestHandler BlockEnderChestHandler (E_BLOCK_ENDER_CHEST); constexpr cBlockFarmlandHandler BlockFarmlandHandler (E_BLOCK_FARMLAND); constexpr cBlockFenceHandler BlockFenceHandler (E_BLOCK_FENCE); @@ -283,29 +279,29 @@ namespace constexpr cBlockGlassHandler BlockGlassHandler (E_BLOCK_GLASS); constexpr cBlockGlassHandler BlockGlassPaneHandler (E_BLOCK_GLASS_PANE); constexpr cBlockGlowstoneHandler BlockGlowstoneHandler (E_BLOCK_GLOWSTONE); - constexpr cBlockHandler BlockGoldBlockHandler (E_BLOCK_GOLD_BLOCK); - constexpr cBlockOreHandler BlockGoldOreHandler (E_BLOCK_GOLD_ORE); + constexpr cDefaultBlockHandler BlockGoldBlockHandler (E_BLOCK_GOLD_BLOCK); + constexpr cDefaultOreHandler BlockGoldOreHandler (E_BLOCK_GOLD_ORE); constexpr cBlockGrassHandler BlockGrassHandler (E_BLOCK_GRASS); - constexpr cBlockHandler BlockGrassPathHandler (E_BLOCK_GRASS_PATH); + constexpr cDefaultBlockHandler BlockGrassPathHandler (E_BLOCK_GRASS_PATH); constexpr cBlockGravelHandler BlockGravelHandler (E_BLOCK_GRAVEL); constexpr cBlockGlazedTerracottaHandler BlockGrayGlazedTerracottaHandler (E_BLOCK_GRAY_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockGrayShulkerBoxHandler (E_BLOCK_GRAY_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockGrayShulkerBoxHandler (E_BLOCK_GRAY_SHULKER_BOX); constexpr cBlockGlazedTerracottaHandler BlockGreenGlazedTerracottaHandler (E_BLOCK_GREEN_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockGreenShulkerBoxHandler (E_BLOCK_GREEN_SHULKER_BOX); - constexpr cBlockHandler BlockHardenedClayHandler (E_BLOCK_HARDENED_CLAY); + constexpr cDefaultBlockHandler BlockGreenShulkerBoxHandler (E_BLOCK_GREEN_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockHardenedClayHandler (E_BLOCK_HARDENED_CLAY); constexpr cBlockSidewaysHandler BlockHayBaleHandler (E_BLOCK_HAY_BALE); constexpr cBlockMobHeadHandler BlockHeadHandler (E_BLOCK_HEAD); constexpr cBlockPressurePlateHandler BlockHeavyWeightedPressurePHandler(E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE); constexpr cBlockHopperHandler BlockHopperHandler (E_BLOCK_HOPPER); - constexpr cBlockHandler BlockHugeBrownMushroomHandler (E_BLOCK_HUGE_BROWN_MUSHROOM); - constexpr cBlockHandler BlockHugeRedMushroomHandler (E_BLOCK_HUGE_RED_MUSHROOM); + constexpr cDefaultBlockHandler BlockHugeBrownMushroomHandler (E_BLOCK_HUGE_BROWN_MUSHROOM); + constexpr cDefaultBlockHandler BlockHugeRedMushroomHandler (E_BLOCK_HUGE_RED_MUSHROOM); constexpr cBlockIceHandler BlockIceHandler (E_BLOCK_ICE); constexpr cBlockComparatorHandler BlockInactiveComparatorHandler (E_BLOCK_INACTIVE_COMPARATOR); - constexpr cBlockHandler BlockInfestedBlockHandler (E_BLOCK_SILVERFISH_EGG); - constexpr cBlockHandler BlockIronBarsHandler (E_BLOCK_IRON_BARS); - constexpr cBlockHandler BlockIronBlockHandler (E_BLOCK_IRON_BLOCK); + constexpr cDefaultBlockHandler BlockInfestedBlockHandler (E_BLOCK_SILVERFISH_EGG); + constexpr cDefaultBlockHandler BlockIronBarsHandler (E_BLOCK_IRON_BARS); + constexpr cDefaultBlockHandler BlockIronBlockHandler (E_BLOCK_IRON_BLOCK); constexpr cBlockDoorHandler BlockIronDoorHandler (E_BLOCK_IRON_DOOR); - constexpr cBlockOreHandler BlockIronOreHandler (E_BLOCK_IRON_ORE); + constexpr cDefaultOreHandler BlockIronOreHandler (E_BLOCK_IRON_ORE); constexpr cBlockTrapdoorHandler BlockIronTrapdoorHandler (E_BLOCK_IRON_TRAPDOOR); constexpr cBlockPumpkinHandler BlockJackOLanternHandler (E_BLOCK_JACK_O_LANTERN); constexpr cBlockJukeboxHandler BlockJukeboxHandler (E_BLOCK_JUKEBOX); @@ -314,64 +310,64 @@ namespace constexpr cBlockFenceHandler BlockJungleFenceHandler (E_BLOCK_JUNGLE_FENCE); constexpr cBlockStairsHandler BlockJungleWoodStairsHandler (E_BLOCK_JUNGLE_WOOD_STAIRS); constexpr cBlockLadderHandler BlockLadderHandler (E_BLOCK_LADDER); - constexpr cBlockHandler BlockLapisBlockHandler (E_BLOCK_LAPIS_BLOCK); - constexpr cBlockOreHandler BlockLapisOreHandler (E_BLOCK_LAPIS_ORE); + constexpr cDefaultBlockHandler BlockLapisBlockHandler (E_BLOCK_LAPIS_BLOCK); + constexpr cDefaultOreHandler BlockLapisOreHandler (E_BLOCK_LAPIS_ORE); constexpr cBlockLavaHandler BlockLavaHandler (E_BLOCK_LAVA); constexpr cBlockLeavesHandler BlockLeavesHandler (E_BLOCK_LEAVES); constexpr cBlockLeverHandler BlockLeverHandler (E_BLOCK_LEVER); constexpr cBlockGlazedTerracottaHandler BlockLightBlueGlazedTerracoHandler(E_BLOCK_LIGHT_BLUE_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockLightBlueShulkerBoxHandler (E_BLOCK_LIGHT_BLUE_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockLightBlueShulkerBoxHandler (E_BLOCK_LIGHT_BLUE_SHULKER_BOX); constexpr cBlockGlazedTerracottaHandler BlockLightGrayGlazedTerracoHandler(E_BLOCK_LIGHT_GRAY_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockLightGrayShulkerBoxHandler (E_BLOCK_LIGHT_GRAY_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockLightGrayShulkerBoxHandler (E_BLOCK_LIGHT_GRAY_SHULKER_BOX); constexpr cBlockPressurePlateHandler BlockLightWeightedPressurePHandler(E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE); constexpr cBlockLilypadHandler BlockLilyPadHandler (E_BLOCK_LILY_PAD); constexpr cBlockGlazedTerracottaHandler BlockLimeGlazedTerracottaHandler (E_BLOCK_LIME_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockLimeShulkerBoxHandler (E_BLOCK_LIME_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockLimeShulkerBoxHandler (E_BLOCK_LIME_SHULKER_BOX); constexpr cBlockFurnaceHandler BlockLitFurnaceHandler (E_BLOCK_LIT_FURNACE); constexpr cBlockSidewaysHandler BlockLogHandler (E_BLOCK_LOG); constexpr cBlockGlazedTerracottaHandler BlockMagentaGlazedTerracottHandler(E_BLOCK_MAGENTA_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockMagentaShulkerBoxHandler (E_BLOCK_MAGENTA_SHULKER_BOX); - constexpr cBlockHandler BlockMagmaHandler (E_BLOCK_MAGMA); + constexpr cDefaultBlockHandler BlockMagentaShulkerBoxHandler (E_BLOCK_MAGENTA_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockMagmaHandler (E_BLOCK_MAGMA); constexpr cBlockMelonHandler BlockMelonHandler (E_BLOCK_MELON); constexpr cBlockMelonStemHandler BlockMelonStemHandler (E_BLOCK_MELON_STEM); constexpr cBlockMobSpawnerHandler BlockMobSpawnerHandler (E_BLOCK_MOB_SPAWNER); - constexpr cBlockHandler BlockMossyCobblestoneHandler (E_BLOCK_MOSSY_COBBLESTONE); + constexpr cDefaultBlockHandler BlockMossyCobblestoneHandler (E_BLOCK_MOSSY_COBBLESTONE); constexpr cBlockMyceliumHandler BlockMyceliumHandler (E_BLOCK_MYCELIUM); constexpr cBlockFenceHandler BlockNetherBrickFenceHandler (E_BLOCK_NETHER_BRICK_FENCE); - constexpr cBlockHandler BlockNetherBrickHandler (E_BLOCK_NETHER_BRICK); + constexpr cDefaultBlockHandler BlockNetherBrickHandler (E_BLOCK_NETHER_BRICK); constexpr cBlockStairsHandler BlockNetherBrickStairsHandler (E_BLOCK_NETHER_BRICK_STAIRS); constexpr cBlockPortalHandler BlockNetherPortalHandler (E_BLOCK_NETHER_PORTAL); - constexpr cBlockOreHandler BlockNetherQuartzOreHandler (E_BLOCK_NETHER_QUARTZ_ORE); - constexpr cBlockHandler BlockNetherWartBlockHandler (E_BLOCK_NETHER_WART_BLOCK); + constexpr cDefaultOreHandler BlockNetherQuartzOreHandler (E_BLOCK_NETHER_QUARTZ_ORE); + constexpr cDefaultBlockHandler BlockNetherWartBlockHandler (E_BLOCK_NETHER_WART_BLOCK); constexpr cBlockNetherWartHandler BlockNetherWartHandler (E_BLOCK_NETHER_WART); constexpr cBlockNetherrack BlockNetherrackHandler (E_BLOCK_NETHERRACK); constexpr cBlockLeavesHandler BlockNewLeavesHandler (E_BLOCK_NEW_LEAVES); constexpr cBlockSidewaysHandler BlockNewLogHandler (E_BLOCK_NEW_LOG); - constexpr cBlockEntityHandler BlockNoteBlockHandler (E_BLOCK_NOTE_BLOCK); + constexpr cDefaultBlockEntityHandler BlockNoteBlockHandler (E_BLOCK_NOTE_BLOCK); constexpr cBlockDoorHandler BlockOakDoorHandler (E_BLOCK_OAK_DOOR); constexpr cBlockFenceGateHandler BlockOakFenceGateHandler (E_BLOCK_OAK_FENCE_GATE); constexpr cBlockStairsHandler BlockOakWoodStairsHandler (E_BLOCK_OAK_WOOD_STAIRS); constexpr cBlockObserverHandler BlockObserverHandler (E_BLOCK_OBSERVER); - constexpr cBlockHandler BlockObsidianHandler (E_BLOCK_OBSIDIAN); + constexpr cDefaultBlockHandler BlockObsidianHandler (E_BLOCK_OBSIDIAN); constexpr cBlockGlazedTerracottaHandler BlockOrangeGlazedTerracottaHandler(E_BLOCK_ORANGE_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockOrangeShulkerBoxHandler (E_BLOCK_ORANGE_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockOrangeShulkerBoxHandler (E_BLOCK_ORANGE_SHULKER_BOX); constexpr cBlockPackedIceHandler BlockPackedIceHandler (E_BLOCK_PACKED_ICE); constexpr cBlockGlazedTerracottaHandler BlockPinkGlazedTerracottaHandler (E_BLOCK_PINK_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockPinkShulkerBoxHandler (E_BLOCK_PINK_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockPinkShulkerBoxHandler (E_BLOCK_PINK_SHULKER_BOX); constexpr cBlockPistonHandler BlockPistonHandler (E_BLOCK_PISTON); constexpr cBlockPistonHeadHandler BlockPistonHeadHandler; - constexpr cBlockHandler BlockPistonMovedBlockHandler (E_BLOCK_PISTON_MOVED_BLOCK); + constexpr cDefaultBlockHandler BlockPistonMovedBlockHandler (E_BLOCK_PISTON_MOVED_BLOCK); constexpr cBlockPlanksHandler BlockPlanksHandler (E_BLOCK_PLANKS); constexpr cBlockCropsHandler<7> BlockPotatoesHandler (E_BLOCK_POTATOES); // 8 stages of growth constexpr cBlockRailHandler BlockPoweredRailHandler (E_BLOCK_POWERED_RAIL); - constexpr cBlockHandler BlockPrismarineBlockHandler (E_BLOCK_PRISMARINE_BLOCK); + constexpr cDefaultBlockHandler BlockPrismarineBlockHandler (E_BLOCK_PRISMARINE_BLOCK); constexpr cBlockPumpkinHandler BlockPumpkinHandler (E_BLOCK_PUMPKIN); constexpr cBlockPumpkinStemHandler BlockPumpkinStemHandler (E_BLOCK_PUMPKIN_STEM); constexpr cBlockGlazedTerracottaHandler BlockPurpleGlazedTerracottaHandler(E_BLOCK_PURPLE_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockPurpleShulkerBoxHandler (E_BLOCK_PURPLE_SHULKER_BOX); - constexpr cBlockHandler BlockPurpurBlockHandler (E_BLOCK_PURPUR_BLOCK); + constexpr cDefaultBlockHandler BlockPurpleShulkerBoxHandler (E_BLOCK_PURPLE_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockPurpurBlockHandler (E_BLOCK_PURPUR_BLOCK); constexpr cBlockDoubleSlabHandler BlockPurpurDoubleSlabHandler (E_BLOCK_PURPUR_DOUBLE_SLAB); - constexpr cBlockHandler BlockPurpurPillarHandler (E_BLOCK_PURPUR_PILLAR); + constexpr cDefaultBlockHandler BlockPurpurPillarHandler (E_BLOCK_PURPUR_PILLAR); constexpr cBlockSlabHandler BlockPurpurSlabHandler (E_BLOCK_PURPUR_SLAB); constexpr cBlockStairsHandler BlockPurpurStairsHandler (E_BLOCK_PURPUR_STAIRS); constexpr cBlockQuartzHandler BlockQuartzBlockHandler (E_BLOCK_QUARTZ_BLOCK); @@ -379,12 +375,12 @@ namespace constexpr cBlockRailHandler BlockRailHandler (E_BLOCK_RAIL); constexpr cBlockGlazedTerracottaHandler BlockRedGlazedTerracottaHandler (E_BLOCK_RED_GLAZED_TERRACOTTA); constexpr cBlockMushroomHandler BlockRedMushroomHandler (E_BLOCK_RED_MUSHROOM); - constexpr cBlockHandler BlockRedNetherBrickHandler (E_BLOCK_RED_NETHER_BRICK); + constexpr cDefaultBlockHandler BlockRedNetherBrickHandler (E_BLOCK_RED_NETHER_BRICK); constexpr cBlockFlowerHandler BlockRedRoseHandler (E_BLOCK_RED_ROSE); - constexpr cBlockHandler BlockRedSandstoneHandler (E_BLOCK_RED_SANDSTONE); + constexpr cDefaultBlockHandler BlockRedSandstoneHandler (E_BLOCK_RED_SANDSTONE); constexpr cBlockSlabHandler BlockRedSandstoneSlabHandler (E_BLOCK_RED_SANDSTONE_SLAB); constexpr cBlockStairsHandler BlockRedSandstoneStairsHandler (E_BLOCK_RED_SANDSTONE_STAIRS); - constexpr cBlockHandler BlockRedShulkerBoxHandler (E_BLOCK_RED_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockRedShulkerBoxHandler (E_BLOCK_RED_SHULKER_BOX); constexpr cBlockRedstoneLampHandler BlockRedstoneLampHandler (E_BLOCK_REDSTONE_LAMP_ON); constexpr cBlockGlowingRedstoneOreHandler BlockRedstoneOreGlowingHandler (E_BLOCK_REDSTONE_ORE_GLOWING); constexpr cBlockRedstoneOreHandler BlockRedstoneOreHandler (E_BLOCK_REDSTONE_ORE); @@ -395,35 +391,35 @@ namespace constexpr cBlockRedstoneHandler BlockRedstoneWireHandler (E_BLOCK_REDSTONE_WIRE); constexpr cBlockCommandBlockHandler BlockRepeatingCommandBlockHandler (E_BLOCK_REPEATING_COMMAND_BLOCK); constexpr cBlockSandHandler BlockSandHandler (E_BLOCK_SAND); - constexpr cBlockHandler BlockSandstoneHandler (E_BLOCK_SANDSTONE); + constexpr cDefaultBlockHandler BlockSandstoneHandler (E_BLOCK_SANDSTONE); constexpr cBlockStairsHandler BlockSandstoneStairsHandler (E_BLOCK_SANDSTONE_STAIRS); constexpr cBlockSaplingHandler BlockSaplingHandler (E_BLOCK_SAPLING); constexpr cBlockSeaLanternHandler BlockSeaLanternHandler (E_BLOCK_SEA_LANTERN); constexpr cBlockSignPostHandler BlockSignPostHandler (E_BLOCK_SIGN_POST); constexpr cBlockSlimeHandler BlockSlimeBlockHandler (E_BLOCK_SLIME_BLOCK); - constexpr cBlockHandler BlockSnowBlockHandler (E_BLOCK_SNOW_BLOCK); + constexpr cDefaultBlockHandler BlockSnowBlockHandler (E_BLOCK_SNOW_BLOCK); constexpr cBlockSnowHandler BlockSnowHandler (E_BLOCK_SNOW); - constexpr cBlockHandler BlockSoulSandHandler (E_BLOCK_SOULSAND); + constexpr cDefaultBlockHandler BlockSoulSandHandler (E_BLOCK_SOULSAND); constexpr cBlockSpongeHandler BlockSpongeHandler (E_BLOCK_SPONGE); constexpr cBlockDoorHandler BlockSpruceDoorHandler (E_BLOCK_SPRUCE_DOOR); constexpr cBlockFenceGateHandler BlockSpruceFenceGateHandler (E_BLOCK_SPRUCE_FENCE_GATE); constexpr cBlockFenceHandler BlockSpruceFenceHandler (E_BLOCK_SPRUCE_FENCE); constexpr cBlockStairsHandler BlockSpruceWoodStairsHandler (E_BLOCK_SPRUCE_WOOD_STAIRS); - constexpr cBlockHandler BlockStainedClayHandler (E_BLOCK_STAINED_CLAY); + constexpr cDefaultBlockHandler BlockStainedClayHandler (E_BLOCK_STAINED_CLAY); constexpr cBlockGlassHandler BlockStainedGlassHandler (E_BLOCK_STAINED_GLASS); constexpr cBlockGlassHandler BlockStainedGlassPaneHandler (E_BLOCK_STAINED_GLASS_PANE); - constexpr cBlockHandler BlockStandingBannerHandler (E_BLOCK_STANDING_BANNER); // TODO: drops correct? + constexpr cDefaultBlockHandler BlockStandingBannerHandler (E_BLOCK_STANDING_BANNER); // TODO: drops correct? constexpr cBlockLavaHandler BlockStationaryLavaHandler (E_BLOCK_STATIONARY_LAVA); - constexpr cBlockFluidHandler BlockStationaryWaterHandler (E_BLOCK_STATIONARY_WATER); + constexpr cBlockWaterHandler BlockStationaryWaterHandler (E_BLOCK_STATIONARY_WATER); constexpr cBlockPistonHandler BlockStickyPistonHandler (E_BLOCK_STICKY_PISTON); constexpr cBlockStairsHandler BlockStoneBrickStairsHandler (E_BLOCK_STONE_BRICK_STAIRS); - constexpr cBlockHandler BlockStoneBricksHandler (E_BLOCK_STONE_BRICKS); + constexpr cDefaultBlockHandler BlockStoneBricksHandler (E_BLOCK_STONE_BRICKS); constexpr cBlockButtonHandler BlockStoneButtonHandler (E_BLOCK_STONE_BUTTON); constexpr cBlockStoneHandler BlockStoneHandler (E_BLOCK_STONE); constexpr cBlockPressurePlateHandler BlockStonePressurePlateHandler (E_BLOCK_STONE_PRESSURE_PLATE); constexpr cBlockSlabHandler BlockStoneSlabHandler (E_BLOCK_STONE_SLAB); - constexpr cBlockHandler BlockStructureBlockHandler (E_BLOCK_STRUCTURE_BLOCK); - constexpr cBlockHandler BlockStructureVoidHandler (E_BLOCK_STRUCTURE_VOID); + constexpr cDefaultBlockHandler BlockStructureBlockHandler (E_BLOCK_STRUCTURE_BLOCK); + constexpr cDefaultBlockHandler BlockStructureVoidHandler (E_BLOCK_STRUCTURE_VOID); constexpr cBlockSugarcaneHandler BlockSugarcaneHandler (E_BLOCK_SUGARCANE); constexpr cBlockTallGrassHandler BlockTallGrassHandler (E_BLOCK_TALL_GRASS); constexpr cBlockTNTHandler BlockTntHandler (E_BLOCK_TNT); @@ -433,11 +429,11 @@ namespace constexpr cBlockTripwireHandler BlockTripwireHandler (E_BLOCK_TRIPWIRE); constexpr cBlockTripwireHookHandler BlockTripwireHookHandler (E_BLOCK_TRIPWIRE_HOOK); constexpr cBlockVineHandler BlockVinesHandler (E_BLOCK_VINES); - constexpr cBlockHandler BlockWallBannerHandler (E_BLOCK_WALL_BANNER); // TODO: drops correct? + constexpr cDefaultBlockHandler BlockWallBannerHandler (E_BLOCK_WALL_BANNER); // TODO: drops correct? constexpr cBlockWallSignHandler BlockWallsignHandler (E_BLOCK_WALLSIGN); - constexpr cBlockFluidHandler BlockWaterHandler (E_BLOCK_WATER); + constexpr cBlockWaterHandler BlockWaterHandler (E_BLOCK_WATER); constexpr cBlockGlazedTerracottaHandler BlockWhiteGlazedTerracottaHandler (E_BLOCK_WHITE_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockWhiteShulkerBoxHandler (E_BLOCK_WHITE_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockWhiteShulkerBoxHandler (E_BLOCK_WHITE_SHULKER_BOX); constexpr cBlockButtonHandler BlockWoodenButtonHandler (E_BLOCK_WOODEN_BUTTON); constexpr cBlockPressurePlateHandler BlockWoodenPressurePlateHandler (E_BLOCK_WOODEN_PRESSURE_PLATE); constexpr cBlockSlabHandler BlockWoodenSlabHandler (E_BLOCK_WOODEN_SLAB); @@ -445,7 +441,7 @@ namespace constexpr cBlockWorkbenchHandler BlockWorkbenchHandler (E_BLOCK_WORKBENCH); constexpr cBlockFlowerHandler BlockYellowFlowerHandler (E_BLOCK_YELLOW_FLOWER); constexpr cBlockGlazedTerracottaHandler BlockYellowGlazedTerracottaHandler(E_BLOCK_YELLOW_GLAZED_TERRACOTTA); - constexpr cBlockHandler BlockYellowShulkerBoxHandler (E_BLOCK_YELLOW_SHULKER_BOX); + constexpr cDefaultBlockHandler BlockYellowShulkerBoxHandler (E_BLOCK_YELLOW_SHULKER_BOX); } @@ -647,7 +643,7 @@ unsigned char cBlockHandler::ToolFortuneLevel(const cItem * a_Tool) if ((a_Tool != nullptr) && ItemCategory::IsTool(a_Tool->m_ItemType)) { // Return enchantment level, limited to avoid spawning excessive pickups (crashing the server) when modified items are used: - return std::min(8U, a_Tool->m_Enchantments.GetLevel(cEnchantments::enchFortune)); + return static_cast<unsigned char>(std::min(8U, a_Tool->m_Enchantments.GetLevel(cEnchantments::enchFortune))); } // Not a tool: diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index cc701ca8e..13c3a84af 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -66,12 +66,12 @@ public: cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta - ) const {}; + ) const {} /** Called by cPlayer::PlaceBlocks() for each block after it has been set to the world. Called after OnPlaced(). */ virtual void OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, const sSetBlock & a_BlockChange - ) const {}; + ) const {} /** Called just after the player breaks the block. The block is already dug up in the world, the original block type and meta is passed in a_OldBlockType and a_OldBlockMeta. @@ -91,7 +91,7 @@ public: cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta - ) const {}; + ) const {} /** Called when a direct neighbor of this block has been changed. The position is the block's own position, NOT the changed neighbor's position. @@ -241,5 +241,7 @@ public: protected: - BLOCKTYPE m_BlockType; + ~cBlockHandler() = default; + + const BLOCKTYPE m_BlockType; }; diff --git a/src/Blocks/BlockHopper.h b/src/Blocks/BlockHopper.h index 7380b8d34..915a8d8d5 100644 --- a/src/Blocks/BlockHopper.h +++ b/src/Blocks/BlockHopper.h @@ -7,7 +7,7 @@ -class cBlockHopperHandler : +class cBlockHopperHandler final : public cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>> { using Super = cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>>; diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h index 12505b3fd..c61abef57 100644 --- a/src/Blocks/BlockIce.h +++ b/src/Blocks/BlockIce.h @@ -7,7 +7,7 @@ -class cBlockIceHandler : +class cBlockIceHandler final : public cBlockHandler { using Super = cBlockHandler; @@ -54,7 +54,7 @@ private: } }; - for (const auto Offset : Adjacents) + for (const auto & Offset : Adjacents) { auto Position = a_RelPos + Offset; const auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(Position); diff --git a/src/Blocks/BlockJukebox.h b/src/Blocks/BlockJukebox.h index c2c9bda63..970f10fc1 100644 --- a/src/Blocks/BlockJukebox.h +++ b/src/Blocks/BlockJukebox.h @@ -8,7 +8,7 @@ -class cBlockJukeboxHandler : +class cBlockJukeboxHandler final : public cClearMetaOnDrop<cBlockEntityHandler> { public: diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index 59c13a406..b4e8294b6 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -8,7 +8,7 @@ -class cBlockLadderHandler: +class cBlockLadderHandler final : public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04> > { using Super = cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04>>; diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 1f726f779..f50f6abc5 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -14,7 +14,7 @@ -class cBlockLeavesHandler: +class cBlockLeavesHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index d3b03bbda..2bea6a846 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -6,7 +6,7 @@ #include "BlockSlab.h" -class cBlockLeverHandler: +class cBlockLeverHandler final : public cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, false> { using Super = cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, false>; diff --git a/src/Blocks/BlockLilypad.h b/src/Blocks/BlockLilypad.h index 4ee0e8133..165e2d310 100644 --- a/src/Blocks/BlockLilypad.h +++ b/src/Blocks/BlockLilypad.h @@ -7,7 +7,7 @@ -class cBlockLilypadHandler: +class cBlockLilypadHandler final : public cClearMetaOnDrop<cBlockHandler> { using Super = cClearMetaOnDrop<cBlockHandler>; diff --git a/src/Blocks/BlockMelon.h b/src/Blocks/BlockMelon.h index da021830c..6a90f217a 100644 --- a/src/Blocks/BlockMelon.h +++ b/src/Blocks/BlockMelon.h @@ -7,7 +7,7 @@ -class cBlockMelonHandler : +class cBlockMelonHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index fb81a07d8..1e1e4c8d6 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -7,7 +7,7 @@ -class cBlockMobHeadHandler : +class cBlockMobHeadHandler final : public cBlockEntityHandler { using Super = cBlockEntityHandler; diff --git a/src/Blocks/BlockMobSpawner.h b/src/Blocks/BlockMobSpawner.h index b9d8cd29f..a002a4eb9 100644 --- a/src/Blocks/BlockMobSpawner.h +++ b/src/Blocks/BlockMobSpawner.h @@ -8,7 +8,7 @@ -class cBlockMobSpawnerHandler: +class cBlockMobSpawnerHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockMushroom.h b/src/Blocks/BlockMushroom.h index c025f3ad5..bad4fc247 100644 --- a/src/Blocks/BlockMushroom.h +++ b/src/Blocks/BlockMushroom.h @@ -8,7 +8,7 @@ /** Handler for the small (singleblock) mushrooms. */ -class cBlockMushroomHandler: +class cBlockMushroomHandler final : public cClearMetaOnDrop<cBlockHandler> { using Super = cClearMetaOnDrop<cBlockHandler>; diff --git a/src/Blocks/BlockMycelium.h b/src/Blocks/BlockMycelium.h index bf489eed7..bb05195ff 100644 --- a/src/Blocks/BlockMycelium.h +++ b/src/Blocks/BlockMycelium.h @@ -7,7 +7,7 @@ -class cBlockMyceliumHandler: +class cBlockMyceliumHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockNetherWart.h b/src/Blocks/BlockNetherWart.h index dde6b17d4..0b0bbf2bd 100644 --- a/src/Blocks/BlockNetherWart.h +++ b/src/Blocks/BlockNetherWart.h @@ -8,7 +8,7 @@ -class cBlockNetherWartHandler: +class cBlockNetherWartHandler final : public cBlockPlant<false> { using Super = cBlockPlant<false>; diff --git a/src/Blocks/BlockNetherrack.h b/src/Blocks/BlockNetherrack.h index 4c839d5ee..dfcfeacbd 100644 --- a/src/Blocks/BlockNetherrack.h +++ b/src/Blocks/BlockNetherrack.h @@ -7,7 +7,7 @@ -class cBlockNetherrack : public cBlockHandler +class cBlockNetherrack final : public cBlockHandler { public: diff --git a/src/Blocks/BlockObserver.h b/src/Blocks/BlockObserver.h index 5c3f62fbd..b2ac955f9 100644 --- a/src/Blocks/BlockObserver.h +++ b/src/Blocks/BlockObserver.h @@ -5,7 +5,7 @@ #include "Mixins.h" -class cBlockObserverHandler: +class cBlockObserverHandler final : public cClearMetaOnDrop<cPitchYawRotator<cBlockHandler>> { using Super = cClearMetaOnDrop<cPitchYawRotator<cBlockHandler>>; diff --git a/src/Blocks/BlockOre.h b/src/Blocks/BlockOre.h index 95bffc75e..023e149d9 100644 --- a/src/Blocks/BlockOre.h +++ b/src/Blocks/BlockOre.h @@ -7,7 +7,7 @@ -class cBlockOreHandler: +class cBlockOreHandler : public cBlockHandler { using Super = cBlockHandler; @@ -16,6 +16,10 @@ public: using Super::Super; +protected: + + ~cBlockOreHandler() = default; + private: virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override @@ -124,3 +128,11 @@ private: + +class cDefaultOreHandler final : + public cBlockOreHandler +{ +public: + + using cBlockOreHandler::cBlockOreHandler; +}; diff --git a/src/Blocks/BlockPackedIce.h b/src/Blocks/BlockPackedIce.h index cad82d121..a2d13005c 100644 --- a/src/Blocks/BlockPackedIce.h +++ b/src/Blocks/BlockPackedIce.h @@ -7,7 +7,7 @@ -class cBlockPackedIceHandler : +class cBlockPackedIceHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index cbde5967e..fd8f3fe8a 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -15,7 +15,7 @@ class cWorld; -class cBlockPistonHandler: +class cBlockPistonHandler final : public cClearMetaOnDrop<cPitchYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>> { using Super = cClearMetaOnDrop<cPitchYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>; @@ -141,7 +141,7 @@ private: -class cBlockPistonHeadHandler: +class cBlockPistonHeadHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockPlanks.h b/src/Blocks/BlockPlanks.h index 158b9451d..f095f9ea3 100644 --- a/src/Blocks/BlockPlanks.h +++ b/src/Blocks/BlockPlanks.h @@ -7,7 +7,7 @@ -class cBlockPlanksHandler: +class cBlockPlanksHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockPlant.h b/src/Blocks/BlockPlant.h index e99a0b130..71890b3cf 100644 --- a/src/Blocks/BlockPlant.h +++ b/src/Blocks/BlockPlant.h @@ -9,7 +9,7 @@ /** Base class for plants that use light values to decide whether to grow or not. On block update, the plant decides whether to grow, die or stay as-is, based on the CanGrow() overridable method result. */ template <bool NeedsLightToGrow> -class cBlockPlant: +class cBlockPlant : public cBlockHandler { using Super = cBlockHandler; @@ -18,39 +18,10 @@ public: using Super::Super; -private: - - virtual void OnUpdate( - cChunkInterface & a_ChunkInterface, - cWorldInterface & a_WorldInterface, - cBlockPluginInterface & a_PluginInterface, - cChunk & a_Chunk, - const Vector3i a_RelPos - ) const override - { - auto Action = CanGrow(a_Chunk, a_RelPos); - switch (Action) - { - case paGrowth: - { - Grow(a_Chunk, a_RelPos); - break; - } - case paDeath: - { - a_ChunkInterface.SetBlock(a_Chunk.RelativeToAbsolute(a_RelPos), E_BLOCK_AIR, 0); - break; - } - case paStay: break; // do nothing - } - } - - - - - protected: + ~cBlockPlant() = default; + /** The action the plant can take on an update. */ enum PlantAction { @@ -59,10 +30,6 @@ protected: paStay }; - - - - /** Checks whether there is enough light for the plant to grow. If the plant doesn't require light to grow, then it returns paGrowth. If the plant requires light to grow and there is enough light, it returns paGrowth. @@ -167,4 +134,31 @@ protected: } return FloorC(24.0f / Chance) + 1; } + +private: + + virtual void OnUpdate( + cChunkInterface & a_ChunkInterface, + cWorldInterface & a_WorldInterface, + cBlockPluginInterface & a_PluginInterface, + cChunk & a_Chunk, + const Vector3i a_RelPos + ) const override + { + auto Action = CanGrow(a_Chunk, a_RelPos); + switch (Action) + { + case paGrowth: + { + Grow(a_Chunk, a_RelPos); + break; + } + case paDeath: + { + a_ChunkInterface.SetBlock(a_Chunk.RelativeToAbsolute(a_RelPos), E_BLOCK_AIR, 0); + break; + } + case paStay: break; // do nothing + } + } }; diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h index 64815f38f..1a2c4ef50 100644 --- a/src/Blocks/BlockPortal.h +++ b/src/Blocks/BlockPortal.h @@ -7,7 +7,7 @@ -class cBlockPortalHandler: +class cBlockPortalHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockPressurePlate.h b/src/Blocks/BlockPressurePlate.h index 3bf0e0861..c9a72a751 100644 --- a/src/Blocks/BlockPressurePlate.h +++ b/src/Blocks/BlockPressurePlate.h @@ -6,7 +6,7 @@ -class cBlockPressurePlateHandler : +class cBlockPressurePlateHandler final : public cClearMetaOnDrop<cBlockHandler> { using Super = cClearMetaOnDrop<cBlockHandler>; diff --git a/src/Blocks/BlockPumpkin.h b/src/Blocks/BlockPumpkin.h index d1ca23790..e627eeaee 100644 --- a/src/Blocks/BlockPumpkin.h +++ b/src/Blocks/BlockPumpkin.h @@ -5,7 +5,7 @@ -class cBlockPumpkinHandler : +class cBlockPumpkinHandler final : public cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>> { using Super = cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>>; diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h index cb10cbb04..d05c05ba3 100644 --- a/src/Blocks/BlockQuartz.h +++ b/src/Blocks/BlockQuartz.h @@ -7,7 +7,7 @@ -class cBlockQuartzHandler: +class cBlockQuartzHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 513ba26c0..af85e0afc 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -16,7 +16,7 @@ enum ENUM_PURE -class cBlockRailHandler : +class cBlockRailHandler final : public cClearMetaOnDrop<cBlockHandler> { using Super = cClearMetaOnDrop<cBlockHandler>; diff --git a/src/Blocks/BlockRedstone.h b/src/Blocks/BlockRedstone.h index 39fdf7d2d..0ba670558 100644 --- a/src/Blocks/BlockRedstone.h +++ b/src/Blocks/BlockRedstone.h @@ -8,7 +8,7 @@ -class cBlockRedstoneHandler: +class cBlockRedstoneHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockRedstoneLamp.h b/src/Blocks/BlockRedstoneLamp.h index 3382f543b..7a98f7870 100644 --- a/src/Blocks/BlockRedstoneLamp.h +++ b/src/Blocks/BlockRedstoneLamp.h @@ -7,7 +7,7 @@ -class cBlockRedstoneLampHandler: +class cBlockRedstoneLampHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockRedstoneOre.h b/src/Blocks/BlockRedstoneOre.h index bdba531f5..82e7c618c 100644 --- a/src/Blocks/BlockRedstoneOre.h +++ b/src/Blocks/BlockRedstoneOre.h @@ -8,7 +8,7 @@ -class cBlockRedstoneOreHandler : +class cBlockRedstoneOreHandler final : public cBlockOreHandler { using Super = cBlockOreHandler; @@ -60,7 +60,7 @@ public: -class cBlockGlowingRedstoneOreHandler: +class cBlockGlowingRedstoneOreHandler final : public cBlockOreHandler { using Super = cBlockOreHandler; diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index eccb497e6..b56f4ad28 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -11,7 +11,7 @@ -class cBlockRedstoneRepeaterHandler: +class cBlockRedstoneRepeaterHandler final : public cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03> { using Super = cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>; diff --git a/src/Blocks/BlockRedstoneTorch.h b/src/Blocks/BlockRedstoneTorch.h deleted file mode 100644 index 9680ca0dd..000000000 --- a/src/Blocks/BlockRedstoneTorch.h +++ /dev/null @@ -1,40 +0,0 @@ - -#pragma once - -#include "BlockTorch.h" - - - - - -class cBlockRedstoneTorchHandler : - public cBlockTorchHandler -{ - using Super = cBlockTorchHandler; - -public: - - using Super::Super; - -private: - - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override - { - // Always drop the ON torch, meta 0 - return cItem(E_BLOCK_REDSTONE_TORCH_ON, 1, 0); - } - - - - - - virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override - { - UNUSED(a_Meta); - return 0; - } -} ; - - - - diff --git a/src/Blocks/BlockSand.h b/src/Blocks/BlockSand.h index 9011766c5..0c117c40f 100644 --- a/src/Blocks/BlockSand.h +++ b/src/Blocks/BlockSand.h @@ -7,7 +7,7 @@ -class cBlockSandHandler : +class cBlockSandHandler final : public cBlockHandler { public: diff --git a/src/Blocks/BlockSapling.h b/src/Blocks/BlockSapling.h index 3bce74fb1..ee71bf1d0 100644 --- a/src/Blocks/BlockSapling.h +++ b/src/Blocks/BlockSapling.h @@ -8,7 +8,7 @@ -class cBlockSaplingHandler : +class cBlockSaplingHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockSeaLantern.h b/src/Blocks/BlockSeaLantern.h index d3adc95f4..224f8872d 100644 --- a/src/Blocks/BlockSeaLantern.h +++ b/src/Blocks/BlockSeaLantern.h @@ -7,7 +7,7 @@ -class cBlockSeaLanternHandler : +class cBlockSeaLanternHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h index 95619f564..a8eb52fc6 100644 --- a/src/Blocks/BlockSideways.h +++ b/src/Blocks/BlockSideways.h @@ -10,7 +10,7 @@ /** Handler for blocks that have 3 orientations (hay bale, log), specified by the upper 2 bits in meta. Handles setting the correct orientation on placement. Additionally supports the metadata specifying block sub-type in its lower 2 bits. */ -class cBlockSidewaysHandler: +class cBlockSidewaysHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockSignPost.h b/src/Blocks/BlockSignPost.h index 8f0a1c157..39ad6a73b 100644 --- a/src/Blocks/BlockSignPost.h +++ b/src/Blocks/BlockSignPost.h @@ -8,7 +8,7 @@ -class cBlockSignPostHandler: +class cBlockSignPostHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 2de4922b8..e6b1b445f 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -17,7 +17,7 @@ -class cBlockSlabHandler : +class cBlockSlabHandler final : public cBlockHandler { using Super = cBlockHandler; @@ -235,7 +235,7 @@ private: -class cBlockDoubleSlabHandler: +class cBlockDoubleSlabHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockSlime.h b/src/Blocks/BlockSlime.h index 87a2faa05..28b50527d 100644 --- a/src/Blocks/BlockSlime.h +++ b/src/Blocks/BlockSlime.h @@ -6,7 +6,7 @@ -class cBlockSlimeHandler: +class cBlockSlimeHandler final : public cClearMetaOnDrop<cBlockHandler> { public: diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index 43e341e0c..d4d8bcc50 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -7,7 +7,7 @@ -class cBlockSnowHandler : +class cBlockSnowHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockSponge.h b/src/Blocks/BlockSponge.h index 097b89cf9..a089bc0d0 100644 --- a/src/Blocks/BlockSponge.h +++ b/src/Blocks/BlockSponge.h @@ -7,7 +7,7 @@ -class cBlockSpongeHandler : +class cBlockSpongeHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index be86faa1b..701ad38e1 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -7,7 +7,7 @@ -class cBlockStairsHandler : +class cBlockStairsHandler final : public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x02, 0x01, true>> { using Super = cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x02, 0x01, true>>; diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h index dc30fa6ec..be64d81f8 100644 --- a/src/Blocks/BlockStems.h +++ b/src/Blocks/BlockStems.h @@ -11,7 +11,7 @@ ProduceBlockType is the blocktype for the produce to be grown. StemPickupType is the item type for the pickup resulting from breaking the stem. */ template <BLOCKTYPE ProduceBlockType, ENUM_ITEM_TYPE StemPickupType> -class cBlockStemsHandler: +class cBlockStemsHandler final : public cBlockPlant<true> { using Super = cBlockPlant<true>; diff --git a/src/Blocks/BlockStone.h b/src/Blocks/BlockStone.h index 846ddf5df..5309f5c41 100644 --- a/src/Blocks/BlockStone.h +++ b/src/Blocks/BlockStone.h @@ -6,7 +6,7 @@ -class cBlockStoneHandler: +class cBlockStoneHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h index 24c08db9f..b21f698f6 100644 --- a/src/Blocks/BlockSugarcane.h +++ b/src/Blocks/BlockSugarcane.h @@ -7,7 +7,7 @@ -class cBlockSugarcaneHandler : +class cBlockSugarcaneHandler final : public cBlockPlant<false> { using Super = cBlockPlant<false>; diff --git a/src/Blocks/BlockTNT.h b/src/Blocks/BlockTNT.h index ed478ce94..470cfa91a 100644 --- a/src/Blocks/BlockTNT.h +++ b/src/Blocks/BlockTNT.h @@ -7,7 +7,7 @@ -class cBlockTNTHandler : +class cBlockTNTHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h index d43d3ad04..1c679c2be 100644 --- a/src/Blocks/BlockTallGrass.h +++ b/src/Blocks/BlockTallGrass.h @@ -9,7 +9,7 @@ /** Handles the grass that is 1 block tall */ -class cBlockTallGrassHandler: +class cBlockTallGrassHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index a3ded9369..f8b4bfa04 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -8,15 +8,20 @@ -class cBlockTorchHandler: - public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x7, 0x4, 0x1, 0x3, 0x2>> + +class cBlockTorchBaseHandler : + public cMetaRotator<cBlockHandler, 0x7, 0x4, 0x1, 0x3, 0x2> { - using Super = cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x7, 0x4, 0x1, 0x3, 0x2>>; + using Super = cMetaRotator<cBlockHandler, 0x7, 0x4, 0x1, 0x3, 0x2>; public: using Super::Super; +protected: + + ~cBlockTorchBaseHandler() = default; + private: virtual bool GetPlacementBlockTypeMeta( @@ -214,3 +219,41 @@ private: + +class cBlockTorchHandler final : + public cClearMetaOnDrop<cBlockTorchBaseHandler> +{ + using Super = cClearMetaOnDrop<cBlockTorchBaseHandler>; + +public: + + using Super::Super; +}; + + + + + +class cBlockRedstoneTorchHandler final : + public cBlockTorchBaseHandler +{ + using Super = cBlockTorchBaseHandler; + +public: + + using Super::Super; + +private: + + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override + { + // Always drop the ON torch, meta 0: + return { E_BLOCK_REDSTONE_TORCH_ON }; + } + + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override + { + UNUSED(a_Meta); + return 0; + } +}; diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 2392fc2d3..cef7fb6e9 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -8,7 +8,7 @@ -class cBlockTrapdoorHandler : +class cBlockTrapdoorHandler final : public cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x01, 0x02, 0x00, 0x03, false>> { using Super = cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x01, 0x02, 0x00, 0x03, false>>; diff --git a/src/Blocks/BlockTripwire.h b/src/Blocks/BlockTripwire.h index 7fbcc678d..7a68c24be 100644 --- a/src/Blocks/BlockTripwire.h +++ b/src/Blocks/BlockTripwire.h @@ -7,7 +7,7 @@ -class cBlockTripwireHandler : +class cBlockTripwireHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockTripwireHook.h b/src/Blocks/BlockTripwireHook.h index 466ca2502..0d46da437 100644 --- a/src/Blocks/BlockTripwireHook.h +++ b/src/Blocks/BlockTripwireHook.h @@ -7,7 +7,7 @@ -class cBlockTripwireHookHandler : +class cBlockTripwireHookHandler final : public cMetaRotator<cClearMetaOnDrop<cBlockHandler>, 0x03, 0x02, 0x03, 0x00, 0x01> { using Super = cMetaRotator<cClearMetaOnDrop<cBlockHandler>, 0x03, 0x02, 0x03, 0x00, 0x01>; diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 5d4da0319..9738cd89b 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -6,7 +6,7 @@ -class cBlockVineHandler : +class cBlockVineHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockWallSign.h b/src/Blocks/BlockWallSign.h index d4b1ca59d..800781198 100644 --- a/src/Blocks/BlockWallSign.h +++ b/src/Blocks/BlockWallSign.h @@ -8,7 +8,7 @@ -class cBlockWallSignHandler: +class cBlockWallSignHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/BlockWorkbench.h b/src/Blocks/BlockWorkbench.h index 5b1e8705b..e654a6b84 100644 --- a/src/Blocks/BlockWorkbench.h +++ b/src/Blocks/BlockWorkbench.h @@ -9,7 +9,7 @@ -class cBlockWorkbenchHandler: +class cBlockWorkbenchHandler final : public cBlockHandler { using Super = cBlockHandler; diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt index 34b8276b6..d9d6e58f1 100644 --- a/src/Blocks/CMakeLists.txt +++ b/src/Blocks/CMakeLists.txt @@ -7,6 +7,7 @@ target_sources( BlockPiston.cpp ChunkInterface.cpp + BlockAir.h BlockAnvil.h BlockBed.h BlockBigFlower.h @@ -26,6 +27,7 @@ target_sources( BlockConcretePowder.h BlockCrops.h BlockDeadBush.h + BlockDefaultBlock.h BlockDirt.h BlockDoor.h BlockDropSpenser.h @@ -42,6 +44,7 @@ target_sources( BlockFluid.h BlockFurnace.h BlockGlass.h + BlockGlazedTerracotta.h BlockGlowstone.h BlockGrass.h BlockGravel.h @@ -76,21 +79,21 @@ target_sources( BlockRedstoneLamp.h BlockRedstoneOre.h BlockRedstoneRepeater.h - BlockRedstoneTorch.h BlockSand.h BlockSapling.h BlockSeaLantern.h BlockSideways.h BlockSignPost.h BlockSlab.h + BlockSlime.h BlockSnow.h BlockSponge.h BlockStairs.h BlockStems.h BlockStone.h BlockSugarcane.h - BlockTallGrass.h BlockTNT.h + BlockTallGrass.h BlockTorch.h BlockTrapdoor.h BlockTripwire.h diff --git a/src/Blocks/Mixins.h b/src/Blocks/Mixins.h index a5c3e751e..0a356fe58 100644 --- a/src/Blocks/Mixins.h +++ b/src/Blocks/Mixins.h @@ -25,33 +25,9 @@ class cBlockLadder: public cMetaRotator<cClearMetaOnDrop, ...> -template <class Base = cBlockHandler> -class cBlockWithNoDrops: - public Base -{ -public: - - constexpr cBlockWithNoDrops(BLOCKTYPE a_BlockType): - Base(a_BlockType) - { - } - -private: - - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override - { - // Don't drop anything: - return {}; - } -}; - - - - - /** Mixin to clear the block's meta value when converting to a pickup. */ template <class Base> -class cClearMetaOnDrop: +class cClearMetaOnDrop : public Base { public: @@ -61,6 +37,10 @@ public: { } +protected: + + ~cClearMetaOnDrop() = default; + private: virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override @@ -78,7 +58,7 @@ private: Inherit from this class providing your base class as Base, the BitMask for the direction bits in bitmask and the masked value for the directions in North, East, South, West. There is also an aptional parameter AssertIfNotMatched, set this if it is invalid for a block to exist in any other state. */ template <class Base, NIBBLETYPE BitMask, NIBBLETYPE North, NIBBLETYPE East, NIBBLETYPE South, NIBBLETYPE West, bool AssertIfNotMatched = false> -class cMetaRotator: +class cMetaRotator : public Base { public: @@ -90,6 +70,8 @@ public: protected: + ~cMetaRotator() = default; + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) const override { NIBBLETYPE OtherMeta = a_Meta & (~BitMask); @@ -176,7 +158,7 @@ template < NIBBLETYPE West = 0x04, bool AssertIfNotMatched = false > -class cYawRotator: +class cYawRotator : public cMetaRotator<Base, BitMask, North, East, South, West, AssertIfNotMatched> { using Super = cMetaRotator<Base, BitMask, North, East, South, West, AssertIfNotMatched>; @@ -185,8 +167,6 @@ public: using Super::Super; -public: - virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer & a_Player, const Vector3i a_BlockPos, @@ -230,6 +210,10 @@ public: return North; } } + +protected: + + ~cYawRotator() = default; }; @@ -259,6 +243,8 @@ public: protected: + ~cPitchYawRotator() = default; + virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer & a_Player, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9f18fd9d0..69ea7dbd1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,6 +155,7 @@ target_sources( WebAdmin.h World.h XMLParser.h + main.h ) set(FOLDERS diff --git a/src/Chunk.h b/src/Chunk.h index 04f305f69..3a8763398 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -589,7 +589,7 @@ private: cBlockEntities m_BlockEntities; /** Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero, the chunk can be unloaded */ - unsigned m_StayCount; + int m_StayCount; int m_PosX, m_PosZ; cWorld * m_World; @@ -619,7 +619,7 @@ private: /** If greater than zero, the chunk is ticked even if it has no clients. Manipulated by the SetAlwaysTicked() function, allows for nested calls of the function. This is the support for plugin-accessible chunk tick forcing. */ - unsigned m_AlwaysTicked; + int m_AlwaysTicked; // Pick up a random block of this chunk void GetRandomBlockCoords(int & a_X, int & a_Y, int & a_Z); diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c7d96f9b3..0ef041f32 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -809,10 +809,10 @@ void cClientHandle::HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment) const auto DeltaForPercent = CurrentFillPercent * (m_Player->XpForLevel(TargetLevel + 1) - m_Player->XpForLevel(TargetLevel)); // Apply the experience delta: - m_Player->DeltaExperience(DeltaForLevel + DeltaForPercent); + m_Player->DeltaExperience(FloorC(DeltaForLevel + DeltaForPercent)); // Now reduce the lapis in our stack and send it back: - LapisStack.AddCount(-LapisRequired); + LapisStack.AddCount(static_cast<char>(-LapisRequired)); Window->m_SlotArea->SetSlot(1, *m_Player, LapisStack); } else diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index d0d729567..6d92eff6a 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -3232,17 +3232,17 @@ float cPlayer::GetMiningProgressPerTick(BLOCKTYPE a_Block) ASSERT(BlockHardness > 0); // Can't divide by 0 or less, IsOneHitDig should have returned true if (GetEquippedItem().GetHandler()->CanHarvestBlock(a_Block)) { - BlockHardness*=1.5; + BlockHardness *= 1.5f; } else { - BlockHardness*=5; + BlockHardness *= 5.0f; } float DigSpeed = GetDigSpeed(a_Block); // LOGD("Time to mine block = %f", BlockHardness/DigSpeed); // Number of ticks to mine = (20 * BlockHardness)/DigSpeed; // Therefore take inverse to get fraction mined per tick: - return DigSpeed / (20 * BlockHardness); + return DigSpeed / (20.0f * BlockHardness); } diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp index 6aea6e228..ef013c347 100644 --- a/src/Entities/TNTEntity.cpp +++ b/src/Entities/TNTEntity.cpp @@ -58,8 +58,12 @@ void cTNTEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) BroadcastMovementUpdate(); - m_FuseTicks -= 1; - if (m_FuseTicks <= 0) + if (m_FuseTicks > 0) + { + --m_FuseTicks; + } + + if (m_FuseTicks == 0) { Explode(); } diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h index 5b1c853bd..d181eee22 100644 --- a/src/Entities/TNTEntity.h +++ b/src/Entities/TNTEntity.h @@ -39,5 +39,5 @@ public: // tolua_export // tolua_end protected: - int m_FuseTicks; ///< How much ticks is left, while the tnt will explode + unsigned m_FuseTicks; ///< How much ticks is left, while the tnt will explode }; // tolua_export diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 113acc3a5..8c5eb92a4 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -709,29 +709,3 @@ void cFile::Flush(void) { fflush(m_File); } - - - - - -template <class StreamType> -FileStream<StreamType>::FileStream(const std::string & Path) : - StreamType() -{ - // Except on failbit, which is what open sets on failure: - FileStream::exceptions(FileStream::failbit | FileStream::badbit); - - // Open the file: - FileStream::open(Path); - - // Only subsequently except on serious errors, and not on conditions like EOF or malformed input: - FileStream::exceptions(FileStream::badbit); -} - - - - - -// Instantiate the templated wrapper for input and output: -template class FileStream<std::ifstream>; -template class FileStream<std::ofstream>; diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index 62853ede7..59f3a5558 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -192,7 +192,17 @@ class FileStream final : public StreamType { public: - FileStream(const std::string & Path); + FileStream(const std::string & Path) + { + // Except on failbit, which is what open sets on failure: + FileStream::exceptions(FileStream::failbit | FileStream::badbit); + + // Open the file: + FileStream::open(Path); + + // Only subsequently except on serious errors, and not on conditions like EOF or malformed input: + FileStream::exceptions(FileStream::badbit); + } }; diff --git a/src/Physics/Explodinator.cpp b/src/Physics/Explodinator.cpp index ca8b82b9b..d68dc8541 100644 --- a/src/Physics/Explodinator.cpp +++ b/src/Physics/Explodinator.cpp @@ -1,6 +1,7 @@ #include "Globals.h" #include "BlockInfo.h" +#include "Explodinator.h" #include "Blocks/BlockHandler.h" #include "Blocks/ChunkInterface.h" #include "Chunk.h" @@ -19,7 +20,7 @@ namespace Explodinator const auto KnockbackFactor = 25U; const auto StepAttenuation = 0.225f; const auto TraceCubeSideLength = 16U; - const auto BoundingBoxStepUnit = 0.5f; + const auto BoundingBoxStepUnit = 0.5; /** Converts an absolute floating-point Position into a Chunk-relative one. */ static Vector3f AbsoluteToRelative(const Vector3f a_Position, const cChunkCoords a_ChunkPosition) @@ -41,17 +42,18 @@ namespace Explodinator /** Calculates the approximate percentage of an Entity's bounding box that is exposed to an explosion centred at Position. */ static float CalculateEntityExposure(cChunk & a_Chunk, const cEntity & a_Entity, const Vector3f a_Position, const float a_SquareRadius) { + const Vector3d Position = a_Position; unsigned Unobstructed = 0, Total = 0; const auto Box = a_Entity.GetBoundingBox(); - for (float X = Box.GetMinX(); X < Box.GetMaxX(); X += BoundingBoxStepUnit) + for (double X = Box.GetMinX(); X < Box.GetMaxX(); X += BoundingBoxStepUnit) { - for (float Y = Box.GetMinY(); Y < Box.GetMaxY(); Y += BoundingBoxStepUnit) + for (double Y = Box.GetMinY(); Y < Box.GetMaxY(); Y += BoundingBoxStepUnit) { - for (float Z = Box.GetMinZ(); Z < Box.GetMaxZ(); Z += BoundingBoxStepUnit) + for (double Z = Box.GetMinZ(); Z < Box.GetMaxZ(); Z += BoundingBoxStepUnit) { - const auto Destination = Vector3f(X, Y, Z); - if ((Destination - a_Position).SqrLength() > a_SquareRadius) + const Vector3d Destination{X, Y, Z}; + if ((Destination - Position).SqrLength() > a_SquareRadius) { // Don't bother with points outside our designated area-of-effect // This is, surprisingly, a massive amount of work saved (~3m to detonate a sphere of 37k TNT before, ~1m after): diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp index 2fd9e1cc2..9f8b91ac1 100644 --- a/src/Protocol/ChunkDataSerializer.cpp +++ b/src/Protocol/ChunkDataSerializer.cpp @@ -503,31 +503,30 @@ inline void cChunkDataSerializer::WriteSectionDataSeamless(const cChunkData::sCh ASSERT(a_BitsPerEntry < 64); UInt64 Buffer = 0; // A buffer to compose multiple smaller bitsizes into one 64-bit number - unsigned char BitIndex = 0; // The bit-position in Buffer that represents where to write next + int BitIndex = 0; // The bit-position in Buffer that represents where to write next for (size_t Index = 0; Index != cChunkData::SectionBlockCount; Index++) { - const UInt32 BlockType = a_Section.m_BlockTypes[Index]; - const UInt32 BlockMeta = (a_Section.m_BlockMetas[Index / 2] >> ((Index % 2) * 4)) & 0x0f; - const UInt32 Value = Palette(BlockType, BlockMeta); + const BLOCKTYPE BlockType = a_Section.m_BlockTypes[Index]; + const NIBBLETYPE BlockMeta = (a_Section.m_BlockMetas[Index / 2] >> ((Index % 2) * 4)) & 0x0f; + const auto Value = static_cast<UInt64>(Palette(BlockType, BlockMeta)); // Write as much as possible of Value, starting from BitIndex, into Buffer: - Buffer |= static_cast<UInt64>(Value) << BitIndex; + Buffer |= Value << BitIndex; // The _signed_ count of bits in Value left to write - const char Remaining = a_BitsPerEntry - (64 - BitIndex); - if (Remaining >= 0) + if (BitIndex + a_BitsPerEntry >= 64) { // There were some bits remaining: we've filled the buffer. Flush it: m_Packet.WriteBEUInt64(Buffer); // And write the remaining bits, setting the new BitIndex: - Buffer = Value >> (a_BitsPerEntry - Remaining); - BitIndex = Remaining; + Buffer = Value >> (64 - BitIndex); + BitIndex = a_BitsPerEntry - (64 - BitIndex); } else { - // It fit, sexcellent. + // It fit, excellent. BitIndex += a_BitsPerEntry; } } diff --git a/src/Protocol/ChunkDataSerializer.h b/src/Protocol/ChunkDataSerializer.h index cb39e27d6..aeff7c356 100644 --- a/src/Protocol/ChunkDataSerializer.h +++ b/src/Protocol/ChunkDataSerializer.h @@ -31,7 +31,7 @@ class cChunkDataSerializer v401, v477, - Count + Last = CacheVersion::v477 }; /** A single cache entry containing the raw data, compressed data, and a validity flag. */ @@ -79,7 +79,7 @@ protected: /** A cache, mapping protocol version to a fully serialised chunk. It is used during a single invocation of SendToClients with more than one client. */ - std::array<ChunkDataCache, static_cast<size_t>(CacheVersion::Count)> m_Cache; + std::array<ChunkDataCache, static_cast<size_t>(CacheVersion::Last) + 1> m_Cache; } ; diff --git a/src/Protocol/Palettes/Palette_1_13.cpp b/src/Protocol/Palettes/Palette_1_13.cpp index 7950ee72e..b6a8bbc0a 100644 --- a/src/Protocol/Palettes/Palette_1_13.cpp +++ b/src/Protocol/Palettes/Palette_1_13.cpp @@ -7916,7 +7916,7 @@ namespace Palette_1_13 case Statistic::WalkOneCm: return 5; case Statistic::WalkOnWaterOneCm: return 18; case Statistic::WalkUnderWaterOneCm: return 12; - default: return -1; + default: return UInt32(-1); } } diff --git a/src/Protocol/Palettes/Palette_1_13_1.cpp b/src/Protocol/Palettes/Palette_1_13_1.cpp index 25f02e47b..0786cf4fe 100644 --- a/src/Protocol/Palettes/Palette_1_13_1.cpp +++ b/src/Protocol/Palettes/Palette_1_13_1.cpp @@ -7932,7 +7932,7 @@ namespace Palette_1_13_1 case Statistic::WalkOneCm: return 5; case Statistic::WalkOnWaterOneCm: return 18; case Statistic::WalkUnderWaterOneCm: return 12; - default: return -1; + default: return UInt32(-1); } } diff --git a/src/Protocol/Palettes/Palette_1_14.cpp b/src/Protocol/Palettes/Palette_1_14.cpp index e98234ff2..29e9fcef9 100644 --- a/src/Protocol/Palettes/Palette_1_14.cpp +++ b/src/Protocol/Palettes/Palette_1_14.cpp @@ -9578,7 +9578,7 @@ namespace Palette_1_14 case Statistic::WalkOneCm: return 5; case Statistic::WalkOnWaterOneCm: return 8; case Statistic::WalkUnderWaterOneCm: return 12; - default: return -1; + default: return static_cast<UInt32>(-1); } } diff --git a/src/Protocol/Palettes/Palette_1_15.cpp b/src/Protocol/Palettes/Palette_1_15.cpp index cb07523a6..6cc67a488 100644 --- a/src/Protocol/Palettes/Palette_1_15.cpp +++ b/src/Protocol/Palettes/Palette_1_15.cpp @@ -9653,7 +9653,7 @@ namespace Palette_1_15 case Statistic::WalkOnWaterOneCm: return 8; case Statistic::WalkOneCm: return 5; case Statistic::WalkUnderWaterOneCm: return 12; - default: return -1; + default: return UInt32(-1); } } diff --git a/src/Protocol/Palettes/Palette_1_16.cpp b/src/Protocol/Palettes/Palette_1_16.cpp index 4d0c6fa39..baef7dfd0 100644 --- a/src/Protocol/Palettes/Palette_1_16.cpp +++ b/src/Protocol/Palettes/Palette_1_16.cpp @@ -12758,8 +12758,8 @@ namespace Palette_1_16 case Item::ZombieSpawnEgg: return 818; case Item::ZombieVillagerSpawnEgg: return 820; case Item::ZombiePigmanSpawnEgg: return 821; - default: return 0; } + UNREACHABLE("Invalid item"); } UInt32 From(const Statistic ID) @@ -12840,7 +12840,7 @@ namespace Palette_1_16 case Statistic::WalkOnWaterOneCm: return 8; case Statistic::WalkOneCm: return 5; case Statistic::WalkUnderWaterOneCm: return 12; - default: return -1; + default: return UInt32(-1); } } diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index cf3458040..5c9d5105f 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -350,7 +350,6 @@ public: Status = 1, Login = 2, Game = 3, - Invalid = 255 }; /** Called when client sends some data */ diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index b72f73f3d..94208cbf3 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -244,7 +244,7 @@ std::unique_ptr<cProtocol> cMultiVersionProtocol::TryRecognizeLengthedProtocol(c UInt32 ProtocolVersion; AString ServerAddress; UInt16 ServerPort; - cProtocol::State NextState; + UInt32 NextStateValue; if (!m_Buffer.ReadVarInt(PacketType) || (PacketType != 0x00)) { @@ -262,7 +262,7 @@ std::unique_ptr<cProtocol> cMultiVersionProtocol::TryRecognizeLengthedProtocol(c !m_Buffer.ReadVarInt(ProtocolVersion) || !m_Buffer.ReadVarUTF8String(ServerAddress) || !m_Buffer.ReadBEUInt16(ServerPort) || - !m_Buffer.ReadVarInt(NextState) + !m_Buffer.ReadVarInt(NextStateValue) ) { // TryRecognizeProtocol guarantees that we will have as much @@ -270,6 +270,22 @@ std::unique_ptr<cProtocol> cMultiVersionProtocol::TryRecognizeLengthedProtocol(c throw TriedToJoinWithUnsupportedProtocolException("Incorrect amount of data received - hacked client?"); } + cProtocol::State NextState = [&] + { + switch (NextStateValue) + { + case cProtocol::State::Status: return cProtocol::State::Status; + case cProtocol::State::Login: return cProtocol::State::Login; + case cProtocol::State::Game: return cProtocol::State::Game; + default: + { + throw TriedToJoinWithUnsupportedProtocolException( + fmt::format("Invalid next game state: {}", NextStateValue) + ); + } + } + }(); + // TODO: this should be a protocol property, not ClientHandle: a_Client.SetProtocolVersion(ProtocolVersion); @@ -285,23 +301,23 @@ std::unique_ptr<cProtocol> cMultiVersionProtocol::TryRecognizeLengthedProtocol(c // All good, eat up the data: m_Buffer.CommitRead(); - switch (static_cast<cProtocol::Version>(ProtocolVersion)) + switch (ProtocolVersion) { - case cProtocol::Version::v1_8_0: return std::make_unique<cProtocol_1_8_0> (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_9_0: return std::make_unique<cProtocol_1_9_0> (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_9_1: return std::make_unique<cProtocol_1_9_1> (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_9_2: return std::make_unique<cProtocol_1_9_2> (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_9_4: return std::make_unique<cProtocol_1_9_4> (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_10_0: return std::make_unique<cProtocol_1_10_0>(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_11_0: return std::make_unique<cProtocol_1_11_0>(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_11_1: return std::make_unique<cProtocol_1_11_1>(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_12: return std::make_unique<cProtocol_1_12> (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_12_1: return std::make_unique<cProtocol_1_12_1>(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_12_2: return std::make_unique<cProtocol_1_12_2>(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_13: return std::make_unique<cProtocol_1_13> (&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_13_1: return std::make_unique<cProtocol_1_13_1>(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_13_2: return std::make_unique<cProtocol_1_13_2>(&a_Client, ServerAddress, NextState); - case cProtocol::Version::v1_14: return std::make_unique<cProtocol_1_14> (&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_8_0): return std::make_unique<cProtocol_1_8_0> (&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_9_0): return std::make_unique<cProtocol_1_9_0> (&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_9_1): return std::make_unique<cProtocol_1_9_1> (&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_9_2): return std::make_unique<cProtocol_1_9_2> (&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_9_4): return std::make_unique<cProtocol_1_9_4> (&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_10_0): return std::make_unique<cProtocol_1_10_0>(&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_11_0): return std::make_unique<cProtocol_1_11_0>(&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_11_1): return std::make_unique<cProtocol_1_11_1>(&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_12): return std::make_unique<cProtocol_1_12> (&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_12_1): return std::make_unique<cProtocol_1_12_1>(&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_12_2): return std::make_unique<cProtocol_1_12_2>(&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_13): return std::make_unique<cProtocol_1_13> (&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_13_1): return std::make_unique<cProtocol_1_13_1>(&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_13_2): return std::make_unique<cProtocol_1_13_2>(&a_Client, ServerAddress, NextState); + case static_cast<UInt32>(cProtocol::Version::v1_14): return std::make_unique<cProtocol_1_14> (&a_Client, ServerAddress, NextState); default: { LOGD("Client \"%s\" uses an unsupported protocol (lengthed, version %u (0x%x))", diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 8a3076980..16651bdf6 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -1082,23 +1082,6 @@ bool cProtocol_1_12::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketTyp } break; } - default: - { - // Received a packet in an unknown state, report: - LOGWARNING("Received a packet in an unknown protocol state %d. Ignoring further packets.", m_State); - - // Cannot kick the client - we don't know this state and thus the packet number for the kick packet - - // Switch to a state when all further packets are silently ignored: - m_State = State::Invalid; - return false; - } - case State::Invalid: - { - // This is the state used for "not processing packets anymore" when we receive a bad packet from a client. - // Do not output anything (the caller will do that for us), just return failure - return false; - } } // switch (m_State) // Unknown packet type, report to the ClientHandle: @@ -1229,23 +1212,6 @@ bool cProtocol_1_12_1::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketT } break; } - default: - { - // Received a packet in an unknown state, report: - LOGWARNING("Received a packet in an unknown protocol state %d. Ignoring further packets.", m_State); - - // Cannot kick the client - we don't know this state and thus the packet number for the kick packet - - // Switch to a state when all further packets are silently ignored: - m_State = State::Invalid; - return false; - } - case State::Invalid: - { - // This is the state used for "not processing packets anymore" when we receive a bad packet from a client. - // Do not output anything (the caller will do that for us), just return failure - return false; - } } // switch (m_State) // Unknown packet type, report to the ClientHandle: diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index 0259565f5..1b505d58d 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -315,7 +315,9 @@ void cProtocol_1_13::HandlePacketSetBeaconEffect(cByteBuffer & a_ByteBuffer) { HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect1); HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect2); - m_Client->HandleBeaconSelection(Effect1, Effect2); + m_Client->HandleBeaconSelection( + static_cast<int>(Effect1), static_cast<int>(Effect2) + ); } @@ -655,7 +657,7 @@ bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t return true; } - const auto Translated = GetItemFromProtocolID(ItemID); + const auto Translated = GetItemFromProtocolID(ToUnsigned(ItemID)); a_Item.m_ItemType = Translated.first; a_Item.m_ItemDamage = Translated.second; @@ -698,7 +700,7 @@ void cProtocol_1_13::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) } // Normal item - a_Pkt.WriteBEInt16(GetProtocolItemType(a_Item.m_ItemType, a_Item.m_ItemDamage)); + a_Pkt.WriteBEInt16(static_cast<Int16>(GetProtocolItemType(a_Item.m_ItemType, a_Item.m_ItemDamage))); a_Pkt.WriteBEInt8(a_Item.m_ItemCount); // TODO: NBT diff --git a/src/Protocol/Protocol_1_14.cpp b/src/Protocol/Protocol_1_14.cpp index 335677155..a77cd2d7d 100644 --- a/src/Protocol/Protocol_1_14.cpp +++ b/src/Protocol/Protocol_1_14.cpp @@ -21,36 +21,6 @@ Implements the 1.14 protocol classes: -#define HANDLE_READ(ByteBuf, Proc, Type, Var) \ - Type Var; \ - do { \ - if (!ByteBuf.Proc(Var))\ - {\ - return;\ - } \ - } while (false) - - - - - -#define HANDLE_PACKET_READ(ByteBuf, Proc, Type, Var) \ - Type Var; \ - do { \ - { \ - if (!ByteBuf.Proc(Var)) \ - { \ - ByteBuf.CheckValid(); \ - return false; \ - } \ - ByteBuf.CheckValid(); \ - } \ - } while (false) - - - - - //////////////////////////////////////////////////////////////////////////////// // cProtocol_1_14: @@ -89,7 +59,7 @@ void cProtocol_1_14::SendLogin(const cPlayer & a_Player, const cWorld & a_World) Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension())); Pkt.WriteBEUInt8(static_cast<UInt8>(Clamp<size_t>(Server->GetMaxPlayers(), 0, 255))); Pkt.WriteString("default"); - Pkt.WriteVarInt32(a_World.GetMaxViewDistance()); + Pkt.WriteVarInt32(ToUnsigned(a_World.GetMaxViewDistance())); Pkt.WriteBool(false); } diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index ae3137eb6..5856a87d2 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -9,6 +9,7 @@ Implements the 1.8 protocol classes: #include "Globals.h" #include "Protocol_1_8.h" +#include "main.h" #include "../mbedTLS++/Sha1Checksum.h" #include "Packetizer.h" @@ -91,20 +92,13 @@ static const UInt32 CompressionThreshold = 256; // After how large a packet sho -// fwd: main.cpp: -extern bool g_ShouldLogCommIn, g_ShouldLogCommOut; - - - - - //////////////////////////////////////////////////////////////////////////////// // cProtocol_1_8_0: cProtocol_1_8_0::cProtocol_1_8_0(cClientHandle * a_Client, const AString & a_ServerAddress, State a_State) : Super(a_Client), - m_ServerAddress(a_ServerAddress), m_State(a_State), + m_ServerAddress(a_ServerAddress), m_IsEncrypted(false) { AStringVector Params; @@ -395,6 +389,13 @@ void cProtocol_1_8_0::SendDisconnect(const AString & a_Reason) Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Reason).c_str())); break; } + default: + { + FLOGERROR( + "Tried to send disconnect in invalid game state {0}", + static_cast<int>(m_State) + ); + } } } @@ -1725,7 +1726,8 @@ bool cProtocol_1_8_0::CompressPacket(const AString & a_Packet, AString & a_Compr ---------------------------------------------- */ const UInt32 DataSize = 0; - const auto PacketSize = cByteBuffer::GetVarIntSize(DataSize) + UncompressedSize; + const auto PacketSize = static_cast<UInt32>( + cByteBuffer::GetVarIntSize(DataSize) + UncompressedSize); cByteBuffer LengthHeaderBuffer( cByteBuffer::GetVarIntSize(PacketSize) + @@ -1776,8 +1778,9 @@ bool cProtocol_1_8_0::CompressPacket(const AString & a_Packet, AString & a_Compr return false; } - const UInt32 DataSize = UncompressedSize; - const auto PacketSize = cByteBuffer::GetVarIntSize(DataSize) + CompressedSize; + const UInt32 DataSize = static_cast<UInt32>(UncompressedSize); + const auto PacketSize = static_cast<UInt32>( + cByteBuffer::GetVarIntSize(DataSize) + CompressedSize); cByteBuffer LengthHeaderBuffer( cByteBuffer::GetVarIntSize(PacketSize) + @@ -2272,23 +2275,6 @@ bool cProtocol_1_8_0::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketTy } break; } - default: - { - // Received a packet in an unknown state, report: - LOGWARNING("Received a packet in an unknown protocol state %d. Ignoring further packets.", m_State); - - // Cannot kick the client - we don't know this state and thus the packet number for the kick packet - - // Switch to a state when all further packets are silently ignored: - m_State = State::Invalid; - return false; - } - case State::Invalid: - { - // This is the state used for "not processing packets anymore" when we receive a bad packet from a client. - // Do not output anything (the caller will do that for us), just return failure - return false; - } } // switch (m_State) // Unknown packet type, report to the ClientHandle: diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index c170227b5..a152a46cb 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -632,23 +632,6 @@ bool cProtocol_1_9_0::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketTy } break; } - default: - { - // Received a packet in an unknown state, report: - LOGWARNING("Received a packet in an unknown protocol state %d. Ignoring further packets.", m_State); - - // Cannot kick the client - we don't know this state and thus the packet number for the kick packet - - // Switch to a state when all further packets are silently ignored: - m_State = State::Invalid; - return false; - } - case State::Invalid: - { - // This is the state used for "not processing packets anymore" when we receive a bad packet from a client. - // Do not output anything (the caller will do that for us), just return failure - return false; - } } // switch (m_State) // Unknown packet type, report to the ClientHandle: diff --git a/src/Root.cpp b/src/Root.cpp index 0decfd4dd..49adf3f6c 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -45,10 +45,8 @@ -extern bool g_RunAsService; -decltype(cRoot::s_Root) cRoot::s_Root; -decltype(cRoot::s_NextState) cRoot::s_NextState; -decltype(cRoot::s_StopEvent) cRoot::s_StopEvent; +extern bool g_RunAsService; +cRoot * cRoot::s_Root = nullptr; @@ -194,7 +192,7 @@ bool cRoot::Run(cSettingsRepositoryInterface & a_OverridesRepo) m_StartTime = std::chrono::steady_clock::now(); HandleInput(); - s_StopEvent.Wait(); + m_StopEvent.Wait(); // Stop the server: m_WebAdmin->Stop(); @@ -233,7 +231,7 @@ bool cRoot::Run(cSettingsRepositoryInterface & a_OverridesRepo) LOG("Shutdown successful!"); LOG("--- Stopped Log ---"); - return s_NextState == NextState::Restart; + return m_NextState == NextState::Restart; } @@ -957,7 +955,7 @@ void cRoot::HandleInput() cLogCommandOutputCallback Output; AString Command; - while (s_NextState == NextState::Run) + while (m_NextState == NextState::Run) { #ifndef _WIN32 timeval Timeout{ 0, 0 }; @@ -980,7 +978,7 @@ void cRoot::HandleInput() return; } - if (s_NextState != NextState::Run) + if (m_NextState != NextState::Run) { // Already shutting down, can't execute commands break; @@ -1001,7 +999,7 @@ void cRoot::HandleInput() void cRoot::TransitionNextState(NextState a_NextState) { { - auto Current = s_NextState.load(); + auto Current = m_NextState.load(); do { // Stopping is final, so stops override restarts: @@ -1010,15 +1008,15 @@ void cRoot::TransitionNextState(NextState a_NextState) return; } } - while (!s_NextState.compare_exchange_strong(Current, a_NextState)); + while (!m_NextState.compare_exchange_strong(Current, a_NextState)); } - if (s_NextState == NextState::Run) + if (m_NextState == NextState::Run) { return; } - s_StopEvent.Set(); + m_StopEvent.Set(); #ifdef WIN32 diff --git a/src/Root.h b/src/Root.h index 696b31ce3..e055950c0 100644 --- a/src/Root.h +++ b/src/Root.h @@ -62,10 +62,10 @@ public: bool Run(cSettingsRepositoryInterface & a_OverridesRepo); /** Interrupts the server and stops it, as if "/stop" typed in the console. */ - static void Stop(); + void Stop(); /** Interrupts the server and restarts it, as if "/restart" was typed in the console. */ - static void Restart(); + void Restart(); // tolua_begin cServer * GetServer(void) { return m_Server; } @@ -208,12 +208,12 @@ private: void HandleInput(); /** Performs run state transition, enforcing guarantees about state transitions. */ - static void TransitionNextState(NextState a_NextState); + void TransitionNextState(NextState a_NextState); cWorld * m_pDefaultWorld; WorldMap m_WorldsByName; - static cEvent s_StopEvent; + cEvent m_StopEvent; cServer * m_Server; cMonsterConfig * m_MonsterConfig; @@ -249,5 +249,5 @@ private: static cRoot * s_Root; /** Indicates the next action of cRoot, whether to run, stop or restart. */ - static std::atomic<NextState> s_NextState; + std::atomic<NextState> m_NextState; }; // tolua_export diff --git a/src/SettingsRepositoryInterface.h b/src/SettingsRepositoryInterface.h index d10f94119..5f73c49c8 100644 --- a/src/SettingsRepositoryInterface.h +++ b/src/SettingsRepositoryInterface.h @@ -10,7 +10,9 @@ public: noID = -1, }; + cSettingsRepositoryInterface() = default; virtual ~cSettingsRepositoryInterface() = default; + DISALLOW_COPY_AND_ASSIGN(cSettingsRepositoryInterface); /** Returns true iff the specified key exists */ virtual bool KeyExists(const AString keyname) const = 0; diff --git a/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp b/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp index 4c676b405..d5433f25a 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp @@ -74,7 +74,7 @@ void ForEachSourceCallback::CheckIndirectPower() ForEachSourceCallback QuasiQueryCallback(m_Chunk, Above, m_Chunk.GetBlock(Above)); // Manually feed the callback object all positions that may deliver power to Above: - for (const auto QuasiPowerOffset : cSimulator::GetLinkedOffsets(OffsetYP)) + for (const auto & QuasiPowerOffset : cSimulator::GetLinkedOffsets(OffsetYP)) { QuasiQueryCallback(m_Position + QuasiPowerOffset); } @@ -116,7 +116,7 @@ PowerLevel ForEachSourceCallback::QueryLinkedPower(const cChunk & Chunk, const V PowerLevel Power = 0; // Loop through all linked powerable offsets in the direction requested: - for (const auto Offset : cSimulator::GetLinkedOffsets(SolidBlockPosition - QueryPosition)) + for (const auto & Offset : cSimulator::GetLinkedOffsets(SolidBlockPosition - QueryPosition)) { auto SourcePosition = QueryPosition + Offset; if (!cChunk::IsValidHeight(SourcePosition.y)) diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp index d9e4aa961..459cf672e 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp @@ -39,7 +39,7 @@ void cIncrementalRedstoneSimulator::SimulateChunk(std::chrono::milliseconds a_Dt ProcessWorkItem(*NeighbourChunk, *a_Chunk, CurrentLocation); } - for (const auto Position : ChunkData.AlwaysTickedPositions) + for (const auto & Position : ChunkData.AlwaysTickedPositions) { ChunkData.WakeUp(Position); } @@ -119,7 +119,7 @@ void cIncrementalRedstoneSimulator::WakeUp(cChunk & a_Chunk, Vector3i a_Position // The only thing to do go one block farther than this cross-coord, in the direction of Offset // in order to notify linked-powered positions that there was a change - for (const auto Offset : cSimulator::GetLinkedOffsets(a_Offset)) + for (const auto & Offset : cSimulator::GetLinkedOffsets(a_Offset)) { auto Relative = a_Position - a_Offset + Offset; if (!cChunkDef::IsValidHeight(Relative.y)) diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h index dc00f73c7..cf08a672f 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.h @@ -94,7 +94,7 @@ private: } } - virtual void Simulate(float Dt) override {}; + virtual void Simulate(float Dt) override {} virtual void SimulateChunk(std::chrono::milliseconds Dt, int ChunkX, int ChunkZ, cChunk * Chunk) override; void ProcessWorkItem(cChunk & Chunk, cChunk & TickingSource, const Vector3i Position); diff --git a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h index 851b32498..e528788f7 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h @@ -53,7 +53,7 @@ namespace PistonHandler const auto Face = cBlockPistonHandler::MetaDataToDirection(a_Meta); const auto FrontOffset = AddFaceDirection(Vector3i(), Face); - for (const auto Offset : RelativeAdjacents) + for (const auto & Offset : RelativeAdjacents) { if (Offset != FrontOffset) { diff --git a/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h index b949db98b..6fa397c06 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/PoweredRailHandler.h @@ -7,7 +7,9 @@ namespace PoweredRailHandler { - Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta) // Not in cBlockRailHandler since specific to powered rails + /** Get the offset along which the rail faces. + Not in cBlockRailHandler since specific to powered rails. */ + inline Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta) { switch (a_Meta & 0x7) { diff --git a/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h index 14d8c3017..46409b101 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h @@ -12,7 +12,7 @@ namespace PressurePlateHandler { inline unsigned char GetPowerLevel(const cChunk & Chunk, const Vector3i Position, const BLOCKTYPE BlockType) { - unsigned NumberOfEntities = 0; + Int64 NumberOfEntities = 0; bool FoundPlayer = false; Chunk.ForEachEntityInBox(cBoundingBox(Vector3d(0.5, 0, 0.5) + Position, 0.5, 0.5), [&](cEntity & Entity) @@ -39,7 +39,7 @@ namespace PressurePlateHandler } case E_BLOCK_WOODEN_PRESSURE_PLATE: { - return (NumberOfEntities != 0 ? 15 : 0); + return (NumberOfEntities > 0 ? 15 : 0); } case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: { diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h index a1045cdbb..f62a7156f 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h @@ -113,7 +113,7 @@ namespace RedstoneComparatorHandler const auto RearPower = GetPowerLevel(a_Chunk, a_Position, a_BlockType, a_Meta); const auto FrontPower = GetFrontPowerLevel(a_Meta, Power, RearPower); - const auto NewMeta = (FrontPower > 0) ? (a_Meta | 0x8) : (a_Meta & 0x7); + const NIBBLETYPE NewMeta = (FrontPower > 0) ? (a_Meta | 0x08u) : (a_Meta & 0x07u); // Don't care about the previous power level so return value ignored Data.ExchangeUpdateOncePowerData(a_Position, FrontPower); diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h index 16d6924b1..2f827206f 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneDataHelper.h @@ -12,7 +12,7 @@ inline void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const { DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + Offset)); - for (const auto LinkedOffset : cSimulator::GetLinkedOffsets(Offset)) + for (const auto & LinkedOffset : cSimulator::GetLinkedOffsets(Offset)) { DataForChunk(To).WakeUp(cIncrementalRedstoneSimulatorChunkData::RebaseRelativePosition(From, To, Position + LinkedOffset)); } @@ -21,7 +21,7 @@ inline void UpdateAdjustedRelative(const cChunk & From, const cChunk & To, const template <typename ArrayType> inline void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, const Vector3i Position, const ArrayType & Relative) { - for (const auto Offset : Relative) + for (const auto & Offset : Relative) { UpdateAdjustedRelative(From, To, Position, Offset); } @@ -30,12 +30,18 @@ inline void UpdateAdjustedRelatives(const cChunk & From, const cChunk & To, cons template <typename ArrayType> inline void InvokeForAdjustedRelatives(ForEachSourceCallback & Callback, const Vector3i Position, const ArrayType & Relative) { - for (const auto Offset : Relative) + for (const auto & Offset : Relative) { Callback(Position + Offset); } } +// Warning shouldn't trigger for inline variables, this is fixed in clang 7 +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-variable-declarations" +#endif + inline constexpr Vector3i OffsetYP{ 0, 1, 0 }; inline constexpr Vector3i OffsetYM{ 0, -1, 0 }; @@ -61,3 +67,7 @@ inline constexpr std::array<Vector3i, 4> RelativeLaterals { 0, 0, -1 }, } }; + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp b/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp index dc2c690f9..ff109c824 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneHandler.cpp @@ -30,56 +30,59 @@ -#define INVOKE_FOR_HANDLERS(Callback) \ - switch (BlockType) \ - { \ - case E_BLOCK_ACTIVATOR_RAIL: \ - case E_BLOCK_DETECTOR_RAIL: \ - case E_BLOCK_POWERED_RAIL: return PoweredRailHandler::Callback; \ - case E_BLOCK_ACTIVE_COMPARATOR: \ - case E_BLOCK_INACTIVE_COMPARATOR: return RedstoneComparatorHandler::Callback; \ - case E_BLOCK_DISPENSER: \ - case E_BLOCK_DROPPER: return DropSpenserHandler::Callback; \ - case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: \ - case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: \ - case E_BLOCK_STONE_PRESSURE_PLATE: \ - case E_BLOCK_WOODEN_PRESSURE_PLATE: return PressurePlateHandler::Callback; \ - case E_BLOCK_ACACIA_FENCE_GATE: \ - case E_BLOCK_BIRCH_FENCE_GATE: \ - case E_BLOCK_DARK_OAK_FENCE_GATE: \ - case E_BLOCK_FENCE_GATE: \ - case E_BLOCK_IRON_TRAPDOOR: \ - case E_BLOCK_JUNGLE_FENCE_GATE: \ - case E_BLOCK_SPRUCE_FENCE_GATE: \ - case E_BLOCK_TRAPDOOR: return SmallGateHandler::Callback; \ - case E_BLOCK_REDSTONE_LAMP_OFF: \ - case E_BLOCK_REDSTONE_LAMP_ON: return RedstoneLampHandler::Callback; \ - case E_BLOCK_REDSTONE_REPEATER_OFF: \ - case E_BLOCK_REDSTONE_REPEATER_ON: return RedstoneRepeaterHandler::Callback; \ - case E_BLOCK_REDSTONE_TORCH_OFF: \ - case E_BLOCK_REDSTONE_TORCH_ON: return RedstoneTorchHandler::Callback; \ - case E_BLOCK_OBSERVER: return ObserverHandler::Callback; \ - case E_BLOCK_PISTON: \ - case E_BLOCK_STICKY_PISTON: return PistonHandler::Callback; \ - case E_BLOCK_LEVER: \ - case E_BLOCK_STONE_BUTTON: \ - case E_BLOCK_WOODEN_BUTTON: return RedstoneToggleHandler::Callback; \ - case E_BLOCK_BLOCK_OF_REDSTONE: return RedstoneBlockHandler::Callback; \ - case E_BLOCK_COMMAND_BLOCK: return CommandBlockHandler::Callback; \ - case E_BLOCK_HOPPER: return HopperHandler::Callback; \ - case E_BLOCK_NOTE_BLOCK: return NoteBlockHandler::Callback; \ - case E_BLOCK_REDSTONE_WIRE: return RedstoneWireHandler::Callback; \ - case E_BLOCK_TNT: return TNTHandler::Callback; \ - case E_BLOCK_TRAPPED_CHEST: return TrappedChestHandler::Callback; \ - case E_BLOCK_TRIPWIRE_HOOK: return TripwireHookHandler::Callback; \ - default: \ - { \ - if (cBlockDoorHandler::IsDoorBlockType(BlockType)) \ - { \ - return DoorHandler::Callback; \ - } \ - } \ - } +#define INVOKE_FOR_HANDLERS(Callback) \ + do \ + { \ + switch (BlockType) \ + { \ + case E_BLOCK_ACTIVATOR_RAIL: \ + case E_BLOCK_DETECTOR_RAIL: \ + case E_BLOCK_POWERED_RAIL: return PoweredRailHandler::Callback; \ + case E_BLOCK_ACTIVE_COMPARATOR: \ + case E_BLOCK_INACTIVE_COMPARATOR: return RedstoneComparatorHandler::Callback; \ + case E_BLOCK_DISPENSER: \ + case E_BLOCK_DROPPER: return DropSpenserHandler::Callback; \ + case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE: \ + case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: \ + case E_BLOCK_STONE_PRESSURE_PLATE: \ + case E_BLOCK_WOODEN_PRESSURE_PLATE: return PressurePlateHandler::Callback; \ + case E_BLOCK_ACACIA_FENCE_GATE: \ + case E_BLOCK_BIRCH_FENCE_GATE: \ + case E_BLOCK_DARK_OAK_FENCE_GATE: \ + case E_BLOCK_FENCE_GATE: \ + case E_BLOCK_IRON_TRAPDOOR: \ + case E_BLOCK_JUNGLE_FENCE_GATE: \ + case E_BLOCK_SPRUCE_FENCE_GATE: \ + case E_BLOCK_TRAPDOOR: return SmallGateHandler::Callback; \ + case E_BLOCK_REDSTONE_LAMP_OFF: \ + case E_BLOCK_REDSTONE_LAMP_ON: return RedstoneLampHandler::Callback; \ + case E_BLOCK_REDSTONE_REPEATER_OFF: \ + case E_BLOCK_REDSTONE_REPEATER_ON: return RedstoneRepeaterHandler::Callback; \ + case E_BLOCK_REDSTONE_TORCH_OFF: \ + case E_BLOCK_REDSTONE_TORCH_ON: return RedstoneTorchHandler::Callback; \ + case E_BLOCK_OBSERVER: return ObserverHandler::Callback; \ + case E_BLOCK_PISTON: \ + case E_BLOCK_STICKY_PISTON: return PistonHandler::Callback; \ + case E_BLOCK_LEVER: \ + case E_BLOCK_STONE_BUTTON: \ + case E_BLOCK_WOODEN_BUTTON: return RedstoneToggleHandler::Callback; \ + case E_BLOCK_BLOCK_OF_REDSTONE: return RedstoneBlockHandler::Callback; \ + case E_BLOCK_COMMAND_BLOCK: return CommandBlockHandler::Callback; \ + case E_BLOCK_HOPPER: return HopperHandler::Callback; \ + case E_BLOCK_NOTE_BLOCK: return NoteBlockHandler::Callback; \ + case E_BLOCK_REDSTONE_WIRE: return RedstoneWireHandler::Callback; \ + case E_BLOCK_TNT: return TNTHandler::Callback; \ + case E_BLOCK_TRAPPED_CHEST: return TrappedChestHandler::Callback; \ + case E_BLOCK_TRIPWIRE_HOOK: return TripwireHookHandler::Callback; \ + default: \ + { \ + if (cBlockDoorHandler::IsDoorBlockType(BlockType)) \ + { \ + return DoorHandler::Callback; \ + } \ + } \ + } \ + } while (false) diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h index ac739d3b8..a2964ea38 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneTorchHandler.h @@ -75,7 +75,7 @@ namespace RedstoneTorchHandler a_Chunk.FastSetBlock(a_Position, ShouldPowerOn ? E_BLOCK_REDSTONE_TORCH_ON : E_BLOCK_REDSTONE_TORCH_OFF, a_Meta); Data.m_MechanismDelays.erase(a_Position); - for (const auto Adjacent : RelativeAdjacents) + for (const auto & Adjacent : RelativeAdjacents) { // Update all adjacents (including linked power positions) // apart from our attachment, which can't possibly need an update: diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h index 0bf3d58f3..c97f37aa5 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h @@ -109,7 +109,7 @@ namespace RedstoneWireHandler const bool IsYPTerracingBlocked = cBlockInfo::IsSolid(YPTerraceBlock) && !cBlockInfo::IsTransparent(YPTerraceBlock); // Loop through laterals, discovering terracing connections: - for (const auto Offset : RelativeLaterals) + for (const auto & Offset : RelativeLaterals) { auto Adjacent = Position + Offset; auto NeighbourChunk = Chunk.GetRelNeighborChunkAdjustCoords(Adjacent); @@ -268,7 +268,7 @@ namespace RedstoneWireHandler a_Chunk.SetMeta(a_Position, Power); // Notify all positions, sans YP, to update: - for (const auto Offset : RelativeAdjacents) + for (const auto & Offset : RelativeAdjacents) { if (Offset == OffsetYP) { @@ -291,7 +291,7 @@ namespace RedstoneWireHandler const auto Block = Data.WireStates.find(a_Position)->second; // Figure out, based on our pre-computed block, where we connect to: - for (const auto Offset : RelativeLaterals) + for (const auto & Offset : RelativeLaterals) { const auto Relative = a_Position + Offset; Callback(Relative); @@ -311,10 +311,10 @@ namespace RedstoneWireHandler const auto YMDiagonalPosition = Relative + OffsetYM; if ( - BLOCKTYPE Block; + BLOCKTYPE QueryBlock; cChunkDef::IsValidHeight(YMDiagonalPosition.y) && - a_Chunk.UnboundedRelGetBlockType(YMDiagonalPosition, Block) && - (Block == E_BLOCK_REDSTONE_WIRE) + a_Chunk.UnboundedRelGetBlockType(YMDiagonalPosition, QueryBlock) && + (QueryBlock == E_BLOCK_REDSTONE_WIRE) ) { Callback(YMDiagonalPosition); diff --git a/src/Simulator/SimulatorManager.cpp b/src/Simulator/SimulatorManager.cpp index 81044d705..8af56c791 100644 --- a/src/Simulator/SimulatorManager.cpp +++ b/src/Simulator/SimulatorManager.cpp @@ -63,12 +63,12 @@ void cSimulatorManager::WakeUp(cChunk & a_Chunk, Vector3i a_Position) { ASSERT(a_Chunk.IsValid()); - for (const auto Item : m_Simulators) + for (const auto & Item : m_Simulators) { Item.first->WakeUp(a_Chunk, a_Position, a_Chunk.GetBlock(a_Position)); } - for (const auto Offset : cSimulator::AdjacentOffsets) + for (const auto & Offset : cSimulator::AdjacentOffsets) { auto Relative = a_Position + Offset; if (!cChunkDef::IsValidHeight(Relative.y)) @@ -86,7 +86,7 @@ void cSimulatorManager::WakeUp(cChunk & a_Chunk, Vector3i a_Position) // Since they all need this we save them querying it themselves const auto Block = Chunk->GetBlock(Relative); - for (const auto Item : m_Simulators) + for (const auto & Item : m_Simulators) { Item.first->WakeUp(*Chunk, Relative, Offset, Block); } @@ -99,7 +99,7 @@ void cSimulatorManager::WakeUp(cChunk & a_Chunk, Vector3i a_Position) void cSimulatorManager::WakeUp(const cCuboid & a_Area) { - for (const auto Item : m_Simulators) + for (const auto & Item : m_Simulators) { Item.first->WakeUp(a_Area); } diff --git a/src/Statistics.cpp b/src/Statistics.cpp index 55bca5095..7bc5ae413 100644 --- a/src/Statistics.cpp +++ b/src/Statistics.cpp @@ -63,9 +63,8 @@ bool cStatManager::SatisfiesPrerequisite(const Statistic a_Stat) case Statistic::AchKillWither: return IsStatisticPresent(Statistic::AchSpawnWither); case Statistic::AchFullBeacon: return IsStatisticPresent(Statistic::AchKillWither); case Statistic::AchDiamondsToYou: return IsStatisticPresent(Statistic::AchDiamonds); + default: return true; } - - return true; } diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 53d406e65..a452227f8 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1684,18 +1684,18 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) } // Pseudocode found at: https://minecraft.gamepedia.com/Enchanting_mechanics - const auto Bookshelves = std::min(GetBookshelvesCount(*a_Player.GetWorld()), 15U); + const auto Bookshelves = std::min(static_cast<int>(GetBookshelvesCount(*a_Player.GetWorld())), 15); // A PRNG initialised using the player's enchantment seed. auto Random = a_Player.GetEnchantmentRandomProvider(); // Calculate the levels for the offered enchantment options: - const auto Base = (Random.RandInt(1U, 8U) + (Bookshelves / 2) + Random.RandInt(0U, Bookshelves)); - const std::array<unsigned int, 3> OptionLevels + const auto Base = (Random.RandInt(1, 8) + (Bookshelves / 2) + Random.RandInt(0, Bookshelves)); + const std::array<short, 3> OptionLevels { - std::max(Base / 3, 1U), - (Base * 2) / 3 + 1, - std::max(Base, Bookshelves * 2) + static_cast<short>(std::max(Base / 3, 1)), + static_cast<short>((Base * 2) / 3 + 1), + static_cast<short>(std::max(Base, Bookshelves * 2)) }; // Properties set according to: https://wiki.vg/Protocol#Window_Property @@ -1714,16 +1714,16 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) LOGD("Generated enchanted item %d with enchantments: %s", i, EnchantedItem.m_Enchantments.ToString()); // Send the level requirement for the enchantment option: - m_ParentWindow.SetProperty(i, static_cast<short>(OptionLevels[i])); + m_ParentWindow.SetProperty(i, OptionLevels[i]); // Get the first enchantment ID, which must exist: ASSERT(EnchantedItem.m_Enchantments.begin() != EnchantedItem.m_Enchantments.end()); - const short EnchantmentID = static_cast<short>(EnchantedItem.m_Enchantments.begin()->first); + const auto EnchantmentID = static_cast<short>(EnchantedItem.m_Enchantments.begin()->first); // Send the enchantment ID of the first enchantment on our item: m_ParentWindow.SetProperty(4 + i, EnchantmentID); - const short EnchantmentLevel = static_cast<short>(EnchantedItem.m_Enchantments.GetLevel(EnchantmentID)); + const auto EnchantmentLevel = static_cast<short>(EnchantedItem.m_Enchantments.GetLevel(EnchantmentID)); ASSERT(EnchantmentLevel > 0); // Send the level for the first enchantment on our item: diff --git a/src/World.cpp b/src/World.cpp index ed29123b8..32ce7b4f9 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1394,7 +1394,7 @@ void cWorld::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_Blo if (!cPluginManager::Get()->CallHookExploding(*this, a_ExplosionSize, a_CanCauseFire, a_BlockX, a_BlockY, a_BlockZ, a_Source, a_SourceData) && (a_ExplosionSize > 0)) { // TODO: CanCauseFire gets reset to false for some reason - Explodinator::Kaboom(*this, Vector3f(a_BlockX, a_BlockY, a_BlockZ), a_ExplosionSize, a_CanCauseFire); + Explodinator::Kaboom(*this, Vector3d(a_BlockX, a_BlockY, a_BlockZ), FloorC<unsigned>(a_ExplosionSize), a_CanCauseFire); cPluginManager::Get()->CallHookExploded(*this, a_ExplosionSize, a_CanCauseFire, a_BlockX, a_BlockY, a_BlockZ, a_Source, a_SourceData); } } diff --git a/src/WorldStorage/NamespaceSerializer.cpp b/src/WorldStorage/NamespaceSerializer.cpp index e717e7b3e..41023caea 100644 --- a/src/WorldStorage/NamespaceSerializer.cpp +++ b/src/WorldStorage/NamespaceSerializer.cpp @@ -131,125 +131,129 @@ namespace NamespaceSerializer UNREACHABLE("Tried to save unhandled statistic"); } - static const std::unordered_map<std::string_view, Statistic> CustomStatistics - { - { "animals_bred", Statistic::AnimalsBred }, - { "aviate_one_cm", Statistic::AviateOneCm }, - { "bell_ring", Statistic::BellRing }, - { "boat_one_cm", Statistic::BoatOneCm }, - { "clean_armor", Statistic::CleanArmor }, - { "clean_banner", Statistic::CleanBanner }, - { "clean_shulker_box", Statistic::CleanShulkerBox }, - { "climb_one_cm", Statistic::ClimbOneCm }, - { "crouch_one_cm", Statistic::CrouchOneCm }, - { "damage_absorbed", Statistic::DamageAbsorbed }, - { "damage_blocked_by_shield", Statistic::DamageBlockedByShield }, - { "damage_dealt", Statistic::DamageDealt }, - { "damage_dealt_absorbed", Statistic::DamageDealtAbsorbed }, - { "damage_dealt_resisted", Statistic::DamageDealtResisted }, - { "damage_resisted", Statistic::DamageResisted }, - { "damage_taken", Statistic::DamageTaken }, - { "deaths", Statistic::Deaths }, - { "drop", Statistic::Drop }, - { "eat_cake_slice", Statistic::EatCakeSlice }, - { "enchant_item", Statistic::EnchantItem }, - { "fall_one_cm", Statistic::FallOneCm }, - { "fill_cauldron", Statistic::FillCauldron }, - { "fish_caught", Statistic::FishCaught }, - { "fly_one_cm", Statistic::FlyOneCm }, - { "horse_one_cm", Statistic::HorseOneCm }, - { "inspect_dispenser", Statistic::InspectDispenser }, - { "inspect_dropper", Statistic::InspectDropper }, - { "inspect_hopper", Statistic::InspectHopper }, - { "interact_with_anvil", Statistic::InteractWithAnvil }, - { "interact_with_beacon", Statistic::InteractWithBeacon }, - { "interact_with_blast_furnace", Statistic::InteractWithBlastFurnace }, - { "interact_with_brewingstand", Statistic::InteractWithBrewingstand }, - { "interact_with_campfire", Statistic::InteractWithCampfire }, - { "interact_with_cartography_table", Statistic::InteractWithCartographyTable }, - { "interact_with_crafting_table", Statistic::InteractWithCraftingTable }, - { "interact_with_furnace", Statistic::InteractWithFurnace }, - { "interact_with_grindstone", Statistic::InteractWithGrindstone }, - { "interact_with_lectern", Statistic::InteractWithLectern }, - { "interact_with_loom", Statistic::InteractWithLoom }, - { "interact_with_smithing_table", Statistic::InteractWithSmithingTable }, - { "interact_with_smoker", Statistic::InteractWithSmoker }, - { "interact_with_stonecutter", Statistic::InteractWithStonecutter }, - { "jump", Statistic::Jump }, - { "leave_game", Statistic::LeaveGame }, - { "minecart_one_cm", Statistic::MinecartOneCm }, - { "mob_kills", Statistic::MobKills }, - { "open_barrel", Statistic::OpenBarrel }, - { "open_chest", Statistic::OpenChest }, - { "open_enderchest", Statistic::OpenEnderchest }, - { "open_shulker_box", Statistic::OpenShulkerBox }, - { "pig_one_cm", Statistic::PigOneCm }, - { "play_noteblock", Statistic::PlayNoteblock }, - { "play_one_minute", Statistic::PlayOneMinute }, - { "play_record", Statistic::PlayRecord }, - { "player_kills", Statistic::PlayerKills }, - { "pot_flower", Statistic::PotFlower }, - { "raid_trigger", Statistic::RaidTrigger }, - { "raid_win", Statistic::RaidWin }, - { "sleep_in_bed", Statistic::SleepInBed }, - { "sneak_time", Statistic::SneakTime }, - { "sprint_one_cm", Statistic::SprintOneCm }, - { "strider_one_cm", Statistic::StriderOneCm }, - { "swim_one_cm", Statistic::SwimOneCm }, - { "talked_to_villager", Statistic::TalkedToVillager }, - { "target_hit", Statistic::TargetHit }, - { "time_since_death", Statistic::TimeSinceDeath }, - { "time_since_rest", Statistic::TimeSinceRest }, - { "traded_with_villager", Statistic::TradedWithVillager }, - { "trigger_trapped_chest", Statistic::TriggerTrappedChest }, - { "tune_noteblock", Statistic::TuneNoteblock }, - { "use_cauldron", Statistic::UseCauldron }, - { "walk_on_water_one_cm", Statistic::WalkOnWaterOneCm }, - { "walk_one_cm", Statistic::WalkOneCm }, - { "walk_under_water_one_cm", Statistic::WalkUnderWaterOneCm }, - // Old ones just for compatibility - { "junk_fished", Statistic::JunkFished }, - { "treasure_fished", Statistic::TreasureFished }, - // The old advancements - { "cuberite:achievement.openInventory", Statistic::AchOpenInventory }, - { "cuberite:achievement.mineWood", Statistic::AchMineWood }, - { "cuberite:achievement.buildWorkBench", Statistic::AchBuildWorkBench }, - { "cuberite:achievement.buildPickaxe", Statistic::AchBuildPickaxe }, - { "cuberite:achievement.buildFurnace", Statistic::AchBuildFurnace }, - { "cuberite:achievement.acquireIron", Statistic::AchAcquireIron }, - { "cuberite:achievement.buildHoe", Statistic::AchBuildHoe }, - { "cuberite:achievement.makeBread", Statistic::AchMakeBread }, - { "cuberite:achievement.bakeCake", Statistic::AchBakeCake }, - { "cuberite:achievement.buildBetterPickaxe", Statistic::AchBuildBetterPickaxe }, - { "cuberite:achievement.cookFish", Statistic::AchCookFish }, - { "cuberite:achievement.onARail", Statistic::AchOnARail }, - { "cuberite:achievement.buildSword", Statistic::AchBuildSword }, - { "cuberite:achievement.killEnemy", Statistic::AchKillEnemy }, - { "cuberite:achievement.killCow", Statistic::AchKillCow }, - { "cuberite:achievement.flyPig", Statistic::AchFlyPig }, - { "cuberite:achievement.snipeSkeleton", Statistic::AchSnipeSkeleton }, - { "cuberite:achievement.diamonds", Statistic::AchDiamonds }, - { "cuberite:achievement.portal", Statistic::AchPortal }, - { "cuberite:achievement.ghast", Statistic::AchGhast }, - { "cuberite:achievement.blazeRod", Statistic::AchBlazeRod }, - { "cuberite:achievement.potion", Statistic::AchPotion }, - { "cuberite:achievement.theEnd", Statistic::AchTheEnd }, - { "cuberite:achievement.theEnd2", Statistic::AchTheEnd2 }, - { "cuberite:achievement.enchantments", Statistic::AchEnchantments }, - { "cuberite:achievement.overkill", Statistic::AchOverkill }, - { "cuberite:achievement.bookcase", Statistic::AchBookcase }, - { "cuberite:achievement.exploreAllBiomes", Statistic::AchExploreAllBiomes }, - { "cuberite:achievement.spawnWither", Statistic::AchSpawnWither }, - { "cuberite:achievement.killWither", Statistic::AchKillWither }, - { "cuberite:achievement.fullBeacon", Statistic::AchFullBeacon }, - { "cuberite:achievement.breedCow", Statistic::AchBreedCow }, - { "cuberite:achievement.diamondsToYou", Statistic::AchDiamondsToYou} - }; + Statistic ToCustomStatistic(const std::string_view ID) { + static const std::unordered_map<std::string_view, Statistic> CustomStatistics + { + { "animals_bred", Statistic::AnimalsBred }, + { "aviate_one_cm", Statistic::AviateOneCm }, + { "bell_ring", Statistic::BellRing }, + { "boat_one_cm", Statistic::BoatOneCm }, + { "clean_armor", Statistic::CleanArmor }, + { "clean_banner", Statistic::CleanBanner }, + { "clean_shulker_box", Statistic::CleanShulkerBox }, + { "climb_one_cm", Statistic::ClimbOneCm }, + { "crouch_one_cm", Statistic::CrouchOneCm }, + { "damage_absorbed", Statistic::DamageAbsorbed }, + { "damage_blocked_by_shield", Statistic::DamageBlockedByShield }, + { "damage_dealt", Statistic::DamageDealt }, + { "damage_dealt_absorbed", Statistic::DamageDealtAbsorbed }, + { "damage_dealt_resisted", Statistic::DamageDealtResisted }, + { "damage_resisted", Statistic::DamageResisted }, + { "damage_taken", Statistic::DamageTaken }, + { "deaths", Statistic::Deaths }, + { "drop", Statistic::Drop }, + { "eat_cake_slice", Statistic::EatCakeSlice }, + { "enchant_item", Statistic::EnchantItem }, + { "fall_one_cm", Statistic::FallOneCm }, + { "fill_cauldron", Statistic::FillCauldron }, + { "fish_caught", Statistic::FishCaught }, + { "fly_one_cm", Statistic::FlyOneCm }, + { "horse_one_cm", Statistic::HorseOneCm }, + { "inspect_dispenser", Statistic::InspectDispenser }, + { "inspect_dropper", Statistic::InspectDropper }, + { "inspect_hopper", Statistic::InspectHopper }, + { "interact_with_anvil", Statistic::InteractWithAnvil }, + { "interact_with_beacon", Statistic::InteractWithBeacon }, + { "interact_with_blast_furnace", Statistic::InteractWithBlastFurnace }, + { "interact_with_brewingstand", Statistic::InteractWithBrewingstand }, + { "interact_with_campfire", Statistic::InteractWithCampfire }, + { "interact_with_cartography_table", Statistic::InteractWithCartographyTable }, + { "interact_with_crafting_table", Statistic::InteractWithCraftingTable }, + { "interact_with_furnace", Statistic::InteractWithFurnace }, + { "interact_with_grindstone", Statistic::InteractWithGrindstone }, + { "interact_with_lectern", Statistic::InteractWithLectern }, + { "interact_with_loom", Statistic::InteractWithLoom }, + { "interact_with_smithing_table", Statistic::InteractWithSmithingTable }, + { "interact_with_smoker", Statistic::InteractWithSmoker }, + { "interact_with_stonecutter", Statistic::InteractWithStonecutter }, + { "jump", Statistic::Jump }, + { "leave_game", Statistic::LeaveGame }, + { "minecart_one_cm", Statistic::MinecartOneCm }, + { "mob_kills", Statistic::MobKills }, + { "open_barrel", Statistic::OpenBarrel }, + { "open_chest", Statistic::OpenChest }, + { "open_enderchest", Statistic::OpenEnderchest }, + { "open_shulker_box", Statistic::OpenShulkerBox }, + { "pig_one_cm", Statistic::PigOneCm }, + { "play_noteblock", Statistic::PlayNoteblock }, + { "play_one_minute", Statistic::PlayOneMinute }, + { "play_record", Statistic::PlayRecord }, + { "player_kills", Statistic::PlayerKills }, + { "pot_flower", Statistic::PotFlower }, + { "raid_trigger", Statistic::RaidTrigger }, + { "raid_win", Statistic::RaidWin }, + { "sleep_in_bed", Statistic::SleepInBed }, + { "sneak_time", Statistic::SneakTime }, + { "sprint_one_cm", Statistic::SprintOneCm }, + { "strider_one_cm", Statistic::StriderOneCm }, + { "swim_one_cm", Statistic::SwimOneCm }, + { "talked_to_villager", Statistic::TalkedToVillager }, + { "target_hit", Statistic::TargetHit }, + { "time_since_death", Statistic::TimeSinceDeath }, + { "time_since_rest", Statistic::TimeSinceRest }, + { "traded_with_villager", Statistic::TradedWithVillager }, + { "trigger_trapped_chest", Statistic::TriggerTrappedChest }, + { "tune_noteblock", Statistic::TuneNoteblock }, + { "use_cauldron", Statistic::UseCauldron }, + { "walk_on_water_one_cm", Statistic::WalkOnWaterOneCm }, + { "walk_one_cm", Statistic::WalkOneCm }, + { "walk_under_water_one_cm", Statistic::WalkUnderWaterOneCm }, + + // Old ones just for compatibility + { "junk_fished", Statistic::JunkFished }, + { "treasure_fished", Statistic::TreasureFished }, + + // The old advancements + { "cuberite:achievement.openInventory", Statistic::AchOpenInventory }, + { "cuberite:achievement.mineWood", Statistic::AchMineWood }, + { "cuberite:achievement.buildWorkBench", Statistic::AchBuildWorkBench }, + { "cuberite:achievement.buildPickaxe", Statistic::AchBuildPickaxe }, + { "cuberite:achievement.buildFurnace", Statistic::AchBuildFurnace }, + { "cuberite:achievement.acquireIron", Statistic::AchAcquireIron }, + { "cuberite:achievement.buildHoe", Statistic::AchBuildHoe }, + { "cuberite:achievement.makeBread", Statistic::AchMakeBread }, + { "cuberite:achievement.bakeCake", Statistic::AchBakeCake }, + { "cuberite:achievement.buildBetterPickaxe", Statistic::AchBuildBetterPickaxe }, + { "cuberite:achievement.cookFish", Statistic::AchCookFish }, + { "cuberite:achievement.onARail", Statistic::AchOnARail }, + { "cuberite:achievement.buildSword", Statistic::AchBuildSword }, + { "cuberite:achievement.killEnemy", Statistic::AchKillEnemy }, + { "cuberite:achievement.killCow", Statistic::AchKillCow }, + { "cuberite:achievement.flyPig", Statistic::AchFlyPig }, + { "cuberite:achievement.snipeSkeleton", Statistic::AchSnipeSkeleton }, + { "cuberite:achievement.diamonds", Statistic::AchDiamonds }, + { "cuberite:achievement.portal", Statistic::AchPortal }, + { "cuberite:achievement.ghast", Statistic::AchGhast }, + { "cuberite:achievement.blazeRod", Statistic::AchBlazeRod }, + { "cuberite:achievement.potion", Statistic::AchPotion }, + { "cuberite:achievement.theEnd", Statistic::AchTheEnd }, + { "cuberite:achievement.theEnd2", Statistic::AchTheEnd2 }, + { "cuberite:achievement.enchantments", Statistic::AchEnchantments }, + { "cuberite:achievement.overkill", Statistic::AchOverkill }, + { "cuberite:achievement.bookcase", Statistic::AchBookcase }, + { "cuberite:achievement.exploreAllBiomes", Statistic::AchExploreAllBiomes }, + { "cuberite:achievement.spawnWither", Statistic::AchSpawnWither }, + { "cuberite:achievement.killWither", Statistic::AchKillWither }, + { "cuberite:achievement.fullBeacon", Statistic::AchFullBeacon }, + { "cuberite:achievement.breedCow", Statistic::AchBreedCow }, + { "cuberite:achievement.diamondsToYou", Statistic::AchDiamondsToYou} + }; + return CustomStatistics.at(ID); } diff --git a/src/WorldStorage/StatSerializer.cpp b/src/WorldStorage/StatSerializer.cpp index 95652a8d7..11b5ffbf9 100644 --- a/src/WorldStorage/StatSerializer.cpp +++ b/src/WorldStorage/StatSerializer.cpp @@ -4,6 +4,7 @@ #include "Globals.h" #include "../Statistics.h" +#include "StatSerializer.h" #include "NamespaceSerializer.h" #include <json/json.h> @@ -12,100 +13,9 @@ -// Upgrade mapping from pre-1.13 names. TODO: remove on 2020-09-18 -static const std::unordered_map<std::string_view, Statistic> LegacyMapping -{ - { "achievement.openInventory", Statistic::AchOpenInventory }, - { "achievement.mineWood", Statistic::AchMineWood }, - { "achievement.buildWorkBench", Statistic::AchBuildWorkBench }, - { "achievement.buildPickaxe", Statistic::AchBuildPickaxe }, - { "achievement.buildFurnace", Statistic::AchBuildFurnace }, - { "achievement.acquireIron", Statistic::AchAcquireIron }, - { "achievement.buildHoe", Statistic::AchBuildHoe }, - { "achievement.makeBread", Statistic::AchMakeBread }, - { "achievement.bakeCake", Statistic::AchBakeCake }, - { "achievement.buildBetterPickaxe", Statistic::AchBuildBetterPickaxe }, - { "achievement.cookFish", Statistic::AchCookFish }, - { "achievement.onARail", Statistic::AchOnARail }, - { "achievement.buildSword", Statistic::AchBuildSword }, - { "achievement.killEnemy", Statistic::AchKillEnemy }, - { "achievement.killCow", Statistic::AchKillCow }, - { "achievement.flyPig", Statistic::AchFlyPig }, - { "achievement.snipeSkeleton", Statistic::AchSnipeSkeleton }, - { "achievement.diamonds", Statistic::AchDiamonds }, - { "achievement.portal", Statistic::AchPortal }, - { "achievement.ghast", Statistic::AchGhast }, - { "achievement.blazeRod", Statistic::AchBlazeRod }, - { "achievement.potion", Statistic::AchPotion }, - { "achievement.theEnd", Statistic::AchTheEnd }, - { "achievement.theEnd2", Statistic::AchTheEnd2 }, - { "achievement.enchantments", Statistic::AchEnchantments }, - { "achievement.overkill", Statistic::AchOverkill }, - { "achievement.bookcase", Statistic::AchBookcase }, - { "achievement.exploreAllBiomes", Statistic::AchExploreAllBiomes }, - { "achievement.spawnWither", Statistic::AchSpawnWither }, - { "achievement.killWither", Statistic::AchKillWither }, - { "achievement.fullBeacon", Statistic::AchFullBeacon }, - { "achievement.breedCow", Statistic::AchBreedCow }, - { "achievement.diamondsToYou", Statistic::AchDiamondsToYou }, - { "stat.animalsBred", Statistic::AnimalsBred }, - { "stat.boatOneCm", Statistic::BoatOneCm }, - { "stat.climbOneCm", Statistic::ClimbOneCm }, - { "stat.crouchOneCm", Statistic::CrouchOneCm }, - { "stat.damageDealt", Statistic::DamageDealt }, - { "stat.damageTaken", Statistic::DamageTaken }, - { "stat.deaths", Statistic::Deaths }, - { "stat.drop", Statistic::Drop }, - { "stat.fallOneCm", Statistic::FallOneCm }, - { "stat.fishCaught", Statistic::FishCaught }, - { "stat.flyOneCm", Statistic::FlyOneCm }, - { "stat.horseOneCm", Statistic::HorseOneCm }, - { "stat.jump", Statistic::Jump }, - { "stat.leaveGame", Statistic::LeaveGame }, - { "stat.minecartOneCm", Statistic::MinecartOneCm }, - { "stat.mobKills", Statistic::MobKills }, - { "stat.pigOneCm", Statistic::PigOneCm }, - { "stat.playerKills", Statistic::PlayerKills }, - { "stat.playOneMinute", Statistic::PlayOneMinute }, - { "stat.sprintOneCm", Statistic::SprintOneCm }, - { "stat.swimOneCm", Statistic::SwimOneCm }, - { "stat.talkedToVillager", Statistic::TalkedToVillager }, - { "stat.timeSinceDeath", Statistic::TimeSinceDeath }, - { "stat.tradedWithVillager", Statistic::TradedWithVillager }, - { "stat.walkOneCm", Statistic::WalkOneCm }, - { "stat.diveOneCm", Statistic::WalkUnderWaterOneCm }, - { "stat.armorCleaned", Statistic::CleanArmor }, - { "stat.bannerCleaned", Statistic::CleanBanner }, - { "stat.cakeSlicesEaten", Statistic::EatCakeSlice }, - { "stat.itemEnchanted", Statistic::EnchantItem }, - { "stat.cauldronFilled", Statistic::FillCauldron }, - { "stat.dispenserInspected", Statistic::InspectDispenser }, - { "stat.dropperInspected", Statistic::InspectDropper }, - { "stat.hopperInspected", Statistic::InspectHopper }, - { "stat.beaconInteraction", Statistic::InteractWithBeacon }, - { "stat.brewingstandInteraction", Statistic::InteractWithBrewingstand }, - { "stat.craftingTableInteraction", Statistic::InteractWithCraftingTable }, - { "stat.furnaceInteraction", Statistic::InteractWithFurnace }, - { "stat.chestOpened", Statistic::OpenChest }, - { "stat.enderchestOpened", Statistic::OpenEnderchest }, - { "stat.noteblockPlayed", Statistic::PlayNoteblock }, - { "stat.recordPlayed", Statistic::PlayRecord }, - { "stat.flowerPotted", Statistic::PotFlower }, - { "stat.trappedChestTriggered", Statistic::TriggerTrappedChest }, - { "stat.noteblockTuned", Statistic::TuneNoteblock }, - { "stat.cauldronUsed", Statistic::UseCauldron }, - { "stat.aviateOneCm", Statistic::AviateOneCm }, - { "stat.sleepInBed", Statistic::SleepInBed }, - { "stat.sneakTime", Statistic::SneakTime } -}; - - - - - namespace StatSerializer { - auto MakeStatisticsDirectory(const std::string & WorldPath, std::string && FileName) + static auto MakeStatisticsDirectory(const std::string & WorldPath, std::string && FileName) { // Even though stats are shared between worlds, they are (usually) saved // inside the folder of the default world. @@ -123,7 +33,7 @@ namespace StatSerializer - void SaveStatToJSON(const cStatManager & Manager, Json::Value & a_Out) + static void SaveStatToJSON(const cStatManager & Manager, Json::Value & a_Out) { Manager.ForEachStatisticType([&a_Out](const cStatManager::CustomStore & Store) { @@ -145,8 +55,95 @@ namespace StatSerializer - void LoadLegacyFromJSON(cStatManager & Manager, const Json::Value & In) + static void LoadLegacyFromJSON(cStatManager & Manager, const Json::Value & In) { + // Upgrade mapping from pre-1.13 names. TODO: remove on 2020-09-18 + static const std::unordered_map<std::string_view, Statistic> LegacyMapping + { + { "achievement.openInventory", Statistic::AchOpenInventory }, + { "achievement.mineWood", Statistic::AchMineWood }, + { "achievement.buildWorkBench", Statistic::AchBuildWorkBench }, + { "achievement.buildPickaxe", Statistic::AchBuildPickaxe }, + { "achievement.buildFurnace", Statistic::AchBuildFurnace }, + { "achievement.acquireIron", Statistic::AchAcquireIron }, + { "achievement.buildHoe", Statistic::AchBuildHoe }, + { "achievement.makeBread", Statistic::AchMakeBread }, + { "achievement.bakeCake", Statistic::AchBakeCake }, + { "achievement.buildBetterPickaxe", Statistic::AchBuildBetterPickaxe }, + { "achievement.cookFish", Statistic::AchCookFish }, + { "achievement.onARail", Statistic::AchOnARail }, + { "achievement.buildSword", Statistic::AchBuildSword }, + { "achievement.killEnemy", Statistic::AchKillEnemy }, + { "achievement.killCow", Statistic::AchKillCow }, + { "achievement.flyPig", Statistic::AchFlyPig }, + { "achievement.snipeSkeleton", Statistic::AchSnipeSkeleton }, + { "achievement.diamonds", Statistic::AchDiamonds }, + { "achievement.portal", Statistic::AchPortal }, + { "achievement.ghast", Statistic::AchGhast }, + { "achievement.blazeRod", Statistic::AchBlazeRod }, + { "achievement.potion", Statistic::AchPotion }, + { "achievement.theEnd", Statistic::AchTheEnd }, + { "achievement.theEnd2", Statistic::AchTheEnd2 }, + { "achievement.enchantments", Statistic::AchEnchantments }, + { "achievement.overkill", Statistic::AchOverkill }, + { "achievement.bookcase", Statistic::AchBookcase }, + { "achievement.exploreAllBiomes", Statistic::AchExploreAllBiomes }, + { "achievement.spawnWither", Statistic::AchSpawnWither }, + { "achievement.killWither", Statistic::AchKillWither }, + { "achievement.fullBeacon", Statistic::AchFullBeacon }, + { "achievement.breedCow", Statistic::AchBreedCow }, + { "achievement.diamondsToYou", Statistic::AchDiamondsToYou }, + { "stat.animalsBred", Statistic::AnimalsBred }, + { "stat.boatOneCm", Statistic::BoatOneCm }, + { "stat.climbOneCm", Statistic::ClimbOneCm }, + { "stat.crouchOneCm", Statistic::CrouchOneCm }, + { "stat.damageDealt", Statistic::DamageDealt }, + { "stat.damageTaken", Statistic::DamageTaken }, + { "stat.deaths", Statistic::Deaths }, + { "stat.drop", Statistic::Drop }, + { "stat.fallOneCm", Statistic::FallOneCm }, + { "stat.fishCaught", Statistic::FishCaught }, + { "stat.flyOneCm", Statistic::FlyOneCm }, + { "stat.horseOneCm", Statistic::HorseOneCm }, + { "stat.jump", Statistic::Jump }, + { "stat.leaveGame", Statistic::LeaveGame }, + { "stat.minecartOneCm", Statistic::MinecartOneCm }, + { "stat.mobKills", Statistic::MobKills }, + { "stat.pigOneCm", Statistic::PigOneCm }, + { "stat.playerKills", Statistic::PlayerKills }, + { "stat.playOneMinute", Statistic::PlayOneMinute }, + { "stat.sprintOneCm", Statistic::SprintOneCm }, + { "stat.swimOneCm", Statistic::SwimOneCm }, + { "stat.talkedToVillager", Statistic::TalkedToVillager }, + { "stat.timeSinceDeath", Statistic::TimeSinceDeath }, + { "stat.tradedWithVillager", Statistic::TradedWithVillager }, + { "stat.walkOneCm", Statistic::WalkOneCm }, + { "stat.diveOneCm", Statistic::WalkUnderWaterOneCm }, + { "stat.armorCleaned", Statistic::CleanArmor }, + { "stat.bannerCleaned", Statistic::CleanBanner }, + { "stat.cakeSlicesEaten", Statistic::EatCakeSlice }, + { "stat.itemEnchanted", Statistic::EnchantItem }, + { "stat.cauldronFilled", Statistic::FillCauldron }, + { "stat.dispenserInspected", Statistic::InspectDispenser }, + { "stat.dropperInspected", Statistic::InspectDropper }, + { "stat.hopperInspected", Statistic::InspectHopper }, + { "stat.beaconInteraction", Statistic::InteractWithBeacon }, + { "stat.brewingstandInteraction", Statistic::InteractWithBrewingstand }, + { "stat.craftingTableInteraction", Statistic::InteractWithCraftingTable }, + { "stat.furnaceInteraction", Statistic::InteractWithFurnace }, + { "stat.chestOpened", Statistic::OpenChest }, + { "stat.enderchestOpened", Statistic::OpenEnderchest }, + { "stat.noteblockPlayed", Statistic::PlayNoteblock }, + { "stat.recordPlayed", Statistic::PlayRecord }, + { "stat.flowerPotted", Statistic::PotFlower }, + { "stat.trappedChestTriggered", Statistic::TriggerTrappedChest }, + { "stat.noteblockTuned", Statistic::TuneNoteblock }, + { "stat.cauldronUsed", Statistic::UseCauldron }, + { "stat.aviateOneCm", Statistic::AviateOneCm }, + { "stat.sleepInBed", Statistic::SleepInBed }, + { "stat.sneakTime", Statistic::SneakTime } + }; + for (auto Entry = In.begin(); Entry != In.end(); ++Entry) { const auto & Key = Entry.key().asString(); @@ -154,7 +151,13 @@ namespace StatSerializer if ((FindResult != LegacyMapping.end()) && Entry->isInt()) { - Manager.SetValue(FindResult->second, Entry->asInt()); + auto Value = Entry->asInt(); + if (Value < 0) + { + FLOGWARNING("Invalid stat value: {0} = {1}", Key, Value); + continue; + } + Manager.SetValue(FindResult->second, ToUnsigned(Value)); } } } @@ -163,7 +166,7 @@ namespace StatSerializer - void LoadCustomStatFromJSON(cStatManager & Manager, const Json::Value & a_In) + static void LoadCustomStatFromJSON(cStatManager & Manager, const Json::Value & a_In) { for (auto it = a_In.begin(); it != a_In.end(); ++it) { @@ -178,13 +181,19 @@ namespace StatSerializer const auto & StatName = StatInfo.second; try { - Manager.SetValue(NamespaceSerializer::ToCustomStatistic(StatName), it->asInt()); + auto Value = it->asInt(); + if (Value < 0) + { + FLOGWARNING("Invalid statistic value: {0} = {1}", Key, Value); + continue; + } + Manager.SetValue(NamespaceSerializer::ToCustomStatistic(StatName), ToUnsigned(Value)); } - catch (const std::out_of_range & Oops) + catch (const std::out_of_range &) { FLOGWARNING("Invalid statistic type \"{}\"", StatName); } - catch (const Json::LogicError & Oops) + catch (const Json::LogicError &) { FLOGWARNING("Invalid statistic value for type \"{}\"", StatName); } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 03decbea3..f822f9375 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1450,7 +1450,7 @@ OwnedBlockEntity cWSSAnvil::LoadNoteBlockFromNBT(const cParsedNBT & a_NBT, int a int note = a_NBT.FindChildByName(a_TagIdx, "note"); if (note >= 0) { - NoteBlock->SetNote(static_cast<char>(a_NBT.GetByte(note))); + NoteBlock->SetNote(a_NBT.GetByte(note)); } return NoteBlock; } @@ -1856,7 +1856,7 @@ void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse"); if (FuseTicks > 0) { - TNT->SetFuseTicks(static_cast<int>(a_NBT.GetByte(FuseTicks))); + TNT->SetFuseTicks(a_NBT.GetByte(FuseTicks)); } a_Entities.emplace_back(std::move(TNT)); diff --git a/src/main.cpp b/src/main.cpp index e0ce68a8c..cb7633df3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +#include "main.h" #include "BuildInfo.h" #include "Logger.h" #include "MemorySettingsRepository.h" @@ -17,17 +18,12 @@ -/** If set to true, the protocols will log each player's incoming (C->S) communication to a per-connection logfile. */ bool g_ShouldLogCommIn; - -/** If set to true, the protocols will log each player's outgoing (S->C) communication to a per-connection logfile. */ bool g_ShouldLogCommOut; - -/** If set to true, binary will attempt to run as a service. */ bool g_RunAsService; /** Global that registers itself as a last chance exception handler to write a minidump on crash. */ -MiniDumpWriter g_MiniDumpWriter; +static MiniDumpWriter g_MiniDumpWriter; @@ -90,7 +86,7 @@ static void NonCtrlHandler(int a_Signal) case SIGTERM: { // Server is shutting down, wait for it... - cRoot::Stop(); + cRoot::Get()->Stop(); return; } #ifdef SIGPIPE @@ -115,7 +111,7 @@ static void NonCtrlHandler(int a_Signal) // Handle CTRL events in windows, including console window close static BOOL CtrlHandler(DWORD fdwCtrlType) { - cRoot::Stop(); + cRoot::Get()->Stop(); LOGD("Terminate event raised from the Windows CtrlHandler"); // Delay as much as possible to try to get the server to shut down cleanly - 10 seconds given by Windows @@ -134,7 +130,7 @@ static BOOL CtrlHandler(DWORD fdwCtrlType) //////////////////////////////////////////////////////////////////////////////// // ParseArguments - Read the startup arguments and store into a settings object -static cMemorySettingsRepository ParseArguments(int argc, char ** argv) +static void ParseArguments(int argc, char ** argv, cMemorySettingsRepository & repo) { // Parse the comand line args: TCLAP::CmdLine cmd("Cuberite"); @@ -152,7 +148,6 @@ static cMemorySettingsRepository ParseArguments(int argc, char ** argv) cmd.parse(argc, argv); // Copy the parsed args' values into a settings repository: - cMemorySettingsRepository repo; if (confArg.isSet()) { AString conf_file = confArg.getValue(); @@ -204,8 +199,6 @@ static cMemorySettingsRepository ParseArguments(int argc, char ** argv) { g_MiniDumpWriter.AddDumpFlags(MiniDumpFlags::WithFullMemory); } - - return repo; } @@ -238,7 +231,8 @@ static int UniversalMain(int argc, char * argv[], bool RunningAsService) try { // Make sure g_RunAsService is set correctly before checking it's value - auto Settings = ParseArguments(argc, argv); + cMemorySettingsRepository Settings; + ParseArguments(argc, argv, Settings); // Attempt to run as a service if (!RunningAsService && g_RunAsService) diff --git a/src/main.h b/src/main.h new file mode 100644 index 000000000..312fb051b --- /dev/null +++ b/src/main.h @@ -0,0 +1,10 @@ +#pragma once + +/** If set to true, the protocols will log each player's incoming (C->S) communication to a per-connection logfile. */ +extern bool g_ShouldLogCommIn; + +/** If set to true, the protocols will log each player's outgoing (S->C) communication to a per-connection logfile. */ +extern bool g_ShouldLogCommOut; + +/** If set to true, binary will attempt to run as a service. */ +extern bool g_RunAsService; |